pablisco
09/28/2020, 5:15 PMcarbaj0
09/28/2020, 5:37 PMpablisco
09/28/2020, 5:53 PMfirstOrNull()
carbaj0
09/28/2020, 6:20 PMraulraja
09/28/2020, 6:21 PMsuspend
so the effects including exceptions are handled by the continuation that runs the suspended program.carbaj0
09/28/2020, 6:27 PMkioba
09/30/2020, 2:23 PMgetOrThrow
? Should I understand more about where to use Either and where not to?pablisco
09/30/2020, 3:32 PMOption
to nullables it could be possible to do:
stream.first().orElse { error("Oops!") }
If first() returns nullableraulraja
09/30/2020, 3:39 PMfirstOrElse
?pablisco
09/30/2020, 3:47 PMfun <O> Stream<O>.first() : O?
fun <O> O?.orElse(block: () -> O) : O
As I mention here:
https://github.com/arrow-kt/arrow-fx/pull/291#discussion_r497532005
This means that other operations that result in a nullable can benefit of that api, even the ones that are not part of Arrow. It would mean that we don’t have to maintain firstOrElse
or similar for other types like ListK, etc.
That said, I see the benefit of having shortcuts. For instance if we do:
stream.effectTap { .. }.drain()
We could have: effectDrain {}
which does something similar…
However, maybe there is a way we can automate/generate these composite shortcuts (are these comprehensions?) using Meta 🤔raulraja
09/30/2020, 4:30 PMorElse
different than ?:
pablisco
09/30/2020, 6:19 PMorElse
is easier to chain with other operations. Obviously, in this case we are talking about a terminal operation but I can see cases where it would facilitate working with the result from ?:
Which involves wrapping the statement in parentheses.
The other thing is that it can be used to make the code more readable to some people:
fetchMemory()
.orElse { fetchLocal() }
.orElse { fetchRemote().andSave() }
Vs
fetchMemory() ?: fetchLocal() ?: fetchRemote().andSave()
Which, if a well intended developer comes after and adds some parentheses:
fetchMemory() ?: (fetchLocal() ?: fetchRemote()).andSave()
Boom! Behaviour is now changed 😅orElse
can be considered a flatMapLeft
, kind of, right?raulraja
09/30/2020, 9:57 PMpablisco
09/30/2020, 10:07 PMinline class Option<out A>(val value: A?)
nor:
typealias Option<A> = A?
😞
That would have been so nice for migration 😅