I've been doing some experiments with Either myself and what I came up with has IMO a nice way of mapping either choice in a concise fashion, you might want to take a look at it and see if this is something for funktionale-either. It appears to be what Either is doing in fold but expanded by infix operations.
// A method handling that choice type
val f = { u: Choice<Number, String> ->
// Map either side accordingly
val d = u onLeft {
it.toDouble() / 2
} onRight {
it.length.toDouble()
}
println(d)
}
I've been doing some experiments with Either myself and what I came up with has IMO a nice way of mapping either choice in a concise fashion, you might want to take a look at it and see if this is something for funktionale-either. It appears to be what Either is doing in
fold
but expanded by infix operations.Relevant code starts here: https://gist.github.com/lukashaertel/02b8dd4a5ad8c691bc783eb7b88fba9b#file-choice-kt-L37
And here's an example of how it's applied: