Marius Kotsbak
06/09/2021, 2:21 PMfun <A, B> Collection<Either<A, B>>.allLefts(): List<A> = this.mapNotNull { either -> either.fold({ it }, { null }) }
Do you have any ideas for better ways to do it with Arrow or should something be added? Use case here is to not do short circuit, so we can't use traverseEither.raulraja
06/10/2021, 7:30 AMfun <E, A> Iterable<Either<E, A>>.leftValues(): List<E>
fun <E, A> Iterable<Either<E, A>>.rightValues(): List<A>
fun <E, A> Iterable<Either<E, A>>.filterLeft(): List<Left<E>>
fun <E, A> Iterable<Either<E, A>>.filterRight(): List<Right<A>>
Marius Kotsbak
06/10/2021, 1:15 PMraulraja
06/10/2021, 1:17 PMsimon.vergauwen
06/17/2021, 10:21 AMJascha Smacka
06/18/2021, 1:58 PMfp-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>