You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: handbook/strings/join.md
+40-13Lines changed: 40 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -12,42 +12,69 @@ Joins a set of strings into a single string
12
12
## Syntax
13
13
14
14
```eve
15
-
text = join[token, index, with]
15
+
text = join[token, given, index, with]
16
16
```
17
17
18
18
## Attributes
19
19
20
-
-`token` - set of elements to be joined
21
-
-`index` - indicates the order of the `tokens` in the joined string
22
-
-`with` - inserted between every element in `tokens`
20
+
-`token` - set of strings to be joined
21
+
-`given` - establishes the set being joined. If tokens are not unique, you can add attributes here that will make them unique. Must at least provide `token` as part of the given set, or only the first one will be returned.
22
+
-`index` - indicates where each `token` is ordered in `text`.
23
+
-`with` - inserted between every element in `token`.
23
24
24
25
## Description
25
26
26
-
`text = join[token, index, with]` takes `tokens` tokens together using `with` in an order specified by `index`. Returns the joined string.
27
+
`text = join[token, index, given, with]` takes `tokens` together using `with` in an order specified by `index`. Returns the joined string.
27
28
28
29
## Examples
29
30
30
-
Split a sentence into tokens
31
+
Split a sentence into tokens, and join the tokens into a sentence again
31
32
32
33
```eve
33
34
search
35
+
// Split the sentence into words
34
36
(token, index) = split[text: "the quick brown fox", by: " "]
35
37
36
-
bind
37
-
[#token token index]
38
+
// Join the words back into a sentence, but with hyphens instead of spaces
Join the tokens into a sentence again, but with hyphens instead of spaces
45
+
---
46
+
47
+
Since join is an aggregate, set semantics play an important part here; if we don't specify what makes each token unique, then the results can be surprising. The following example will demonstrate this.
48
+
49
+
Let's split the phrase "hello world" into letters:
Let's join this phrase back together. Like last time, we'll join with a `-`. You'll notice that some tokens are duplicate ("l" and "o" appear multiple times in the phrase). To correctly join these tokens, we can add `index` as part of the `given` set:
0 commit comments