Skip to content

Commit f03b02c

Browse files
committed
String.split: Improve documentation
- Add more examples - Fix typo
1 parent 3d3e2f7 commit f03b02c

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- `split` (#165)
15+
- Add more examples.
16+
- Fix typo in documentation.
1417

1518
## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16
1619

src/Data/String/Common.purs

+8-1
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,18 @@ foreign import replace :: Pattern -> Replacement -> String -> String
5656
-- | ```
5757
foreign import replaceAll :: Pattern -> Replacement -> String -> String
5858

59-
-- | Returns the substrings of the second string separated along occurences
59+
-- | Returns the substrings of the second string separated along occurrences
6060
-- | of the first string.
6161
-- |
6262
-- | ```purescript
63+
-- | -- single match
6364
-- | split (Pattern " ") "hello world" == ["hello", "world"]
65+
-- | -- multiple matches
66+
-- | split (Pattern " | ") "foo | bar | baz" == ["foo", "bar", "baz"]
67+
-- | -- no match
68+
-- | split (Pattern "baz") "foo bar" == ["foo bar"]
69+
-- | -- empty string
70+
-- | split (Pattern "") "foo bar" == ["f","o","o"," ","b","a","r"]
6471
-- | ```
6572
foreign import split :: Pattern -> String -> Array String
6673

test/Test/Data/String.purs

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ testString = do
9999
{ actual: S.split (Pattern "d") "abc"
100100
, expected: ["abc"]
101101
}
102+
assertEqual
103+
{ actual: S.split (Pattern "--") "a--b--c"
104+
, expected: ["a", "b", "c"]
105+
}
102106

103107
log "toLower"
104108
assertEqual

0 commit comments

Comments
 (0)