Skip to content

Commit

Permalink
make it compile
Browse files Browse the repository at this point in the history
  • Loading branch information
tonivade committed Jun 22, 2024
1 parent 95a8138 commit 37b9683
Show file tree
Hide file tree
Showing 95 changed files with 352 additions and 491 deletions.

This file was deleted.

2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ dependencies {
jacocoAggregation projects.purefunInstances
jacocoAggregation projects.purefunMonad
jacocoAggregation projects.purefunOptics
jacocoAggregation projects.purefunProcessor
jacocoAggregation projects.purefunStream
jacocoAggregation projects.purefunTransformer
jacocoAggregation projects.purefunTypeclasses
Expand All @@ -31,7 +30,6 @@ dependencies {
testReportAggregation projects.purefunInstances
testReportAggregation projects.purefunMonad
testReportAggregation projects.purefunOptics
testReportAggregation projects.purefunProcessor
testReportAggregation projects.purefunStream
testReportAggregation projects.purefunTransformer
testReportAggregation projects.purefunTypeclasses
Expand Down
1 change: 0 additions & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

dependencies {
annotationProcessor projects.purefunProcessor
api projects.purefunAnnotation
api libs.pcollections
testImplementation libs.assertj
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.core.Bindable;
import com.github.tonivade.purefun.core.CheckedRunnable;
Expand All @@ -32,7 +31,6 @@
import com.github.tonivade.purefun.data.ImmutableList;
import com.github.tonivade.purefun.data.Sequence;
import com.github.tonivade.purefun.type.Try;
import com.github.tonivade.purefun.type.TryOf;

/**
* <p>This type is an abstraction of a computation executed in another thread. To run the computation an {@code Executor}
Expand Down Expand Up @@ -66,8 +64,7 @@
* @see Try
* @see Promise
*/
@HigherKind
public sealed interface Future<T> extends FutureOf<T>, Bindable<Future<?>, T> {
public sealed interface Future<T> extends Kind<Future<?>, T>, Bindable<Future<?>, T> {

Executor DEFAULT_EXECUTOR = Executors.newVirtualThreadPerTaskExecutor();

Expand Down Expand Up @@ -382,7 +379,7 @@ public Future<T> orElse(Future<? extends T> other) {
@Override
public <X extends Throwable> Future<T> recoverWith(Class<X> type, Function1<? super X, ? extends T> mapper) {
return transform(value -> {
Try<T> try1 = TryOf.toTry(value);
Try<T> try1 = value.fix();
return try1.recoverWith(type, mapper);
});
}
Expand Down Expand Up @@ -424,7 +421,7 @@ private <R> Future<R> chain(Function1<? super Try<? extends T>, ? extends Kind<F
checkNonNull(mapper);
return new FutureImpl<>(executor,
(p, c) ->
promise.onComplete(value -> mapper.andThen(FutureOf::<R>toFuture).apply(value).onComplete(p::tryComplete)), this::cancel);
promise.onComplete(value -> mapper.apply(value).<Future<R>>fix().onComplete(p::tryComplete)), this::cancel);
}

static <T> Future<T> sync(Executor executor, Try<? extends T> result) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.core.Applicable;
import com.github.tonivade.purefun.core.Bindable;
Expand All @@ -32,10 +31,8 @@
import com.github.tonivade.purefun.core.Unit;
import com.github.tonivade.purefun.type.Option;
import com.github.tonivade.purefun.type.Try;
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 Kind<Promise<?>, T>, Bindable<Promise<?>, T>, Applicable<Promise<?>, T> permits PromiseImpl {

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

Expand Down Expand Up @@ -75,7 +72,7 @@ default Promise<T> onFailure(Consumer1<? super Throwable> consumer) {

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

@Override
Expand Down Expand Up @@ -238,7 +235,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) {
Promise<R> result = new PromiseImpl<>(executor);
onComplete(try1 -> PromiseOf.toPromise(apply).onComplete(
onComplete(try1 -> apply.<Promise<Function1<T, R>>>fix().onComplete(
try2 -> result.tryComplete(Try.map2(try2, try1, Function1::apply))));
return result;
}
Expand All @@ -254,7 +251,7 @@ public <R> Promise<R> map(Function1<? super T, ? 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::toPromise));
Try<Promise<R>> map = value.map(mapper).fix();
map.fold(
error -> other.tryComplete(Try.failure(error)),
next -> next.onComplete(other::tryComplete));
Expand All @@ -276,9 +273,9 @@ private Option<Try<T>> current(Consumer1<? super Try<? extends T>> consumer) {
return Option.of(safeGet());
}

@SuppressWarnings("NullAway")
@SuppressWarnings({ "NullAway", "unchecked" })
private Try<T> safeGet() {
return TryOf.toTry(reference.get());
return (Try<T>) reference.get();
}

private void set(Try<? extends T> value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package com.github.tonivade.purefun.core;

import static com.github.tonivade.purefun.data.Sequence.listOf;

import java.util.Optional;
import java.util.stream.Stream;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.concurrent.Future;
import com.github.tonivade.purefun.data.Sequence;
import com.github.tonivade.purefun.type.Either;
Expand All @@ -23,9 +24,8 @@
* @param <A> type of function parameter
* @param <R> type of return value
*/
@HigherKind
@FunctionalInterface
public non-sealed interface Function1<A, R> extends Function1Of<A, R>, Recoverable {
public interface Function1<A, R> extends Kind<Function1<A, ?>, R>, Recoverable {

default R apply(A value) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
package com.github.tonivade.purefun.core;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.type.Either;
import com.github.tonivade.purefun.type.Option;
import com.github.tonivade.purefun.type.Try;
Expand All @@ -14,9 +14,8 @@
* but with additional functionality like the ability to memoize the result.
* @param <T> the returned type
*/
@HigherKind
@FunctionalInterface
public non-sealed interface Producer<T> extends ProducerOf<T>, Recoverable {
public interface Producer<T> extends Kind<Producer<?>, T>, Recoverable {

default T get() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import static com.github.tonivade.purefun.core.Precondition.checkNonNull;
import java.util.stream.Stream;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;

@HigherKind
public sealed interface Trampoline<T> extends TrampolineOf<T>, Bindable<Trampoline<?>, T> {
public sealed interface Trampoline<T> extends Kind<Trampoline<?>, T>, Bindable<Trampoline<?>, T> {

@Override
default <R> Trampoline<R> map(Function1<? super T, ? extends R> map) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import java.io.Serializable;
import java.util.Objects;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.data.Sequence;

@HigherKind
public final class Tuple1<A> implements Tuple, Tuple1Of<A>, Serializable {
public final class Tuple1<A> implements Tuple, Kind<Tuple1<?>, A>, Serializable {

@Serial
private static final long serialVersionUID = 6343431593011527978L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import java.io.Serializable;
import java.util.Objects;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.data.Sequence;

@HigherKind
public final class Tuple2<A, B> implements Tuple, Tuple2Of<A, B>, Serializable {
public final class Tuple2<A, B> implements Tuple, Serializable {

@Serial
private static final long serialVersionUID = 5034828839532504174L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,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) {
return ImmutableArray.from(stream().flatMap(mapper.andThen(SequenceOf::toSequence).andThen(Sequence::stream)::apply));
return ImmutableArray.from(stream().flatMap(e -> mapper.apply(e).<Sequence<R>>fix().stream()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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) {
return ImmutableList.from(stream().flatMap(mapper.andThen(SequenceOf::toSequence).andThen(Sequence::stream)::apply));
return ImmutableList.from(stream().flatMap(e -> mapper.apply(e).<Sequence<R>>fix().stream()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,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) {
return ImmutableSet.from(stream().flatMap(mapper.andThen(SequenceOf::toSequence).andThen(Sequence::stream)::apply));
return ImmutableSet.from(stream().flatMap(e -> mapper.apply(e).<Sequence<R>>fix().stream()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,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) {
return ImmutableTree.from(naturalOrder(), stream().flatMap(mapper.andThen(SequenceOf::toSequence).andThen(Sequence::stream)::apply));
return ImmutableTree.from(naturalOrder(), stream().flatMap(e -> mapper.apply(e).<Sequence<R>>fix().stream()));
}

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::toSequence).andThen(Sequence::stream)::apply));
return ImmutableTree.from(comparator, stream().flatMap(e -> mapper.apply(e).<Sequence<R>>fix().stream()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.core.Bindable;
import com.github.tonivade.purefun.core.Function1;
Expand All @@ -32,8 +31,7 @@
import com.github.tonivade.purefun.core.Tuple2;
import com.github.tonivade.purefun.type.Option;

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

int size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@

import java.io.Serializable;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;

@HigherKind
public record Const<T, A>(T value) implements ConstOf<T, A>, Serializable {
public record Const<T, A>(T value) implements Kind<Const<T, ?>, A>, Serializable {

public Const {
checkNonNull(value);
Expand Down
10 changes: 4 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 @@ -12,7 +12,6 @@
import java.util.NoSuchElementException;
import java.util.stream.Stream;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.Nullable;
import com.github.tonivade.purefun.core.Applicable;
Expand All @@ -37,8 +36,7 @@
* @param <L> type of the left value, negative case
* @param <R> type of the right value, positive case
*/
@HigherKind
public sealed interface Either<L, R> extends EitherOf<L, R>, Bindable<Either<L, ?>, R>, Applicable<Either<L, ?>, R> {
public sealed interface Either<L, R> extends Kind<Either<L, ?>, R>, Bindable<Either<L, ?>, R>, Applicable<Either<L, ?>, R> {

static <L, R> Either<L, R> left(L value) {
return new Left<>(value);
Expand Down Expand Up @@ -119,7 +117,7 @@ default <T> Either<T, R> mapLeft(Function1<? super L, ? extends T> map) {
@SuppressWarnings("unchecked")
default <T> Either<L, T> flatMap(Function1<? super R, ? extends Kind<Either<L, ?>, ? extends T>> map) {
if (this instanceof Right<L, R>(var right)) {
return map.andThen(EitherOf::<L, T>toEither).apply(right);
return map.apply(right).fix();
}
return (Either<L, T>) this;
}
Expand Down Expand Up @@ -150,12 +148,12 @@ default Either<L, R> filterOrElse(Matcher1<? super R> matcher, Producer<? extend
if (this instanceof Right<L, R>(var right) && matcher.match(right)) {
return this;
}
return orElse.andThen(EitherOf::toEither).get();
return orElse.get().fix();
}

default Either<L, R> or(Producer<Kind<Either<L, ?>, R>> orElse) {
if (this instanceof Left) {
return orElse.andThen(EitherOf::toEither).get();
return orElse.get().fix();
}
return this;
}
Expand Down
8 changes: 3 additions & 5 deletions core/src/main/java/com/github/tonivade/purefun/type/Eval.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.ArrayDeque;
import java.util.Deque;

import com.github.tonivade.purefun.HigherKind;
import com.github.tonivade.purefun.Kind;
import com.github.tonivade.purefun.core.Bindable;
import com.github.tonivade.purefun.core.Function1;
Expand All @@ -29,8 +28,7 @@
* </ul>
* @param <A> result of the computation
*/
@HigherKind
public sealed interface Eval<A> extends EvalOf<A>, Bindable<Eval<?>, A> {
public sealed interface Eval<A> extends Kind<Eval<?>, A>, Bindable<Eval<?>, A> {

Eval<Boolean> TRUE = now(true);
Eval<Boolean> FALSE = now(false);
Expand Down Expand Up @@ -142,11 +140,11 @@ public <R> Eval<R> flatMap(Function1<? super B, ? extends Kind<Eval<?>, ? extend
}

private Eval<A> start() {
return EvalOf.toEval(start.get());
return start.get().fix();
}

private Eval<B> run(A value) {
Function1<? super A, Eval<B>> andThen = run.andThen(EvalOf::toEval);
Function1<? super A, Eval<B>> andThen = run.fix();
return andThen.apply(value);
}

Expand Down
Loading

0 comments on commit 37b9683

Please sign in to comment.