Skip to content

Commit c45d7d2

Browse files
committed
add operator to the docs
1 parent 1e3b7d9 commit c45d7d2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

modules/docs/src/main/mdoc/docs/08-Fragments.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,21 @@ fr0"IN (" ++ List(1, 2, 3).map(n => fr0"$n").intercalate(fr",") ++ fr")"
105105
```
106106
Note that the `sql` interpolator is simply an alias for `fr0`.
107107

108+
Additionally, you can use the `+~+` operator to concatenate two fragments, ensuring at least one space between them.
109+
This is useful when you want to maintain proper spacing without worrying about trailing spaces in individual fragments.
110+
111+
```scala mdoc
112+
// Assume we don't know (or don't want to worry) if `codeCondFrag` or `populationCondFrag` end with whitespaces or not.
113+
def codeCondFrag: Fragment = ???
114+
def populationCondFrag: Fragment = ???
115+
116+
const0("SELECT code, name, population FROM country\n") +~+ // a newline will be preserved, no extra whitespace added
117+
fr0"WHERE" +~+ codeCondFrag +~+ fr0"AND" +~+ populationCondFrag +~+
118+
fr0"ORDER BY population DESC"
119+
```
120+
121+
In the above example, spaces will be added between fragments where needed automatically.
122+
108123
### The `Fragments` Module
109124

110125
The `Fragments` module provides some combinators for common patterns when working with fragments. The following example illustrates a few of them. See the Scaladoc or source for more information.
@@ -147,4 +162,3 @@ select(None, None, Nil, 10).check.unsafeRunSync() // no filters
147162
select(Some("U%"), None, Nil, 10).check.unsafeRunSync() // one filter
148163
select(Some("U%"), Some(12345), List("FRA", "GBR"), 10).check.unsafeRunSync() // three filters
149164
```
150-

0 commit comments

Comments
 (0)