Skip to content

Commit

Permalink
expose intersperse as mkFragment - analogue to `IterableOnce#mkSt…
Browse files Browse the repository at this point in the history
…ring`
  • Loading branch information
oyvindberg committed Oct 28, 2023
1 parent dde6c6b commit 8948b61
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/src/main/scala/zio/jdbc/SqlFragment.scala
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ object SqlFragment {
def fromFunction(f: ChunkBuilder[Segment] => Unit): SqlFragment =
SqlFragment.FromFunction(f)

implicit final class FragmentOps[I[t] <: Iterable[t]](private val fragments: I[SqlFragment]) extends AnyVal {
def mkFragment(sep: SqlFragment): SqlFragment =
intersperse(sep, fragments)

def mkFragment(start: SqlFragment, sep: SqlFragment, end: SqlFragment): SqlFragment =
start ++ fragments.mkFragment(sep) ++ end
}

implicit final class NonEmptyChunkOps(private val fragments: NonEmptyChunk[SqlFragment]) extends AnyVal {
def mkFragment(sep: SqlFragment): SqlFragment =
fragments.toChunk.mkFragment(sep)

def mkFragment(start: SqlFragment, sep: SqlFragment, end: SqlFragment): SqlFragment =
fragments.toChunk.mkFragment(start, sep, end)
}

sealed trait Segment
object Segment {
case object Empty extends Segment
Expand Down

0 comments on commit 8948b61

Please sign in to comment.