diff options
author | Jed Barber <jjbarber@y7mail.com> | 2017-01-26 21:11:21 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2017-01-26 21:11:21 +1100 |
commit | e7dbb4348d17f44c0f9162bea68738f3e2dc72f8 (patch) | |
tree | 5d0c2908c72f28b548c8ef4c18d32aba55f84401 /src/Miscellaneous.hs | |
parent | d07277cf6b1ae0d94fa3bf3829ddf1a2357e3d9d (diff) |
Moving some code to Miscellaneous
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) + + |