https://kotlinlang.org logo
#arrow-contributors
Title
# arrow-contributors
i

Imran/Malic

07/16/2019, 11:11 PM
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

raulraja

07/16/2019, 11:16 PM
Is this already on Arrow?
i

Imran/Malic

07/16/2019, 11:16 PM
I wrote tests and the expected behavior as ascribed above happend
In order to add the FunctorFilterLaws I thought that would make sense
r

raulraja

07/17/2019, 12:18 AM
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

Imran/Malic

07/17/2019, 4:04 AM
I am not sure how to read this. Do anyone agree on what I propose or is there another way to do this.
r

raulraja

07/17/2019, 10:31 AM
Why does Nel need mapFilter or what is the relationship between Nel and mapFilter in what you are doing?
s

simon.vergauwen

07/17/2019, 10:51 AM
Nel doesn't have a FunctorFilter instance. A Nel with 1 element that is filtered makes it an empty list. Or when
mapFilter { None}
3 Views