Permalink
Browse files

Added having.

  • Loading branch information...
1 parent bf357f6 commit 2b43ab73d6ba148bf021f8b2531fb6fa68130ed2 @sjoerdvisscher sjoerdvisscher committed Nov 12, 2010
Showing with 6 additions and 1 deletion.
  1. +6 −1 Web/Zwaluw.hs
View
@@ -15,7 +15,7 @@ module Web.Zwaluw (
-- second argument is a (partial) destructor.
, constr0, constr1, constr2, constr3
, int, string, part, val, slash, lit
- , opt, duck, satisfy
+ , opt, duck, satisfy, having
, manyr, somer, chainr1
, manyl, somel, chainl1
, nilP, consP, listP
@@ -135,6 +135,11 @@ apply r = Router
+having :: (forall r. Router r (a :- r)) -> (a -> Bool) -> Router r (a :- r)
+having r p = Router
+ (\(a :- t) -> if (p a) then ser r (a :- t) else mzero)
+ (\s -> map (first ((:-) . hhead . ($ ()))) $ filter (p . hhead . ($ ()) . fst) $ prs r s)
+
satisfy :: (Char -> Bool) -> Router r (Char :- r)
satisfy p = Router
(\(c :- a) -> if (p c) then return (a, [c]) else mzero)

0 comments on commit 2b43ab7

Please sign in to comment.