mitch
09/15/2020, 8:54 AMraulraja
09/15/2020, 11:49 AMstojan
09/15/2020, 5:26 PMnull
raulraja
09/15/2020, 8:41 PMstojan
09/15/2020, 9:57 PMio.reactivex.Maybe
is an Observable
that can emit 0 or 1 values (or can error). (Observable
emits 0-n values (or can error).
So the use case for Observable<Option<T>>
is to make the distinction between: the cache is empty, and the cache is not empty but has 0 items.stojan
09/15/2020, 9:58 PMstojan
09/15/2020, 9:59 PMstojan
09/15/2020, 10:01 PMstojan
09/15/2020, 10:04 PMOption
in a separate, optional module, where we clearly point out it's not recommended but there as a last resort (for Java interop reasons).
I am happy to contribute in any such migration.
I don't expect such module to have more than 1 release, since Option
is based on years of FP experience and algebraic lawsstojan
09/15/2020, 10:06 PMWe are not gonna introduce Option back in Arrow unless we can have special inlining for it like the Result type has in Kotlin. That means that is inlined an almost zero cost abstraction like nullable typesit's an admirable goal, but when talking to the BE people in my company, most services are IO bound, so this is not really an issue. In cases where it is, they would probably never use it to begin with
raulraja
09/15/2020, 10:18 PMI suggest that we keepin a separate, optional module, where we clearly point out it’s not recommended but there as a last resort (for Java interop reasons).Option
I am happy to contribute in any such migration.
raulraja
09/15/2020, 10:18 PMraulraja
09/15/2020, 10:22 PMI don’t expect such module to have more than 1 release, sinceWe’ll see about that xD but yeah I get what you are saying. If this is a problem only surfacing in the JVM thenis based on years of FP experience and algebraic lawsOption
arrow-optional
fits and we can also include there the interop DSL to Java’s Optional beside nullables.stojan
09/15/2020, 10:24 PMraulraja
09/15/2020, 10:24 PMraulraja
09/15/2020, 10:24 PMraulraja
09/15/2020, 10:24 PMmitch
09/15/2020, 10:25 PMmitch
09/15/2020, 11:22 PMMono.empty
which is not exactly what’s intended. Mono.empty means the source doesn’t emit anything and unless handled in runtime using .defaultWhenEmpty(T)
yields an infinitely hanging mono.
val monoNull: Mono<Int?> = Mono.just(5).map { null } // never resolves
To circumvent this we use Mono<Option<T>>
as the return type. The trick here is we need a concrete type to box T?
to make reactor behave sanely..
val monoOption: Mono<Option<T>> = Mono.just(5).map { none() } // resolves
val monoIdNull: Mono<Id<Int?>> = Mono.just(Id(null)) // resolves
val monoEither: Mono<Either<Unit, Int>> = Mono.fromCallable { Unit.left() } // resolves
hence the reason why Arrow’s Option<T> (and Either<L, R>) is very integral to ensure safety in our services. True we do lose a tiny performance, but it’s a more than acceptable tradeoff to the behaviourial correctness that we get by employing Arrow’s data types.
Regarding inline Option / Either, e.g. similarly kotlin.std’s Result<T>
i think it’s going to be very cool when we get there. I guess how that is designed currently will have to change tremendously, as inline classes have so much restrictions around it. i.e. it can’t extend anything, idk if that’s going to work with higher kinds right now (maybe that’ll change with meta evolving).mitch
09/15/2020, 11:26 PMraulraja
09/15/2020, 11:56 PMraulraja
09/15/2020, 11:58 PMnull
that impacts kotlin main use case to have null in the type hierarchy as A?.mitch
09/16/2020, 12:14 AMOption and nullable types are not necessarily different, so far what I heard is more a design decision this frameworks have made regardingI see your point, essentially ? is our wrapper similarly to how -> is the wrapper in kleislis. That does mean we’ll be passing nulls around under the hood. Some java libraries (like we’ve seen in rxjava and reactor) are sensitive to that. How do we plan to approach inlining Either at the moment? I may need to check that out - i’m still keen to have a go inlining Option similarly. If there’s a way to keep option in arrow core and removing the performance penalty, i’m all for it.that impacts kotlin main use case to have null in the type hierarchy as A?.null
raulraja
09/16/2020, 12:19 AMId
in those examples as a valid wrapper which is still in core. What does Option give you that Id or Either don’t give you in your use case?raulraja
09/16/2020, 12:22 AMmitch
09/16/2020, 12:27 AMraulraja
09/16/2020, 1:21 AMraulraja
09/16/2020, 1:22 AMmitch
09/16/2020, 6:32 AMIf your kotlin project uses webflux, use Arrow option. Avoid nulls.there’s another comment just popped in recently in the github issue I quoted saying the exact same problem and also a similar solution using java optional. In kotlin we have Arrow’s Option which is lightyears better than that of Java’s. To lose that will deal a huge blow to many teams..
stojan
09/16/2020, 7:00 AMnull
did allow to use null
as uninitialised internally, leading to better performance (in RxJava2 compared to RxJava1 which allowed null
)stojan
09/16/2020, 7:10 AMsimon.vergauwen
09/16/2020, 7:41 AMWell, prohibitingThere are other solutions for this, albeit ugly and harder to maintain.did allow to usenull
as uninitialised internally, leading to better performance (in RxJava2 compared to RxJava1 which allowednull
)null
Youssef Shoaib [MOD]
09/16/2020, 6:30 PMSome
and None
?raulraja
09/16/2020, 8:56 PMmitch
09/20/2020, 5:37 AMKind<ForOption, A>
.. unless we have a different way to tackle HKT in 1.x ?raulraja
09/20/2020, 8:00 AMraulraja
09/20/2020, 8:02 AMmitch
10/05/2020, 5:58 AMmitch
10/05/2020, 6:08 AMraulraja
10/05/2020, 11:36 AMraulraja
10/05/2020, 11:38 AM