diff options
author | tzlil <tzlils@protonmail.com> | 2023-12-02 15:22:56 +0200 |
---|---|---|
committer | tzlil <tzlils@protonmail.com> | 2023-12-02 15:22:56 +0200 |
commit | 1b9ea3c36d2f32bedc0416898764f6039320274e (patch) | |
tree | ea0d0ea980fc117bc89e670bce465d626daef14b /1/2.hs | |
parent | d7e41f1e93eac045329b6ea91ae150d517e443a3 (diff) |
pass filename to parse
Diffstat (limited to '1/2.hs')
-rw-r--r-- | 1/2.hs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/1/2.hs b/1/2.hs index dd932d5..a5ba754 100644 --- a/1/2.hs +++ b/1/2.hs @@ -8,9 +8,10 @@ import System.Environment digits = ["one","two","three","four","five","six","seven","eight","nine"] parse [] = (mempty,mempty) -parse l@(x:xs) = case findIndex (`isPrefixOf` l) digits of - Just i -> f (Just $ i+1) <> parse xs - Nothing -> f (readMaybe [x]) <> parse xs + +parse l@(x:xs) + | Just i <- findIndex (`isPrefixOf` l) digits = f (Just $ i+1) <> parse xs + | otherwise = f (readMaybe [x]) <> parse xs where f = (,) . First <*> Last |