Skip to content

Non-empty strings & various operations #100

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

Merged
merged 3 commits into from
Feb 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 22 additions & 2 deletions src/Data/String.purs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ module Data.String
, replace
, replaceAll
, take
, takeRight
, takeWhile
, drop
, dropRight
, dropWhile
, stripPrefix
, stripSuffix
Expand Down Expand Up @@ -274,8 +276,8 @@ foreign import _lastIndexOf
-> Maybe Int

-- | Returns the index of the last occurrence of the pattern in the
-- | given string, starting at the specified index
-- | and searching backwards towards the beginning of the string.
-- | given string, starting at the specified index
-- | and searching backwards towards the beginning of the string.
-- | Returns `Nothing` if there is no match.
-- |
-- | ```purescript
Expand Down Expand Up @@ -347,6 +349,15 @@ foreign import replaceAll :: Pattern -> Replacement -> String -> String
-- |
foreign import take :: Int -> String -> String

-- | Returns the last `n` characters of the string.
-- |
-- | ```purescript
-- | take 5 "Hello World" == "World"
-- | ```
-- |
takeRight :: Int -> String -> String
takeRight i s = drop (length s - i) s

-- | Returns the string without the first `n` characters.
-- |
-- | ```purescript
Expand All @@ -355,6 +366,15 @@ foreign import take :: Int -> String -> String
-- |
foreign import drop :: Int -> String -> String

-- | Returns the string without the last `n` characters.
-- |
-- | ```purescript
-- | dropRight 6 "Hello World" == "Hello"
-- | ```
-- |
dropRight :: Int -> String -> String
dropRight i s = take (length s - i) s

-- | Returns the number of contiguous characters at the beginning
-- | of the string for which the predicate holds.
-- |
Expand Down
Loading