module Rakka.Utils ( parseYesOrNo , maybeA , defaultTo , deleteIfEmpty ) where import Control.Arrow import Control.Arrow.ArrowList parseYesOrNo :: ArrowChoice a => a String Bool parseYesOrNo = proc str -> do case str of "yes" -> returnA -< True "no" -> returnA -< False _ -> returnA -< error ("Expected yes or no: " ++ str) maybeA :: (ArrowList a, ArrowChoice a) => a b c -> a b (Maybe c) maybeA a = listA a >>> proc xs -> case xs of [] -> returnA -< Nothing (x:_) -> returnA -< Just x defaultTo :: ArrowChoice a => b -> a (Maybe b) b defaultTo def = proc m -> case m of Nothing -> returnA -< def Just x -> returnA -< x deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String deleteIfEmpty = proc str -> do case str of "" -> none -< () _ -> returnA -< str