-
Notifications
You must be signed in to change notification settings - Fork 29
/
WithFilter.scala
26 lines (24 loc) · 1.1 KB
/
WithFilter.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
package com.thoughtworks.dsl.keywords
import com.thoughtworks.dsl.Dsl
final case class WithFilter[UpstreamKeyword, UpstreamValue](upstream: UpstreamKeyword,
condition: UpstreamValue => Boolean)
extends Dsl.Keyword[WithFilter[UpstreamKeyword, UpstreamValue], UpstreamValue]
object WithFilter {
implicit def withFilterDsl[UpstreamKeyword, Domain, UpstreamValue](
implicit
upstreamDsl: Dsl[UpstreamKeyword, Domain, UpstreamValue],
continueDsl: Dsl[Continue, Domain, Nothing]
): Dsl[WithFilter[UpstreamKeyword, UpstreamValue], Domain, UpstreamValue] =
new Dsl[WithFilter[UpstreamKeyword, UpstreamValue], Domain, UpstreamValue] {
def cpsApply(keyword: WithFilter[UpstreamKeyword, UpstreamValue], handler: UpstreamValue => Domain) = {
val WithFilter(upstream, condition) = keyword
upstreamDsl.cpsApply(upstream, { upstreamValue =>
if (condition(upstreamValue)) {
handler(upstreamValue)
} else {
continueDsl.cpsApply(Continue, identity)
}
})
}
}
}