That in the future can be done in Arrow like this ...
# arrow
r
That in the future can be done in Arrow like this with union types once we figure out the compiler plugin for it.
Copy code
typealias RemoteData<A, B> = Union<Initial, Pending, Failure<A>, Success<B>>
val initial: RemoteData<Throwable, Result> = initialValue //ok
val pending: RemoteData<Throwable, Result> = pendingValue //ok
val failure: RemoteData<Throwable, Result> = failureValue //ok
val success: RemoteData<Throwable, Result> = successValue //ok
val maybeSuccess: Success<Result>? = anyOfTheValues //ok
val maybeSuccess: Success<Result>? = "some other type not in the union //not ok and does not compile
No need for Either or fold when you have union types and smart casts work accordingly if you use when expressions
❤️ 9