Added invert
function. Fixes #60
This commit is contained in:
parent
d575bf0949
commit
d5e04e14d7
1 changed files with 13 additions and 0 deletions
|
@ -81,6 +81,7 @@ module Turtle.Pattern (
|
|||
, prefix
|
||||
, suffix
|
||||
, has
|
||||
, invert
|
||||
, once
|
||||
, star
|
||||
, plus
|
||||
|
@ -426,6 +427,18 @@ signed p = do
|
|||
sign <- (char '+' *> pure id) <|> (char '-' *> pure negate) <|> (pure id)
|
||||
fmap sign p
|
||||
|
||||
{-| @(`invert` p)@ succeeds if @p@ fails and fails if @p@ succeeds
|
||||
|
||||
>>> match (invert "A") "A"
|
||||
[]
|
||||
>>> match (invert "A") "B"
|
||||
[()]
|
||||
-}
|
||||
invert :: Pattern a -> Pattern ()
|
||||
invert p = Pattern (StateT (\str -> case runStateT (runPattern p) str of
|
||||
[] -> [((), "")]
|
||||
_ -> [] ))
|
||||
|
||||
{-| Match a `Char`, but return `Text`
|
||||
|
||||
>>> match (once (char '1')) "1"
|
||||
|
|
Loading…
Reference in a new issue