diff options
Diffstat (limited to 'src/Miscellaneous.hs')
-rw-r--r-- | src/Miscellaneous.hs | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/Miscellaneous.hs b/src/Miscellaneous.hs index 5a559a5..5f018e6 100644 --- a/src/Miscellaneous.hs +++ b/src/Miscellaneous.hs @@ -1,7 +1,9 @@ module Miscellaneous( if', (?), - selectFrom + selectFrom, + readMaybe, + partBeforeAfter ) where @@ -45,3 +47,22 @@ selectFrom pick has from = in Con.foldM foldFunc [] (zip [1,2..] from) + + +readMaybe :: Read a => String -> Maybe a +readMaybe s = + case reads s of + [(val, "")] -> Just val + _ -> Nothing + + + + +partBeforeAfter :: (Eq a) => a -> [a] -> ([a],[a]) +partBeforeAfter item list = + let (x,y) = List.break (== item) list + in if (length y <= 1) + then (x,[]) + else (x,tail y) + + |