26 lines
558 B
Elm
26 lines
558 B
Elm
|
module Bergamot.Search exposing (..)
|
||
|
|
||
|
type SearchStep a
|
||
|
= Empty
|
||
|
| Found a (Search a)
|
||
|
|
||
|
type alias Search a = () -> SearchStep a
|
||
|
|
||
|
map : (a -> b) -> Search a -> Search b
|
||
|
map f s () =
|
||
|
case s () of
|
||
|
Empty -> Empty
|
||
|
Found a sp -> Found (f a) (map f sp)
|
||
|
|
||
|
interleave : Search a -> Search a -> Search a
|
||
|
interleave s1 s2 () =
|
||
|
case s1 () of
|
||
|
Empty -> s2 ()
|
||
|
Found a s1p -> Found a (interleave s2 s1p)
|
||
|
|
||
|
one : Search a -> Maybe (a, Search a)
|
||
|
one s =
|
||
|
case s () of
|
||
|
Empty -> Nothing
|
||
|
Found a sp -> Just (a, sp)
|