Skip to content

//workflow/com.squareup.workflow1/contraMap

contraMap

[jvm]
Content
fun <T1, T2> Sink<T1>.contraMap(transform: (T2) -> T1): Sink<T2>
More info

Generates a new sink of type T2.

Given a transform closure, the following code is functionally equivalent:

1
2
3
sink.send(transform(value))

sink.contraMap(transform).send(value)

Trivia: Why is this called contraMap? - map turns Type into Type via (T)->U. - contraMap turns Type into Type via (U)->T

Another way to think about this is: map transforms a type by changing the output types of its API, while contraMap transforms a type by changing the input types of its API.