diff --git a/CHANGELOG.md b/CHANGELOG.md index f36a713..e02eb78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ Bugfixes: Other improvements: +- `split` + - Add more examples. + - Fix typo in documentation. + ## [v6.0.1](https://github.com/purescript/purescript-strings/releases/tag/v6.0.1) - 2022-08-16 Bugfixes: diff --git a/src/Data/String/Common.purs b/src/Data/String/Common.purs index 9e3132e..f419f34 100644 --- a/src/Data/String/Common.purs +++ b/src/Data/String/Common.purs @@ -56,11 +56,18 @@ foreign import replace :: Pattern -> Replacement -> String -> String -- | ``` foreign import replaceAll :: Pattern -> Replacement -> String -> String --- | Returns the substrings of the second string separated along occurences +-- | Returns the substrings of the second string separated along occurrences -- | of the first string. -- | -- | ```purescript +-- | -- single match -- | split (Pattern " ") "hello world" == ["hello", "world"] +-- | -- multiple matches +-- | split (Pattern " | ") "foo | bar | baz" == ["foo", "bar", "baz"] +-- | -- no match +-- | split (Pattern "baz") "foo bar" == ["foo bar"] +-- | -- empty string +-- | split (Pattern "") "foo bar" == ["f","o","o"," ","b","a","r"] -- | ``` foreign import split :: Pattern -> String -> Array String diff --git a/test/Test/Data/String.purs b/test/Test/Data/String.purs index 5c73153..82e1426 100644 --- a/test/Test/Data/String.purs +++ b/test/Test/Data/String.purs @@ -99,6 +99,10 @@ testString = do { actual: S.split (Pattern "d") "abc" , expected: ["abc"] } + assertEqual + { actual: S.split (Pattern "--") "a--b--c" + , expected: ["a", "b", "c"] + } log "toLower" assertEqual