-
Notifications
You must be signed in to change notification settings - Fork 29
/
FlatMap.scala
28 lines (26 loc) · 1.16 KB
/
FlatMap.scala
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
package com.thoughtworks.dsl.keywords
import com.thoughtworks.dsl.Dsl
final case class FlatMap[UpstreamKeyword, UpstreamValue, NestedKeyword, NestedValue](
upstream: UpstreamKeyword,
flatMapper: UpstreamValue => NestedKeyword
) extends Dsl.Keyword[FlatMap[UpstreamKeyword, UpstreamValue, NestedKeyword, NestedValue], NestedValue]
object FlatMap {
implicit def flatMapDsl[UpstreamKeyword, UpstreamValue, Domain, NestedKeyword, NestedValue](implicit
upstreamDsl: Dsl[UpstreamKeyword, Domain, UpstreamValue],
nestedDsl: Dsl[NestedKeyword, Domain, NestedValue]
): Dsl[FlatMap[UpstreamKeyword, UpstreamValue, NestedKeyword, NestedValue], Domain, NestedValue] =
new Dsl[FlatMap[UpstreamKeyword, UpstreamValue, NestedKeyword, NestedValue], Domain, NestedValue] {
def cpsApply(
keyword: FlatMap[UpstreamKeyword, UpstreamValue, NestedKeyword, NestedValue],
handler: NestedValue => Domain
) = {
val FlatMap(upstream, flatMapper) = keyword
upstreamDsl.cpsApply(
upstream,
{ upstreamValue =>
nestedDsl.cpsApply(flatMapper(upstreamValue), handler)
}
)
}
}
}