Add a few more convenient operations to Search.elm
Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
parent
2cc1012a09
commit
b13cdea15d
|
@ -1,4 +1,4 @@
|
||||||
module Bergamot.Search exposing (..)
|
module Bergamot.Search exposing (Search, map, apply, andThen, pure, fail, interleave, one)
|
||||||
|
|
||||||
type SearchStep a
|
type SearchStep a
|
||||||
= Empty
|
= Empty
|
||||||
|
@ -12,6 +12,24 @@ map f s () =
|
||||||
Empty -> Empty
|
Empty -> Empty
|
||||||
Found a sp -> Found (f a) (map f sp)
|
Found a sp -> Found (f a) (map f sp)
|
||||||
|
|
||||||
|
apply : Search (a -> b) -> Search a -> Search b
|
||||||
|
apply sf sa () =
|
||||||
|
case sf () of
|
||||||
|
Empty -> Empty
|
||||||
|
Found f sfp -> interleave (map f sa) (apply sfp sa) ()
|
||||||
|
|
||||||
|
andThen : (a -> Search b) -> Search a -> Search b
|
||||||
|
andThen f sa () =
|
||||||
|
case sa () of
|
||||||
|
Empty -> Empty
|
||||||
|
Found a sap -> interleave (f a) (andThen f sap) ()
|
||||||
|
|
||||||
|
pure : a -> Search a
|
||||||
|
pure a () = Found a (\() -> Empty)
|
||||||
|
|
||||||
|
fail : Search a
|
||||||
|
fail () = Empty
|
||||||
|
|
||||||
interleave : Search a -> Search a -> Search a
|
interleave : Search a -> Search a -> Search a
|
||||||
interleave s1 s2 () =
|
interleave s1 s2 () =
|
||||||
case s1 () of
|
case s1 () of
|
||||||
|
|
Loading…
Reference in New Issue
Block a user