From 0f160a8029b5f353dc803f4f88df08058535d22d Mon Sep 17 00:00:00 2001 From: William Carroll Date: Sat, 3 Oct 2020 11:00:11 +0100 Subject: Ignore comments in output for grocery export TL;DR: - Ignore lines starting with "#" - Tidy up the code --- scratch/groceries/export.hs | 17 ++++++++++++++--- 1 file 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 () -- cgit 1.4.1