4 ms·
strSum :: String -> Either String Int strSum = fmap sum . mapM readEither . words
by mrkeen 2y ago
strSum :: String -> Either String Int
strSum = fmap sum . mapM readEither . words
- Tainnor 2y agoThat doesn't exactly give a good error message, though: > strSum "10 20 x" Left "Prelude.read: no parse" But yeah, I didn't remember "mapM". mapM f = sequence . fmap f, which is what I used.