From e7dbb4348d17f44c0f9162bea68738f3e2dc72f8 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Thu, 26 Jan 2017 21:11:21 +1100 Subject: Moving some code to Miscellaneous --- src/Miscellaneous.hs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'src/Miscellaneous.hs') 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) + + -- cgit