Even though, this compiles it’s clear that there a...
# arrow-contributors
i
Even though, this compiles it’s clear that there are cornerCases where this doesn’t work.
Copy code
fun <B> mapFilter(f: (A) -> Option<B>): NonEmptyList<B> =
    map(f).foldLeft(NonEmptyList(listOf())) { acc, o -> o.fold({ acc }, { acc + it }) }
Well I suggest to change the returnType to something like
Option<NonEmptyList<B>>
, because if there doesn’t exist any value which fulfills the f function and returns an Some<B> the return List is empty thus it’s not an NonEmptyList<B>. I also consider something like an
Either<List<Nothing>, NonEmptyList<B>>
, which is in my opinion more granular. I am happy for Feedback 🙂
r
Is this already on Arrow?
i
I wrote tests and the expected behavior as ascribed above happend
In order to add the FunctorFilterLaws I thought that would make sense
r
in order to filter you need an empty identity to bail when no predicate is match
Nel does not have that as Paco said, there is no empty value for Nel
not sure if there is a way around it
i
I am not sure how to read this. Do anyone agree on what I propose or is there another way to do this.
r
Why does Nel need mapFilter or what is the relationship between Nel and mapFilter in what you are doing?
s
Nel doesn't have a FunctorFilter instance. A Nel with 1 element that is filtered makes it an empty list. Or when
mapFilter { None}