diff options
author | William Carroll <wpcarro@gmail.com> | 2020-10-03T10·00+0100 |
---|---|---|
committer | William Carroll <wpcarro@gmail.com> | 2020-10-03T10·00+0100 |
commit | 0f160a8029b5f353dc803f4f88df08058535d22d (patch) | |
tree | ac0fe9cee547178ad13de740244996edd9832bf0 | |
parent | 3b525e6d63f8877b451437b264da87d7aaf8f0b0 (diff) |
Ignore comments in output for grocery export
TL;DR: - Ignore lines starting with "#" - Tidy up the code
-rw-r--r-- | scratch/groceries/export.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/scratch/groceries/export.hs b/scratch/groceries/export.hs index c76033391d02..ed43c9a3e887 100644 --- a/scratch/groceries/export.hs +++ b/scratch/groceries/export.hs @@ -1,11 +1,22 @@ module Main where -import Data.Function ((&)) import qualified Data.List as L +(|>) :: a -> (a -> b) -> b +x |> f = f x + +-- | Ignore items with zero quantity (i.e. "0x") and comments (i.e. "#") +isUndesirableOutput :: String -> Bool +isUndesirableOutput x = + (L.isPrefixOf "- 0x" x) || (L.isPrefixOf "#" x) + -- | Run this to export the grocery list. main :: IO () main = do - x <- readFile "./list.org" - x & lines & filter (not . L.isPrefixOf "- 0x") & unlines & putStrLn + content <- readFile "./list.org" + content + |> lines + |> filter (not . isUndesirableOutput) + |> unlines + |> putStrLn pure () |