module Rakka.Utils ( yesOrNo , parseYesOrNo , maybeA , deleteIfEmpty , chomp ) where import Control.Arrow import Control.Arrow.ArrowList yesOrNo :: Bool -> String yesOrNo True = "yes" yesOrNo False = "no" 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 deleteIfEmpty :: (ArrowList a, ArrowChoice a) => a String String deleteIfEmpty = proc str -> do case str of "" -> none -< () _ -> returnA -< str chomp :: String -> String chomp = reverse . snd . break (/= '\n') . reverse