Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split: Add more examples #165

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ New features:
Bugfixes:

Other improvements:
- `split` (#165)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you follow the formatting used in the rest of this changelog (e.g. including your username)?

If you want to provide more details, do something like this

- main entry (#PR by @<name>)

  Some more details here
  
- next main entry...

- Add more examples.
- Fix typo in documentation.

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

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