Skip to content

Commit

Permalink
add missing methods andThen
Browse files Browse the repository at this point in the history
  • Loading branch information
tonivade committed Oct 13, 2024
1 parent 0cd8062 commit 6fe3827
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ default <B> Writer<L, B> flatMap(Function1<? super A, ? extends Kind<Writer<L, ?
return writer(monoid(), Tuple.of(combine.get1(), apply.getValue()));
}

@Override
default <R> Writer<L, R> andThen(Kind<Writer<L, ?>, ? extends R> next) {
return flatMap(ignore -> next);
}

static <L, A> Writer<L, A> pure(Monoid<L> monoid, A value) {
return writer(monoid, Tuple.of(monoid.zero(), value));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ default <V> EitherT<F, L, V> flatMap(Function1<? super R, ? extends Kind<EitherT
return EitherT.of(monad(), flatMapF(v -> map.andThen(EitherTOf::<F, L, V>toEitherT).apply(v).value()));
}

@Override
default <V> EitherT<F, L, V> andThen(Kind<EitherT<F, L, ?>, ? extends V> next) {
return flatMap(ignore -> next);
}

default <T, V> EitherT<F, T, V> bimap(Function1<? super L, ? extends T> leftMapper, Function1<? super R, ? extends V> rightMapper) {
return EitherT.of(monad(), monad().map(value(), v -> v.bimap(leftMapper, rightMapper)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ default <R> Kleisli<F, Z, R> flatMap(Function1<? super A, ? extends Kind<Kleisli
return Kleisli.of(monad(), value -> monad().flatMap(run(value), a -> map.andThen(KleisliOf::toKleisli).apply(a).run(value)));
}

@Override
default <R> Kleisli<F, Z, R> andThen(Kind<Kleisli<F, Z, ?>, ? extends R> next) {
return flatMap(ignore -> next);
}

default <B> Kleisli<F, Z, B> compose(Kleisli<F, A, B> other) {
return Kleisli.of(monad(), value -> monad().flatMap(run(value), other::run));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ default <R> OptionT<F, R> flatMap(Function1<? super T, ? extends Kind<OptionT<F,
return OptionT.of(monad(), flatMapF(v -> map.andThen(OptionTOf::<F, R>toOptionT).apply(v).value()));
}

@Override
default <R> OptionT<F, R> andThen(Kind<OptionT<F, ?>, ? extends R> next) {
return flatMap(ignore -> next);
}

default <R> Kind<F, R> fold(Producer<? extends R> orElse, Function1<? super T, ? extends R> map) {
return monad().map(value(), v -> v.fold(orElse, map));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ default <R> WriterT<F, L, R> flatMap(Function1<? super A, ? extends Kind<WriterT
other -> Tuple.of(monoid().combine(current.get1(), other.get1()), other.get2()))));
}

@Override
default <R> WriterT<F, L, R> andThen(Kind<WriterT<F, L, ?>, ? extends R> next) {
return flatMap(ignore -> next);
}

static <F extends Kind<F, ?>, L, A> WriterT<F, L, A> pure(Monoid<L> monoid, Monad<F> monad, A value) {
return lift(monoid, monad, Tuple2.of(monoid.zero(), value));
}
Expand Down

0 comments on commit 6fe3827

Please sign in to comment.