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
+7-19Lines changed: 7 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,10 +17,10 @@ text = join[token, given, index, with]
17
17
18
18
## Attributes
19
19
20
-
-`token` - set of elements to be joined
21
-
-`given` - establishes the set being joined, in case tokens are not unique, you can add attributes here that will make them unique. See examples for more. Must at least provide tokens as part of the given set, or only the first token will be returned.
22
-
-`index` - indicates the order of the `tokens` in the joined string
23
-
-`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`.
24
24
25
25
## Description
26
26
@@ -60,32 +60,20 @@ bind @view
60
60
[#value | value: token]
61
61
```
62
62
63
-
You'll notice here that when we display the tokens on their own, we're missing some letters. This is Eve's set semantics at work: the letter `l` is displayed once, and it's not displayed again because this would be a duplicate element in the set. The letters are also probably out of order, because sets are unordered. This is why we need the index when reconstructing the phrase.
64
-
65
-
So let's join this phrase back together. Like last time, we'll join with a `-`.
66
-
67
-
```eve
68
-
search
69
-
[#phrase token index]
70
-
text = join[token given: token index with: "-"]
71
-
72
-
bind @view
73
-
[#value | value: text]
74
-
```
75
-
76
-
The output here is "h-e-l-o- -w-r-d", which from the previous block we could have guessed. The problem is that we've joined the tokens, given only the tokens themselves. Since some tokens are duplicate, they are filtered out of the set before it's joined into a string. In order to keep the duplicate tokens, we have to provide more to make them unique. The `index` is a perfect candidate for this:
63
+
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