-
Notifications
You must be signed in to change notification settings - Fork 0
/
Posts.elm
39 lines (34 loc) · 1.15 KB
/
Posts.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
module Posts (yearMonthToPost, postById) where
import Post
import Posts.FavorDeletableCodeOverReusableCode
import Posts.FunctionalProgrammingAhaMoments
import Posts.IntroducingMappy
import Posts.OOPSettersPartialApplication
import Posts.ObjectOrientedClojureExample
import Posts.TrieInHaskell
import Posts.WriteAFileInIdris
import Dict
yearMonthToPost : Dict.Dict (Int, Int) (List (Int, Post.Post))
yearMonthToPost =
let
getWithDefault def k d = Maybe.withDefault def <| Dict.get k d
reducer ((id, (Post.BlogPost _ _ (year, month, _) _)) as post) r =
let key = (year, month)
in Dict.insert key (post::getWithDefault [] key r) r
in
List.foldr reducer Dict.empty postsWithIds
postById : Int -> Maybe Post.Post
postById id =
postsWithIds |>
Dict.fromList |>
Dict.get id
postsWithIds : List (Int, Post.Post)
postsWithIds =
[ (100, Posts.IntroducingMappy.post)
, (99, Posts.ObjectOrientedClojureExample.post)
, (98, Posts.TrieInHaskell.post)
, (97,Posts.WriteAFileInIdris.post)
, (96,Posts.FavorDeletableCodeOverReusableCode.post)
, (95,Posts.FunctionalProgrammingAhaMoments.post)
, (94,Posts.OOPSettersPartialApplication.post)
]