:wave: To concatenate two `Option<Nel<Stuff...
# arrow
g
👋 To concatenate two
Option<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>?
c
Can't you just
list1?.plus(list2)
?
Oh, no, because
list2
could be empty Then:
Copy code
operator fun <T> NonEmptyList<T>?.plus(other: NonEmptyList<T>?): NonEmptyList<T>? {
    val first = this ?: return null
    val second = this ?: return null

    return first + second
}
g
yes i could, and we did somewhere, but that function is also inside maybeCombine of the semigroup, and i was asking because i thought there was a way to use semigroups for that
In the end I could not find anything better then:
Copy code
operator fun <T> NonEmptyList<T>?.plus(other: NonEmptyList<T>?) =
    Semigroup.option(Semigroup.nonEmptyList<T>()).run {
        this@plus.toOption() + other.toOption()
    }.orNull()
c
Out of curiosity, why are you using nullable
NonEmptyList
s?
NonEmptyList
+`null` is isomorphic with just
List
, isn't it?
g
I understand your seciquestion