Imran/Malic
07/16/2019, 11:11 PMfun <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 🙂raulraja
07/16/2019, 11:16 PMImran/Malic
07/16/2019, 11:16 PMraulraja
07/17/2019, 12:18 AMImran/Malic
07/17/2019, 4:04 AMraulraja
07/17/2019, 10:31 AMsimon.vergauwen
07/17/2019, 10:51 AMmapFilter { None}