Satyam Agarwal
05/01/2022, 11:44 AMIor.fromNullables(Nel.fromList(list1).getOrElse { null }, Nel.fromList(list2),getOrElse { null})
This is obviously not good, as Nel<A>?
effectively means List<A>
, so i can just list1.isEmpty() && list2.isEmpty
to cover Ior
cases.
However, what I want is Nel
after checking the states.
Is there something better that can be done here ?
Pattern matching on Option<Nel<A>> to Option<Nel<B>>
also doesn’t work. I can’t say for example when exp is Pair<Some, None>
simon.vergauwen
05/01/2022, 1:43 PMIor<Nel<A>, Nel<B>>
?
What do you expect if both are empty?Satyam Agarwal
05/01/2022, 1:45 PMIor<Nel<A>, Nel<B>>?
Then I can just check if Ior is null, then I perform operation that doesn't need any of these lists.Satyam Agarwal
05/01/2022, 1:47 PMIor.fromlists(..)
, but I thought I can ask here first.simon.vergauwen
05/01/2022, 1:49 PMorNull()
instead of getOrElse { null }
thoughSatyam Agarwal
05/01/2022, 1:51 PMSatyam Agarwal
05/01/2022, 1:51 PMmitch
05/01/2022, 4:40 PMOption<A>.align(other: Option<B>, fn: (Ior<A, B>) -> C): Option<C>
?
val first: Option<NonEmptyList<Int>> = Nel.fromList(listOf(5))
val second: Option<NonEmptyList<String>> = Nel.fromList(listOf("one"))
val result: Option<...> = first.align(second) { ior: Ior<Nel<Int>, Nel<String>> ->
// ...
}
mitch
05/01/2022, 4:45 PMalign
will give you a Some<Ior<A, B>>
if either Option<A>
or Option<B>
is some. it will otherwise yield None
mitch
05/01/2022, 4:51 PMoption { }
context if you’d wish to have a more complex operation, i.e.:
option {
val ior: Ior<NonEmptyList<A>, NonEmptyList<B>> = maybeNelA.align(maybeNelB).bind()
// do more things here if ior is defined
}
Satyam Agarwal
05/01/2022, 6:08 PM