]> gitweb @ CieloNegro.org - Rakka.git/blob - Rakka/Utils.hs
wrote Loader.DefaultPage but not tested yet
[Rakka.git] / Rakka / Utils.hs
1 module Rakka.Utils
2     ( parseYesOrNo
3     , maybeA
4     , defaultTo
5     , deleteIfEmpty
6     )
7     where
8
9 import           Control.Arrow
10 import           Control.Arrow.ArrowList
11
12
13 parseYesOrNo :: ArrowChoice a => a String Bool
14 parseYesOrNo 
15     = proc str -> do case str of
16                        "yes" -> returnA -< True
17                        "no"  -> returnA -< False
18                        _     -> returnA -< error ("Expected yes or no: " ++ str)
19
20
21 maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c)
22 maybeA a = listA a
23            >>>
24            proc xs -> case xs of
25                         []    -> returnA -< Nothing
26                         (x:_) -> returnA -< Just x
27
28
29 defaultTo :: ArrowChoice a => b -> a (Maybe b) b
30 defaultTo def
31     = proc m -> case m of
32                   Nothing -> returnA -< def
33                   Just x  -> returnA -< x
34
35
36 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String
37 deleteIfEmpty
38     = proc str -> do case str of
39                        "" -> none    -< ()
40                        _  -> returnA -< str