-
Notifications
You must be signed in to change notification settings - Fork 1
/
episode5.fsx
55 lines (46 loc) · 975 Bytes
/
episode5.fsx
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
let icecreamShop = "Klaras Parlor"
let dayResults sold price =
sold * price
let priceFor ice =
if ice = "Strawberry" then
1.1
else
0.9
let resultsFor ice sold =
ice
|> priceFor
|> dayResults sold
let iceFor ice =
if ice = "Red Rising" then
"Strawberry"
else
"Vanilla"
let priceForSpecial =
iceFor >> priceFor
let sales =
[
"Red Rising"
"Red Rising"
"Cream Dream"
"Red Rising"
"Cream Dream"
"RedRising"
]
// map each element of the list to a price
// List.map : (string -> float) -> string list -> float list
sales
|> List.map priceForSpecial
// sum all the elements in the list
|> List.sum
sales
|> List.filter (fun flavour -> flavour = "Red Rising")
|> List.map priceForSpecial
|> List.sum
sales
|> List.filter (fun flavour -> flavour = "Red Rising")
|> List.map priceForSpecial
|> List.map (fun x -> x + 0.2)
|> List.sum
sales
|> List.filter (fun flavour -> flavour = "Cream Dream")
|> List.length