-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMain03.elm
56 lines (39 loc) · 1.02 KB
/
Main03.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
module Main exposing (..)
import Html
type alias Item =
{ name : String
, price : Float
, qty : Int
, discounted : Bool
}
cart : List Item
cart =
[ { name = "Lemmon", price = 0.5, qty = 1, discounted = False }
, { name = "Apple", price = 1.0, qty = 5, discounted = False }
, { name = "Pear", price = 1.25, qty = 10, discounted = False }
]
--fiveOrMoreDiscount item =
-- if item.qty >= 5 then
-- { item
-- | price = item.price * 0.8
-- , discounted = True
-- }
-- else
-- item
discount : Int -> Float -> Item -> Item
discount minQty discPct item =
if not item.discounted && item.qty >= minQty then
{ item
| price = item.price * (1.0 - discPct)
, discounted = True
}
else
item
--newCart =
-- List.map fiveOrMoreDiscount cart
newCart : List Item
newCart =
List.map ((discount 10 0.3) >> (discount 5 0.2)) cart
main : Html.Html msg
main =
Html.text (toString newCart)