| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Nero.Match
Contents
Description
Matching
This Prism' strips/prepends a prefix.
>>>("/hello/there"::Text) ^? prefixed "/hello/"Just "there"
>>>prefixed "/hello/" # ("there"::Text)"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>("hello"::Text) ^? prefixed "hello"Just ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>prefixed "hello" # (mempty::Text)"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (prefixed "hello") (review (prefixed "hello") (mempty::Text)) <&> is _EmptyJust True
This Prism' strips/appends a suffix.
>>>("/hello/there"::Text) ^? suffixed "there"Just "/hello/"
>>>suffixed "there" # ("/hello/"::Text)"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>("hello"::Text) ^? suffixed "hello"Just ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>suffixed "hello" # (mempty::Text)"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (suffixed "hello") (review (suffixed "hello") (mempty::Text)) <&> is _EmptyJust True
sep :: Text -> Prism' Match Match Source
This Prism' splits/joins at the first occurrence of a boundary
for the first value of a Match.
>>>pure "hello/out/there" ^? sep "/" <&> toListOf foldedJust ["out/there","hello"]
>>>sep "/" # (pure "out/there" <> pure "hello") & view _head"hello/out/there"
Notice what happens when there is no source before or after a boundary:
>>>pure "hello/" ^? sep "/"Just ["","hello"]>>>(pure "hello/" <> pure "there") ^? sep "/"Just ["","hello","there"]
>>>pure "/hello" ^? sep "/"Just ["hello",""]>>>(pure "/hello" <> pure "there") ^? sep "/"Just ["hello","","there"]
When the source is identical to the boundary: >>> pure "hello" ^? sep "hello" Just []