-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEx05A.elm
60 lines (50 loc) · 1.18 KB
/
Ex05A.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
57
58
59
60
module Ex05A exposing (..)
type OrgId = OrgId String
type Organisation = Organisation {
id : OrgId,
name : String
}
type UserId = UserId String
type User org = User {
id : UserId,
username : String,
organisation : org
}
coWorkers :
User Organisation ->
List (User OrgId) ->
List (User OrgId)
coWorkers (User user) allUsers =
case user.organisation of
Organisation org ->
findByOrgId org.id allUsers
findByOrgId :
OrgId ->
List (User OrgId) ->
List (User OrgId)
findByOrgId id users =
List.filter
(\(User u) -> u.organisation == id)
users
someUser : User Organisation
someUser =
User
{ id = UserId "2"
, username = "Sam"
, organisation =
Organisation
{ id = OrgId "1"
, name = "Elm Illuminati"
}
}
someUsers : List (User OrgId)
someUsers =
[ User { id = UserId "1", username = "Kate"
, organisation = OrgId "1" }
, User { id = UserId "2", username = "Sam"
, organisation = OrgId "1" }
, User { id = UserId "3", username = "Sally"
, organisation = OrgId "2" }
, User { id = UserId "4", username = "Harish"
, organisation = OrgId "1" }
]