| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Nero.Match
Contents
Description
Matching
prefixed :: Text -> Prism' Match Match Source
This Prism' strips/prepends a prefix to the first element of a Match.
>>>pure "/hello/there" ^? prefixed "/hello/" . _headJust "there"
>>>prefixed "/hello/" # pure "there" & view _head"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>pure "hello" ^? prefixed "hello" . _headJust ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>prefixed "hello" # pure mempty & view _head"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (prefixed "hello") (review (prefixed "hello") mempty) <&> is _EmptyJust True
suffixed :: Text -> Prism' Match Match Source
This Prism' strips/appends a suffix to the first value of a Match.
>>>pure "/hello/there" ^? suffixed "there" . _headJust "/hello/"
>>>suffixed "there" # pure "/hello/" & view _head"/hello/there"
If matching the entire source it previews to an empty Text. You might
use exact if you are expecting this behavior.
>>>pure "hello" ^? suffixed "hello" . _headJust ""
This also means that to review an entire source, you need to give it
an empty Text.
>>>suffixed "hello" # pure mempty & view _head"hello"
An empty Match matches to itself regardless of the pattern.
>>>preview (suffixed "hello") (review (suffixed "hello") mempty) <&> 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 []