Skip to content

Commit d8668e2

Browse files
PP144ghrober-m
andauthored
Update Solution.hs (#21)
* Update Solution.hs the use of the filter function can be avoided, zipWith already has this built-in, it will only zip a number of times equal to the length of the smaller list. This can only be done because of "Assume that the two lists have the beers in the same order." * Cleanup --------- Co-authored-by: Robertino <48034748+rober-m@users.noreply.github.com>
1 parent b407919 commit d8668e2

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

Homework06/Solution.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ deliveryCost :: Double
127127
deliveryCost = 8.50
128128

129129
beerCosts :: [(String, Double)] -> Double
130-
beerCosts =
131-
foldr (+) deliveryCost
132-
. zipWith (*) (map snd bevogBeerPrices)
133-
. map snd
134-
. filter (\name -> fst name `elem` map fst bevogBeerPrices)
130+
beerCosts = foldl' (+) deliveryCost . zipWith' (\(_, price) (_, qty) -> price * qty) bevogBeerPrices
131+
132+

0 commit comments

Comments
 (0)