Regarding naming: In
fp-ts
(
https://github.com/gcanti/fp-ts), this is part of the
Filterable
typeclass:
export interface Filterable<F> extends Functor<F>, Compactable<F> {
readonly partitionMap: <A, B, C>(fa: HKT<F, A>, f: (a: A) => Either<B, C>) => Separated<HKT<F, B>, HKT<F, C>>
readonly partition: Partition<F> // <A>(fa: HKT<F, A>, predicate: Predicate<A>): Separated<HKT<F, A>, HKT<F, A>>
readonly filterMap: <A, B>(fa: HKT<F, A>, f: (a: A) => Option<B>) => HKT<F, B>
readonly filter: Filter<F> // <A>(fa: HKT<F, A>, predicate: Predicate<A>): HKT<F, A>
}
I did not check with Haskell but would expect similar naming there. Personally, I think the following would look most consistent with those conventions:
fun <E, A, B> Iterable<A>.filterLeft(p: (A) -> Either<E, B>): List<E>
fun <E, A, B> Iterable<A>.filterRight(p: (A) -> Either<E, B>): List<B>