Giulio Caccin
12/29/2022, 3:39 PMOption<Nel<Stuff>>
we where using Semigroup.option(Semigroup.nonemptylist<Stuff>())
, now i’m bumping Arrow version and I wanted to try using null as much as possible. Is there any elegant way to use semigroup to concatenate NonEmptyList<Stuff>?
CLOVIS
12/29/2022, 3:43 PMlist1?.plus(list2)
?CLOVIS
12/29/2022, 3:45 PMlist2
could be empty
Then:
operator fun <T> NonEmptyList<T>?.plus(other: NonEmptyList<T>?): NonEmptyList<T>? {
val first = this ?: return null
val second = this ?: return null
return first + second
}
Giulio Caccin
12/29/2022, 3:47 PMGiulio Caccin
01/10/2023, 8:56 AMoperator fun <T> NonEmptyList<T>?.plus(other: NonEmptyList<T>?) =
Semigroup.option(Semigroup.nonEmptyList<T>()).run {
this@plus.toOption() + other.toOption()
}.orNull()
CLOVIS
01/10/2023, 9:44 AMNonEmptyList
s?CLOVIS
01/10/2023, 9:45 AMNonEmptyList
+`null` is isomorphic with just List
, isn't it?Giulio Caccin
01/11/2023, 7:39 AM