Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove witness #137

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import com.github.tonivade.purefun.core.Tuple2;

@HigherKind
public sealed interface Control<T> extends ControlOf<T>, Bindable<Control_, T> {
public sealed interface Control<T> extends ControlOf<T>, Bindable<Control<?>, T> {

<R> Result<R> apply(MetaCont<T, R> cont);

Expand All @@ -29,12 +29,12 @@ default <R> Control<R> map(Function1<? super T, ? extends R> mapper) {
}

@Override
default <R> Control<R> flatMap(Function1<? super T, ? extends Kind<Control_, ? extends R>> mapper) {
default <R> Control<R> flatMap(Function1<? super T, ? extends Kind<Control<?>, ? extends R>> mapper) {
return new FlatMapped<>(Control.this, mapper);
}

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

Expand Down Expand Up @@ -85,9 +85,9 @@ public <R1> Result<R1> apply(MetaCont<R, R1> cont) {
final class FlatMapped<T, R> implements Control<R> {

private final Control<T> self;
private final Function1<? super T, ? extends Kind<Control_, ? extends R>> outer;
private final Function1<? super T, ? extends Kind<Control<?>, ? extends R>> outer;

private FlatMapped(Control<T> self, Function1<? super T, ? extends Kind<Control_, ? extends R>> outer) {
private FlatMapped(Control<T> self, Function1<? super T, ? extends Kind<Control<?>, ? extends R>> outer) {
this.self = checkNonNull(self);
this.outer = checkNonNull(outer);
}
Expand Down Expand Up @@ -225,7 +225,7 @@ public <R> Control<R> map(Function1<? super T, ? extends R> mapper) {

@Override
@SuppressWarnings("unchecked")
public <R> Control<R> flatMap(Function1<? super T, ? extends Kind<Control_, ? extends R>> mapper) {
public <R> Control<R> flatMap(Function1<? super T, ? extends Kind<Control<?>, ? extends R>> mapper) {
return (Control<R>) this;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ default <R> MetaCont<R, B> map(Function1<? super R, ? extends A> mapper) {
}

@SuppressWarnings({"unchecked", "rawtypes"})
default <R> MetaCont<R, B> flatMap(Function1<? super R, ? extends Kind<Control_, ? extends A>> mapper) {
default <R> MetaCont<R, B> flatMap(Function1<? super R, ? extends Kind<Control<?>, ? extends A>> mapper) {
Function1<?, Control<?>> f = (Function1) mapper;
return new Frames<>(NonEmptyList.of(f), this);
}
Expand Down Expand Up @@ -114,7 +114,7 @@ public <R> Tuple2<MetaCont<A, R>, MetaCont<R, C>> splitAt(Marker.Cont<R> cont) {

@Override
@SuppressWarnings({"unchecked", "rawtypes"})
public <R> MetaCont<R, C> flatMap(Function1<? super R, ? extends Kind<Control_, ? extends A>> mapper) {
public <R> MetaCont<R, C> flatMap(Function1<? super R, ? extends Kind<Control<?>, ? extends A>> mapper) {
NonEmptyList<Function1<?, Control<?>>> list = NonEmptyList.of((Function1) mapper);
return new Frames<>(list.appendAll(frames), tail);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private Control<Integer> program(Amb amb) {
}

private Control<Integer> program(State<Integer> state, Amb amb) {
return Instances.monad(Control_.class).use()
return Instances.<Control<?>>monad().use()
.then(state.get())
.flatMap(x -> amb.flip().flatMap(b -> b ? state.set(x + 1) : pure(unit())))
.then(state.get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ static abstract class Process<R, P, E> extends Stateful<R, Kind<P, Control<R>>,
}
}

static final class Down<R> extends Process<R, Prod_, Receive> implements Receive {
static final class Down<R> extends Process<R, Prod<?>, Receive> implements Receive {

Down(Kind<Prod_, Control<R>> init) {
Down(Kind<Prod<?>, Control<R>> init) {
super(init);
}

Expand All @@ -91,9 +91,9 @@ public Control<Integer> receive() {
}
}

static final class Up<R> extends Process<R, Cons_, Send> implements Send {
static final class Up<R> extends Process<R, Cons<?>, Send> implements Send {

Up(Kind<Cons_, Control<R>> init) {
Up(Kind<Cons<?>, Control<R>> init) {
super(init);
}

Expand All @@ -110,27 +110,27 @@ public Control<Unit> send(int n) {
@HigherKind
final class Prod<R> implements ProdOf<R> {

private final Function1<Unit, Function1<Kind<Cons_, R>, R>> apply;
private final Function1<Unit, Function1<Kind<Cons<?>, R>, R>> apply;

Prod(Function1<Unit, Function1<Kind<Cons_, R>, R>> apply) {
Prod(Function1<Unit, Function1<Kind<Cons<?>, R>, R>> apply) {
this.apply = requireNonNull(apply);
}

public Function1<Kind<Cons_, R>, R> apply(Unit unit) {
public Function1<Kind<Cons<?>, R>, R> apply(Unit unit) {
return apply.apply(unit);
}
}

@HigherKind
final class Cons<R> implements ConsOf<R> {

private final Function1<Integer, Function1<Kind<Prod_, R>, R>> apply;
private final Function1<Integer, Function1<Kind<Prod<?>, R>, R>> apply;

Cons(Function1<Integer, Function1<Kind<Prod_, R>, R>> apply) {
Cons(Function1<Integer, Function1<Kind<Prod<?>, R>, R>> apply) {
this.apply = requireNonNull(apply);
}

public Function1<Kind<Prod_, R>, R> apply(int n) {
public Function1<Kind<Prod<?>, R>, R> apply(int n) {
return apply.apply(n);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static <R> Control<R> instanceOf(Function1<Twitter, Control<R>> apply) {
}

private Control<ImmutableList<Tweet>> program(Twitter twitter) {
return Instances.<Control_>monad().use()
return Instances.<Control<?>>monad().use()
.then(twitter.userTweets("12345"))
.then(twitter.userTweets("54321"))
.apply(ImmutableList::appendAll)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
* @see Promise
*/
@HigherKind
public sealed interface Future<T> extends FutureOf<T>, Bindable<Future_, T> {
public sealed interface Future<T> extends FutureOf<T>, Bindable<Future<?>, T> {

Executor DEFAULT_EXECUTOR = Executors.newVirtualThreadPerTaskExecutor();

Expand All @@ -88,7 +88,7 @@ public sealed interface Future<T> extends FutureOf<T>, Bindable<Future_, T> {
Future<T> mapError(Function1<? super Throwable, ? extends Throwable> mapper);

@Override
<R> Future<R> flatMap(Function1<? super T, ? extends Kind<Future_, ? extends R>> mapper);
<R> Future<R> flatMap(Function1<? super T, ? extends Kind<Future<?>, ? extends R>> mapper);

<R> Future<R> andThen(Future<? extends R> next);

Expand Down Expand Up @@ -352,7 +352,7 @@ public Future<T> mapError(Function1<? super Throwable, ? extends Throwable> mapp
}

@Override
public <R> Future<R> flatMap(Function1<? super T, ? extends Kind<Future_, ? extends R>> mapper) {
public <R> Future<R> flatMap(Function1<? super T, ? extends Kind<Future<?>, ? extends R>> mapper) {
return chain(value -> value.fold(e -> Future.failure(executor, e), mapper));
}

Expand Down Expand Up @@ -419,7 +419,7 @@ private <R> Future<R> transform(Function1<? super Try<? extends T>, ? extends Tr
promise.onComplete(value -> p.tryComplete(mapper.apply(value))), this::cancel);
}

private <R> Future<R> chain(Function1<? super Try<? extends T>, ? extends Kind<Future_, ? extends R>> mapper) {
private <R> Future<R> chain(Function1<? super Try<? extends T>, ? extends Kind<Future<?>, ? extends R>> mapper) {
checkNonNull(executor);
checkNonNull(mapper);
return new FutureImpl<>(executor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

@HigherKind
@FunctionalInterface
public non-sealed interface Par<T> extends ParOf<T>, Bindable<Par_, T> {
public non-sealed interface Par<T> extends ParOf<T>, Bindable<Par<?>, T> {

Future<T> apply(Executor executor);

Expand All @@ -46,7 +46,7 @@ default <R> Par<R> map(Function1<? super T, ? extends R> mapper) {
}

@Override
default <R> Par<R> flatMap(Function1<? super T, ? extends Kind<Par_, ? extends R>> mapper) {
default <R> Par<R> flatMap(Function1<? super T, ? extends Kind<Par<?>, ? extends R>> mapper) {
return executor -> apply(executor).flatMap(value -> mapper.andThen(ParOf::narrowK).apply(value).apply(executor));
}

Expand Down Expand Up @@ -104,7 +104,7 @@ static <T> Par<T> task(Producer<? extends T> producer) {
return executor -> Future.task(executor, producer);
}

static <T> Par<T> defer(Producer<? extends Kind<Par_, ? extends T>> producer) {
static <T> Par<T> defer(Producer<? extends Kind<Par<?>, ? extends T>> producer) {
return executor -> {
Producer<Par<T>> andThen = producer.andThen(ParOf::narrowK);
return andThen.get().apply(executor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import com.github.tonivade.purefun.type.TryOf;

@HigherKind
public sealed interface Promise<T> extends PromiseOf<T>, Bindable<Promise_, T>, Applicable<Promise_, T> permits PromiseImpl {
public sealed interface Promise<T> extends PromiseOf<T>, Bindable<Promise<?>, T>, Applicable<Promise<?>, T> permits PromiseImpl {

boolean tryComplete(Try<? extends T> value);

Expand Down Expand Up @@ -71,15 +71,15 @@ default Promise<T> onFailure(Consumer1<? super Throwable> consumer) {
<R> Promise<R> map(Function1<? super T, ? extends R> mapper);

@Override
<R> Promise<R> ap(Kind<Promise_, ? extends Function1<? super T, ? extends R>> apply);
<R> Promise<R> ap(Kind<Promise<?>, ? extends Function1<? super T, ? extends R>> apply);

@Override
default <R> Promise<R> andThen(Kind<Promise_, ? extends R> next) {
default <R> Promise<R> andThen(Kind<Promise<?>, ? extends R> next) {
return PromiseOf.narrowK(Bindable.super.andThen(next));
}

@Override
<R> Promise<R> flatMap(Function1<? super T, ? extends Kind<Promise_, ? extends R>> mapper);
<R> Promise<R> flatMap(Function1<? super T, ? extends Kind<Promise<?>, ? extends R>> mapper);

default Promise<Unit> then(Consumer1<? super T> next) {
return map(next.asFunction());
Expand Down Expand Up @@ -236,7 +236,7 @@ public Promise<T> onComplete(Consumer1<? super Try<? extends T>> consumer) {
}

@Override
public <R> Promise<R> ap(Kind<Promise_, ? extends Function1<? super T, ? extends R>> apply) {
public <R> Promise<R> ap(Kind<Promise<?>, ? extends Function1<? super T, ? extends R>> apply) {
Promise<R> result = new PromiseImpl<>(executor);
onComplete(try1 -> PromiseOf.narrowK(apply).onComplete(
try2 -> result.tryComplete(Try.map2(try2, try1, Function1::apply))));
Expand All @@ -251,7 +251,7 @@ public <R> Promise<R> map(Function1<? super T, ? extends R> mapper) {
}

@Override
public <R> Promise<R> flatMap(Function1<? super T, ? extends Kind<Promise_, ? extends R>> mapper) {
public <R> Promise<R> flatMap(Function1<? super T, ? extends Kind<Promise<?>, ? extends R>> mapper) {
Promise<R> other = new PromiseImpl<>(executor);
onComplete(value -> {
Try<Promise<R>> map = value.map(mapper.andThen(PromiseOf::narrowK));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ default <R> ImmutableArray<R> map(Function1<? super E, ? extends R> mapper) {
}

@Override
default <R> ImmutableArray<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
default <R> ImmutableArray<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return ImmutableArray.from(stream().flatMap(mapper.andThen(SequenceOf::<R>narrowK).andThen(Sequence::stream)::apply));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ default <R> ImmutableList<R> map(Function1<? super E, ? extends R> mapper) {
}

@Override
default <R> ImmutableList<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
default <R> ImmutableList<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return ImmutableList.from(stream().flatMap(mapper.andThen(SequenceOf::<R>narrowK).andThen(Sequence::stream)::apply));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ default <R> ImmutableSet<R> map(Function1<? super E, ? extends R> mapper) {
}

@Override
default <R> ImmutableSet<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
default <R> ImmutableSet<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return ImmutableSet.from(stream().flatMap(mapper.andThen(SequenceOf::narrowK).andThen(Sequence::stream)::apply));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ default <R> ImmutableTree<R> map(Comparator<? super R> comparator, Function1<? s
}

@Override
default <R> ImmutableTree<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
default <R> ImmutableTree<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return ImmutableTree.from(naturalOrder(), stream().flatMap(mapper.andThen(SequenceOf::narrowK).andThen(Sequence::stream)::apply));
}

default <R> ImmutableTree<R> flatMap(Comparator<? super R> comparator, Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
default <R> ImmutableTree<R> flatMap(Comparator<? super R> comparator, Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return ImmutableTree.from(comparator, stream().flatMap(mapper.andThen(SequenceOf::narrowK).andThen(Sequence::stream)::apply));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public <R> NonEmptyList<R> map(Function1<? super E, ? extends R> mapper) {
}

@Override
public <R> NonEmptyList<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper) {
public <R> NonEmptyList<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper) {
return of(value.flatMap(mapper));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import com.github.tonivade.purefun.type.Option;

@HigherKind
public non-sealed interface Sequence<E> extends SequenceOf<E>, Iterable<E>, Bindable<Sequence_, E> {
public non-sealed interface Sequence<E> extends SequenceOf<E>, Iterable<E>, Bindable<Sequence<?>, E> {

int size();

Expand All @@ -59,7 +59,7 @@ default boolean containsAll(Iterable<?> elements) {
<R> Sequence<R> map(Function1<? super E, ? extends R> mapper);

@Override
<R> Sequence<R> flatMap(Function1<? super E, ? extends Kind<Sequence_, ? extends R>> mapper);
<R> Sequence<R> flatMap(Function1<? super E, ? extends Kind<Sequence<?>, ? extends R>> mapper);

Sequence<E> filter(Matcher1<? super E> matcher);

Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/com/github/tonivade/purefun/type/Either.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @param <R> type of the right value, positive case
*/
@HigherKind
public sealed interface Either<L, R> extends EitherOf<L, R>, Bindable<Kind<Either_, L>, R>, Applicable<Kind<Either_, L>, R> {
public sealed interface Either<L, R> extends EitherOf<L, R>, Bindable<Kind<Either<?, ?>, L>, R>, Applicable<Kind<Either<?, ?>, L>, R> {

static <L, R> Either<L, R> left(L value) {
return new Left<>(value);
Expand Down Expand Up @@ -108,7 +108,7 @@ default <T> Either<L, T> map(Function1<? super R, ? extends T> map) {

@Override
default <T> Either<L, T> ap(
Kind<Kind<Either_, L>, ? extends Function1<? super R, ? extends T>> apply) {
Kind<Kind<Either<?, ?>, L>, ? extends Function1<? super R, ? extends T>> apply) {
return apply.fix(toEither()).flatMap(this::map);
}

Expand All @@ -118,7 +118,7 @@ default <T> Either<T, R> mapLeft(Function1<? super L, ? extends T> map) {

@Override
@SuppressWarnings("unchecked")
default <T> Either<L, T> flatMap(Function1<? super R, ? extends Kind<Kind<Either_, L>, ? extends T>> map) {
default <T> Either<L, T> flatMap(Function1<? super R, ? extends Kind<Kind<Either<?, ?>, L>, ? extends T>> map) {
if (this instanceof Right<L, R>(var right)) {
return map.andThen(EitherOf::<L, T>narrowK).apply(right);
}
Expand All @@ -144,7 +144,7 @@ default Option<Either<L, R>> filterNot(Matcher1<? super R> matcher) {
return filter(matcher.negate());
}

default Either<L, R> filterOrElse(Matcher1<? super R> matcher, Producer<? extends Kind<Kind<Either_, L>, R>> orElse) {
default Either<L, R> filterOrElse(Matcher1<? super R> matcher, Producer<? extends Kind<Kind<Either<?, ?>, L>, R>> orElse) {
if (this instanceof Left) {
return this;
}
Expand All @@ -154,14 +154,14 @@ default Either<L, R> filterOrElse(Matcher1<? super R> matcher, Producer<? extend
return orElse.andThen(EitherOf::narrowK).get();
}

default Either<L, R> or(Producer<Kind<Kind<Either_, L>, R>> orElse) {
default Either<L, R> or(Producer<Kind<Kind<Either<?, ?>, L>, R>> orElse) {
if (this instanceof Left) {
return orElse.andThen(EitherOf::narrowK).get();
}
return this;
}

default Either<L, R> orElse(Kind<Kind<Either_, L>, R> orElse) {
default Either<L, R> orElse(Kind<Kind<Either<?, ?>, L>, R> orElse) {
return or(Producer.cons(orElse));
}

Expand Down
Loading