@@ -74,28 +74,30 @@ object JsonPlaceholder {
74
74
75
75
object fetch {
76
76
import Lambda ._
77
- def users : Any ~> List [User ] = Lambda
77
+
78
+ def users : Any ~> List [User ] = Lambda
78
79
.constant(Request (url = " https://jsonplaceholder.typicode.com/users" )) >>>
79
80
Lambda .http.decode[List [User ]]
80
81
.fold(Lambda .constant(List .empty[User ]))(Lambda .identity[List [User ]])
81
- def posts : Any ~> List [Post ] = Lambda
82
+
83
+ def posts : Any ~> List [Post ] = Lambda
82
84
.constant(Request (url = " https://jsonplaceholder.typicode.com/posts" )) >>>
83
85
Lambda .http.decode[List [Post ]]
84
86
.fold(Lambda .constant(List .empty[Post ]))(Lambda .identity[List [Post ]])
85
- def postUser : Post ~> User = Lambda .die
86
- def userPosts : User ~> List [Post ] = Lambda .die
87
- def userAlbums : User ~> List [Album ] = Lambda .die
88
87
89
88
def albums : UserId ~> List [Album ] = Lambda
90
89
.constant(Request (url = " https://jsonplaceholder.typicode.com/albums" )) >>>
91
90
Lambda .http.decode[List [Album ]]
92
91
.fold(Lambda .constant(List .empty[Album ]))(Lambda .identity[List [Album ]])
93
92
94
- def albumPhotos : Album ~> List [Photo ] = Lambda .die
95
- def postComments : Post ~> List [Comment ] = Lambda .die
96
- def albumUser : Album ~> User = Lambda .die
97
- def userComments : User ~> List [Comment ] = Lambda .die
98
- def photoAlbum : Photo ~> Album = Lambda .die
93
+ def diePostUser : Post ~> User = Lambda .die
94
+ def dieUserPosts : User ~> List [Post ] = Lambda .die
95
+ def dieUserAlbums : User ~> List [Album ] = Lambda .die
96
+ def dieAlbumPhotos : Album ~> List [Photo ] = Lambda .die
97
+ def diePostComments : Post ~> List [Comment ] = Lambda .die
98
+ def dieAlbumUser : Album ~> User = Lambda .die
99
+ def dieUserComments : User ~> List [Comment ] = Lambda .die
100
+ def diePhotoAlbum : Photo ~> Album = Lambda .die
99
101
}
100
102
101
103
case class UserId (userId : Option [Int ])
@@ -104,15 +106,18 @@ object JsonPlaceholder {
104
106
val lens = DeriveAccessors .gen[UserId ]
105
107
}
106
108
107
- val graph : Graph = Graph [Unit , Unit ](" posts" , fetch.posts) ++
108
- Graph [Unit , Unit ](" users" , fetch.users) ++
109
- Graph [UserId , Unit ](" albums" , fetch.albums <<< Lambda ._1) ++
110
- Graph [Unit , User ](" albums" , fetch.userAlbums <<< Lambda ._2) ++
111
- Graph [Unit , Post ](" comments" , fetch.postComments <<< Lambda ._2) ++
112
- Graph [Unit , User ](" comments" , fetch.userComments <<< Lambda ._2) ++
113
- Graph [Unit , Album ](" photos" , fetch.albumPhotos <<< Lambda ._2) ++
114
- Graph [Unit , User ](" posts" , fetch.userPosts <<< Lambda ._2) ++
115
- Graph [Unit , Album ](" user" , fetch.albumUser <<< Lambda ._2) ++
116
- Graph [Unit , Post ](" user" , fetch.postUser <<< Lambda ._2) ++
117
- Graph [Unit , Photo ](" album" , fetch.photoAlbum <<< Lambda ._2)
109
+ val graph : Graph = Graph .empty
110
+ .add[Unit , Unit ](" posts" , fetch.posts)
111
+ .add[Unit , Unit ](" users" , fetch.users)
112
+ .add[UserId , Unit ](" albums" , fetch.albums <<< Lambda ._1)
113
+
114
+ // TODO: remove die implementations
115
+ .add[Unit , User ](" albums" , fetch.dieUserAlbums <<< Lambda ._2)
116
+ .add[Unit , Post ](" comments" , fetch.diePostComments <<< Lambda ._2)
117
+ .add[Unit , User ](" comments" , fetch.dieUserComments <<< Lambda ._2)
118
+ .add[Unit , Album ](" photos" , fetch.dieAlbumPhotos <<< Lambda ._2)
119
+ .add[Unit , User ](" posts" , fetch.dieUserPosts <<< Lambda ._2)
120
+ .add[Unit , Album ](" user" , fetch.dieAlbumUser <<< Lambda ._2)
121
+ .add[Unit , Post ](" user" , fetch.diePostUser <<< Lambda ._2)
122
+ .add[Unit , Photo ](" album" , fetch.diePhotoAlbum <<< Lambda ._2)
118
123
}
0 commit comments