Last active
April 2, 2024 20:16
-
-
Save tfausak/fcd11dfcec616622033dfb64eb2378e1 to your computer and use it in GitHub Desktop.
Sums numbers on the command line.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env stack | |
-- stack --resolver lts-8.15 --install-ghc script --package base | |
-- Usage: | |
-- $ echo -e "1.2 3.4\n5.6 not-a-number" | ./total.hs | |
-- 10.2 | |
import Data.Maybe (mapMaybe) | |
import Text.Read (readMaybe) | |
main :: IO () | |
main = | |
. (\x -> x :: Double) | |
. sum | |
. mapMaybe readMaybe | |
. words | |
=<< getContents |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment