carbaj0
02/25/2022, 10:28 AMraulraja
02/25/2022, 11:11 AMsimon.vergauwen
02/25/2022, 1:45 PMis something that i should be using regularly as kotlin fp programmer?TL;DR no 😄
pakoito
02/25/2022, 2:38 PMlet
pakoito
02/25/2022, 2:38 PMlet?.
that gives you additional behaviorcarbaj0
02/25/2022, 3:10 PMPeter
02/25/2022, 3:11 PMkierans777
02/28/2022, 9:24 AMMarko Novakovic
02/28/2022, 1:17 PMcarbaj0
02/28/2022, 5:39 PMkierans777
03/01/2022, 1:19 AMlet
etc. Where the value of a pipe operator (and what Wlaschin highlights in his talks) is the ability to "switch tracks", or use a Sum/Monad type (like Arrow's Either
) without having to worry about the complexity of gluing the functions together. Composing functions together that return a Monad with a "pipe" function/operator requires Kleisli composition (https://blog.ssanj.net/posts/2017-06-07-composing-monadic-functions-with-kleisli-arrows.html). F# seems to use its pipe operator for both types of function composition.
Of course, Arrow has Monad comprehensions for that so you can take the ideas of a simple pipeK
and do the piping yourself.
F#
request
|> validate()
|> persist()
|> notify()
|> getResponse();
Kotlin/Arrow
either {
val valid = validate(request).bind()
val persisted = persist(valid).bind()
val notified = notify(persisted).bind()
val response = getResponse(notified).bind()
response
}
However (as per my previous comment) it requires the creation of "intermediate" variables, and is therefore not pointfree which a lot of FP code strives to be. I understand that the Kotlin/Arrow designers have made very well thought out decisions as to why they've done what they've done (due to the JVM platform, Kotlin being a statically typed language, performance concerns, etc). It does mean however that we're not going to get the same level of "FP niceness" in Kotlin/Arrow that you get in other languages.raulraja
03/01/2022, 11:23 AMlet + bind
but Kotlin unviversal way of invokation is not a pipe but callable references
which are currently quit limiting, specially polymorphic function shapes like Kleisli.
You can oberserve in that code that receivers allow you to remove the complexity. In general if you use the EffectScope coming to arrow you don’t ever need to return Either<E, A>, just A
where EffectScope<E>
is a receiver. that already gives you the power to shift out a value of E
.
I’m saying this because bind
can also be eliminated if you don’t return Either in the first place.Marko Novakovic
03/01/2022, 2:55 PM|>
so much. we don’t have same feature in Kotlin but I wanted to bring attention that it’s not all that bad and that Kotlin has similar feature(s)