diff options
| author | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-28 17:20:55 +0200 |
|---|---|---|
| committer | Jan Tuomi <jans.tuomi@gmail.com> | 2022-01-28 17:20:55 +0200 |
| commit | ad711dc91b1f916d27d3ce5cb286f991d3f4ec32 (patch) | |
| tree | efb993eb99108ef3204464c3dec9967dd0a26822 /src/utils.hs | |
| parent | b1eb5d0dd99ad0449b0808cdc1e6857404e49186 (diff) | |
Add floats, number conversions
Diffstat (limited to 'src/utils.hs')
| -rw-r--r-- | src/utils.hs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/utils.hs b/src/utils.hs index 33f3f6e..9ba2fa0 100644 --- a/src/utils.hs +++ b/src/utils.hs @@ -5,3 +5,26 @@ module Utils where ($>) = flip ($) infixr 6 $> + +countCond :: (a -> Bool) -> [a] -> Int +countCond cond list = filter cond list $> length + +occursTimes :: Eq a => a -> [a] -> Int +occursTimes needle = countCond (== needle) + +readMaybe :: (Read a) => String -> Maybe a +readMaybe s = case reads s of + [(x, "")] -> Just x + _ -> Nothing + +isFloatStr str = + let ir = readMaybe str :: Maybe Double + in case ir of + Just _ -> True + Nothing -> False + +isIntStr str = + let ir = readMaybe str :: Maybe Integer + in case ir of + Just _ -> True + Nothing -> False |
