diff --git a/README.md b/README.md index 7d84c6295..2e6aa98db 100644 --- a/README.md +++ b/README.md @@ -672,24 +672,15 @@ There are three functions that lambda provides that interface directly with lens Lenses can be easily created. Consider the following `Person` class: ```Java -public final class Person { - private final int age; +public record Person(int age) { - public Person(int age) { - this.age = age; - } - - public int getAge() { - return age; - } + public Person setAge(int age) { + return new Person(age); + } - public Person setAge(int age) { - return new Person(age); - } - - public Person setAge(LocalDate dob) { - return setAge((int) YEARS.between(dob, LocalDate.now())); - } + public Person setAge(LocalDate dob) { + return setAge((int) YEARS.between(dob, LocalDate.now())); + } } ``` diff --git a/pom.xml b/pom.xml index bae03b1e3..07e735029 100644 --- a/pom.xml +++ b/pom.xml @@ -91,8 +91,8 @@ maven-compiler-plugin ${maven-compiler-plugin.version} - 1.8 - 1.8 + 17 + 17 -Xlint:all -Werror diff --git a/src/main/java/com/jnape/palatable/lambda/adt/Maybe.java b/src/main/java/com/jnape/palatable/lambda/adt/Maybe.java index dc5595983..acb463115 100644 --- a/src/main/java/com/jnape/palatable/lambda/adt/Maybe.java +++ b/src/main/java/com/jnape/palatable/lambda/adt/Maybe.java @@ -18,7 +18,6 @@ import com.jnape.palatable.lambda.monad.MonadRec; import com.jnape.palatable.lambda.traversable.Traversable; -import java.util.Objects; import java.util.Optional; import static com.jnape.palatable.lambda.adt.Either.left; @@ -38,14 +37,12 @@ * @param the optional parameter type * @see Optional */ -public abstract class Maybe implements +public sealed interface Maybe extends CoProduct2>, MonadError>, MonadRec>, - Traversable> { + Traversable> permits Just, Nothing { - private Maybe() { - } /** * If the value is present, return it; otherwise, return the value supplied by otherSupplier. @@ -53,7 +50,7 @@ private Maybe() { * @param otherFn0 the supplier for the other value * @return this value, or the supplied other value */ - public final A orElseGet(Fn0 otherFn0) { + default A orElseGet(Fn0 otherFn0) { return match(__ -> otherFn0.apply(), id()); } @@ -63,7 +60,7 @@ public final A orElseGet(Fn0 otherFn0) { * @param other the other value * @return this value, or the other value */ - public final A orElse(A other) { + default A orElse(A other) { return orElseGet(() -> other); } @@ -76,7 +73,7 @@ public final A orElse(A other) { * @return the value, if present * @throws E the throwable, if the value is absent */ - public final A orElseThrow(Fn0 throwableSupplier) throws E { + default A orElseThrow(Fn0 throwableSupplier) throws E { return orElseGet(fn0(() -> { throw throwableSupplier.apply(); })); @@ -89,7 +86,7 @@ public final A orElseThrow(Fn0 throwableSuppl * @param predicate the predicate to apply to the possibly absent value * @return maybe the present value that satisfied the predicate */ - public final Maybe filter(Fn1 predicate) { + default Maybe filter(Fn1 predicate) { return flatMap(a -> predicate.apply(a) ? just(a) : nothing()); } @@ -97,7 +94,7 @@ public final Maybe filter(Fn1 predicate) { * {@inheritDoc} */ @Override - public Maybe throwError(Unit unit) { + default Maybe throwError(Unit unit) { return nothing(); } @@ -105,7 +102,7 @@ public Maybe throwError(Unit unit) { * {@inheritDoc} */ @Override - public Maybe catchError(Fn1>> recoveryFn) { + default Maybe catchError(Fn1>> recoveryFn) { return match(recoveryFn, Maybe::just).coerce(); } @@ -117,7 +114,7 @@ public Maybe catchError(Fn1>> recov * @param lFn0 the supplier for the left value * @return this value wrapped in an Either.right, or an Either.left around the result of lSupplier */ - public final Either toEither(Fn0 lFn0) { + default Either toEither(Fn0 lFn0) { return fmap(Either::right).orElseGet(() -> left(lFn0.apply())); } @@ -126,7 +123,7 @@ public final Either toEither(Fn0 lFn0) { * * @return the Optional */ - public final Optional toOptional() { + default Optional toOptional() { return fmap(Optional::of).orElseGet(Optional::empty); } @@ -138,7 +135,7 @@ public final Optional toOptional() { * @return Just b */ @Override - public final Maybe pure(B b) { + default Maybe pure(B b) { return just(b); } @@ -149,7 +146,7 @@ public final Maybe pure(B b) { * {@link Maybe#nothing}. */ @Override - public final Maybe fmap(Fn1 fn) { + default Maybe fmap(Fn1 fn) { return MonadError.super.fmap(fn).coerce(); } @@ -157,7 +154,7 @@ public final Maybe fmap(Fn1 fn) { * {@inheritDoc} */ @Override - public final Maybe zip(Applicative, Maybe> appFn) { + default Maybe zip(Applicative, Maybe> appFn) { return MonadError.super.zip(appFn).coerce(); } @@ -169,7 +166,7 @@ public final Maybe zip(Applicative, Maybe> * @return the zipped {@link Maybe} */ @Override - public Lazy> lazyZip(Lazy, Maybe>> lazyAppFn) { + default Lazy> lazyZip(Lazy, Maybe>> lazyAppFn) { return match(constantly(lazy(nothing())), a -> lazyAppFn.fmap(maybeF -> maybeF.fmap(f -> f.apply(a)).coerce())); } @@ -178,7 +175,7 @@ public Lazy> lazyZip(Lazy Maybe discardL(Applicative> appB) { + default Maybe discardL(Applicative> appB) { return MonadError.super.discardL(appB).coerce(); } @@ -186,7 +183,7 @@ public final Maybe discardL(Applicative> appB) { * {@inheritDoc} */ @Override - public final Maybe discardR(Applicative> appB) { + default Maybe discardR(Applicative> appB) { return MonadError.super.discardR(appB).coerce(); } @@ -195,7 +192,7 @@ public final Maybe discardR(Applicative> appB) { */ @SuppressWarnings("RedundantTypeArguments") @Override - public final Maybe flatMap(Fn1>> f) { + default Maybe flatMap(Fn1>> f) { return match(constantly(nothing()), f.fmap(Monad>::coerce)); } @@ -203,7 +200,7 @@ public final Maybe flatMap(Fn1>> f * {@inheritDoc} */ @Override - public Maybe trampolineM(Fn1, Maybe>> fn) { + default Maybe trampolineM(Fn1, Maybe>> fn) { return match(constantly(nothing()), trampoline(a -> fn.apply(a).>>coerce() .match(constantly(terminate(nothing())), aOrB -> aOrB.fmap(Maybe::just)))); @@ -213,7 +210,7 @@ public Maybe trampolineM(Fn1 Choice3 diverge() { + default Choice3 diverge() { return match(Choice3::a, Choice3::b); } @@ -221,7 +218,7 @@ public Choice3 diverge() { * {@inheritDoc} */ @Override - public Tuple2, Maybe> project() { + default Tuple2, Maybe> project() { return CoProduct2.super.project().into(HList::tuple); } @@ -229,7 +226,7 @@ public Tuple2, Maybe> project() { * {@inheritDoc} */ @Override - public Choice2 invert() { + default Choice2 invert() { return match(Choice2::b, Choice2::a); } @@ -241,13 +238,13 @@ public Choice2 invert() { * @deprecated in favor of {@link Maybe#match(Fn1, Fn1) matching} into an {@link IO} and explicitly running it */ @Deprecated - public final Maybe peek(Fn1> effect) { + default Maybe peek(Fn1> effect) { return match(constantly(io(this)), a -> effect.apply(a).fmap(constantly(this))).unsafePerformIO(); } @Override @SuppressWarnings("unchecked") - public final , TravB extends Traversable>, + default , TravB extends Traversable>, AppTrav extends Applicative> AppTrav traverse(Fn1> fn, Fn1 pure) { return match(__ -> pure.apply((TravB) Maybe.nothing()), a -> (AppTrav) fn.apply(a).fmap(Maybe::just)); @@ -261,7 +258,7 @@ AppTrav extends Applicative> AppTrav traverse(Fn1 the potential right value * @return "Just" the right value, or nothing */ - public static Maybe fromEither(Either either) { + static Maybe fromEither(Either either) { return either.toMaybe(); } @@ -272,7 +269,7 @@ public static Maybe fromEither(Either either) { * @param the optional parameter type * @return the equivalent Maybe instance */ - public static Maybe fromOptional(Optional optional) { + static Maybe fromOptional(Optional optional) { return optional.map(Maybe::just).orElse(Maybe.nothing()); } @@ -284,7 +281,7 @@ public static Maybe fromOptional(Optional optional) { * @param the value parameter type * @return "Just" the value, or nothing */ - public static Maybe maybe(A a) { + static Maybe maybe(A a) { return a == null ? nothing() : just(a); } @@ -297,7 +294,7 @@ public static Maybe maybe(A a) { * @return "Just" the value * @throws NullPointerException if a is null */ - public static Maybe just(A a) { + static Maybe just(A a) { if (a == null) throw new NullPointerException(); return new Just<>(a); @@ -310,7 +307,7 @@ public static Maybe just(A a) { * @return nothing */ @SuppressWarnings("unchecked") - public static Maybe nothing() { + static Maybe nothing() { return (Maybe) Nothing.INSTANCE; } @@ -319,53 +316,22 @@ public static Maybe nothing() { * * @return the {@link Pure} instance */ - public static Pure> pureMaybe() { + static Pure> pureMaybe() { return Maybe::just; } +} +record Nothing() implements Maybe { + static final Nothing INSTANCE = new Nothing<>(); - private static final class Nothing extends Maybe { - private static final Nothing INSTANCE = new Nothing<>(); - - private Nothing() { - } - - @Override - public R match(Fn1 aFn, Fn1 bFn) { - return aFn.apply(UNIT); - } - - @Override - public String toString() { - return "Nothing"; - } + @Override + public R match(Fn1 aFn, Fn1 bFn) { + return aFn.apply(UNIT); } +} - private static final class Just extends Maybe { - - private final A a; - - private Just(A a) { - this.a = a; - } - - @Override - public R match(Fn1 aFn, Fn1 bFn) { - return bFn.apply(a); - } - - @Override - public boolean equals(Object other) { - return other instanceof Just && Objects.equals(this.a, ((Just) other).a); - } - - @Override - public int hashCode() { - return Objects.hash(a); - } - - @Override - public String toString() { - return "Just " + a; - } +record Just(A a) implements Maybe { + @Override + public R match(Fn1 aFn, Fn1 bFn) { + return bFn.apply(a); } -} +} \ No newline at end of file diff --git a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java b/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java index 705e43bad..0dc877fcd 100644 --- a/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java +++ b/src/main/java/com/jnape/palatable/lambda/adt/hlist/HList.java @@ -263,8 +263,7 @@ public Tail tail() { @Override public final boolean equals(Object other) { - if (other instanceof HCons) { - HCons that = (HCons) other; + if (other instanceof HCons that) { return this.head.equals(that.head) && this.tail.equals(that.tail); } diff --git a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java b/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java index 62c922ece..db106f410 100644 --- a/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java +++ b/src/main/java/com/jnape/palatable/lambda/adt/hmap/HMap.java @@ -162,8 +162,7 @@ public Collection values() { @Override public boolean equals(Object other) { - if (other instanceof HMap) { - HMap that = (HMap) other; + if (other instanceof HMap that) { return Objects.equals(this.table, that.table); } return false; diff --git a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Exchange.java b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Exchange.java index f04050368..bfd861e15 100644 --- a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Exchange.java +++ b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Exchange.java @@ -12,20 +12,15 @@ * @param the larger viewing value of an {@link Iso} * @param the larger viewed value of an {@link Iso} */ -public final class Exchange implements Profunctor> { - private final Fn1 sa; - private final Fn1 bt; - - public Exchange(Fn1 sa, Fn1 bt) { - this.sa = sa; - this.bt = bt; - } +public record Exchange(Fn1 sa, + Fn1 bt) implements Profunctor> { /** * Extract the mapping S -> A. * * @return an {@link Fn1}<S, A> */ + @Override public Fn1 sa() { return sa; } @@ -35,6 +30,7 @@ public Exchange(Fn1 sa, Fn1 bt) * * @return an {@link Fn1}<B, T> */ + @Override public Fn1 bt() { return bt; } diff --git a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java index 83ec47711..6d941173d 100644 --- a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java +++ b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Lazy.java @@ -182,8 +182,7 @@ public A value() { tuple((Lazy) this, new LinkedList<>()); @SuppressWarnings("unchecked") A a = (A) trampoline(into((source, flatMaps) -> { - if (source instanceof Compose) { - Compose nested = (Compose) source; + if (source instanceof Compose nested) { flatMaps.push(nested.flatMap); return recurse(tuple(nested.source, flatMaps)); } diff --git a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Market.java b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Market.java index 3c8ce7576..f5cb2937e 100644 --- a/src/main/java/com/jnape/palatable/lambda/functor/builtin/Market.java +++ b/src/main/java/com/jnape/palatable/lambda/functor/builtin/Market.java @@ -28,13 +28,10 @@ * @param the input that might fail to map to its output * @param the guaranteed output */ -public final class Market implements +public record Market(Fn1 bt, Fn1> sta) implements MonadRec>, Cocartesian> { - private final Fn1 bt; - private final Fn1> sta; - public Market(Fn1 bt, Fn1> sta) { this.bt = fn1(bt); this.sta = fn1(sta); @@ -45,6 +42,7 @@ public Market(Fn1 bt, Fn1{@link Fn1}<B, T> */ + @Override public Fn1 bt() { return bt; } @@ -54,6 +52,7 @@ public Market(Fn1 bt, Fn1{@link Fn1}<S, {@link Either}<T, A>> */ + @Override public Fn1> sta() { return sta; } @@ -72,9 +71,9 @@ public Market pure(U u) { @Override public Market flatMap(Fn1>> f) { return new Market<>(b -> f.apply(bt().apply(b)).>coerce().bt().apply(b), - s -> sta().apply(s).invert() - .flatMap(t -> f.apply(t).>coerce().sta() - .apply(s).invert()).invert()); + s -> sta().apply(s).invert() + .flatMap(t -> f.apply(t).>coerce().sta() + .apply(s).invert()).invert()); } /** @@ -89,7 +88,7 @@ public Market trampolineM( trampoline(t -> fn.apply(t).>>coerce() .sta.apply(s) .match(tOrU -> tOrU.match(RecursiveResult::recurse, u -> terminate(left(u))), - a -> terminate(right(a)))), + a -> terminate(right(a)))), Either::right))); return new Market<>(bu, sua); } @@ -101,7 +100,7 @@ public Market trampolineM( public Market zip(Applicative, Market> appFn) { Market> marketF = appFn.coerce(); return new Market<>(b -> marketF.bt().apply(b).apply(bt().apply(b)), - s -> sta().apply(s).invert().zip(marketF.sta().apply(s).invert()).invert()); + s -> sta().apply(s).invert().zip(marketF.sta().apply(s).invert()).invert()); } /** @@ -118,8 +117,8 @@ public Market fmap(Fn1 fn) { @Override public Market, Choice2> cocartesian() { return new Market<>(bt.fmap(Choice2::b), - cs -> cs.fmap(sta).match(c -> left(a(c)), - tOrA -> tOrA.match(t -> left(b(t)), Either::right))); + cs -> cs.fmap(sta).match(c -> left(a(c)), + tOrA -> tOrA.match(t -> left(b(t)), Either::right))); } /** diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/DroppingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/DroppingIterable.java index 1d9534b17..88a1719e4 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/DroppingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/DroppingIterable.java @@ -7,8 +7,7 @@ public final class DroppingIterable implements Iterable { private final Iterable as; public DroppingIterable(int n, Iterable as) { - while (as instanceof DroppingIterable) { - DroppingIterable nested = (DroppingIterable) as; + while (as instanceof DroppingIterable nested) { as = nested.as; n += nested.n; } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/FilteringIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/FilteringIterable.java index 7accde2f8..75c4879a8 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/FilteringIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/FilteringIterable.java @@ -15,8 +15,7 @@ public final class FilteringIterable implements Iterable { public FilteringIterable(Fn1 predicate, Iterable as) { List> predicates = new ArrayList<>(singletonList(predicate)); - while (as instanceof FilteringIterable) { - FilteringIterable nested = (FilteringIterable) as; + while (as instanceof FilteringIterable nested) { predicates.addAll(0, nested.predicates); as = nested.as; } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/MappingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/MappingIterable.java index 3d2f1ba65..548fc7956 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/MappingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/MappingIterable.java @@ -16,8 +16,7 @@ public final class MappingIterable implements Iterable { @SuppressWarnings("unchecked") public MappingIterable(Fn1 fn, Iterable as) { List> mappers = new ArrayList<>(singletonList(fn)); - while (as instanceof MappingIterable) { - MappingIterable nested = (MappingIterable) as; + while (as instanceof MappingIterable nested) { as = (Iterable) nested.as; mappers.addAll(0, nested.mappers); } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedDroppingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedDroppingIterable.java index ea7b68bc7..e96310b1f 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedDroppingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedDroppingIterable.java @@ -11,8 +11,7 @@ public final class PredicatedDroppingIterable implements Iterable { public PredicatedDroppingIterable(Fn1 predicate, Iterable as) { ImmutableQueue> predicates = ImmutableQueue.singleton(predicate); - while (as instanceof PredicatedDroppingIterable) { - PredicatedDroppingIterable nested = (PredicatedDroppingIterable) as; + while (as instanceof PredicatedDroppingIterable nested) { as = nested.as; predicates = nested.predicates.concat(predicates); } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedTakingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedTakingIterable.java index de9c7682e..92d5a5a53 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedTakingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/PredicatedTakingIterable.java @@ -15,8 +15,7 @@ public final class PredicatedTakingIterable implements Iterable { public PredicatedTakingIterable(Fn1 predicate, Iterable as) { List> predicates = new ArrayList<>(singletonList(predicate)); - while (as instanceof PredicatedTakingIterable) { - PredicatedTakingIterable nested = (PredicatedTakingIterable) as; + while (as instanceof PredicatedTakingIterable nested) { predicates.addAll(0, nested.predicates); as = nested.as; } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/RateLimitingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/RateLimitingIterable.java index 3a7c856d4..fe5240dd8 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/RateLimitingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/RateLimitingIterable.java @@ -15,8 +15,7 @@ public final class RateLimitingIterable implements Iterable { public RateLimitingIterable(Iterable as, Set>> rateLimits) { Set>> combinedRateLimits = new HashSet<>(rateLimits); - if (as instanceof RateLimitingIterable) { - RateLimitingIterable inner = (RateLimitingIterable) as; + if (as instanceof RateLimitingIterable inner) { combinedRateLimits.addAll(inner.rateLimits); as = inner.as; } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/ReversingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/ReversingIterable.java index 29aff81db..46afde55d 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/ReversingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/ReversingIterable.java @@ -8,8 +8,7 @@ public final class ReversingIterable implements Iterable { public ReversingIterable(Iterable as) { boolean reverse = true; - while (as instanceof ReversingIterable) { - ReversingIterable nested = (ReversingIterable) as; + while (as instanceof ReversingIterable nested) { as = nested.as; reverse = !nested.reverse; } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/SnocIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/SnocIterable.java index 9a0118200..b43c994b6 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/SnocIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/SnocIterable.java @@ -12,8 +12,7 @@ public final class SnocIterable implements Iterable { public SnocIterable(A a, Iterable as) { Iterable snocs = cons(a, Collections::emptyIterator); - while (as instanceof SnocIterable) { - SnocIterable nested = ((SnocIterable) as); + while (as instanceof SnocIterable nested) { as = nested.as; snocs = concat(nested.snocs, snocs); } diff --git a/src/main/java/com/jnape/palatable/lambda/internal/iteration/TakingIterable.java b/src/main/java/com/jnape/palatable/lambda/internal/iteration/TakingIterable.java index f228b596a..3d153dd5e 100644 --- a/src/main/java/com/jnape/palatable/lambda/internal/iteration/TakingIterable.java +++ b/src/main/java/com/jnape/palatable/lambda/internal/iteration/TakingIterable.java @@ -9,8 +9,7 @@ public final class TakingIterable implements Iterable { private final Iterable as; public TakingIterable(int n, Iterable as) { - while (as instanceof TakingIterable) { - TakingIterable nested = (TakingIterable) as; + while (as instanceof TakingIterable nested) { n = min(n, nested.n); as = nested.as; } diff --git a/src/main/java/com/jnape/palatable/lambda/io/IO.java b/src/main/java/com/jnape/palatable/lambda/io/IO.java index 6af4dc1b1..65214986a 100644 --- a/src/main/java/com/jnape/palatable/lambda/io/IO.java +++ b/src/main/java/com/jnape/palatable/lambda/io/IO.java @@ -430,8 +430,7 @@ private Compose(IO source, Choice2, Fn1>> composition) { public A unsafePerformIO() { Lazy lazyA = LazyRec., Object>lazyRec( (f, io) -> { - if (io instanceof IO.Compose) { - Compose compose = (Compose) io; + if (io instanceof Compose compose) { Lazy head = f.apply(compose.source); return compose.composition .match(zip -> head.flatMap(x -> f.apply(zip) @@ -450,8 +449,7 @@ public A unsafePerformIO() { public CompletableFuture unsafePerformAsyncIO(Executor executor) { Lazy> lazyFuture = LazyRec., CompletableFuture>lazyRec( (f, io) -> { - if (io instanceof IO.Compose) { - Compose compose = (Compose) io; + if (io instanceof Compose compose) { Lazy> head = f.apply(compose.source); return compose.composition .match(zip -> head.flatMap(futureX -> f.apply(zip) diff --git a/src/test/java/com/jnape/palatable/lambda/optics/lenses/MapLensTest.java b/src/test/java/com/jnape/palatable/lambda/optics/lenses/MapLensTest.java index 5a97e5b4a..39c15b3e7 100644 --- a/src/test/java/com/jnape/palatable/lambda/optics/lenses/MapLensTest.java +++ b/src/test/java/com/jnape/palatable/lambda/optics/lenses/MapLensTest.java @@ -176,17 +176,9 @@ public void mappingValuesWithIsoRetainsMapStructureWithMappedValues() { assertLensLawfulness(mappingValues(iso(Integer::parseInt, Object::toString)), asList(emptyMap(), singletonMap("foo", "1"), - unmodifiableMap(new HashMap() {{ - put("foo", "1"); - put("bar", "2"); - put("baz", "3"); - }})), + Map.of("foo", "1", "bar", "2", "baz", "3")), asList(emptyMap(), singletonMap("foo", 1), - unmodifiableMap(new HashMap() {{ - put("foo", 1); - put("bar", 2); - put("baz", 3); - }}))); + Map.of("foo", 1, "bar", 2, "baz", 3))); } } \ No newline at end of file diff --git a/src/test/java/testsupport/assertion/PrismAssert.java b/src/test/java/testsupport/assertion/PrismAssert.java index 443130fb4..f10e30e87 100644 --- a/src/test/java/testsupport/assertion/PrismAssert.java +++ b/src/test/java/testsupport/assertion/PrismAssert.java @@ -59,29 +59,19 @@ private static Maybe falsify(String label, Fn2 l, Fn2 .apply(cases); } - private static final class PrismResult { - private final Maybe maybeS; - - private PrismResult(Maybe maybeS) { - this.maybeS = maybeS; - } + private record PrismResult(Maybe maybeS) { @Override - public boolean equals(Object other) { - if (other instanceof PrismResult) { - return maybeS.zip(((PrismResult) other).maybeS.fmap(fn2(Objects::equals))).orElse(true); + public boolean equals(Object other) { + if (other instanceof PrismResult) { + return maybeS.zip(((PrismResult) other).maybeS.fmap(fn2(Objects::equals))).orElse(true); + } + return false; } - return false; - } - - @Override - public int hashCode() { - return Objects.hash(maybeS); - } @Override - public String toString() { - return maybeS.toString(); + public String toString() { + return maybeS.toString(); + } } - } }