Skip to content

Commit

Permalink
String.split: Improve documentation
Browse files Browse the repository at this point in the history
- Add more examples
- Fix typo
  • Loading branch information
gasi committed Nov 9, 2022
1 parent 3d3e2f7 commit f74f1a0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ Bugfixes:

Other improvements:

- `split` (#165)
- 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:
Expand Down
9 changes: 8 additions & 1 deletion src/Data/String/Common.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions test/Test/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f74f1a0

Please sign in to comment.