From 5c6a4d19c5bc74c4a5838dc643c3cc63a5560371 Mon Sep 17 00:00:00 2001 From: mrbackend Date: Sat, 27 Feb 2016 00:42:55 +0100 Subject: [PATCH 001/336] #235 fj.test.Gen.pick is broken --- quickcheck/src/main/java/fj/test/Gen.java | 237 +++++++++++++++--- quickcheck/src/test/java/fj/test/TestGen.java | 190 ++++++++++++++ 2 files changed, 396 insertions(+), 31 deletions(-) create mode 100644 quickcheck/src/test/java/fj/test/TestGen.java diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 9ff45dfe..2bac9cfc 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -1,25 +1,28 @@ package fj.test; -import static fj.Bottom.error; -import fj.Effect; import fj.F; import fj.Function; -import static fj.Function.flip; -import static fj.Function.curry; import fj.P2; -import static fj.P2.__1; import fj.Unit; -import fj.F2; -import static fj.data.Array.array; +import fj.control.Trampoline; +import fj.data.Array; import fj.data.List; -import static fj.data.List.nil; -import static fj.data.List.replicate; import fj.data.Option; import fj.function.Effect1; +import static fj.Bottom.error; +import static fj.Function.curry; +import static fj.Function.flip; import static fj.Monoid.intAdditionMonoid; import static fj.Ord.intOrd; - +import static fj.P.lazy; +import static fj.P2.__1; +import static fj.control.Trampoline.pure; +import static fj.control.Trampoline.suspend; +import static fj.data.Array.array; +import static fj.data.List.cons; +import static fj.data.List.nil; +import static fj.data.List.replicate; import static java.lang.Math.max; import static java.lang.Math.min; @@ -564,43 +567,215 @@ public static Gen> listOf1(final Gen g) { * Returns a generator of lists that picks the given number of elements from the given list. If * the given number is less than zero or greater than the length of the given list, then the * returned generator will never produce a value. + *

+ * Note: pick is synonymous with pickCombinationWithoutReplacement + * + * @param n The number of elements to pick from the given list. + * @param as The list from which to pick elements. + * @return A generator of lists that picks the given number of elements from the given list. + */ + @Deprecated + public static Gen> pick(int n, List as) { + return pickCombinationWithoutReplacement(n, as); + } + + /** + * Returns a generator of lists that picks the given number of elements from the given list. The selection is + * a combination without replacement of elements from the given list, i.e. + *

+ *

+ * If the given number is less than zero or greater than the length of the given list, then the + * returned generator will never produce a value. * * @param n The number of elements to pick from the given list. * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. */ - public static Gen> pick(final int n, final List as) { - return n < 0 || n > as.length() ? Gen.>fail() : sequenceN(n, choose(0, as.length() - 1)).map(new F, List>() { - public List f(final List is) { - List r = nil(); + public static Gen> pickCombinationWithoutReplacement(int n, List as) { + int aLength = as.length(); + return ((n >= 0) && (n <= aLength)) ? + parameterised(s -> r -> { + final class Tramp { + + // Picks elements in constant stack space + private Trampoline> tramp(List remainAs, int remainN, int remainALength) { + return suspend(lazy(() -> + (remainN == 0) ? + // We have picked N elements; stop + pure(nil()) : + // For M remaining elements of which N will be picked, pick remainAs.head() with probability N/M + (r.choose(0, remainALength - 1) < remainN) ? + tramp(remainAs.tail(), remainN - 1, remainALength - 1) + .map(pickedTail -> cons(remainAs.head(), pickedTail)) : + tramp(remainAs.tail(), remainN, remainALength - 1))); + } - List iis = is.sort(intOrd); - List> aas = as.zipIndex(); + } + return value(new Tramp().tramp(as, n, aLength).run()); + }) : + fail(); + } - //noinspection ForLoopWithMissingComponent - for(; iis.isNotEmpty() && aas.isNotEmpty(); aas = aas.tail()) - if(iis.head().equals(aas.head()._2())) - iis = iis.tail(); - else - r = r.snoc(aas.head()._1()); + /** + * Returns a generator of lists that picks the given number of elements from the given list. The selection is + * a combination with replacement of elements from the given list, i.e. + *

+ *

+ * If the given number is less than zero, then the returned generator will never produce a value. Note that, + * with replacement, the given number may be larger than the length of the given list. + * + * @param n The number of elements to pick from the given list. + * @param as The list from which to pick elements. + * @return A generator of lists that picks the given number of elements from the given list. + */ + public static Gen> pickCombinationWithReplacement(int n, List as) { + Array aArr = as.toArray(); + return (n >= 0) ? + pick(indexPermutation(n, aArr.length()).map(indexes -> indexes.sort(intOrd)), aArr) : + fail(); + } - return r; - } - }); + /** + * Returns a generator of lists that picks the given number of elements from the given list. The selection is + * a permutation without replacement of elements from the given list, i.e. + *

+ *

+ * If the given number is less than zero or greater than the length of the given list, then the + * returned generator will never produce a value. + * + * @param n The number of elements to pick from the given list. + * @param as The list from which to pick elements. + * @return A generator of lists that picks the given number of elements from the given list. + */ + public static Gen> pickPermutationWithoutReplacement(int n, List as) { + return parameterised(s -> r -> + pickCombinationWithoutReplacement(n, as).map(combination -> { + // Shuffle combination using the Fisher-Yates algorithm + Array aArr = combination.toArray(); + int length = aArr.length(); + for (int i = length - 1; i > 0; --i) { + int j = r.choose(0, i); + A tmp = aArr.get(i); + aArr.set(i, aArr.get(j)); + aArr.set(j, tmp); + } + return aArr.toList(); + })); + } + + /** + * Returns a generator of lists that picks the given number of elements from the given list. The selection is + * a permutation with replacement of elements from the given list, i.e. + *

+ *

+ * If the given number is less than zero, then the returned generator will never produce a value. Note that, + * with replacement, the given number may be larger than the length of the given list. + * + * @param n The number of elements to pick from the given list. + * @param as The list from which to pick elements. + * @return A generator of lists that picks the given number of elements from the given list. + */ + public static Gen> pickPermutationWithReplacement(int n, List as) { + Array aArr = as.toArray(); + return (n >= 0) ? + pick(indexPermutation(n, aArr.length()), aArr) : + fail(); + } + + private static Gen> indexPermutation(int n, int m) { + return sequenceN(n, choose(0, m - 1)); + } + + private static Gen> pick(Gen> indexesGen, Array as) { + return indexesGen.map(indexes -> + indexes.foldLeft((acc, index) -> cons(as.get(index), acc), List.nil()).reverse()); } /** * Returns a generator of lists that produces some of the values of the given list. + *

+ * Note: someOf is synonymous with someCombinationWithoutReplacementOf * * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ - public static Gen> someOf(final List as) { - return choose(0, as.length()).bind(new F>>() { - public Gen> f(final Integer i) { - return pick(i, as); - } - }); + @Deprecated + public static Gen> someOf(List as) { + return someCombinationWithoutReplacementOf(as); + } + + /** + * Returns a generator of lists that produces some of the values of the given list. The selection is + * a combination without replacement of elements from the given list, i.e. + *

+ * + * @param as The list from which to pick values. + * @return A generator of lists that produces some of the values of the given list. + */ + public static Gen> someCombinationWithoutReplacementOf(List as) { + return choose(0, as.length()).bind(n -> pickCombinationWithoutReplacement(n, as)); + } + + /** + * Returns a generator of lists that produces some of the values of the given list. The selection is + * a combination with replacement of elements from the given list, i.e. + * + * + * @param maxLength The maximum length of a generated list + * @param as The list from which to pick values. + * @return A generator of lists that produces some of the values of the given list. + */ + public static Gen> someCombinationWithReplacementOf(int maxLength, List as) { + return choose(0, maxLength).bind(n -> pickCombinationWithReplacement(n, as)); + } + + /** + * Returns a generator of lists that produces some of the values of the given list. The selection is + * a permutation without replacement of elements from the given list, i.e. + * + * + * @param as The list from which to pick values. + * @return A generator of lists that produces some of the values of the given list. + */ + public static Gen> somePermutationWithoutReplacementOf(List as) { + return choose(0, as.length()).bind(n -> pickPermutationWithoutReplacement(n, as)); + } + + /** + * Returns a generator of lists that produces some of the values of the given list. The selection is + * a permutation with replacement of elements from the given list, i.e. + * + * + * @param maxLength The maximum length of a generated list + * @param as The list from which to pick values. + * @return A generator of lists that produces some of the values of the given list. + */ + public static Gen> somePermutationWithReplacementOf(int maxLength, List as) { + return choose(0, maxLength).bind(n -> pickPermutationWithReplacement(n, as)); } /** diff --git a/quickcheck/src/test/java/fj/test/TestGen.java b/quickcheck/src/test/java/fj/test/TestGen.java new file mode 100644 index 00000000..5db6759c --- /dev/null +++ b/quickcheck/src/test/java/fj/test/TestGen.java @@ -0,0 +1,190 @@ +package fj.test; + +import fj.data.List; +import fj.function.Effect1; +import org.junit.Test; + +import static fj.Ord.charOrd; +import static fj.data.List.list; +import static fj.data.List.range; +import static fj.test.Gen.pickCombinationWithReplacement; +import static fj.test.Gen.pickCombinationWithoutReplacement; +import static fj.test.Gen.pickPermutationWithReplacement; +import static fj.test.Gen.pickPermutationWithoutReplacement; +import static fj.test.Rand.standard; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public final class TestGen { + + private static final List AS = list('A', 'B', 'C'); + + @Test + public void testPickCombinationWithoutReplacement_none() { + Gen> instance = pickCombinationWithoutReplacement(0, AS); + testPick(100, instance, actual -> { + assertTrue(actual.isEmpty()); + }); + } + + @Test + public void testPickCombinationWithoutReplacement_one() { + Gen> instance = pickCombinationWithoutReplacement(1, AS); + testPick(100, instance, actual -> { + assertEquals(1, actual.length()); + assertTrue(AS.exists(a -> a.equals(actual.head()))); + }); + } + + @Test + public void testPickCombinationWithoutReplacement_two() { + Gen> instance = pickCombinationWithoutReplacement(2, AS); + testPick(100, instance, actual -> { + assertEquals(2, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> charOrd.isGreaterThan(a, l.head())))); + }); + } + + @Test + public void testPickCombinationWithoutReplacement_three() { + Gen> instance = pickCombinationWithoutReplacement(3, AS); + testPick(100, instance, actual -> { + assertEquals(3, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> charOrd.isGreaterThan(a, l.head())))); + }); + } + + @Test + public void testPickCombinationWithReplacement_none() { + Gen> instance = pickCombinationWithReplacement(0, AS); + testPick(100, instance, actual -> { + assertTrue(actual.isEmpty()); + }); + } + + @Test + public void testPickCombinationWithReplacement_one() { + Gen> instance = pickCombinationWithReplacement(1, AS); + testPick(100, instance, actual -> { + assertEquals(1, actual.length()); + assertTrue(AS.exists(a -> a.equals(actual.head()))); + }); + } + + @Test + public void testPickCombinationWithReplacement_two() { + Gen> instance = pickCombinationWithReplacement(2, AS); + testPick(100, instance, actual -> { + assertEquals(2, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !charOrd.isLessThan(a, l.head())))); + }); + } + + @Test + public void testPickCombinationWithReplacement_three() { + Gen> instance = pickCombinationWithReplacement(3, AS); + testPick(100, instance, actual -> { + assertEquals(3, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !charOrd.isLessThan(a, l.head())))); + }); + } + + @Test + public void testPickCombinationWithReplacement_four() { + Gen> instance = pickCombinationWithReplacement(4, AS); + testPick(100, instance, actual -> { + assertEquals(4, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !charOrd.isLessThan(a, l.head())))); + }); + } + + @Test + public void testPickPermutationWithoutReplacement_none() { + Gen> instance = pickPermutationWithoutReplacement(0, AS); + testPick(100, instance, actual -> { + assertTrue(actual.isEmpty()); + }); + } + + @Test + public void testPickPermutationWithoutReplacement_one() { + Gen> instance = pickPermutationWithoutReplacement(1, AS); + testPick(100, instance, actual -> { + assertEquals(1, actual.length()); + assertTrue(AS.exists(a -> a.equals(actual.head()))); + }); + } + + @Test + public void testPickPermutationWithoutReplacement_two() { + Gen> instance = pickCombinationWithoutReplacement(2, AS); + testPick(100, instance, actual -> { + assertEquals(2, actual.length()); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !a.equals(l.head())))); + }); + } + + @Test + public void testPickPermutationWithoutReplacement_three() { + Gen> instance = pickPermutationWithoutReplacement(3, AS); + testPick(100, instance, actual -> { + assertEquals(3, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !a.equals(l.head())))); + }); + } + + @Test + public void testPickPermutationWithReplacement_none() { + Gen> instance = pickPermutationWithReplacement(0, AS); + testPick(100, instance, actual -> { + assertTrue(actual.isEmpty()); + }); + } + + @Test + public void testPickPermutationWithReplacement_one() { + Gen> instance = pickPermutationWithReplacement(1, AS); + testPick(100, instance, actual -> { + assertEquals(1, actual.length()); + assertTrue(AS.exists(a -> a.equals(actual.head()))); + }); + } + + @Test + public void testPickPermutationWithReplacement_two() { + Gen> instance = pickPermutationWithReplacement(2, AS); + testPick(100, instance, actual -> { + assertEquals(2, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + }); + } + + @Test + public void testPickPermutationWithReplacement_three() { + Gen> instance = pickPermutationWithReplacement(3, AS); + testPick(100, instance, actual -> { + assertEquals(3, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + }); + } + + @Test + public void testPickPermutationWithReplacement_four() { + Gen> instance = pickPermutationWithReplacement(4, AS); + testPick(100, instance, actual -> { + assertEquals(4, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + }); + } + + private static void testPick(int n, Gen> instance, Effect1> test) { + range(0, n).map(i -> instance.gen(0, standard)).foreachDoEffect(test::f); + } + +} From 498e59b11dd9a9090c3b766bff3815645bd31ba2 Mon Sep 17 00:00:00 2001 From: mrbackend Date: Fri, 4 Mar 2016 03:23:34 +0100 Subject: [PATCH 002/336] fj.test.Rand.reseed() is broken (#237) --- .../src/main/java/fj/test/Property.java | 14 +- quickcheck/src/main/java/fj/test/Rand.java | 136 ++++++++++++------ .../src/test/java/fj/test/TestRand.java | 17 +++ 3 files changed, 113 insertions(+), 54 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 232911bd..18baccc3 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -184,7 +184,7 @@ else if (x.isFalsified()) { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator} and the given + * Checks this property using a {@link Rand#standard standard random generator} and the given * arguments to produce a result. * * @param minSuccessful The minimum number of successful tests before a result is reached. @@ -226,7 +226,7 @@ public CheckResult check(final Rand r, final int minSize, final int maxSize) { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, 100 minimum + * Checks this property using a {@link Rand#standard standard random generator}, 100 minimum * successful checks, 500 maximum discarded tests and the given arguments to produce a result. * * @param minSize The minimum size to use for checking. @@ -239,7 +239,7 @@ public CheckResult check(final int minSize, } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, 100 minimum + * Checks this property using a {@link Rand#standard standard random generator}, 100 minimum * successful checks, 500 maximum discarded tests, minimum size of 0, maximum size of 100. * * @return A result after checking this property. @@ -249,7 +249,7 @@ public CheckResult check() { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, the given minimum + * Checks this property using a {@link Rand#standard standard random generator}, the given minimum * successful checks, 500 maximum discarded tests, minimum size of 0, maximum size of 100. * * @param minSuccessful The minimum number of successful tests before a result is reached. @@ -272,7 +272,7 @@ public CheckResult minSuccessful(final Rand r, final int minSuccessful) { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, 100 minimum + * Checks this property using a {@link Rand#standard standard random generator}, 100 minimum * successful checks, the given maximum discarded tests, minimum size of 0, maximum size of 100. * * @param maxDiscarded The maximum number of tests discarded because they did not satisfy @@ -297,7 +297,7 @@ public CheckResult maxDiscarded(final Rand r, final int maxDiscarded) { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, 100 minimum + * Checks this property using a {@link Rand#standard standard random generator}, 100 minimum * successful checks, 500 maximum discarded tests, the given minimum size, maximum size of 100. * * @param minSize The minimum size to use for checking. @@ -320,7 +320,7 @@ public CheckResult minSize(final Rand r, final int minSize) { } /** - * Checks this property using a {@link Rand#Rand(F, F) standard random generator}, 100 minimum + * Checks this property using a {@link Rand#standard standard random generator}, 100 minimum * successful checks, 500 maximum discarded tests, minimum size of 0, the given maximum size. * * @param maxSize The maximum size to use for checking. diff --git a/quickcheck/src/main/java/fj/test/Rand.java b/quickcheck/src/main/java/fj/test/Rand.java index 500d04eb..567dba77 100644 --- a/quickcheck/src/main/java/fj/test/Rand.java +++ b/quickcheck/src/main/java/fj/test/Rand.java @@ -2,11 +2,13 @@ import fj.F; import fj.data.Option; -import static fj.data.Option.some; +import java.util.Random; + +import static fj.data.Option.none; +import static fj.data.Option.some; import static java.lang.Math.max; import static java.lang.Math.min; -import java.util.Random; /** * A random number generator. @@ -17,9 +19,17 @@ public final class Rand { private final F, F>> f; private final F, F>> g; - private Rand(final F, F>> f, final F, F>> g) { + // TODO Change to F when rand(f,g) is removed + private final Option> optOnReseed; + + private Rand( + F, F>> f, + F, F>> g, + Option> optOnReseed) { + this.f = f; this.g = g; + this.optOnReseed = optOnReseed; } /** @@ -74,65 +84,97 @@ public double choose(final double from, final double to) { * @param seed The seed of the new random generator. * @return A random generator with the given seed. */ - public Rand reseed(final long seed) { - return new Rand(new F, F>>() { - public F> f(final Option old) { - return new F>() { - public F f(final Integer from) { - return new F() { - public Integer f(final Integer to) { - return f.f(some(seed)).f(from).f(to); - } - }; - } - }; - } - }, new F, F>>() { - public F> f(final Option old) { - return new F>() { - public F f(final Double from) { - return new F() { - public Double f(final Double to) { - return g.f(some(seed)).f(from).f(to); - } - }; - } - }; - } - }); + public Rand reseed(long seed) { + return optOnReseed.option( + () -> { + throw new IllegalStateException("reseed() called on a Rand created with deprecated rand() method"); + }, + onReseed -> onReseed.f(seed)); } /** * Constructs a random generator from the given functions that supply a range to produce a * result. + *

+ * Calling {@link #reseed(long)} on an instance returned from this method will + * result in an exception being thrown. Use {@link #rand(F, F, F)} instead. * * @param f The integer random generator. * @param g The floating-point random generator. * @return A random generator from the given functions that supply a range to produce a result. */ - public static Rand rand(final F, F>> f, final F, F>> g) { - return new Rand(f, g); + // TODO Change Option> optOnReseed to F onReseed when removing this method + @Deprecated + public static Rand rand( + F, F>> f, + F, F>> g) { + + return new Rand(f, g, none()); } + /** + * Constructs a reseedable random generator from the given functions that supply a range to produce a + * result. + * + * @param f The integer random generator. + * @param g The floating-point random generator. + * @param onReseed Function to create a reseeded Rand. + * @return A random generator from the given functions that supply a range to produce a result. + */ + public static Rand rand( + F, F>> f, + F, F>> g, + F onReseed) { - private static final F fr = new F() { - public Random f(final Long x) { - return new Random(x); - } - }; + return new Rand(f, g, some(onReseed)); + } /** * A standard random generator that uses {@link Random}. */ - public static final Rand standard = new Rand(seed -> from -> to -> { - final int min = min(from, to); - final int max = max(from, to); - final Random random = seed.map(fr).orSome(new Random()); - return (int) ((random.nextLong() & Long.MAX_VALUE) % (1L + max - min)) + min; - }, seed -> from -> to -> { - final double min = min(from, to); - final double max = max(from, to); - final Random random = seed.map(fr).orSome(new Random()); - return random.nextDouble() * (max - min) + min; - }); + public static final Rand standard = createStandard(new Random()); + + private static Rand createStandard(Random defaultRandom) { + return rand( + optSeed -> from -> to -> + standardChooseInt(optSeed.option(() -> defaultRandom, Random::new), from, to), + optSeed -> from -> to -> + standardChooseDbl(optSeed.option(() -> defaultRandom, Random::new), from, to), + newSeed -> createStandard(new Random(newSeed))); + } + + /* + * Returns a uniformly distributed value between min(from,to) (inclusive) and max(from,to) (inclusive). + */ + private static int standardChooseInt(Random random, int from, int to) { + int result; + if (from != to) { + int min = min(from, to); + int max = max(from, to); + long range = (1L + max) - min; + long bound = Long.MAX_VALUE - (Long.MAX_VALUE % range); + long r = random.nextLong() & Long.MAX_VALUE; + while (r >= bound) { + // Ensure uniformity + r = random.nextLong() & Long.MAX_VALUE; + } + result = (int) ((r % range) + min); + } else { + result = from; + } + return result; + } + + /* + * Returns a uniformly distributed value between min(from,to) (inclusive) and max(from,to) (exclusive) + * + * In theory, this differs from the choose() contract, which specifies a closed interval. + * In practice, the difference shouldn't matter. + */ + private static double standardChooseDbl(Random random, double from, double to) { + double min = min(from, to); + double max = max(from, to); + return ((max - min) * random.nextDouble()) + min; + } + } diff --git a/quickcheck/src/test/java/fj/test/TestRand.java b/quickcheck/src/test/java/fj/test/TestRand.java index 9df9639a..6c72b3b1 100644 --- a/quickcheck/src/test/java/fj/test/TestRand.java +++ b/quickcheck/src/test/java/fj/test/TestRand.java @@ -1,7 +1,10 @@ package fj.test; +import fj.Equal; import fj.Ord; +import fj.data.List; import fj.data.Stream; +import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.assertTrue; @@ -21,4 +24,18 @@ public void testRandLowHighInclusive() { assertTrue(s.head() == min && s.last() == max); } + @Test + public void testReseed() { + Rand rand1 = Rand.standard.reseed(42); + List s1 = + List.range(0, 10).map(i -> rand1.choose(Integer.MIN_VALUE, Integer.MAX_VALUE)); + + Rand rand2 = rand1.reseed(42); + List s2 = + List.range(0, 10).map(i -> rand2.choose(Integer.MIN_VALUE, Integer.MAX_VALUE)); + + assertTrue(s1.zip(s2).forall(p -> p._1().equals(p._2()))); + Assert.assertFalse(s1.allEqual(Equal.intEqual)); + } + } From 3548db113244002b619dd406ab428964e0324f2e Mon Sep 17 00:00:00 2001 From: mrbackend Date: Mon, 7 Mar 2016 23:20:24 +0100 Subject: [PATCH 003/336] #235 Changes after Code Review + added Gen.pickOne() --- quickcheck/src/main/java/fj/test/Gen.java | 52 +++++++----- .../fj/test/{TestGen.java => GenTest.java} | 84 +++++++++---------- 2 files changed, 74 insertions(+), 62 deletions(-) rename quickcheck/src/test/java/fj/test/{TestGen.java => GenTest.java} (59%) diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 2bac9cfc..0aa11adb 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -563,12 +563,24 @@ public static Gen> listOf1(final Gen g) { return listOf(g, 1); } + /** + * Returns a generator that picks one element from the given list. If the given list is empty, then the + * returned generator will never produce a value. + * + * @param as The list from which to pick an element. + * @return A generator that picks an element from the given list. + */ + public static Gen pickOne(List as) { + // This is the fastest of the four; functionally, any of them would do + return wordOf(1, as).map(List::head); + } + /** * Returns a generator of lists that picks the given number of elements from the given list. If * the given number is less than zero or greater than the length of the given list, then the * returned generator will never produce a value. *

- * Note: pick is synonymous with pickCombinationWithoutReplacement + * Note: pick is synonymous with combinationOf * * @param n The number of elements to pick from the given list. * @param as The list from which to pick elements. @@ -576,7 +588,7 @@ public static Gen> listOf1(final Gen g) { */ @Deprecated public static Gen> pick(int n, List as) { - return pickCombinationWithoutReplacement(n, as); + return combinationOf(n, as); } /** @@ -594,7 +606,7 @@ public static Gen> pick(int n, List as) { * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. */ - public static Gen> pickCombinationWithoutReplacement(int n, List as) { + public static Gen> combinationOf(int n, List as) { int aLength = as.length(); return ((n >= 0) && (n <= aLength)) ? parameterised(s -> r -> { @@ -634,10 +646,10 @@ private Trampoline> tramp(List remainAs, int remainN, int remainALeng * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. */ - public static Gen> pickCombinationWithReplacement(int n, List as) { + public static Gen> selectionOf(int n, List as) { Array aArr = as.toArray(); return (n >= 0) ? - pick(indexPermutation(n, aArr.length()).map(indexes -> indexes.sort(intOrd)), aArr) : + pick(indexWord(n, aArr.length()).map(indexes -> indexes.sort(intOrd)), aArr) : fail(); } @@ -656,9 +668,9 @@ public static Gen> pickCombinationWithReplacement(int n, List as) * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. */ - public static Gen> pickPermutationWithoutReplacement(int n, List as) { + public static Gen> permutationOf(int n, List as) { return parameterised(s -> r -> - pickCombinationWithoutReplacement(n, as).map(combination -> { + combinationOf(n, as).map(combination -> { // Shuffle combination using the Fisher-Yates algorithm Array aArr = combination.toArray(); int length = aArr.length(); @@ -687,14 +699,14 @@ public static Gen> pickPermutationWithoutReplacement(int n, List * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. */ - public static Gen> pickPermutationWithReplacement(int n, List as) { + public static Gen> wordOf(int n, List as) { Array aArr = as.toArray(); return (n >= 0) ? - pick(indexPermutation(n, aArr.length()), aArr) : + pick(indexWord(n, aArr.length()), aArr) : fail(); } - private static Gen> indexPermutation(int n, int m) { + private static Gen> indexWord(int n, int m) { return sequenceN(n, choose(0, m - 1)); } @@ -706,14 +718,14 @@ private static Gen> pick(Gen> indexesGen, Array as) /** * Returns a generator of lists that produces some of the values of the given list. *

- * Note: someOf is synonymous with someCombinationWithoutReplacementOf + * Note: someOf is synonymous with someCombinationOf * * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ @Deprecated public static Gen> someOf(List as) { - return someCombinationWithoutReplacementOf(as); + return someCombinationOf(as); } /** @@ -727,8 +739,8 @@ public static Gen> someOf(List as) { * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ - public static Gen> someCombinationWithoutReplacementOf(List as) { - return choose(0, as.length()).bind(n -> pickCombinationWithoutReplacement(n, as)); + public static Gen> someCombinationOf(List as) { + return choose(0, as.length()).bind(n -> combinationOf(n, as)); } /** @@ -743,8 +755,8 @@ public static Gen> someCombinationWithoutReplacementOf(List as) { * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ - public static Gen> someCombinationWithReplacementOf(int maxLength, List as) { - return choose(0, maxLength).bind(n -> pickCombinationWithReplacement(n, as)); + public static Gen> someSelectionOf(int maxLength, List as) { + return choose(0, maxLength).bind(n -> selectionOf(n, as)); } /** @@ -758,8 +770,8 @@ public static Gen> someCombinationWithReplacementOf(int maxLength, L * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ - public static Gen> somePermutationWithoutReplacementOf(List as) { - return choose(0, as.length()).bind(n -> pickPermutationWithoutReplacement(n, as)); + public static Gen> somePermutationOf(List as) { + return choose(0, as.length()).bind(n -> permutationOf(n, as)); } /** @@ -774,8 +786,8 @@ public static Gen> somePermutationWithoutReplacementOf(List as) { * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ - public static Gen> somePermutationWithReplacementOf(int maxLength, List as) { - return choose(0, maxLength).bind(n -> pickPermutationWithReplacement(n, as)); + public static Gen> someWordOf(int maxLength, List as) { + return choose(0, maxLength).bind(n -> wordOf(n, as)); } /** diff --git a/quickcheck/src/test/java/fj/test/TestGen.java b/quickcheck/src/test/java/fj/test/GenTest.java similarity index 59% rename from quickcheck/src/test/java/fj/test/TestGen.java rename to quickcheck/src/test/java/fj/test/GenTest.java index 5db6759c..3bb723b8 100644 --- a/quickcheck/src/test/java/fj/test/TestGen.java +++ b/quickcheck/src/test/java/fj/test/GenTest.java @@ -7,29 +7,29 @@ import static fj.Ord.charOrd; import static fj.data.List.list; import static fj.data.List.range; -import static fj.test.Gen.pickCombinationWithReplacement; -import static fj.test.Gen.pickCombinationWithoutReplacement; -import static fj.test.Gen.pickPermutationWithReplacement; -import static fj.test.Gen.pickPermutationWithoutReplacement; +import static fj.test.Gen.selectionOf; +import static fj.test.Gen.combinationOf; +import static fj.test.Gen.wordOf; +import static fj.test.Gen.permutationOf; import static fj.test.Rand.standard; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -public final class TestGen { +public final class GenTest { private static final List AS = list('A', 'B', 'C'); @Test - public void testPickCombinationWithoutReplacement_none() { - Gen> instance = pickCombinationWithoutReplacement(0, AS); + public void testCombinationOf_none() { + Gen> instance = combinationOf(0, AS); testPick(100, instance, actual -> { assertTrue(actual.isEmpty()); }); } @Test - public void testPickCombinationWithoutReplacement_one() { - Gen> instance = pickCombinationWithoutReplacement(1, AS); + public void testCombinationOf_one() { + Gen> instance = combinationOf(1, AS); testPick(100, instance, actual -> { assertEquals(1, actual.length()); assertTrue(AS.exists(a -> a.equals(actual.head()))); @@ -37,8 +37,8 @@ public void testPickCombinationWithoutReplacement_one() { } @Test - public void testPickCombinationWithoutReplacement_two() { - Gen> instance = pickCombinationWithoutReplacement(2, AS); + public void testCombinationOf_two() { + Gen> instance = combinationOf(2, AS); testPick(100, instance, actual -> { assertEquals(2, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -47,8 +47,8 @@ public void testPickCombinationWithoutReplacement_two() { } @Test - public void testPickCombinationWithoutReplacement_three() { - Gen> instance = pickCombinationWithoutReplacement(3, AS); + public void testCombinationOf_three() { + Gen> instance = combinationOf(3, AS); testPick(100, instance, actual -> { assertEquals(3, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -57,16 +57,16 @@ public void testPickCombinationWithoutReplacement_three() { } @Test - public void testPickCombinationWithReplacement_none() { - Gen> instance = pickCombinationWithReplacement(0, AS); + public void testSelectionOf_none() { + Gen> instance = selectionOf(0, AS); testPick(100, instance, actual -> { assertTrue(actual.isEmpty()); }); } @Test - public void testPickCombinationWithReplacement_one() { - Gen> instance = pickCombinationWithReplacement(1, AS); + public void testSelectionOf_one() { + Gen> instance = selectionOf(1, AS); testPick(100, instance, actual -> { assertEquals(1, actual.length()); assertTrue(AS.exists(a -> a.equals(actual.head()))); @@ -74,8 +74,8 @@ public void testPickCombinationWithReplacement_one() { } @Test - public void testPickCombinationWithReplacement_two() { - Gen> instance = pickCombinationWithReplacement(2, AS); + public void testSelectionOf_two() { + Gen> instance = selectionOf(2, AS); testPick(100, instance, actual -> { assertEquals(2, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -84,8 +84,8 @@ public void testPickCombinationWithReplacement_two() { } @Test - public void testPickCombinationWithReplacement_three() { - Gen> instance = pickCombinationWithReplacement(3, AS); + public void testSelectionOf_three() { + Gen> instance = selectionOf(3, AS); testPick(100, instance, actual -> { assertEquals(3, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -94,8 +94,8 @@ public void testPickCombinationWithReplacement_three() { } @Test - public void testPickCombinationWithReplacement_four() { - Gen> instance = pickCombinationWithReplacement(4, AS); + public void testSelectionOf_four() { + Gen> instance = selectionOf(4, AS); testPick(100, instance, actual -> { assertEquals(4, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -104,16 +104,16 @@ public void testPickCombinationWithReplacement_four() { } @Test - public void testPickPermutationWithoutReplacement_none() { - Gen> instance = pickPermutationWithoutReplacement(0, AS); + public void testPermutationOf_none() { + Gen> instance = permutationOf(0, AS); testPick(100, instance, actual -> { assertTrue(actual.isEmpty()); }); } @Test - public void testPickPermutationWithoutReplacement_one() { - Gen> instance = pickPermutationWithoutReplacement(1, AS); + public void testPermutationOf_one() { + Gen> instance = permutationOf(1, AS); testPick(100, instance, actual -> { assertEquals(1, actual.length()); assertTrue(AS.exists(a -> a.equals(actual.head()))); @@ -121,8 +121,8 @@ public void testPickPermutationWithoutReplacement_one() { } @Test - public void testPickPermutationWithoutReplacement_two() { - Gen> instance = pickCombinationWithoutReplacement(2, AS); + public void testPermutationOf_two() { + Gen> instance = combinationOf(2, AS); testPick(100, instance, actual -> { assertEquals(2, actual.length()); assertTrue(actual.tails().forall(l -> l.isEmpty() || l.tail().forall(a -> !a.equals(l.head())))); @@ -130,8 +130,8 @@ public void testPickPermutationWithoutReplacement_two() { } @Test - public void testPickPermutationWithoutReplacement_three() { - Gen> instance = pickPermutationWithoutReplacement(3, AS); + public void testPermutationOf_three() { + Gen> instance = permutationOf(3, AS); testPick(100, instance, actual -> { assertEquals(3, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -140,16 +140,16 @@ public void testPickPermutationWithoutReplacement_three() { } @Test - public void testPickPermutationWithReplacement_none() { - Gen> instance = pickPermutationWithReplacement(0, AS); + public void testWordOf_none() { + Gen> instance = wordOf(0, AS); testPick(100, instance, actual -> { assertTrue(actual.isEmpty()); }); } @Test - public void testPickPermutationWithReplacement_one() { - Gen> instance = pickPermutationWithReplacement(1, AS); + public void testWordOf_one() { + Gen> instance = wordOf(1, AS); testPick(100, instance, actual -> { assertEquals(1, actual.length()); assertTrue(AS.exists(a -> a.equals(actual.head()))); @@ -157,8 +157,8 @@ public void testPickPermutationWithReplacement_one() { } @Test - public void testPickPermutationWithReplacement_two() { - Gen> instance = pickPermutationWithReplacement(2, AS); + public void testWordOf_two() { + Gen> instance = wordOf(2, AS); testPick(100, instance, actual -> { assertEquals(2, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -166,8 +166,8 @@ public void testPickPermutationWithReplacement_two() { } @Test - public void testPickPermutationWithReplacement_three() { - Gen> instance = pickPermutationWithReplacement(3, AS); + public void testWordOf_three() { + Gen> instance = wordOf(3, AS); testPick(100, instance, actual -> { assertEquals(3, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -175,8 +175,8 @@ public void testPickPermutationWithReplacement_three() { } @Test - public void testPickPermutationWithReplacement_four() { - Gen> instance = pickPermutationWithReplacement(4, AS); + public void testWordOf_four() { + Gen> instance = wordOf(4, AS); testPick(100, instance, actual -> { assertEquals(4, actual.length()); assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); @@ -184,7 +184,7 @@ public void testPickPermutationWithReplacement_four() { } private static void testPick(int n, Gen> instance, Effect1> test) { - range(0, n).map(i -> instance.gen(0, standard)).foreachDoEffect(test::f); + range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test::f); } } From a4695e352e115820e54551aa3d16b8ac50da22b9 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 8 May 2016 22:45:00 +1000 Subject: [PATCH 004/336] Upgraded Gradle to 2.13 --- gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be138e88..a54a2d93 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip From 5d45d6ac407d591c3404f88a27fbb4e46fed7dd5 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 9 May 2016 00:39:43 +1000 Subject: [PATCH 005/336] Updated jacoco version --- build.gradle | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7a3b81cf..3bc75234 100644 --- a/build.gradle +++ b/build.gradle @@ -40,7 +40,9 @@ allprojects { jacoco { - toolVersion = "0.7.1.201405082137" +// toolVersion = "0.7.1.201405082137" + toolVersion = "0.7.6.201602180812" + } defaultTasks "build" From acadf6afd4276ae33377648cd61fa6a6c1ed6206 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Wed, 11 May 2016 22:18:10 +1000 Subject: [PATCH 006/336] Add some optics for Option --- core/src/main/java/fj/data/Option.java | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index c9f9f9f2..476d38db 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -19,6 +19,8 @@ import fj.Equal; import fj.Ord; import fj.Hash; +import fj.data.optic.Prism; +import fj.data.optic.PPrism; import static fj.Function.*; import static fj.P.p; import static fj.Unit.unit; @@ -30,6 +32,8 @@ import static fj.data.Validation.parseInt; import static fj.data.Validation.parseLong; import static fj.data.Validation.parseShort; +import static fj.data.optic.Prism.prism; +import static fj.data.optic.PPrism.pPrism; import static fj.Show.optionShow; import java.util.Collection; @@ -883,4 +887,34 @@ public static F>, Option> join() { * A function that parses a string to a short. */ public static final F> parseShort = s -> parseShort(s).toOption(); + + public static final class Optic { + + private Optic() { + throw new UnsupportedOperationException(); + } + + /** + * None prism + */ + public static Prism, Unit> none() { + return prism(o -> o.option(Option.some(Unit.unit()), a -> Option.none()), u -> Option.none()); + } + + /** + * Polymorphic Some prism + */ + public static PPrism, Option, A, B> pSome() { + return pPrism(o -> o., A>>map(Either::right).orSome(Either.left(Option.none())), Option::some); + } + + /** + * Monomorphic Some prism + */ + public static Prism, A> some() { + return new Prism<>(pSome()); + } + + } + } From 5f1d7ad6660745784987d6e219747ca8d1d8e5e4 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Thu, 12 May 2016 11:52:29 +1000 Subject: [PATCH 007/336] Add property checks for Option optics --- props-core-scalacheck/src/main/scala/fj/package.scala | 8 +++++--- .../src/test/scala/fj/data/CheckOption.scala | 8 ++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/props-core-scalacheck/src/main/scala/fj/package.scala b/props-core-scalacheck/src/main/scala/fj/package.scala index 5a3b9bfc..78afe491 100644 --- a/props-core-scalacheck/src/main/scala/fj/package.scala +++ b/props-core-scalacheck/src/main/scala/fj/package.scala @@ -1,5 +1,5 @@ import fj.Equal -import fj.data.List +import fj.data.{Option, List} package object fj { implicit def Function1F[A, B](g: A => B): F[A, B] = new F[A, B] { def f(a: A) = g(a) @@ -16,9 +16,11 @@ package object fj { implicit def intEqual: Equal[Int] = Equal.equal({(i1:Int, i2:Int) => Boolean.box((i1 == i2))}) implicit def unitEqual: Equal[Unit] = Equal.anyEqual() - + implicit def listEqual[A](implicit aEq: Equal[A]): Equal[List[A]] = Equal.listEqual(aEq) - + + implicit def optionEqual[A](implicit aEq: Equal[A]): Equal[Option[A]] = Equal.optionEqual(aEq) + implicit def p2Equal[A, B](implicit aEq: Equal[A], bEq: Equal[B]): Equal[P2[A, B]] = Equal.p2Equal(aEq, bEq) } \ No newline at end of file diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckOption.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckOption.scala index 18d2cdf2..13059d3f 100644 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckOption.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckOption.scala @@ -1,9 +1,11 @@ package fj package data +import fj.data.optic.PrismLaws import org.scalacheck.Prop._ import ArbitraryOption.arbitraryOption import ArbitraryP.arbitraryP1 +import ArbitraryUnit._ import Equal.{optionEqual, stringEqual} import Unit.unit import Option.{none, some, join} @@ -84,4 +86,10 @@ object CheckOption extends Properties("Option") { a.isNone || optionEqual(stringEqual).eq( join(a), a.some)) + + property("Optic.pSome") = PrismLaws[Option[String], String](Option.Optic.pSome()) + + property("Optic.some") = PrismLaws[Option[String], String](Option.Optic.some()) + + property("Optic.none") = PrismLaws[Option[Unit], Unit](Option.Optic.none()) } From 72f3e761d6c1afc209990d4fc9618e53af634cd1 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Thu, 12 May 2016 15:57:34 +1000 Subject: [PATCH 008/336] Add "as" and "voided" IO functions --- core/src/main/java/fj/data/IOFunctions.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index bb2d7de1..8d766d15 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -339,6 +339,14 @@ public B run() throws IOException { }; } + public static final IO as(final IO io, final B b) { + return map(io, ignored -> b); + } + + public static final IO voided(final IO io) { + return as(io, Unit.unit()); + } + public static final IO bind(final IO io, final F> f) { return new IO() { @Override From 8703a75974b9fa99127660bf70c653c180bb7dc7 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Thu, 12 May 2016 16:12:27 +1000 Subject: [PATCH 009/336] Add "when" and "unless" to IOFunctions --- core/src/main/java/fj/data/IOFunctions.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 8d766d15..9136311b 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -356,6 +356,14 @@ public B run() throws IOException { }; } + public static final IO when(final IO io, final Boolean b) { + return b ? io : ioUnit; + } + + public static final IO unless(final IO io, final Boolean b) { + return when(io, !b); + } + /** * Evaluate each action in the sequence from left to right, and collect the results. */ From 42ee23dca237d739036e5082f682285512da326e Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 11:19:35 +1000 Subject: [PATCH 010/336] Swap arguments to "when" and "unless" --- core/src/main/java/fj/data/IOFunctions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 9136311b..dce5d0af 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -356,12 +356,12 @@ public B run() throws IOException { }; } - public static final IO when(final IO io, final Boolean b) { + public static final IO when(final Boolean b, final IO io) { return b ? io : ioUnit; } - public static final IO unless(final IO io, final Boolean b) { - return when(io, !b); + public static final IO unless(final Boolean b, final IO io) { + return when(!b, io); } /** From 6892c93a687b1df1f523f6e6f9e4ab431df72ac2 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 11:20:15 +1000 Subject: [PATCH 011/336] Add a Semigroup for IO --- core/src/main/java/fj/Semigroup.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index e1e4fdf7..0da2cd77 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -2,6 +2,8 @@ import fj.data.Array; import fj.data.List; +import fj.data.IO; +import fj.data.IOFunctions; import fj.data.Natural; import fj.data.NonEmptyList; import fj.data.Option; @@ -355,6 +357,13 @@ public static Semigroup> p2Semigroup(final Semigroup sa, fina return semigroup((a1, a2) -> P.lazy(() -> sa.sum(a1._1(), a2._1()), () -> sb.sum(a1._2(), a2._2()))); } + /** + * A semigroup for IO values. + */ + public static Semigroup> ioSemigroup(final Semigroup sa) { + return semigroup((a1, a2) -> IOFunctions.liftM2(a1, a2, sa::sum)); + } + /** * A semigroup for the Unit value. */ From f89381d5aeed29ef553b8bb766999036ed2f465d Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 11:31:56 +1000 Subject: [PATCH 012/336] Add "first" and "last" semigroups --- core/src/main/java/fj/Semigroup.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 0da2cd77..18172990 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -264,6 +264,20 @@ public static Semigroup semigroup(final F2 sum) { public static final Semigroup stringBuilderSemigroup = semigroup((s1, s2) -> new StringBuilder(s1).append(s2)); + /** + * A semigroup which always uses the "first" (left-hand side) value. + */ + public static Semigroup firstSemigroup() { + return semigroup((a1, a2) -> a1); + } + + /** + * A semigroup which always uses the "last" (right-hand side) value. + */ + public static Semigroup lastSemigroup() { + return semigroup((a1, a2) -> a2); + } + /** * A semigroup for functions. * From 637c18c9f7c819f6cd52486ecd7cdf07838048cb Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 20:23:47 +1000 Subject: [PATCH 013/336] Add a Monoid for Unit --- core/src/main/java/fj/Monoid.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 40d6e8e7..0d70c481 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -384,6 +384,11 @@ public static Monoid> arrayMonoid() { return monoid(Semigroup.arraySemigroup(), Array.empty()); } + /** + * A monoid for the Unit value. + */ + public static final Monoid unitMonoid = monoid(Semigroup.unitSemigroup, Unit.unit()); + /** * A monoid for sets. * From 77f45b6005bcc2208311c629b86e49bbe8e0df71 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 20:23:54 +1000 Subject: [PATCH 014/336] Add a Monoid for IO --- core/src/main/java/fj/Monoid.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 0d70c481..c2214748 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -4,6 +4,8 @@ import static fj.Function.flip; import fj.data.Array; import fj.data.List; +import fj.data.IO; +import fj.data.IOFunctions; import fj.data.Natural; import fj.data.Option; import fj.data.Set; @@ -384,6 +386,13 @@ public static Monoid> arrayMonoid() { return monoid(Semigroup.arraySemigroup(), Array.empty()); } + /** + * A monoid for IO values. + */ + public static Monoid> ioMonoid(final Monoid ma) { + return monoid(Semigroup.ioSemigroup(ma.semigroup()), IOFunctions.unit(ma.zero())); + } + /** * A monoid for the Unit value. */ From 36a0a784f03730191cf5970433a4e32a8d6c999d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 14 May 2016 00:08:41 +0200 Subject: [PATCH 015/336] Update to latest retrolambda release and gradle plugin. Retro lambda 2.3.0 reduce by ~5% the number of generated methods. --- build.gradle | 6 +++--- lib.gradle | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 3bc75234..2744cd00 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,8 @@ ext { buildscript { ext { uptodateVersion = "1.6.0" - retrolambdaVersion = "3.2.0" + retrolambdaPluginVersion = "3.2.5" + retrolambdaVersion = "2.3.0" } repositories { @@ -18,12 +19,11 @@ buildscript { dependencies { classpath "com.ofg:uptodate-gradle-plugin:$uptodateVersion" - classpath "me.tatarka:gradle-retrolambda:$retrolambdaVersion" + classpath "me.tatarka:gradle-retrolambda:$retrolambdaPluginVersion" classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3' } } - apply plugin: "jacoco" apply plugin: 'com.github.kt3k.coveralls' diff --git a/lib.gradle b/lib.gradle index dbaebe4d..5b84e98b 100644 --- a/lib.gradle +++ b/lib.gradle @@ -90,6 +90,9 @@ void configureRetroLambda(boolean useRetroLambda, String newJdkEnvVar, String ol oldJdk System.getenv(oldJdkEnvVar) javaVersion retroLambdaTarget } + dependencies { + retrolambdaConfig "net.orfjackal.retrolambda:retrolambda:$retrolambdaVersion" + } } } From c7785406ed74b4f31eedb336acf7ab8334154dd7 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 16 May 2016 09:02:42 +1000 Subject: [PATCH 016/336] Fix backwards List#traverseIO Fixes #248 --- core/src/main/java/fj/data/List.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 2d6f7683..36b005f1 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -640,7 +640,7 @@ public P1> traverseP1(final F> f){ public IO> traverseIO(F> f) { return this.foldRight( - (a, acc) -> IOFunctions.bind(acc, (bs) -> IOFunctions.map(f.f(a), b -> bs.cons(b))), + (a, acc) -> IOFunctions.bind(f.f(a), b -> IOFunctions.map(acc, bs -> bs.cons(b))), IOFunctions.unit(List.nil()) ); } From c1565d7b986f5111fb73a412dab0ec4f02742543 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 16 May 2016 16:19:39 +1000 Subject: [PATCH 017/336] Add "ignored" Optional optic --- core/src/main/java/fj/data/optic/Optional.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/fj/data/optic/Optional.java b/core/src/main/java/fj/data/optic/Optional.java index de63fc2d..ed737cf0 100644 --- a/core/src/main/java/fj/data/optic/Optional.java +++ b/core/src/main/java/fj/data/optic/Optional.java @@ -171,6 +171,10 @@ public static Optional id() { return new Optional<>(POptional.pId()); } + public static Optional ignored() { + return optional(s -> Option.none(), a -> s -> s); + } + public static final Optional optional(final F> getOption, final F> set) { return new Optional<>(new POptional() { From 77258ff71237f5d88aad1f833ab799f7021570f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=A4mer?= Date: Mon, 23 May 2016 18:44:00 +1000 Subject: [PATCH 018/336] Fix eager IOW.bind --- core/src/main/java/fj/data/IOW.java | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index 5364f49e..8e8960d7 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -25,20 +25,11 @@ public A run() throws IOException { return io.run(); } - public IOW map(F f) { - return lift(() -> f.f(io.run())); - } + public IOW map(F f) { return lift(IOFunctions.map(io, f)); } - public IOW bind(F> f) throws IOException { - return lift(f.f(io.run())); - } + public IOW bind(F> f) { return lift(IOFunctions.bind(io, f)); } - public IOW append(IO iob) { - return lift(() -> { - io.run(); - return iob.run(); - }); - } + public IOW append(IO iob) { return lift(IOFunctions.append(io, iob)); } public IOW getContents() { return lift(() -> IOFunctions.getContents().run()); From 47b58b8f1c09ce2f9d875412c6f1c4213cd2dd90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=A4mer?= Date: Tue, 24 May 2016 11:43:41 +1000 Subject: [PATCH 019/336] Provide an IO walkthrough example demonstrating basic composition --- core/src/main/java/fj/data/IOFunctions.java | 7 ++ core/src/main/java/fj/data/IOW.java | 4 + demo/src/main/java/fj/demo/IOWalkthrough.java | 83 +++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 demo/src/main/java/fj/demo/IOWalkthrough.java diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index dce5d0af..d53caf9a 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -495,6 +495,13 @@ public static IO stdoutPrintln(final String s) { }; } + public static IO stdoutPrint(final String s) { + return () -> { + System.out.print(s); + return Unit.unit(); + }; + } + public static IO getContents() { Stream> s = Stream.>repeat(() -> (int) stdinBufferedReader.read()); return IOFunctions.map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> { diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index 8e8960d7..4b146cde 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -25,6 +25,10 @@ public A run() throws IOException { return io.run(); } + public SafeIO> safe() { + return IOFunctions.toSafeValidation(io); + } + public IOW map(F f) { return lift(IOFunctions.map(io, f)); } public IOW bind(F> f) { return lift(IOFunctions.bind(io, f)); } diff --git a/demo/src/main/java/fj/demo/IOWalkthrough.java b/demo/src/main/java/fj/demo/IOWalkthrough.java new file mode 100644 index 00000000..85c9a7c9 --- /dev/null +++ b/demo/src/main/java/fj/demo/IOWalkthrough.java @@ -0,0 +1,83 @@ +package fj.demo; + +import fj.F; +import fj.F1Functions; +import fj.F1W; +import fj.Unit; +import fj.data.IO; +import fj.data.IOFunctions; +import fj.data.IOW; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import static fj.data.IOFunctions.stdinReadLine; +import static fj.data.IOFunctions.stdoutPrint; +import static fj.data.IOFunctions.stdoutPrintln; +import static fj.data.IOFunctions.toSafeValidation; + +/** + * Demonstrates how to use IO and basic function composition. + */ +public class IOWalkthrough { + public static void main(String[] args) { + + // IO is just a container to defer a computation (lazy), with the intention to encapsulate computations that either + // consume and/or produce side-effects + // the computation is not (yet) executed on creation hence it can be treated like a value + + final IO askName = () -> { + System.out.println("Hi, what's your name?"); + return Unit.unit(); + }; + + // fj.data.IOFunctions contains a lot of convenience functions regarding IO, the above example could be rewritten with IOFunctions.stdoutPrintln + // we now create an IO value to prompt for the name if executed + + IO promptName = IOFunctions.stdoutPrint("Name: "); + + // we can compose these two values with fj.data.IOFunctions.append, since they both are not interested in any runtime value + + IO askAndPromptName = IOFunctions.append(askName, promptName); + + // now we create an IO value to read a line from stdin + + final IO readName = () -> new BufferedReader(new InputStreamReader(System.in)).readLine(); + + // this is the same as IOFunctions.stdinReadLine() + + // now we create a function which takes a string, upper cases it and creates an IO value that would print the upper cased string if executed + + final F> upperCaseAndPrint = F1Functions., String>o(IOFunctions::stdoutPrintln).f(s -> s.toUpperCase()); + + // we now want to compose reading the name with printing it, for that we need to have access to the runtime value that is returned when the + // IO value for read is executed, hence we use fj.data.IOFunctions.bind instead of fj.data.IOFunctions.append + + final IO readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint); + + // so append is really just a specialised form of bind, ignoring the runtime value of the IO execution that was composed before us + + final IO program = IOFunctions.bind(askAndPromptName, ignored -> readAndPrintUpperCasedName); + + // this is the same as writing IOFunctions.append(askAndPromptName, readAndPrintUpperCasedName) + + // we have recorded the entire program, but have not run anything yet + // now we get to the small dirty part at the end of our program where we actually execute it + // we can either choose to just call program.run(), which allows the execution to escape + // or we use safe to receive an fj.data.Either with the potential exception on the left side + + toSafeValidation(program).run().on((IOException e) -> { e.printStackTrace(); return Unit.unit(); }); + + // doing function composition like this can be quite cumbersome, since you will end up nesting parenthesis unless you flatten it out by + // assigning the functions to variables like above, but you can use the fj.F1W syntax wrapper for composing single-argument functions and fj.data.IOW + // for composing IO values instead, the entire program can be written like so: + + IOW.lift(stdoutPrintln("What's your name again?")) + .append(stdoutPrint("Name: ")) + .append(stdinReadLine()) + .bind(F1W.lift((String s) -> s.toUpperCase()).andThen(IOFunctions::stdoutPrintln)) + .safe().run().on((IOException e) -> { e.printStackTrace(); return Unit.unit(); }); + } +} + From 369986e68bbcd9fa37f9a807e5b3b67dc02980b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Kr=C3=A4mer?= Date: Tue, 24 May 2016 15:24:53 +1000 Subject: [PATCH 020/336] Use instance method reference in IOWalkthrough --- demo/src/main/java/fj/demo/IOWalkthrough.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/main/java/fj/demo/IOWalkthrough.java b/demo/src/main/java/fj/demo/IOWalkthrough.java index 85c9a7c9..609d2502 100644 --- a/demo/src/main/java/fj/demo/IOWalkthrough.java +++ b/demo/src/main/java/fj/demo/IOWalkthrough.java @@ -49,7 +49,7 @@ public static void main(String[] args) { // now we create a function which takes a string, upper cases it and creates an IO value that would print the upper cased string if executed - final F> upperCaseAndPrint = F1Functions., String>o(IOFunctions::stdoutPrintln).f(s -> s.toUpperCase()); + final F> upperCaseAndPrint = F1Functions., String>o(IOFunctions::stdoutPrintln).f(String::toUpperCase); // we now want to compose reading the name with printing it, for that we need to have access to the runtime value that is returned when the // IO value for read is executed, hence we use fj.data.IOFunctions.bind instead of fj.data.IOFunctions.append From 74b0fe43f8acd42ad99aaeadd2cf9bd1192d5e8b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 15 Feb 2016 07:33:51 +1000 Subject: [PATCH 021/336] Changes to release 4.5 --- build.gradle | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2744cd00..e11b2274 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true + isSnapshot = false fjBaseVersion = "4.6" snapshotAppendix = "-SNAPSHOT" @@ -56,7 +56,7 @@ allprojects { fjConsumeVersion = "4.5" signModule = false - useRetroLambda = false + useRetroLambda = true projectTitle = "Functional Java" projectName = "functionaljava" diff --git a/gradle.properties b/gradle.properties index d4552a30..07c2b60c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = false +signingEnabled = true From ff6c580256922884d41c867ef3888737cfe68308 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 15 Feb 2016 07:35:36 +1000 Subject: [PATCH 022/336] Increase version to 4.6-SNAPSHOT --- build.gradle | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index e11b2274..2744cd00 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = false + isSnapshot = true fjBaseVersion = "4.6" snapshotAppendix = "-SNAPSHOT" @@ -56,7 +56,7 @@ allprojects { fjConsumeVersion = "4.5" signModule = false - useRetroLambda = true + useRetroLambda = false projectTitle = "Functional Java" projectName = "functionaljava" diff --git a/gradle.properties b/gradle.properties index 07c2b60c..d4552a30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = true +signingEnabled = false From 61708ee4b0a079066271cee038ba5abbe4913470 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Fri, 4 Mar 2016 08:12:36 +0100 Subject: [PATCH 023/336] Remove deprecated shallowEqualsO --- core/src/main/java/fj/Equal.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 60fcb86d..23ceffd3 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -544,25 +544,6 @@ public static Equal> treeMapEqual(Equal k, Equal v) { public static Equal> writerEqual(Equal eq1, Equal eq2) { return equal(w1 -> w2 -> p2Equal(eq1, eq2).eq(w1.run(), w2.run())); } - - /** - * @return Returns none if no equality can be determined by checking the nullity and reference values, else the equality - * @deprecated see issue #122. - */ - @Deprecated - public static Option shallowEqualsO(Object o1, Object o2) { - if (o1 == null && o2 == null) { - return Option.some(true); - } else if (o1 == o2) { - return Option.some(true); - } else if (o1 != null && o2 != null) { - java.lang.Class c = o1.getClass(); - // WARNING: this may return some(false) for two instance of same type (and thus comparable) but of different class (typicaly anonymous class instance). - return c.isInstance(o2) ? Option.none() : Option.some(false); - } else { - return Option.some(false); - } - } /** * Helper method to implement {@link Object#equals(Object)} correctly. DO NOT USE it for any other purpose. From 5e6da6f8673ed97a2c99866662f757c2b5088e8c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Fri, 4 Mar 2016 22:01:00 +0100 Subject: [PATCH 024/336] Deprecate toJavaArray: unsafe --- core/src/main/java/fj/data/Array.java | 9 ++++++++- core/src/main/java/fj/data/List.java | 9 ++++++++- core/src/main/java/fj/data/Stream.java | 9 ++++++++- core/src/test/java/fj/data/ArrayTest.java | 9 +++++---- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index f24e529c..ea8c7312 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -128,7 +128,14 @@ public Object[] array() { return copyOf(a, a.length); } - @SuppressWarnings("unchecked") + /** + * To be removed in future release: + * affectation of the result of this method to a non generic array + * will result in runtime error (ClassCastException). + * + * @deprecated use {@link #array(Class)} + */ + @Deprecated public A[] toJavaArray() { return (A[]) array(); } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 36b005f1..4920e021 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -211,7 +211,14 @@ public final Object[] toArrayObject() { return a; } - @SuppressWarnings("unchecked") + /** + * To be removed in future release: + * affectation of the result of this method to a non generic array + * will result in runtime error (ClassCastException). + * + * @deprecated use {@link #array(Class)} + */ + @Deprecated public final A[] toJavaArray() { return (A[]) toArrayObject(); } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index d21c2f15..2e7ca879 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -916,7 +916,14 @@ public final Option toOption() { return isEmpty() ? Option.none() : some(head()); } - @SuppressWarnings({"unchecked", "UnnecessaryFullyQualifiedName"}) + /** + * To be removed in future release: + * affectation of the result of this method to a non generic array + * will result in runtime error (ClassCastException). + * + * @deprecated use {@link #array(Class)} + */ + @Deprecated public final A[] toJavaArray() { final A[] array = (A[]) new Object[length()]; int i = 0; diff --git a/core/src/test/java/fj/data/ArrayTest.java b/core/src/test/java/fj/data/ArrayTest.java index e274a00a..886031b3 100644 --- a/core/src/test/java/fj/data/ArrayTest.java +++ b/core/src/test/java/fj/data/ArrayTest.java @@ -3,6 +3,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; /** @@ -11,10 +12,10 @@ public class ArrayTest { @Test - public void toJavaArray() { - final int max = 3; - List list = List.range(1, max + 1); - assertThat(list.toArray().toJavaArray(), equalTo(list.toJavaArray())); + public void array_is_safe() { + List list = List.range(1, 2); + + assertThat(list.toArray().array(Integer[].class), instanceOf(Integer[].class)); } } From 14b7f5c0174ecd0ff99ec224dee73daeef381a74 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 09:37:58 +0100 Subject: [PATCH 025/336] Make non-extendable classes final. --- core/src/main/java/fj/Effect.java | 2 +- core/src/main/java/fj/TryEffect.java | 2 +- core/src/main/java/fj/data/DList.java | 2 +- core/src/main/java/fj/data/IOW.java | 2 +- core/src/main/java/fj/data/State.java | 2 +- core/src/main/java/fj/data/Writer.java | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/fj/Effect.java b/core/src/main/java/fj/Effect.java index aec3e442..387055f1 100644 --- a/core/src/main/java/fj/Effect.java +++ b/core/src/main/java/fj/Effect.java @@ -17,7 +17,7 @@ * * @version %build.number% */ -public class Effect { +public final class Effect { private Effect() {} diff --git a/core/src/main/java/fj/TryEffect.java b/core/src/main/java/fj/TryEffect.java index 02d4521f..90acaf06 100644 --- a/core/src/main/java/fj/TryEffect.java +++ b/core/src/main/java/fj/TryEffect.java @@ -10,7 +10,7 @@ /** * Created by mperry on 29/08/2014. */ -public class TryEffect { +public final class TryEffect { private TryEffect(){} diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index 2c7856de..3f7b2fe3 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -13,7 +13,7 @@ * * @version %build.number% */ -public class DList { +public final class DList { private final F,Trampoline>> appendFn; private DList(final F,Trampoline>> appendFn) { diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index 4b146cde..b508456c 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -8,7 +8,7 @@ /** * Created by MarkPerry on 9/06/2015. */ -public class IOW implements IO { +public final class IOW implements IO { private IO io; diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 46af5392..14620208 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -9,7 +9,7 @@ /** * Created by MarkPerry on 7/07/2014. */ -public class State { +public final class State { private F> run; diff --git a/core/src/main/java/fj/data/Writer.java b/core/src/main/java/fj/data/Writer.java index 96e449e3..ad55c3ae 100644 --- a/core/src/main/java/fj/data/Writer.java +++ b/core/src/main/java/fj/data/Writer.java @@ -5,7 +5,7 @@ /** * Created by MarkPerry on 7/07/2014. */ -public class Writer { +public final class Writer { private A val; private W logValue; From 9d2ca349043c673d468c76a4d8c8b3a0781cd12d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 14:17:47 +0100 Subject: [PATCH 026/336] Fix some final modifiers. Add private constructor on utility classes. --- core/src/main/java/fj/Effect.java | 4 +-- core/src/main/java/fj/F1Functions.java | 5 +++- core/src/main/java/fj/F2Functions.java | 7 +++-- core/src/main/java/fj/F3Functions.java | 7 +++-- core/src/main/java/fj/F4Functions.java | 7 +++-- core/src/main/java/fj/F5Functions.java | 5 +++- core/src/main/java/fj/F6Functions.java | 5 +++- core/src/main/java/fj/F7Functions.java | 5 +++- core/src/main/java/fj/F8Functions.java | 5 +++- core/src/main/java/fj/Ord.java | 2 +- core/src/main/java/fj/Try.java | 5 +++- .../main/java/fj/control/parallel/Actor.java | 4 +-- core/src/main/java/fj/data/IOFunctions.java | 29 ++++++++++--------- core/src/main/java/fj/data/Iteratee.java | 16 +++++----- core/src/main/java/fj/data/Seq.java | 4 +-- .../main/java/fj/data/fingertrees/Deep.java | 4 +-- core/src/main/java/fj/data/optic/Fold.java | 2 +- core/src/main/java/fj/data/optic/Getter.java | 4 +-- core/src/main/java/fj/data/optic/Iso.java | 22 +++++++------- core/src/main/java/fj/data/optic/Lens.java | 20 ++++++------- .../src/main/java/fj/data/optic/Optional.java | 22 +++++++------- core/src/main/java/fj/data/optic/PIso.java | 2 +- core/src/main/java/fj/data/optic/PLens.java | 2 +- .../main/java/fj/data/optic/POptional.java | 2 +- core/src/main/java/fj/data/optic/PSetter.java | 4 +-- core/src/main/java/fj/data/optic/Prism.java | 18 ++++++------ core/src/main/java/fj/data/optic/Setter.java | 12 ++++---- .../main/java/fj/data/optic/Traversal.java | 8 ++--- .../java/fj/data/test/PropertyAssert.java | 4 ++- 29 files changed, 134 insertions(+), 102 deletions(-) diff --git a/core/src/main/java/fj/Effect.java b/core/src/main/java/fj/Effect.java index 387055f1..6e5e7b7f 100644 --- a/core/src/main/java/fj/Effect.java +++ b/core/src/main/java/fj/Effect.java @@ -33,7 +33,7 @@ public static P1 f(Effect0 e) { * * @return The function using the given effect. */ - public static final F f(Effect1 e1) { + public static F f(Effect1 e1) { return a -> { e1.f(a); return unit(); @@ -95,7 +95,7 @@ public static F5 f(Effect5 z * @param f The function to map over the effect. * @return An effect after a contra-variant map. */ - public static final Effect1 contramap(Effect1 e1, final F f) { + public static Effect1 contramap(Effect1 e1, final F f) { return b -> e1.f(f.f(b)); } diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 2d3c56d4..640b624c 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -18,9 +18,12 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F1Functions { +public final class F1Functions { + private F1Functions() { + } + /** * Function composition * diff --git a/core/src/main/java/fj/F2Functions.java b/core/src/main/java/fj/F2Functions.java index c15a68cb..9ce1cc0a 100644 --- a/core/src/main/java/fj/F2Functions.java +++ b/core/src/main/java/fj/F2Functions.java @@ -13,10 +13,13 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F2Functions { +public final class F2Functions { - /** + private F2Functions() { + } + + /** * Partial application. * * @param a The A to which to apply this function. diff --git a/core/src/main/java/fj/F3Functions.java b/core/src/main/java/fj/F3Functions.java index 62d91aee..77a8fa74 100644 --- a/core/src/main/java/fj/F3Functions.java +++ b/core/src/main/java/fj/F3Functions.java @@ -9,10 +9,13 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F3Functions { +public final class F3Functions { - /** + private F3Functions() { + } + + /** * Partial application. * * @param a The A to which to apply this function. diff --git a/core/src/main/java/fj/F4Functions.java b/core/src/main/java/fj/F4Functions.java index 71ee56a3..ab57247b 100644 --- a/core/src/main/java/fj/F4Functions.java +++ b/core/src/main/java/fj/F4Functions.java @@ -6,9 +6,12 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F4Functions { +public final class F4Functions { - /** + private F4Functions() { + } + + /** * Partial application. * * @param a The A to which to apply this function. diff --git a/core/src/main/java/fj/F5Functions.java b/core/src/main/java/fj/F5Functions.java index 8cb26c6d..6345de01 100644 --- a/core/src/main/java/fj/F5Functions.java +++ b/core/src/main/java/fj/F5Functions.java @@ -6,7 +6,10 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F5Functions { +public final class F5Functions { + + private F5Functions() { + } /** * Partial application. diff --git a/core/src/main/java/fj/F6Functions.java b/core/src/main/java/fj/F6Functions.java index 70458593..19269e40 100644 --- a/core/src/main/java/fj/F6Functions.java +++ b/core/src/main/java/fj/F6Functions.java @@ -6,7 +6,10 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F6Functions { +public final class F6Functions { + + private F6Functions() { + } /** * Partial application. diff --git a/core/src/main/java/fj/F7Functions.java b/core/src/main/java/fj/F7Functions.java index a6ceff9f..4abcb986 100644 --- a/core/src/main/java/fj/F7Functions.java +++ b/core/src/main/java/fj/F7Functions.java @@ -6,7 +6,10 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F7Functions { +public final class F7Functions { + + private F7Functions() { + } /** * Partial application. diff --git a/core/src/main/java/fj/F8Functions.java b/core/src/main/java/fj/F8Functions.java index 788f106d..5cb9bb3b 100644 --- a/core/src/main/java/fj/F8Functions.java +++ b/core/src/main/java/fj/F8Functions.java @@ -6,7 +6,10 @@ /** * Created by MarkPerry on 6/04/2014. */ -public class F8Functions { +public final class F8Functions { + + private F8Functions() { + } /** * Partial application. diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index a7a39cac..780f5edf 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -157,7 +157,7 @@ public A min(final A a1, final A a2) { */ public final F> min = curry((a, a1) -> min(a, a1)); - public final Ord reverse() { return ord(Function.flip(f)); } + public Ord reverse() { return ord(Function.flip(f)); } /** * Returns an order instance that uses the given equality test and ordering function. diff --git a/core/src/main/java/fj/Try.java b/core/src/main/java/fj/Try.java index 5ed2673f..c5829b01 100644 --- a/core/src/main/java/fj/Try.java +++ b/core/src/main/java/fj/Try.java @@ -13,7 +13,10 @@ /** * Created by mperry on 24/07/2014. */ -public class Try { +public final class Try { + + private Try() { + } /** * Promotes the Try0 to a Validation that returns an Exception on the failure side and its result on the success side. diff --git a/core/src/main/java/fj/control/parallel/Actor.java b/core/src/main/java/fj/control/parallel/Actor.java index 77d4fe2d..301f057d 100644 --- a/core/src/main/java/fj/control/parallel/Actor.java +++ b/core/src/main/java/fj/control/parallel/Actor.java @@ -69,13 +69,13 @@ public static Actor queueActor(final Strategy s, final Effect1 e } // If there are pending messages, use the strategy to run the processor - protected void work() { + void work() { if (!mbox.isEmpty() && suspended.compareAndSet(true, false)) { s.par(processor); } } }); - }; + } private Actor(final Strategy s, final F> e) { this.s = s; diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index d53caf9a..1a3e93ff 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -26,10 +26,13 @@ * * @author Martin Grotzke */ -public class IOFunctions { +public final class IOFunctions { private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + private IOFunctions() { + } + public static Try0 toTry(IO io) { return () -> io.run(); } @@ -133,7 +136,7 @@ public static IO fileReader(final File f, final Option encoding }; } - public static final IO bracket(final IO init, final F> fin, final F> body) { + public static IO bracket(final IO init, final F> fin, final F> body) { return new IO() { @Override public C run() throws IOException { @@ -149,7 +152,7 @@ public C run() throws IOException { }; } - public static final IO unit(final A a) { + public static IO unit(final A a) { return new IO() { @Override public A run() throws IOException { @@ -160,19 +163,19 @@ public A run() throws IOException { public static final IO ioUnit = unit(Unit.unit()); - public static final IO lazy(final F0 p) { + public static IO lazy(final F0 p) { return fromF(p); } - public static final IO lazy(final F f) { + public static IO lazy(final F f) { return () -> f.f(Unit.unit()); } - public static final SafeIO lazySafe(final F f) { + public static SafeIO lazySafe(final F f) { return () -> f.f(Unit.unit()); } - public static final SafeIO lazySafe(final F0 f) { + public static SafeIO lazySafe(final F0 f) { return f::f; } @@ -330,7 +333,7 @@ public IterV run() throws IOException { }; } - public static final IO map(final IO io, final F f) { + public static IO map(final IO io, final F f) { return new IO() { @Override public B run() throws IOException { @@ -339,15 +342,15 @@ public B run() throws IOException { }; } - public static final IO as(final IO io, final B b) { + public static IO as(final IO io, final B b) { return map(io, ignored -> b); } - public static final IO voided(final IO io) { + public static IO voided(final IO io) { return as(io, Unit.unit()); } - public static final IO bind(final IO io, final F> f) { + public static IO bind(final IO io, final F> f) { return new IO() { @Override public B run() throws IOException { @@ -356,11 +359,11 @@ public B run() throws IOException { }; } - public static final IO when(final Boolean b, final IO io) { + public static IO when(final Boolean b, final IO io) { return b ? io : ioUnit; } - public static final IO unless(final Boolean b, final IO io) { + public static IO unless(final Boolean b, final IO io) { return when(!b, io); } diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index 9eaeb95e..e4cd3530 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -22,7 +22,7 @@ public static abstract class Input { public abstract Z apply(final F0 empty, final F0> el, final F0 eof); /** Input that has no values available */ - public static final Input empty() { + public static Input empty() { return new Input() { @Override public Z apply(final F0 empty, final F0> el, final F0 eof) { @@ -32,7 +32,7 @@ public Z apply(final F0 empty, final F0> el, final F0 eof) { } /** Input that is exhausted */ - public static final Input eof() { + public static Input eof() { return new Input() { @Override public Z apply(final F0 empty, final F0> el, final F0 eof) { @@ -42,7 +42,7 @@ public Z apply(final F0 empty, final F0> el, final F0 eof) { } /** Input that has a value available */ - public static final Input el(final E element) { + public static Input el(final E element) { return new Input() { @Override public Z apply(final F0 empty, final F0> el, final F0 eof) { @@ -121,7 +121,7 @@ public IterV f(final P2> xe) { } /** An iteratee that counts and consumes the elements of the input */ - public static final IterV length() { + public static IterV length() { final F, IterV>> step = new F, IterV>>() { final F, IterV>> step = this; @@ -141,7 +141,7 @@ public F, IterV> f(final Integer acc) { } /** An iteratee that skips the first n elements of the input */ - public static final IterV drop(final int n) { + public static IterV drop(final int n) { final F, IterV> step = new F, IterV>() { final F, IterV> step = this; @@ -163,7 +163,7 @@ public IterV f(final Input s) { } /** An iteratee that consumes the head of the input */ - public static final IterV> head() { + public static IterV> head() { final F, IterV>> step = new F, IterV>>() { final F, IterV>> step = this; @@ -183,7 +183,7 @@ public IterV> f(final Input s) { } /** An iteratee that returns the first element of the input */ - public static final IterV> peek() { + public static IterV> peek() { final F, IterV>> step = new F, IterV>>() { final F, IterV>> step = this; @@ -204,7 +204,7 @@ public IterV> f(final Input s) { /** An iteratee that consumes the input elements and returns them as a list in reverse order, * so that the last line is the first element. This allows to build a list from 2 iteratees. */ - public static final IterV> list() { + public static IterV> list() { final F, F, IterV>>> step = new F, F, IterV>>>() { final F, F, IterV>>> step = this; diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index a29d97c0..00868ef3 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -214,7 +214,7 @@ public List toList() { /** * Converts the sequence to a java.util.List */ - public final java.util.List toJavaList() { + public java.util.List toJavaList() { return new AbstractList() { @Override public A get(int i) { return index(i); } @Override public Iterator iterator() { return Seq.this.iterator(); } @@ -227,7 +227,7 @@ public final java.util.List toJavaList() { * * @return A iterator for this seq. */ - public final Iterator iterator() { + public Iterator iterator() { return new Iterator() { private FingerTree ftree = Seq.this.ftree; diff --git a/core/src/main/java/fj/data/fingertrees/Deep.java b/core/src/main/java/fj/data/fingertrees/Deep.java index e42bde4d..a33637d8 100644 --- a/core/src/main/java/fj/data/fingertrees/Deep.java +++ b/core/src/main/java/fj/data/fingertrees/Deep.java @@ -134,14 +134,14 @@ public FingerTree snoc(final A a) { four -> four.values()._4()); } - private static final FingerTree deepL(final Measured measured, final Option> lOpt, final FingerTree> m, final Digit r) { + private static FingerTree deepL(final Measured measured, final Option> lOpt, final FingerTree> m, final Digit r) { return lOpt.option( P.lazy(() -> m.isEmpty() ? r.toTree() : mkTree(measured).deep(m.head().toDigit(), m.tail(), r)), (F, FingerTree>) l -> mkTree(measured).deep(l, m, r) ); } - private static final FingerTree deepR(final Measured measured, final Option> rOpt, final FingerTree> m, final Digit l) { + private static FingerTree deepR(final Measured measured, final Option> rOpt, final FingerTree> m, final Digit l) { return rOpt.option( P.lazy(() -> m.isEmpty() ? l.toTree() : mkTree(measured).deep(l, m.init(), m.last().toDigit())), (F, FingerTree>) r -> mkTree(measured).deep(l, m, r) diff --git a/core/src/main/java/fj/data/optic/Fold.java b/core/src/main/java/fj/data/optic/Fold.java index 94b8aaf6..21aca09f 100644 --- a/core/src/main/java/fj/data/optic/Fold.java +++ b/core/src/main/java/fj/data/optic/Fold.java @@ -110,7 +110,7 @@ public static Fold id() { return PIso. pId().asFold(); } - public static final Fold, A> codiagonal() { + public static Fold, A> codiagonal() { return new Fold, A>() { @Override public F, B> foldMap(final Monoid m, final F f) { diff --git a/core/src/main/java/fj/data/optic/Getter.java b/core/src/main/java/fj/data/optic/Getter.java index b5c60d50..a5c9fa99 100644 --- a/core/src/main/java/fj/data/optic/Getter.java +++ b/core/src/main/java/fj/data/optic/Getter.java @@ -94,11 +94,11 @@ public static Getter id() { return PIso. pId().asGetter(); } - public static final Getter, A> codiagonal() { + public static Getter, A> codiagonal() { return getter(e -> e.either(Function.identity(), Function.identity())); } - public static final Getter getter(final F get) { + public static Getter getter(final F get) { return new Getter() { @Override diff --git a/core/src/main/java/fj/data/optic/Iso.java b/core/src/main/java/fj/data/optic/Iso.java index 71ca7359..ea9babac 100644 --- a/core/src/main/java/fj/data/optic/Iso.java +++ b/core/src/main/java/fj/data/optic/Iso.java @@ -47,32 +47,32 @@ public Iso, P2> second() { /**********************************************************/ /** compose an {@link Iso} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pIso.composeSetter(other.pSetter)); } /** compose an {@link Iso} with a {@link Traversal} */ - public final Traversal composeTraversal(final Traversal other) { + public Traversal composeTraversal(final Traversal other) { return new Traversal<>(pIso.composeTraversal(other.pTraversal)); } /** compose an {@link Iso} with a {@link Optional} */ - public final Optional composeOptional(final Optional other) { + public Optional composeOptional(final Optional other) { return new Optional<>(pIso.composeOptional(other.pOptional)); } /** compose an {@link Iso} with a {@link Prism} */ - public final Prism composePrism(final Prism other) { + public Prism composePrism(final Prism other) { return new Prism<>(pIso.composePrism(other.pPrism)); } /** compose an {@link Iso} with a {@link Lens} */ - public final Lens composeLens(final Lens other) { + public Lens composeLens(final Lens other) { return asLens().composeLens(other); } /** compose an {@link Iso} with an {@link Iso} */ - public final Iso composeIso(final Iso other) { + public Iso composeIso(final Iso other) { return new Iso<>(pIso.composeIso(other.pIso)); } @@ -82,31 +82,31 @@ public final Iso composeIso(final Iso other) { /** view an {@link Iso} as a {@link Setter} */ @Override - public final Setter asSetter() { + public Setter asSetter() { return new Setter<>(pIso.asSetter()); } /** view an {@link Iso} as a {@link Traversal} */ @Override - public final Traversal asTraversal() { + public Traversal asTraversal() { return new Traversal<>(pIso.asTraversal()); } /** view an {@link Iso} as a {@link Optional} */ @Override - public final Optional asOptional() { + public Optional asOptional() { return new Optional<>(pIso.asOptional()); } /** view an {@link Iso} as a {@link Prism} */ @Override - public final Prism asPrism() { + public Prism asPrism() { return new Prism<>(pIso.asPrism()); } /** view an {@link Iso} as a {@link Lens} */ @Override - public final Lens asLens() { + public Lens asLens() { return new Lens<>(pIso.asLens()); } diff --git a/core/src/main/java/fj/data/optic/Lens.java b/core/src/main/java/fj/data/optic/Lens.java index bb65952b..ceea42c9 100644 --- a/core/src/main/java/fj/data/optic/Lens.java +++ b/core/src/main/java/fj/data/optic/Lens.java @@ -94,7 +94,7 @@ public F modify(final F f) { } /** join two {@link Lens} with the same target */ - public final Lens, A> sum(final Lens other) { + public Lens, A> sum(final Lens other) { return new Lens<>(pLens.sum(other.pLens)); } @@ -105,34 +105,34 @@ public final Lens, A> sum(final Lens other) { /** * compose a {@link Lens} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pLens.composeSetter(other.pSetter)); } /** * compose a {@link Lens} with a {@link Traversal} */ - public final Traversal composeTraversal(final Traversal other) { + public Traversal composeTraversal(final Traversal other) { return new Traversal<>(pLens.composeTraversal(other.pTraversal)); } /** compose a {@link Lens} with an {@link Optional} */ - public final Optional composeOptional(final Optional other) { + public Optional composeOptional(final Optional other) { return new Optional<>(pLens.composeOptional(other.pOptional)); } /** compose a {@link Lens} with a {@link Prism} */ - public final Optional composePrism(final Prism other) { + public Optional composePrism(final Prism other) { return new Optional<>(pLens.composePrism(other.pPrism)); } /** compose a {@link Lens} with a {@link Lens} */ - public final Lens composeLens(final Lens other) { + public Lens composeLens(final Lens other) { return new Lens<>(pLens.composeLens(other.pLens)); } /** compose a {@link Lens} with an {@link Iso} */ - public final Lens composeIso(final Iso other) { + public Lens composeIso(final Iso other) { return new Lens<>(pLens.composeIso(other.pIso)); } @@ -148,17 +148,17 @@ public Setter asSetter() { /** view a {@link Lens} as a {@link Traversal} */ @Override - public final Traversal asTraversal() { + public Traversal asTraversal() { return new Traversal<>(pLens.asTraversal()); } /** view a {@link Lens} as an {@link Optional} */ @Override - public final Optional asOptional() { + public Optional asOptional() { return new Optional<>(pLens.asOptional()); } - public static final Lens id() { + public static Lens id() { return new Lens<>(PLens.pId()); } diff --git a/core/src/main/java/fj/data/optic/Optional.java b/core/src/main/java/fj/data/optic/Optional.java index ed737cf0..200a952d 100644 --- a/core/src/main/java/fj/data/optic/Optional.java +++ b/core/src/main/java/fj/data/optic/Optional.java @@ -103,17 +103,17 @@ public Option getOption(final S s) { } /** join two {@link Optional} with the same target */ - public final Optional, A> sum(final Optional other) { + public Optional, A> sum(final Optional other) { return new Optional<>(pOptional.sum(other.pOptional)); } @Override - public final Optional, P2> first() { + public Optional, P2> first() { return new Optional<>(pOptional.first()); } @Override - public final Optional, P2> second() { + public Optional, P2> second() { return new Optional<>(pOptional.second()); } @@ -122,32 +122,32 @@ public final Optional, P2> second() { /**************************************************************/ /** compose a {@link Optional} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pOptional.composeSetter(other.pSetter)); } /** compose a {@link Optional} with a {@link Traversal} */ - public final Traversal composeTraversal(final Traversal other) { + public Traversal composeTraversal(final Traversal other) { return new Traversal<>(pOptional.composeTraversal(other.pTraversal)); } /** compose a {@link Optional} with a {@link Optional} */ - public final Optional composeOptional(final Optional other) { + public Optional composeOptional(final Optional other) { return new Optional<>(pOptional.composeOptional(other.pOptional)); } /** compose a {@link Optional} with a {@link Prism} */ - public final Optional composePrism(final Prism other) { + public Optional composePrism(final Prism other) { return new Optional<>(pOptional.composePrism(other.pPrism)); } /** compose a {@link Optional} with a {@link Lens} */ - public final Optional composeLens(final Lens other) { + public Optional composeLens(final Lens other) { return new Optional<>(pOptional.composeLens(other.pLens)); } /** compose a {@link Optional} with an {@link Iso} */ - public final Optional composeIso(final Iso other) { + public Optional composeIso(final Iso other) { return new Optional<>(pOptional.composeIso(other.pIso)); } @@ -157,13 +157,13 @@ public final Optional composeIso(final Iso other) { /** view a {@link Optional} as a {@link Setter} */ @Override - public final Setter asSetter() { + public Setter asSetter() { return new Setter<>(pOptional.asSetter()); } /** view a {@link Optional} as a {@link Traversal} */ @Override - public final Traversal asTraversal() { + public Traversal asTraversal() { return new Traversal<>(pOptional.asTraversal()); } diff --git a/core/src/main/java/fj/data/optic/PIso.java b/core/src/main/java/fj/data/optic/PIso.java index 850dedb6..4ed45ca0 100644 --- a/core/src/main/java/fj/data/optic/PIso.java +++ b/core/src/main/java/fj/data/optic/PIso.java @@ -510,7 +510,7 @@ public F> modifyV2F(final F> f) { } /** create a {@link PIso} using a pair of functions: one to get the target and one to get the source. */ - public static final PIso pIso(final F get, final F reverseGet) { + public static PIso pIso(final F get, final F reverseGet) { return new PIso() { @Override diff --git a/core/src/main/java/fj/data/optic/PLens.java b/core/src/main/java/fj/data/optic/PLens.java index ade9b9e7..68de9079 100644 --- a/core/src/main/java/fj/data/optic/PLens.java +++ b/core/src/main/java/fj/data/optic/PLens.java @@ -418,7 +418,7 @@ public F modify(final F f) { }; } - public static final PLens pId() { + public static PLens pId() { return PIso. pId().asLens(); } diff --git a/core/src/main/java/fj/data/optic/POptional.java b/core/src/main/java/fj/data/optic/POptional.java index b1b0fa6e..92e4edf0 100644 --- a/core/src/main/java/fj/data/optic/POptional.java +++ b/core/src/main/java/fj/data/optic/POptional.java @@ -366,7 +366,7 @@ public static POptional pId() { } /** create a {@link POptional} using the canonical functions: getOrModify and set */ - public static final POptional pOptional(final F> getOrModify, final F> set) { + public static POptional pOptional(final F> getOrModify, final F> set) { return new POptional() { @Override public Either getOrModify(final S s) { diff --git a/core/src/main/java/fj/data/optic/PSetter.java b/core/src/main/java/fj/data/optic/PSetter.java index ad8e3ea8..012920cb 100644 --- a/core/src/main/java/fj/data/optic/PSetter.java +++ b/core/src/main/java/fj/data/optic/PSetter.java @@ -84,11 +84,11 @@ public static PSetter pId() { return PIso. pId().asSetter(); } - public static final PSetter, Either, S, T> pCodiagonal() { + public static PSetter, Either, S, T> pCodiagonal() { return pSetter(f -> e -> e.bimap(f, f)); } - public static final PSetter pSetter(final F, F> modify) { + public static PSetter pSetter(final F, F> modify) { return new PSetter() { @Override public F modify(final F f) { diff --git a/core/src/main/java/fj/data/optic/Prism.java b/core/src/main/java/fj/data/optic/Prism.java index 409bfc6d..42decaaf 100644 --- a/core/src/main/java/fj/data/optic/Prism.java +++ b/core/src/main/java/fj/data/optic/Prism.java @@ -35,32 +35,32 @@ public Option getOption(final S s) { /***********************************************************/ /** compose a {@link Prism} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pPrism.composeSetter(other.pSetter)); } /** compose a {@link Prism} with a {@link Traversal} */ - public final Traversal composeTraversal(final Traversal other) { + public Traversal composeTraversal(final Traversal other) { return new Traversal<>(pPrism.composeTraversal(other.pTraversal)); } /** compose a {@link Prism} with a {@link Optional} */ - public final Optional composeOptional(final Optional other) { + public Optional composeOptional(final Optional other) { return new Optional<>(pPrism.composeOptional(other.pOptional)); } /** compose a {@link Prism} with a {@link Lens} */ - public final Optional composeLens(final Lens other) { + public Optional composeLens(final Lens other) { return new Optional<>(pPrism.composeLens(other.pLens)); } /** compose a {@link Prism} with a {@link Prism} */ - public final Prism composePrism(final Prism other) { + public Prism composePrism(final Prism other) { return new Prism<>(pPrism.composePrism(other.pPrism)); } /** compose a {@link Prism} with an {@link Iso} */ - public final Prism composeIso(final Iso other) { + public Prism composeIso(final Iso other) { return new Prism<>(pPrism.composeIso(other.pIso)); } @@ -70,19 +70,19 @@ public final Prism composeIso(final Iso other) { /** view a {@link Prism} as a {@link Setter} */ @Override - public final Setter asSetter() { + public Setter asSetter() { return new Setter<>(pPrism.asSetter()); } /** view a {@link Prism} as a {@link Traversal} */ @Override - public final Traversal asTraversal() { + public Traversal asTraversal() { return new Traversal<>(pPrism.asTraversal()); } /** view a {@link Prism} as a {@link Optional} */ @Override - public final Optional asOptional() { + public Optional asOptional() { return new Optional<>(pPrism.asOptional()); } diff --git a/core/src/main/java/fj/data/optic/Setter.java b/core/src/main/java/fj/data/optic/Setter.java index 40fc8473..95227f10 100644 --- a/core/src/main/java/fj/data/optic/Setter.java +++ b/core/src/main/java/fj/data/optic/Setter.java @@ -23,7 +23,7 @@ public F set(final A b) { } /** join two {@link Setter} with the same target */ - public final Setter, A> sum(final Setter other) { + public Setter, A> sum(final Setter other) { return new Setter<>(pSetter.sum(other.pSetter)); } @@ -32,17 +32,17 @@ public final Setter, A> sum(final Setter other) { /************************************************************/ /** compose a {@link Setter} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pSetter.composeSetter(other.pSetter)); } /** compose a {@link Setter} with a {@link Traversal} */ - public final Setter composeTraversal(final Traversal other) { + public Setter composeTraversal(final Traversal other) { return new Setter<>(pSetter.composeTraversal(other.pTraversal)); } /** compose a {@link Setter} with an {@link Iso} */ - public final Setter composeIso(final Iso other) { + public Setter composeIso(final Iso other) { return new Setter<>(pSetter.composeIso(other.pIso)); } @@ -50,12 +50,12 @@ public static Setter id() { return new Setter<>(PSetter.pId()); } - public static final Setter, S> codiagonal() { + public static Setter, S> codiagonal() { return new Setter<>(PSetter.pCodiagonal()); } /** alias for {@link PSetter} constructor with a monomorphic modify function */ - public static final Setter setter(final F, F> modify) { + public static Setter setter(final F, F> modify) { return new Setter<>(PSetter.pSetter(modify)); } } diff --git a/core/src/main/java/fj/data/optic/Traversal.java b/core/src/main/java/fj/data/optic/Traversal.java index 756a95ed..4064385e 100644 --- a/core/src/main/java/fj/data/optic/Traversal.java +++ b/core/src/main/java/fj/data/optic/Traversal.java @@ -87,7 +87,7 @@ public F foldMap(final Monoid monoid, final F f) { } /** join two {@link Traversal} with the same target */ - public final Traversal, A> sum(final Traversal other) { + public Traversal, A> sum(final Traversal other) { return new Traversal<>(pTraversal.sum(other.pTraversal)); } @@ -96,12 +96,12 @@ public final Traversal, A> sum(final Traversal other) /***************************************************************/ /** compose a {@link Traversal} with a {@link Setter} */ - public final Setter composeSetter(final Setter other) { + public Setter composeSetter(final Setter other) { return new Setter<>(pTraversal.composeSetter(other.pSetter)); } /** compose a {@link Traversal} with a {@link Traversal} */ - public final Traversal composeTraversal(final Traversal other) { + public Traversal composeTraversal(final Traversal other) { return new Traversal<>(pTraversal.composeTraversal(other.pTraversal)); } @@ -111,7 +111,7 @@ public final Traversal composeTraversal(final Traversal other) { /** view a {@link Traversal} as a {@link Setter} */ @Override - public final Setter asSetter() { + public Setter asSetter() { return new Setter<>(pTraversal.asSetter()); } diff --git a/quickcheck/src/main/java/fj/data/test/PropertyAssert.java b/quickcheck/src/main/java/fj/data/test/PropertyAssert.java index bec07f7f..00187b15 100644 --- a/quickcheck/src/main/java/fj/data/test/PropertyAssert.java +++ b/quickcheck/src/main/java/fj/data/test/PropertyAssert.java @@ -8,7 +8,9 @@ /** * Created by MarkPerry on 18/12/2014. */ -public class PropertyAssert { +public final class PropertyAssert { + + private PropertyAssert(){} public static Unit assertResult(Property p) { CheckResult cr = p.check(); From 9eaabfafa0588142555d5976e11b57d43cf3d0c2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 17:07:19 +0100 Subject: [PATCH 027/336] Make instance fields final when possible --- core/src/main/java/fj/control/parallel/Actor.java | 6 +++--- core/src/main/java/fj/data/IOW.java | 2 +- core/src/main/java/fj/data/Reader.java | 2 +- core/src/main/java/fj/data/State.java | 2 +- core/src/main/java/fj/data/Writer.java | 6 +++--- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/fj/control/parallel/Actor.java b/core/src/main/java/fj/control/parallel/Actor.java index 301f057d..bd1956bd 100644 --- a/core/src/main/java/fj/control/parallel/Actor.java +++ b/core/src/main/java/fj/control/parallel/Actor.java @@ -36,14 +36,14 @@ public static Actor queueActor(final Strategy s, final Effect1 e return actor(Strategy.seqStrategy(), new Effect1() { // Lock to ensure the actor only acts on one message at a time - AtomicBoolean suspended = new AtomicBoolean(true); + final AtomicBoolean suspended = new AtomicBoolean(true); // Queue to hold pending messages - ConcurrentLinkedQueue mbox = new ConcurrentLinkedQueue(); + final ConcurrentLinkedQueue mbox = new ConcurrentLinkedQueue(); // Product so the actor can use its strategy (to act on messages in other threads, // to handle exceptions, etc.) - P1 processor = new P1() { + final P1 processor = new P1() { @Override public Unit _1() { // get next item from queue T a = mbox.poll(); diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index b508456c..8b1b2ac6 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -10,7 +10,7 @@ */ public final class IOW implements IO { - private IO io; + private final IO io; private IOW(IO in) { io = in; diff --git a/core/src/main/java/fj/data/Reader.java b/core/src/main/java/fj/data/Reader.java index 34a98c72..749f4c9b 100644 --- a/core/src/main/java/fj/data/Reader.java +++ b/core/src/main/java/fj/data/Reader.java @@ -9,7 +9,7 @@ */ public class Reader { - private F function; + private final F function; public Reader(F f) { function = f; diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 14620208..c54d6cb7 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -11,7 +11,7 @@ */ public final class State { - private F> run; + private final F> run; private State(F> f) { run = f; diff --git a/core/src/main/java/fj/data/Writer.java b/core/src/main/java/fj/data/Writer.java index ad55c3ae..7ff57d07 100644 --- a/core/src/main/java/fj/data/Writer.java +++ b/core/src/main/java/fj/data/Writer.java @@ -7,9 +7,9 @@ */ public final class Writer { - private A val; - private W logValue; - private Monoid monoid; + private final A val; + private final W logValue; + private final Monoid monoid; private Writer(A a, W w, Monoid m) { val = a; From 2b8c1af39c515beb79fd63e34cb66cbfe9913b7a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 17:08:38 +0100 Subject: [PATCH 028/336] Correct order of modifiers according to JLS --- core/src/main/java/fj/F1Functions.java | 136 +++++++++--------- core/src/main/java/fj/F2Functions.java | 52 +++---- core/src/main/java/fj/F3Functions.java | 2 +- core/src/main/java/fj/F4Functions.java | 2 +- core/src/main/java/fj/F5Functions.java | 2 +- core/src/main/java/fj/F6Functions.java | 2 +- core/src/main/java/fj/F7Functions.java | 2 +- core/src/main/java/fj/F8Functions.java | 2 +- core/src/main/java/fj/Try.java | 16 +-- core/src/main/java/fj/control/Trampoline.java | 2 +- core/src/main/java/fj/data/Conversions.java | 2 +- core/src/main/java/fj/data/Iteratee.java | 4 +- java8/src/main/java/fj/data/Java8.java | 36 ++--- 13 files changed, 130 insertions(+), 130 deletions(-) diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 640b624c..5821a893 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -30,7 +30,7 @@ private F1Functions() { * @param g A function to compose with this one. * @return The composed function such that this function is applied last. */ - static public F o(final F f, final F g) { + public static F o(final F f, final F g) { return c -> f.f(g.f(c)); } @@ -39,7 +39,7 @@ static public F o(final F f, final F g) { * * @return A function that composes this function with another. */ - static public F, F> o(final F f) { + public static F, F> o(final F f) { return g -> o(f, g); } @@ -50,7 +50,7 @@ static public F, F> o(final F f) { * @return The composed function such that this function is applied first. */ @SuppressWarnings({"unchecked"}) - static public F andThen(final F f, final F g) { + public static F andThen(final F f, final F g) { return o(g, f); } @@ -59,7 +59,7 @@ static public F andThen(final F f, final F g) { * * @return A function that invokes this function and then a given function on the result. */ - static public F, F> andThen(final F f) { + public static F, F> andThen(final F f) { return g -> andThen(f, g); } @@ -69,7 +69,7 @@ static public F, F> andThen(final F f) { * @param g A function that takes the return value of this function as an argument, yielding a new function. * @return A function that invokes this function on its argument and then the given function on the result. */ - static public F bind(final F f, final F> g) { + public static F bind(final F f, final F> g) { return a -> g.f(f.f(a)).f(a); } @@ -78,7 +78,7 @@ static public F bind(final F f, final F> g) { * * @return A function that binds another function across this function. */ - static public F>, F> bind(final F f) { + public static F>, F> bind(final F f) { return g -> bind(f, g); } @@ -90,7 +90,7 @@ static public F>, F> bind(final F f) { * @return A new function that invokes the given function on its argument, yielding a new function that is then * applied to the result of applying this function to the argument. */ - static public F apply(final F f, final F> g) { + public static F apply(final F f, final F> g) { return a -> g.f(a).f(f.f(a)); } @@ -99,7 +99,7 @@ static public F apply(final F f, final F> g) { * * @return A function that applies a given function within the environment of this function. */ - static public F>, F> apply(final F f) { + public static F>, F> apply(final F f) { return g -> apply(f, g); } @@ -109,7 +109,7 @@ static public F>, F> apply(final F f) { * @param g The function over whose arguments to apply this function. * @return A new function that invokes this function on its arguments before invoking the given function. */ - static public F> on(final F f, final F> g) { + public static F> on(final F f, final F> g) { return a1 -> a2 -> g.f(f.f(a1)).f(f.f(a2)); } @@ -120,7 +120,7 @@ static public F> on(final F f, final F> g) * * @return A function that applies this function over the arguments of another function. */ - static public F>, F>> on(final F f) { + public static F>, F>> on(final F f) { return g -> on(f, g); } @@ -129,7 +129,7 @@ static public F>, F>> on(final F f) { * * @return This function promoted to return its result in a product-1. */ - static public F> lazy(final F f) { + public static F> lazy(final F f) { return a -> P.lazy(() -> f.f(a)); } @@ -139,7 +139,7 @@ static public F> lazy(final F f) { * @param a The A to which to apply this function. * @return The function partially applied to the given argument to return a lazy value. */ - static public P1 f(final F f, final A a) { + public static P1 f(final F f, final A a) { return P.lazy(() -> f.f(a)); } @@ -148,7 +148,7 @@ static public P1 f(final F f, final A a) { * * @return This function promoted to map over a product-1. */ - static public F, P1> mapP1(final F f) { + public static F, P1> mapP1(final F f) { return p -> p.map(f); } @@ -157,7 +157,7 @@ static public F, P1> mapP1(final F f) { * * @return This function promoted to return its result in an Option. */ - static public F> optionK(final F f) { + public static F> optionK(final F f) { return a -> some(f.f(a)); } @@ -166,7 +166,7 @@ static public F> optionK(final F f) { * * @return This function promoted to map over an optional value. */ - static public F, Option> mapOption(final F f) { + public static F, Option> mapOption(final F f) { return o -> o.map(f); } @@ -175,7 +175,7 @@ static public F, Option> mapOption(final F f) { * * @return This function promoted to return its result in a List. */ - static public F> listK(final F f) { + public static F> listK(final F f) { return a -> List.single(f.f(a)); } @@ -184,7 +184,7 @@ static public F> listK(final F f) { * * @return This function promoted to map over a List. */ - static public F, List> mapList(final F f) { + public static F, List> mapList(final F f) { return x -> x.map(f); } @@ -193,7 +193,7 @@ static public F, List> mapList(final F f) { * * @return This function promoted to return its result in a Stream. */ - static public F> streamK(final F f) { + public static F> streamK(final F f) { return a -> Stream.single(f.f(a)); } @@ -202,7 +202,7 @@ static public F> streamK(final F f) { * * @return This function promoted to map over a Stream. */ - static public F, Stream> mapStream(final F f) { + public static F, Stream> mapStream(final F f) { return x -> x.map(f); } @@ -211,7 +211,7 @@ static public F, Stream> mapStream(final F f) { * * @return This function promoted to return its result in a Array. */ - static public F> arrayK(final F f) { + public static F> arrayK(final F f) { return a -> Array.single(f.f(a)); } @@ -221,7 +221,7 @@ static public F> arrayK(final F f) { * * @return This function promoted to map over a Array. */ - static public F, Array> mapArray(final F f) { + public static F, Array> mapArray(final F f) { return x -> x.map(f); } @@ -230,7 +230,7 @@ static public F, Array> mapArray(final F f) { * * @return A function that contramaps over a given actor. */ - static public F, Actor> contramapActor(final F f) { + public static F, Actor> contramapActor(final F f) { return a -> a.contramap(f); } @@ -240,7 +240,7 @@ static public F, Actor> contramapActor(final F f) { * @param s A parallel strategy for concurrent execution. * @return A concurrent function that returns a Promise of a value. */ - static public F> promiseK(final F f, final Strategy s) { + public static F> promiseK(final F f, final Strategy s) { return Promise.promise(s, f); } @@ -249,7 +249,7 @@ static public F> promiseK(final F f, final Strategy F, Promise> mapPromise(final F f) { + public static F, Promise> mapPromise(final F f) { return p -> p.fmap(f); } @@ -260,7 +260,7 @@ static public F, Promise> mapPromise(final F f) { * @return This function promoted to return its result on the left side of an Either. */ @SuppressWarnings({"unchecked"}) - static public F> eitherLeftK(final F f) { + public static F> eitherLeftK(final F f) { return o(Either.left_(), f); } @@ -271,7 +271,7 @@ static public F> eitherLeftK(final F f) { * @return This function promoted to return its result on the right side of an Either. */ @SuppressWarnings({"unchecked"}) - static public F> eitherRightK(final F f) { + public static F> eitherRightK(final F f) { return o(Either.right_(), f); } @@ -281,7 +281,7 @@ static public F> eitherRightK(final F f) { * @return This function promoted to map over the left side of an Either. */ @SuppressWarnings({"unchecked"}) - static public F, Either> mapLeft(final F f) { + public static F, Either> mapLeft(final F f) { return Either.leftMap_().f(f); } @@ -291,7 +291,7 @@ static public F, Either> mapLeft(final F f) { * @return This function promoted to map over the right side of an Either. */ @SuppressWarnings({"unchecked"}) - static public F, Either> mapRight(final F f) { + public static F, Either> mapRight(final F f) { return Either.rightMap_().f(f); } @@ -300,7 +300,7 @@ static public F, Either> mapRight(final F f) * * @return a function that returns the left side of a given Either, or this function applied to the right side. */ - static public F, B> onLeft(final F f) { + public static F, B> onLeft(final F f) { return e -> e.left().on(f); } @@ -309,7 +309,7 @@ static public F, B> onLeft(final F f) { * * @return a function that returns the right side of a given Either, or this function applied to the left side. */ - static public F, B> onRight(final F f) { + public static F, B> onRight(final F f) { return e -> e.right().on(f); } @@ -319,7 +319,7 @@ static public F, B> onRight(final F f) { * @return This function promoted to return its value in an Iterable. */ @SuppressWarnings({"unchecked"}) - static public F> iterableK(final F f) { + public static F> iterableK(final F f) { return IterableW.arrow().f(f); } @@ -329,7 +329,7 @@ static public F> iterableK(final F f) { * @return This function promoted to map over Iterables. */ @SuppressWarnings({"unchecked"}) - static public F, IterableW> mapIterable(final F f) { + public static F, IterableW> mapIterable(final F f) { return F1Functions.o(IterableW.map().f(f), IterableW.>wrap()); } @@ -339,7 +339,7 @@ static public F, IterableW> mapIterable(final F f) { * @return This function promoted to return its value in a NonEmptyList. */ @SuppressWarnings({"unchecked"}) - static public F> nelK(final F f) { + public static F> nelK(final F f) { return o(NonEmptyList.nel(), f); } @@ -348,7 +348,7 @@ static public F> nelK(final F f) { * * @return This function promoted to map over a NonEmptyList. */ - static public F, NonEmptyList> mapNel(final F f) { + public static F, NonEmptyList> mapNel(final F f) { return list -> list.map(f); } @@ -358,7 +358,7 @@ static public F, NonEmptyList> mapNel(final F f) * @param o An order for the set. * @return This function promoted to return its value in a Set. */ - static public F> setK(final F f, final Ord o + public static F> setK(final F f, final Ord o ) { return a -> Set.single(o, f.f(a)); } @@ -369,7 +369,7 @@ static public F> setK(final F f, final Ord o * @param o An order for the resulting set. * @return This function promoted to map over a Set. */ - static public F, Set> mapSet(final F f, final Ord o) { + public static F, Set> mapSet(final F f, final Ord o) { return s -> s.map(o, f); } @@ -378,7 +378,7 @@ static public F, Set> mapSet(final F f, final Ord o) { * * @return This function promoted to return its value in a Tree. */ - static public F> treeK(final F f) { + public static F> treeK(final F f) { return a -> Tree.leaf(f.f(a)); } @@ -388,7 +388,7 @@ static public F> treeK(final F f) { * @return This function promoted to map over a Tree. */ @SuppressWarnings({"unchecked"}) - static public F, Tree> mapTree(final F f) { + public static F, Tree> mapTree(final F f) { return Tree.fmap_().f(f); } @@ -398,7 +398,7 @@ static public F, Tree> mapTree(final F f) { * @param m The monoid with which to fold the mapped tree. * @return a function that maps this function over a tree and folds it with the given monoid. */ - static public F, B> foldMapTree(final F f, final Monoid m) { + public static F, B> foldMapTree(final F f, final Monoid m) { return Tree.foldMap_(f, m); } @@ -407,7 +407,7 @@ static public F, B> foldMapTree(final F f, final Monoid * * @return This function promoted to return its value in a TreeZipper. */ - static public F> treeZipperK(final F f) { + public static F> treeZipperK(final F f) { return andThen(treeK(f), TreeZipper.fromTree()); } @@ -416,7 +416,7 @@ static public F> treeZipperK(final F f) { * * @return This function promoted to map over a TreeZipper. */ - static public F, TreeZipper> mapTreeZipper(final F f) { + public static F, TreeZipper> mapTreeZipper(final F f) { return (z) -> z.map(f); } @@ -426,7 +426,7 @@ static public F, TreeZipper> mapTreeZipper(final F * * @return This function promoted to return its result on the failure side of a Validation. */ - static public F> failK(final F f) { + public static F> failK(final F f) { return a -> Validation.fail(f.f(a)); } @@ -437,7 +437,7 @@ static public F> failK(final F f) { * * @return This function promoted to return its result on the success side of an Validation. */ - static public F> successK(final F f) { + public static F> successK(final F f) { return a -> Validation.success(f.f(a)); } @@ -446,7 +446,7 @@ static public F> successK(final F f) { * * @return This function promoted to map over the failure side of a Validation. */ - static public F, Validation> mapFail(final F f) { + public static F, Validation> mapFail(final F f) { return v -> v.f().map(f); } @@ -455,7 +455,7 @@ static public F, Validation> mapFail(final F F, Validation> mapSuccess(final F f) { + public static F, Validation> mapSuccess(final F f) { return v -> v.map(f); } @@ -466,7 +466,7 @@ static public F, Validation> mapSuccess(final F * @return a function that returns the failure side of a given Validation, * or this function applied to the success side. */ - static public F, B> onFail(final F f) { + public static F, B> onFail(final F f) { return v -> v.f().on(f); } @@ -477,7 +477,7 @@ static public F, B> onFail(final F f) { * @return a function that returns the success side of a given Validation, * or this function applied to the failure side. */ - static public F, B> onSuccess(final F f) { + public static F, B> onSuccess(final F f) { return v -> v.on(f); } @@ -486,7 +486,7 @@ static public F, B> onSuccess(final F f) { * * @return This function promoted to return its value in a Zipper. */ - static public F> zipperK(final F f) { + public static F> zipperK(final F f) { return andThen(streamK(f), s -> fromStream(s).some()); } @@ -495,7 +495,7 @@ static public F> zipperK(final F f) { * * @return This function promoted to map over a Zipper. */ - static public F, Zipper> mapZipper(final F f) { + public static F, Zipper> mapZipper(final F f) { return z -> z.map(f); } @@ -504,7 +504,7 @@ static public F, Zipper> mapZipper(final F f) { * * @return This function promoted to map over an Equal as a contravariant functor. */ - static public F, Equal> contramapEqual(final F f) { + public static F, Equal> contramapEqual(final F f) { return e -> e.contramap(f); } @@ -513,7 +513,7 @@ static public F, Equal> contramapEqual(final F f) { * * @return This function promoted to map over a Hash as a contravariant functor. */ - static public F, Hash> contramapHash(final F f) { + public static F, Hash> contramapHash(final F f) { return h -> h.contramap(f); } @@ -522,7 +522,7 @@ static public F, Hash> contramapHash(final F f) { * * @return This function promoted to map over a Show as a contravariant functor. */ - static public F, Show> contramapShow(final F f) { + public static F, Show> contramapShow(final F f) { return s -> s.contramap(f); } @@ -531,7 +531,7 @@ static public F, Show> contramapShow(final F f) { * * @return This function promoted to map over the first element of a pair. */ - static public F, P2> mapFst(final F f) { + public static F, P2> mapFst(final F f) { return P2.map1_(f); } @@ -540,7 +540,7 @@ static public F, P2> mapFst(final F f) { * * @return This function promoted to map over the second element of a pair. */ - static public F, P2> mapSnd(final F f) { + public static F, P2> mapSnd(final F f) { return P2.map2_(f); } @@ -549,7 +549,7 @@ static public F, P2> mapSnd(final F f) { * * @return This function promoted to map over both elements of a pair. */ - static public F, P2> mapBoth(final F f) { + public static F, P2> mapBoth(final F f) { return p2 -> P2.map(f, p2); } @@ -559,7 +559,7 @@ static public F, P2> mapBoth(final F f) { * @param as A SynchronousQueue to map this function over. * @return A new SynchronousQueue with this function applied to each element. */ - static public SynchronousQueue mapJ(final F f, final SynchronousQueue as) { + public static SynchronousQueue mapJ(final F f, final SynchronousQueue as) { final SynchronousQueue bs = new SynchronousQueue(); bs.addAll(iterableStream(as).map(f).toCollection()); return bs; @@ -572,7 +572,7 @@ static public SynchronousQueue mapJ(final F f, final Synchronous * @param as A PriorityBlockingQueue to map this function over. * @return A new PriorityBlockingQueue with this function applied to each element. */ - static public PriorityBlockingQueue mapJ(final F f, final PriorityBlockingQueue as) { + public static PriorityBlockingQueue mapJ(final F f, final PriorityBlockingQueue as) { return new PriorityBlockingQueue(iterableStream(as).map(f).toCollection()); } @@ -582,7 +582,7 @@ static public PriorityBlockingQueue mapJ(final F f, final Priori * @param as A LinkedBlockingQueue to map this function over. * @return A new LinkedBlockingQueue with this function applied to each element. */ - static public LinkedBlockingQueue mapJ(final F f, final LinkedBlockingQueue as) { + public static LinkedBlockingQueue mapJ(final F f, final LinkedBlockingQueue as) { return new LinkedBlockingQueue(iterableStream(as).map(f).toCollection()); } @@ -592,7 +592,7 @@ static public LinkedBlockingQueue mapJ(final F f, final LinkedBl * @param as A CopyOnWriteArraySet to map this function over. * @return A new CopyOnWriteArraySet with this function applied to each element. */ - static public CopyOnWriteArraySet mapJ(final F f, final CopyOnWriteArraySet as) { + public static CopyOnWriteArraySet mapJ(final F f, final CopyOnWriteArraySet as) { return new CopyOnWriteArraySet(iterableStream(as).map(f).toCollection()); } @@ -602,7 +602,7 @@ static public CopyOnWriteArraySet mapJ(final F f, final CopyOnWr * @param as A CopyOnWriteArrayList to map this function over. * @return A new CopyOnWriteArrayList with this function applied to each element. */ - static public CopyOnWriteArrayList mapJ(final F f, final CopyOnWriteArrayList as) { + public static CopyOnWriteArrayList mapJ(final F f, final CopyOnWriteArrayList as) { return new CopyOnWriteArrayList(iterableStream(as).map(f).toCollection()); } @@ -612,7 +612,7 @@ static public CopyOnWriteArrayList mapJ(final F f, final CopyOnW * @param as A ConcurrentLinkedQueue to map this function over. * @return A new ConcurrentLinkedQueue with this function applied to each element. */ - static public ConcurrentLinkedQueue mapJ(final F f, final ConcurrentLinkedQueue as) { + public static ConcurrentLinkedQueue mapJ(final F f, final ConcurrentLinkedQueue as) { return new ConcurrentLinkedQueue(iterableStream(as).map(f).toCollection()); } @@ -622,7 +622,7 @@ static public ConcurrentLinkedQueue mapJ(final F f, final Concur * @param as An ArrayBlockingQueue to map this function over. * @return A new ArrayBlockingQueue with this function applied to each element. */ - static public ArrayBlockingQueue mapJ(final F f, final ArrayBlockingQueue as) { + public static ArrayBlockingQueue mapJ(final F f, final ArrayBlockingQueue as) { final ArrayBlockingQueue bs = new ArrayBlockingQueue(as.size()); bs.addAll(iterableStream(as).map(f).toCollection()); return bs; @@ -635,7 +635,7 @@ static public ArrayBlockingQueue mapJ(final F f, final ArrayBloc * @param as A TreeSet to map this function over. * @return A new TreeSet with this function applied to each element. */ - static public TreeSet mapJ(final F f, final TreeSet as) { + public static TreeSet mapJ(final F f, final TreeSet as) { return new TreeSet(iterableStream(as).map(f).toCollection()); } @@ -645,7 +645,7 @@ static public TreeSet mapJ(final F f, final TreeSet as) { * @param as A PriorityQueue to map this function over. * @return A new PriorityQueue with this function applied to each element. */ - static public PriorityQueue mapJ(final F f, final PriorityQueue as) { + public static PriorityQueue mapJ(final F f, final PriorityQueue as) { return new PriorityQueue(iterableStream(as).map(f).toCollection()); } @@ -655,7 +655,7 @@ static public PriorityQueue mapJ(final F f, final PriorityQueue< * @param as A LinkedList to map this function over. * @return A new LinkedList with this function applied to each element. */ - static public LinkedList mapJ(final F f, final LinkedList as) { + public static LinkedList mapJ(final F f, final LinkedList as) { return new LinkedList(iterableStream(as).map(f).toCollection()); } @@ -665,15 +665,15 @@ static public LinkedList mapJ(final F f, final LinkedList as) * @param as An ArrayList to map this function over. * @return A new ArrayList with this function applied to each element. */ - static public ArrayList mapJ(final F f, final ArrayList as) { + public static ArrayList mapJ(final F f, final ArrayList as) { return new ArrayList(iterableStream(as).map(f).toCollection()); } - static public F map(F target, F f) { + public static F map(F target, F f) { return andThen(target, f); } - static public F contramap(F target, F f) { + public static F contramap(F target, F f) { return andThen(f, target); } diff --git a/core/src/main/java/fj/F2Functions.java b/core/src/main/java/fj/F2Functions.java index 9ce1cc0a..f69e02ed 100644 --- a/core/src/main/java/fj/F2Functions.java +++ b/core/src/main/java/fj/F2Functions.java @@ -25,7 +25,7 @@ private F2Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F f(final F2 f, final A a) { + public static F f(final F2 f, final A a) { return b -> f.f(a, b); } @@ -34,7 +34,7 @@ static public F f(final F2 f, final A a) { * * @return a wrapped function of arity-1 that returns another wrapped function. */ - static public F> curry(final F2 f) { + public static F> curry(final F2 f) { return a -> b -> f.f(a, b); } @@ -43,7 +43,7 @@ static public F> curry(final F2 f) { * * @return A new function with the arguments of this function flipped. */ - static public F2 flip(final F2 f) { + public static F2 flip(final F2 f) { return (b, a) -> f.f(a, b); } @@ -52,7 +52,7 @@ static public F2 flip(final F2 f) { * * @return A new function that calls this function with the elements of a given tuple. */ - static public F, C> tuple(final F2 f) { + public static F, C> tuple(final F2 f) { return p -> f.f(p._1(), p._2()); } @@ -61,7 +61,7 @@ static public F, C> tuple(final F2 f) { * * @return This function promoted to transform Arrays. */ - static public F2, Array, Array> arrayM(final F2 f) { + public static F2, Array, Array> arrayM(final F2 f) { return (a, b) -> a.bind(b, curry(f)); } @@ -70,7 +70,7 @@ static public F2, Array, Array> arrayM(final F2 F2, Promise, Promise> promiseM(final F2 f) { + public static F2, Promise, Promise> promiseM(final F2 f) { return (a, b) -> a.bind(b, curry(f)); } @@ -79,7 +79,7 @@ static public F2, Promise, Promise> promiseM(final F2 * * @return This function promoted to transform Iterables. */ - static public F2, Iterable, IterableW> iterableM(final F2 f) { + public static F2, Iterable, IterableW> iterableM(final F2 f) { return (a, b) -> IterableW.liftM2(curry(f)).f(a).f(b); } @@ -88,7 +88,7 @@ static public F2, Iterable, IterableW> iterableM(fin * * @return This function promoted to transform Lists. */ - static public F2, List, List> listM(final F2 f) { + public static F2, List, List> listM(final F2 f) { return (a, b) -> List.liftM2(curry(f)).f(a).f(b); } @@ -97,7 +97,7 @@ static public F2, List, List> listM(final F2 f) * * @return This function promoted to transform non-empty lists. */ - static public F2, NonEmptyList, NonEmptyList> nelM(final F2 f) { + public static F2, NonEmptyList, NonEmptyList> nelM(final F2 f) { return (as, bs) -> NonEmptyList.fromList(as.toList().bind(bs.toList(), f)).some(); } @@ -106,7 +106,7 @@ static public F2, NonEmptyList, NonEmptyList> ne * * @return This function promoted to transform Options. */ - static public F2, Option, Option> optionM(final F2 f) { + public static F2, Option, Option> optionM(final F2 f) { return (a, b) -> Option.liftM2(curry(f)).f(a).f(b); } @@ -116,7 +116,7 @@ static public F2, Option, Option> optionM(final F2 F2, Set, Set> setM(final F2 f, final Ord o) { + public static F2, Set, Set> setM(final F2 f, final Ord o) { return (as, bs) -> { Set cs = Set.empty(o); for (final A a : as) @@ -131,7 +131,7 @@ static public F2, Set, Set> setM(final F2 f, fin * * @return This function promoted to transform Streams. */ - static public F2, Stream, Stream> streamM(final F2 f) { + public static F2, Stream, Stream> streamM(final F2 f) { return (as, bs) -> as.bind(bs, f); } @@ -140,7 +140,7 @@ static public F2, Stream, Stream> streamM(final F2 F2, Tree, Tree> treeM(final F2 f) { + public static F2, Tree, Tree> treeM(final F2 f) { return new F2, Tree, Tree>() { public Tree f(final Tree as, final Tree bs) { final F2, Tree, Tree> self = this; @@ -154,7 +154,7 @@ public Tree f(final Tree as, final Tree bs) { * * @return A function that zips two arrays with this function. */ - static public F2, Array, Array> zipArrayM(final F2 f) { + public static F2, Array, Array> zipArrayM(final F2 f) { return (as, bs) -> as.zipWith(bs, f); } @@ -163,7 +163,7 @@ static public F2, Array, Array> zipArrayM(final F2 F2, Iterable, Iterable> zipIterableM(final F2 f) { + public static F2, Iterable, Iterable> zipIterableM(final F2 f) { return (as, bs) -> wrap(as).zipWith(bs, f); } @@ -172,7 +172,7 @@ static public F2, Iterable, Iterable> zipIterableM(f * * @return A function that zips two lists with this function. */ - static public F2, List, List> zipListM(final F2 f) { + public static F2, List, List> zipListM(final F2 f) { return (as, bs) -> as.zipWith(bs, f); } @@ -182,7 +182,7 @@ static public F2, List, List> zipListM(final F2 * * @return A function that zips two streams with this function. */ - static public F2, Stream, Stream> zipStreamM(final F2 f) { + public static F2, Stream, Stream> zipStreamM(final F2 f) { return (as, bs) -> as.zipWith(bs, f); } @@ -191,7 +191,7 @@ static public F2, Stream, Stream> zipStreamM(final F2< * * @return A function that zips two non-empty lists with this function. */ - static public F2, NonEmptyList, NonEmptyList> zipNelM(final F2 f) { + public static F2, NonEmptyList, NonEmptyList> zipNelM(final F2 f) { return (as, bs) -> NonEmptyList.fromList(as.toList().zipWith(bs.toList(), f)).some(); } @@ -201,7 +201,7 @@ static public F2, NonEmptyList, NonEmptyList> zi * @param o An ordering for the resulting set. * @return A function that zips two sets with this function. */ - static public F2, Set, Set> zipSetM(final F2 f, final Ord o) { + public static F2, Set, Set> zipSetM(final F2 f, final Ord o) { return (as, bs) -> iterableSet(o, as.toStream().zipWith(bs.toStream(), f)); } @@ -211,7 +211,7 @@ static public F2, Set, Set> zipSetM(final F2 f, * * @return A function that zips two trees with this function. */ - static public F2, Tree, Tree> zipTreeM(final F2 f) { + public static F2, Tree, Tree> zipTreeM(final F2 f) { return new F2, Tree, Tree>() { public Tree f(final Tree ta, final Tree tb) { final F2, Tree, Tree> self = this; @@ -226,7 +226,7 @@ public Tree f(final Tree ta, final Tree tb) { * * @return A function that zips two zippers with this function. */ - static public F2, Zipper, Zipper> zipZipperM(final F2 f) { + public static F2, Zipper, Zipper> zipZipperM(final F2 f) { return (ta, tb) -> { final F2, Stream, Stream> sf = zipStreamM(f); return zipper(sf.f(ta.lefts(), tb.lefts()), f.f(ta.focus(), tb.focus()), sf.f(ta.rights(), tb.rights())); @@ -239,7 +239,7 @@ static public F2, Zipper, Zipper> zipZipperM(final F2< * * @return A function that zips two TreeZippers with this function. */ - static public F2, TreeZipper, TreeZipper> zipTreeZipperM(final F2 f) { + public static F2, TreeZipper, TreeZipper> zipTreeZipperM(final F2 f) { return (ta, tb) -> { final F2>, Stream>, Stream>> sf = zipStreamM(treeM(f)); final @@ -254,19 +254,19 @@ static public F2, TreeZipper, TreeZipper> zipTreeZ }; } - static public F2 contramapFirst(F2 target, F f) { + public static F2 contramapFirst(F2 target, F f) { return (z, b) -> target.f(f.f(z), b); } - static public F2 contramapSecond(F2 target, F f) { + public static F2 contramapSecond(F2 target, F f) { return (a, z) -> target.f(a, f.f(z)); } - static public F2 contramap(F2 target, F f, F g) { + public static F2 contramap(F2 target, F f, F g) { return contramapSecond(contramapFirst(target, f), g); } - static public F2 map(F2 target, F f) { + public static F2 map(F2 target, F f) { return (a, b) -> f.f(target.f(a, b)); } diff --git a/core/src/main/java/fj/F3Functions.java b/core/src/main/java/fj/F3Functions.java index 77a8fa74..a1e0b8f7 100644 --- a/core/src/main/java/fj/F3Functions.java +++ b/core/src/main/java/fj/F3Functions.java @@ -21,7 +21,7 @@ private F3Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F2 f(final F3 f, final A a) { + public static F2 f(final F3 f, final A a) { return (b, c) -> f.f(a, b, c); } diff --git a/core/src/main/java/fj/F4Functions.java b/core/src/main/java/fj/F4Functions.java index ab57247b..04525167 100644 --- a/core/src/main/java/fj/F4Functions.java +++ b/core/src/main/java/fj/F4Functions.java @@ -17,7 +17,7 @@ private F4Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F3 f(final F4 f, final A a) { + public static F3 f(final F4 f, final A a) { return (b, c, d) -> f.f(a, b, c, d); } diff --git a/core/src/main/java/fj/F5Functions.java b/core/src/main/java/fj/F5Functions.java index 6345de01..d8dda4da 100644 --- a/core/src/main/java/fj/F5Functions.java +++ b/core/src/main/java/fj/F5Functions.java @@ -17,7 +17,7 @@ private F5Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F4 f(final F5 f, final A a) { + public static F4 f(final F5 f, final A a) { return (b, c, d, e) -> f.f(a, b, c, d, e); } diff --git a/core/src/main/java/fj/F6Functions.java b/core/src/main/java/fj/F6Functions.java index 19269e40..69ce270a 100644 --- a/core/src/main/java/fj/F6Functions.java +++ b/core/src/main/java/fj/F6Functions.java @@ -17,7 +17,7 @@ private F6Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F5 f(final F6 func, final A a) { + public static F5 f(final F6 func, final A a) { return (b, c, d, e, f) -> func.f(a, b, c, d, e, f); } diff --git a/core/src/main/java/fj/F7Functions.java b/core/src/main/java/fj/F7Functions.java index 4abcb986..0f2f25ac 100644 --- a/core/src/main/java/fj/F7Functions.java +++ b/core/src/main/java/fj/F7Functions.java @@ -17,7 +17,7 @@ private F7Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F6 f(final F7 func, final A a) { + public static F6 f(final F7 func, final A a) { return (b, c, d, e, f, g) -> func.f(a, b, c, d, e, f, g); } diff --git a/core/src/main/java/fj/F8Functions.java b/core/src/main/java/fj/F8Functions.java index 5cb9bb3b..5eafe1f3 100644 --- a/core/src/main/java/fj/F8Functions.java +++ b/core/src/main/java/fj/F8Functions.java @@ -17,7 +17,7 @@ private F8Functions() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - static public F7 f(final F8 func, final A a) { + public static F7 f(final F8 func, final A a) { return (b, c, d, e, f, g, h) -> func.f(a, b, c, d, e, f, g, h); } diff --git a/core/src/main/java/fj/Try.java b/core/src/main/java/fj/Try.java index c5829b01..d18d7dbd 100644 --- a/core/src/main/java/fj/Try.java +++ b/core/src/main/java/fj/Try.java @@ -25,7 +25,7 @@ private Try() { * @return A Validation with an Exception on the failure side and its result on the success side. */ @SuppressWarnings("unchecked") - static public P1> f(final Try0 t) { + public static P1> f(final Try0 t) { return P.lazy(() -> { try { return success(t.f()); @@ -42,7 +42,7 @@ static public P1> f(final Try0 t * @return A Validation with an Exception on the failure side and its result on the success side. */ @SuppressWarnings("unchecked") - static public F> f(final Try1 t) { + public static F> f(final Try1 t) { return a -> { try { return Validation.success(t.f(a)); @@ -59,7 +59,7 @@ static public F> f(final Try1 F2> f(final Try2 t) { + public static F2> f(final Try2 t) { return (a, b) -> { try { return success(t.f(a, b)); @@ -76,7 +76,7 @@ static public F2> f(final * @return A Validation with an Exception on the failure side and its result on the success side. */ @SuppressWarnings("unchecked") - static public F3> f(final Try3 t) { + public static F3> f(final Try3 t) { return (a, b, c) -> { try { return success(t.f(a, b, c)); @@ -93,7 +93,7 @@ static public F3> f( * @return A Validation with an Exception on the failure side and its result on the success side. */ @SuppressWarnings("unchecked") - static public F4> f(final Try4 t) { + public static F4> f(final Try4 t) { return (a, b, c, d) -> { try { return success(t.f(a, b, c, d)); @@ -110,7 +110,7 @@ static public F4 F5> f(final Try5 t) { + public static F5> f(final Try5 t) { return (a, b, c, d, e) -> { try { return success(t.f(a, b, c, d, e)); @@ -127,7 +127,7 @@ static public F5 F6> f(final Try6 t) { + public static F6> f(final Try6 t) { return (a, b, c, d, e, f) -> { try { return success(t.f(a, b, c, d, e, f)); @@ -144,7 +144,7 @@ static public F6 F7> f(final Try7 t) { + public static F7> f(final Try7 t) { return (a, b, c, d, e, f, g) -> { try { return success(t.f(a, b, c, d, e, f, g)); diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index f609fb0f..49b6bb61 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -15,7 +15,7 @@ public abstract class Trampoline { // A Normal Trampoline is either done or suspended, and is allowed to be a subcomputation of a Codense. // This is the pointed functor part of the Trampoline monad. - private static abstract class Normal extends Trampoline { + private abstract static class Normal extends Trampoline { public abstract R foldNormal(final F pure, final F>, R> k); public Trampoline bind(final F> f) { diff --git a/core/src/main/java/fj/data/Conversions.java b/core/src/main/java/fj/data/Conversions.java index 5405f70a..f6cfb624 100644 --- a/core/src/main/java/fj/data/Conversions.java +++ b/core/src/main/java/fj/data/Conversions.java @@ -616,7 +616,7 @@ public static F, F P1> TryEffect_P(final TryEffect0 t) { + public static P1> TryEffect_P(final TryEffect0 t) { return TryEffect.f(t); } diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index e4cd3530..7b413293 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -15,7 +15,7 @@ public final class Iteratee { /** The input to an iteratee. */ - public static abstract class Input { + public abstract static class Input { Input() {} // sealed @@ -53,7 +53,7 @@ public Z apply(final F0 empty, final F0> el, final F0 eof) { } /** A pure iteratee computation which is either done or needs more input */ - public static abstract class IterV { + public abstract static class IterV { IterV() {} // sealed diff --git a/java8/src/main/java/fj/data/Java8.java b/java8/src/main/java/fj/data/Java8.java index 03e310d2..93fd1e9e 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/java8/src/main/java/fj/data/Java8.java @@ -75,27 +75,27 @@ public static F, BiFunction> F2_BiFunction() { return f -> (a, b) -> f.f(a, b); } - static public Supplier> TryCatch0_Supplier(final Try0 t) { + public static Supplier> TryCatch0_Supplier(final Try0 t) { return Java8.TryCatch0_Supplier().f(t); } - static public F, Supplier>> TryCatch0_Supplier() { + public static F, Supplier>> TryCatch0_Supplier() { return t -> () -> Try.f(t)._1(); } - static public Function> TryCatch1_Function(final Try1 t) { + public static Function> TryCatch1_Function(final Try1 t) { return Java8.TryCatch1_Function().f(t); } - static public F, Function>> TryCatch1_Function() { + public static F, Function>> TryCatch1_Function() { return t -> a -> Try.f(t).f(a); } - static public BiFunction> TryCatch2_BiFunction(final Try2 t) { + public static BiFunction> TryCatch2_BiFunction(final Try2 t) { return Java8.TryCatch2_BiFunction().f(t); } - static public F, BiFunction>> TryCatch2_BiFunction() { + public static F, BiFunction>> TryCatch2_BiFunction() { return t -> (a, b) -> Try.f(t).f(a, b); } @@ -103,23 +103,23 @@ public static java.util.stream.Stream List_JavaStream(final List list) return Iterable_JavaStream(list); } - static public Option Optional_Option(final Optional o) { + public static Option Optional_Option(final Optional o) { return Java8.Optional_Option().f(o); } - static public F, Option> Optional_Option() { + public static F, Option> Optional_Option() { return o -> o.isPresent() ? Option.fromNull(o.get()) : Option.none(); } - static public Optional Option_Optional(final Option o) { + public static Optional Option_Optional(final Option o) { return Java8.Option_Optional().f(o); } - static public F, Optional> Option_Optional() { + public static F, Optional> Option_Optional() { return o -> o.isSome() ? Optional.ofNullable(o.some()) : Optional.empty(); } - static public F, F> Consumer_F() { + public static F, F> Consumer_F() { return c -> Consumer_F(c); } @@ -130,31 +130,31 @@ public static F Consumer_F(final Consumer c) { }; } - static public java.util.stream.Stream Stream_JavaStream(final fj.data.Stream s) { + public static java.util.stream.Stream Stream_JavaStream(final fj.data.Stream s) { return Iterable_JavaStream(s); } - static public java.util.stream.Stream Iterable_JavaStream(final Iterable it) { + public static java.util.stream.Stream Iterable_JavaStream(final Iterable it) { return StreamSupport.stream(it.spliterator(), false); } - static public java.util.stream.Stream Iterator_JavaStream(final Iterator it) { + public static java.util.stream.Stream Iterator_JavaStream(final Iterator it) { return Iterable_JavaStream(() -> it); } - static public F, java.util.stream.Stream> Stream_JavaStream() { + public static F, java.util.stream.Stream> Stream_JavaStream() { return s -> Stream_JavaStream(s); } - static public Stream JavaStream_Stream(final java.util.stream.Stream s) { + public static Stream JavaStream_Stream(final java.util.stream.Stream s) { return s.collect(Collectors.toStream()); } - static public List JavaStream_List(final java.util.stream.Stream s) { + public static List JavaStream_List(final java.util.stream.Stream s) { return s.collect(Collectors.toList()); } - static public Array JavaStream_Array(final java.util.stream.Stream s) { + public static Array JavaStream_Array(final java.util.stream.Stream s) { return s.collect(Collectors.toArray()); } From 045471917902d4e4948a01804091f6cfc97b3cea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 17:10:30 +0100 Subject: [PATCH 029/336] Simplify annotations --- core/src/main/java/fj/Bottom.java | 2 +- core/src/main/java/fj/Class.java | 2 +- core/src/main/java/fj/F1Functions.java | 18 +++---- core/src/main/java/fj/F1W.java | 18 +++---- core/src/main/java/fj/Monoid.java | 2 +- core/src/main/java/fj/P6.java | 2 +- core/src/main/java/fj/P7.java | 2 +- core/src/main/java/fj/P8.java | 2 +- core/src/main/java/fj/data/$.java | 2 +- core/src/main/java/fj/data/Array.java | 16 +++--- core/src/main/java/fj/data/HashMap.java | 2 +- core/src/main/java/fj/data/IterableW.java | 4 +- core/src/main/java/fj/data/List.java | 8 +-- core/src/main/java/fj/data/Option.java | 4 +- core/src/main/java/fj/data/Set.java | 4 +- core/src/main/java/fj/data/Stream.java | 2 +- core/src/main/java/fj/data/TreeMap.java | 2 +- core/src/main/java/fj/data/Validation.java | 8 +-- core/src/main/java/fj/data/Zipper.java | 2 +- .../java/fj/demo/concurrent/PingPong.java | 2 +- .../java/fj/demo/test/ListFunctorLaws.java | 2 +- demo/src/main/java/fj/demo/test/Reflect.java | 2 +- .../src/main/java/fj/test/Arbitrary.java | 28 +++++------ .../src/main/java/fj/test/CheckResult.java | 2 +- .../src/main/java/fj/test/Coarbitrary.java | 50 +++++++++---------- .../src/main/java/fj/test/Property.java | 4 +- quickcheck/src/main/java/fj/test/Result.java | 2 +- quickcheck/src/main/java/fj/test/Shrink.java | 4 +- .../src/main/java/fj/test/reflect/Check.java | 4 +- 29 files changed, 101 insertions(+), 101 deletions(-) diff --git a/core/src/main/java/fj/Bottom.java b/core/src/main/java/fj/Bottom.java index a9951928..0f828102 100644 --- a/core/src/main/java/fj/Bottom.java +++ b/core/src/main/java/fj/Bottom.java @@ -72,7 +72,7 @@ public static Error decons(final A a, final Show sa) { * @param c The type being deconstructed. * @return A deconstruction failure that was non-exhaustive. */ - @SuppressWarnings({"UnnecessaryFullyQualifiedName"}) + @SuppressWarnings("UnnecessaryFullyQualifiedName") public static Error decons(final java.lang.Class c) { return error("Deconstruction failure on type " + c); } diff --git a/core/src/main/java/fj/Class.java b/core/src/main/java/fj/Class.java index 6eac6e39..e2630569 100644 --- a/core/src/main/java/fj/Class.java +++ b/core/src/main/java/fj/Class.java @@ -39,7 +39,7 @@ public java.lang.Class _1() { return c2; } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public java.lang.Class _2() { return c2.getSuperclass(); } diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 5821a893..12f565b2 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -49,7 +49,7 @@ public static F, F> o(final F f) { * @param g A function with which to compose this one. * @return The composed function such that this function is applied first. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F andThen(final F f, final F g) { return o(g, f); } @@ -259,7 +259,7 @@ public static F, Promise> mapPromise(final F f) { * * @return This function promoted to return its result on the left side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F> eitherLeftK(final F f) { return o(Either.left_(), f); } @@ -270,7 +270,7 @@ public static F> eitherLeftK(final F f) { * * @return This function promoted to return its result on the right side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F> eitherRightK(final F f) { return o(Either.right_(), f); } @@ -280,7 +280,7 @@ public static F> eitherRightK(final F f) { * * @return This function promoted to map over the left side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F, Either> mapLeft(final F f) { return Either.leftMap_().f(f); } @@ -290,7 +290,7 @@ public static F, Either> mapLeft(final F f) { * * @return This function promoted to map over the right side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F, Either> mapRight(final F f) { return Either.rightMap_().f(f); } @@ -318,7 +318,7 @@ public static F, B> onRight(final F f) { * * @return This function promoted to return its value in an Iterable. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F> iterableK(final F f) { return IterableW.arrow().f(f); } @@ -328,7 +328,7 @@ public static F> iterableK(final F f) { * * @return This function promoted to map over Iterables. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F, IterableW> mapIterable(final F f) { return F1Functions.o(IterableW.map().f(f), IterableW.>wrap()); } @@ -338,7 +338,7 @@ public static F, IterableW> mapIterable(final F f) { * * @return This function promoted to return its value in a NonEmptyList. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F> nelK(final F f) { return o(NonEmptyList.nel(), f); } @@ -387,7 +387,7 @@ public static F> treeK(final F f) { * * @return This function promoted to map over a Tree. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static F, Tree> mapTree(final F f) { return Tree.fmap_().f(f); } diff --git a/core/src/main/java/fj/F1W.java b/core/src/main/java/fj/F1W.java index 73545411..7fe50e35 100644 --- a/core/src/main/java/fj/F1W.java +++ b/core/src/main/java/fj/F1W.java @@ -41,7 +41,7 @@ public F1W, F> o() { * @param g A function with which to compose this one. * @return The composed function such that this function is applied first. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W andThen(final F g) { return lift(F1Functions.andThen(this, g)); } @@ -254,7 +254,7 @@ public F1W, Promise> mapPromise() { * * @return This function promoted to return its result on the left side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W> eitherLeftK() { return lift(F1Functions.eitherLeftK(this)); } @@ -265,7 +265,7 @@ public F1W> eitherLeftK() { * * @return This function promoted to return its result on the right side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W> eitherRightK() { return lift(F1Functions.eitherRightK(this)); } @@ -275,7 +275,7 @@ public F1W> eitherRightK() { * * @return This function promoted to map over the left side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W, Either> mapLeft() { return lift(F1Functions.mapLeft(this)); } @@ -285,7 +285,7 @@ public F1W, Either> mapLeft() { * * @return This function promoted to map over the right side of an Either. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W, Either> mapRight() { return lift(F1Functions.mapRight(this)); } @@ -313,7 +313,7 @@ public F1W, B> onRight() { * * @return This function promoted to return its value in an Iterable. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W> iterableK() { return lift( F1Functions.iterableK(this)); } @@ -323,7 +323,7 @@ public F1W> iterableK() { * * @return This function promoted to map over Iterables. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W, IterableW> mapIterable() { return lift( F1Functions.mapIterable(this)); } @@ -333,7 +333,7 @@ public F1W, IterableW> mapIterable() { * * @return This function promoted to return its value in a NonEmptyList. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W> nelK() { return lift(F1Functions.nelK(this)); } @@ -381,7 +381,7 @@ public F1W> treeK() { * * @return This function promoted to map over a Tree. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public F1W, Tree> mapTree() { return lift(F1Functions.mapTree(this)); } diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index c2214748..a85a4712 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -381,7 +381,7 @@ public static Monoid> streamMonoid() { * * @return A monoid for arrays. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static Monoid> arrayMonoid() { return monoid(Semigroup.arraySemigroup(), Array.empty()); } diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index a6ed6c8f..c2983298 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -5,7 +5,7 @@ * * @version %build.number% */ -@SuppressWarnings({"UnnecessaryFullyQualifiedName"}) +@SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P6 { /** * Access the first element of the product. diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index 76900fc4..478e3d87 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -5,7 +5,7 @@ * * @version %build.number% */ -@SuppressWarnings({"UnnecessaryFullyQualifiedName"}) +@SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P7 { /** * Access the first element of the product. diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index d9e9f42c..62fef46e 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -5,7 +5,7 @@ * * @version %build.number% */ -@SuppressWarnings({"UnnecessaryFullyQualifiedName"}) +@SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P8 { /** * Access the first element of the product. diff --git a/core/src/main/java/fj/data/$.java b/core/src/main/java/fj/data/$.java index 3ddf92d3..212216bc 100644 --- a/core/src/main/java/fj/data/$.java +++ b/core/src/main/java/fj/data/$.java @@ -6,7 +6,7 @@ * The constant arrow, for attaching a new name to an existing type. For every pair of types A and B, this type * is the identity morphism from B to B. */ -@SuppressWarnings({"UnusedDeclaration"}) +@SuppressWarnings("UnusedDeclaration") public final class $ extends P1 { private final B b; diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index ea8c7312..f9ed8abb 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -202,7 +202,7 @@ public String toString() { * @param f The function to map across this array. * @return A new array after the given function has been applied to each element. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array map(final F f) { final Object[] bs = new Object[a.length]; @@ -323,7 +323,7 @@ public B foldLeft(final F2 f, final B b) { * @param b The beginning value to start the application from. * @return The array containing all intermediate results of the left-fold reduction. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array scanLeft(final F> f, final B b) { final Object[] bs = new Object[a.length]; B x = b; @@ -357,7 +357,7 @@ public Array scanLeft(final F2 f, final B b) { * @param f The function to apply on each argument pair (next array element and first array element/previous result) * @return The array containing all intermediate results of the left-fold reduction. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array scanLeft1(final F> f) { final Object[] bs = new Object[a.length]; A x = get(0); @@ -392,7 +392,7 @@ public Array scanLeft1(final F2 f) { * @param b The beginning value to start the application from. * @return The array containing all intermediate results of the right-fold reduction. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array scanRight(final F>f, final B b) { final Object[] bs = new Object[a.length]; B x = b; @@ -426,7 +426,7 @@ public Array scanRight(final F2 f, final B b) { * @param f The function to apply on each argument pair (previous array element and last array element/previous result) * @return The array containing all intermediate results of the right-fold reduction. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array scanRight1(final F>f) { final Object[] bs = new Object[a.length]; A x = get(length() - 1); @@ -459,7 +459,7 @@ public Array scanRight1(final F2 f) { * @param f The function to apply to each element of this array. * @return A new array after performing the map, then final join. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Array bind(final F> f) { List> x = List.nil(); int len = 0; @@ -849,7 +849,7 @@ public static Array arrayArray(final A...as) { * @param xs The array of pairs to transform. * @return An array of first components and an array of second components. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static P2, Array> unzip(final Array> xs) { final int len = xs.length(); final Array aa = new Array(new Object[len]); @@ -1079,7 +1079,7 @@ public static T[] copyOf(final U[] a, final int len, final Class T[] copyOf(final T[] a, final int len) { return (T[]) copyOf(a, len, a.getClass()); } diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index 7cd9c8dd..3e6ff3b3 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -32,7 +32,7 @@ K k() { return k; } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public boolean equals(final Object o) { return o instanceof Key && e.eq(k, (K) ((Key) o).k()); } diff --git a/core/src/main/java/fj/data/IterableW.java b/core/src/main/java/fj/data/IterableW.java index 52be7d6b..523b4152 100644 --- a/core/src/main/java/fj/data/IterableW.java +++ b/core/src/main/java/fj/data/IterableW.java @@ -324,7 +324,7 @@ public boolean isEmpty() { return iterableStream(IterableW.this).isEmpty(); } - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public boolean contains(final Object o) { return iterableStream(IterableW.this).exists(Equal.anyEqual().eq((A) o)); } @@ -337,7 +337,7 @@ public Object[] toArray() { return Array.iterableArray(iterableStream(IterableW.this)).array(); } - @SuppressWarnings({"SuspiciousToArrayCall"}) + @SuppressWarnings("SuspiciousToArrayCall") public T[] toArray(final T[] a) { return iterableStream(IterableW.this).toCollection().toArray(a); } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 4920e021..26ec5e33 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -195,7 +195,7 @@ public final Stream toStream() { * * @return A array projection of this list. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final Array toArray() { return mkArray(toArrayObject()); } @@ -1124,7 +1124,7 @@ public final List intersperse(final A a) { * @param as The list to intersperse through. * @return This list through the given list then joins the results. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final List intercalate(final List> as) { return join(as.intersperse(this)); } @@ -1154,7 +1154,7 @@ public final List nub(final Equal eq) { * @param o An ordering for the elements. * @return A list without duplicates. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final List nub(final Ord o) { return sort(o).group(o.equal()).map(List.head_()); } @@ -2044,7 +2044,7 @@ public static Buffer iterableBuffer(final Iterable i) { return b; } - @SuppressWarnings({"ObjectEquality"}) + @SuppressWarnings("ObjectEquality") private void copy() { List s = start; final Cons t = tail; diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 476d38db..cb58e61f 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -542,7 +542,7 @@ public final Stream toStream() { * * @return An array projection of this optional value. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final Array toArray() { return isSome() ? Array.array(some()) : Array.empty(); } @@ -553,7 +553,7 @@ public final Array toArray() { * @param c The class type of the array to return. * @return An array projection of this optional value. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final Array toArray(final Class c) { if (isSome()) { final A[] a = (A[]) java.lang.reflect.Array.newInstance(c.getComponentType(), 1); diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 6c23d6d5..09d80279 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -31,7 +31,7 @@ public final boolean isEmpty() { return this instanceof Empty; } - @SuppressWarnings({"ClassEscapesDefinedScope"}) + @SuppressWarnings("ClassEscapesDefinedScope") abstract Color color(); abstract Set l(); @@ -209,7 +209,7 @@ private Set makeBlack() { return new Tree(ord, Color.B, l(), head(), r()); } - @SuppressWarnings({"SuspiciousNameCombination"}) + @SuppressWarnings("SuspiciousNameCombination") private static Tree tr(final Ord o, final Set a, final A x, final Set b, final A y, diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 2e7ca879..cb6fe8d0 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -957,7 +957,7 @@ public final java.util.List toJavaList() { * * @return A array projection of this stream. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public final Array toArray() { final int l = length(); final Object[] a = new Object[l]; diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index 307c279e..e35e6592 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -358,7 +358,7 @@ public P3, Option, TreeMap> splitLookup(final K k) { * @param f A function to apply to the values of this TreeMap. * @return A new TreeMap with the values transformed by the given function. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public TreeMap map(final F f) { final F>, P2>> g = P2.map2_(F1Functions.mapOption(f)); final F>> coord = flip(P.>p2()).f(Option.none()); diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 3a2cfa23..a87b4585 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -172,7 +172,7 @@ public void foreachDoEffect(final Effect1 f) { * @param f The function to map. * @return A new validation with the function mapped. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Validation map(final F f) { return isFail() ? Validation.fail(fail()) : @@ -185,7 +185,7 @@ public Validation map(final F f) { * @param f The function to bind across this validation. * @return A new validation value after binding. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Validation bind(final F> f) { return isSuccess() ? f.f(success()) : Validation.fail(fail()); } @@ -313,7 +313,7 @@ public Stream toStream() { * @return A failing validation if this or the given validation failed (with errors accumulated if both) or a * succeeding validation if both succeeded. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Validation accumapply(final Semigroup s, final Validation> v) { return isFail() ? Validation.fail(v.isFail() ? @@ -1080,7 +1080,7 @@ public Iterator iterator() { * * @return A validation with its failing value in a non-empty list if there is one. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Validation, T> nel() { return isSuccess() ? Validation., T>success(success()) : diff --git a/core/src/main/java/fj/data/Zipper.java b/core/src/main/java/fj/data/Zipper.java index a4377507..6de0d39c 100644 --- a/core/src/main/java/fj/data/Zipper.java +++ b/core/src/main/java/fj/data/Zipper.java @@ -169,7 +169,7 @@ public static Zipper single(final A a) { * @param a The stream from which to create a zipper. * @return a new zipper if the provided stream has at least one element, otherwise None. */ - @SuppressWarnings({"IfMayBeConditional"}) + @SuppressWarnings("IfMayBeConditional") public static Option> fromStream(final Stream a) { if (a.isEmpty()) return none(); diff --git a/demo/src/main/java/fj/demo/concurrent/PingPong.java b/demo/src/main/java/fj/demo/concurrent/PingPong.java index 59038679..d6bddbbf 100644 --- a/demo/src/main/java/fj/demo/concurrent/PingPong.java +++ b/demo/src/main/java/fj/demo/concurrent/PingPong.java @@ -16,7 +16,7 @@ * Example of parallel synchronous messaging using Actors in Functional Java. * Author: Runar */ -@SuppressWarnings({"ArithmeticOnVolatileField"}) +@SuppressWarnings("ArithmeticOnVolatileField") public class PingPong { private final int actors; private final int pings; diff --git a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java index b2c230a5..e0c99f64 100644 --- a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java +++ b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java @@ -39,7 +39,7 @@ For any list, mapping the identity function (\x -> x) produces the same list. Note that to test this second law requires the generation of arbitrary functions. */ -@SuppressWarnings({"PackageVisibleField"}) +@SuppressWarnings("PackageVisibleField") @CheckParams(minSuccessful = 1000) public final class ListFunctorLaws { final Property identity = property(arbList(arbString), x -> prop(listEqual(stringEqual).eq(x, x.map(Function.identity())))); diff --git a/demo/src/main/java/fj/demo/test/Reflect.java b/demo/src/main/java/fj/demo/test/Reflect.java index 8831314e..79d013dc 100644 --- a/demo/src/main/java/fj/demo/test/Reflect.java +++ b/demo/src/main/java/fj/demo/test/Reflect.java @@ -82,7 +82,7 @@ Property leave() { throw error("this should not be executed"); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") Property leave(final int i) { throw error("this should not be executed"); } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index d46f4d4e..34a17ae1 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -95,7 +95,7 @@ public final class Arbitrary { /** * The generator associated with this arbitrary. */ - @SuppressWarnings({"PublicField"}) + @SuppressWarnings("PublicField") public final Gen gen; private Arbitrary(final Gen gen) { @@ -668,7 +668,7 @@ public StringBuilder f(final String s) { */ public static Arbitrary> arbGen(final Arbitrary aa) { return arbitrary(sized(new F>>() { - @SuppressWarnings({"IfMayBeConditional"}) + @SuppressWarnings("IfMayBeConditional") public Gen> f(final Integer i) { if (i == 0) return fail(); @@ -711,7 +711,7 @@ public Option f(final A a) { * defined. * @return An arbitrary implementation for the disjoint union. */ - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public static Arbitrary> arbEither(final Arbitrary aa, final Arbitrary ab) { final Gen> left = aa.gen.map(new F>() { public Either f(final A a) { @@ -916,7 +916,7 @@ public static > Arbitrary arbEnumValue(final Class clazz public static , V> Arbitrary> arbEnumMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, EnumMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public EnumMap f(final Hashtable ht) { return new EnumMap(ht); } @@ -959,7 +959,7 @@ public GregorianCalendar f(final Long i) { */ public static Arbitrary> arbHashMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, HashMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public HashMap f(final Hashtable ht) { return new HashMap(ht); } @@ -993,7 +993,7 @@ public static Arbitrary> arbHashtable(final Arbitrary return arbitrary(arbList(ak).gen.bind(arbList(av).gen, new F, F, Hashtable>>() { public F, Hashtable> f(final List ks) { return new F, Hashtable>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Hashtable f(final List vs) { final Hashtable t = new Hashtable(); @@ -1022,7 +1022,7 @@ public void f(final P2 kv) { public static Arbitrary> arbIdentityHashMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, IdentityHashMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public IdentityHashMap f(final Hashtable ht) { return new IdentityHashMap(ht); } @@ -1040,7 +1040,7 @@ public IdentityHashMap f(final Hashtable ht) { */ public static Arbitrary> arbLinkedHashMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, LinkedHashMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public LinkedHashMap f(final Hashtable ht) { return new LinkedHashMap(ht); } @@ -1094,7 +1094,7 @@ public PriorityQueue f(final Array a) { */ public static final Arbitrary arbProperties = arbitrary(arbHashtable(arbString, arbString).gen.map(new F, Properties>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Properties f(final Hashtable ht) { final Properties p = new Properties(); @@ -1132,7 +1132,7 @@ public Stack f(final Array a) { */ public static Arbitrary> arbJavaTreeMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, java.util.TreeMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public java.util.TreeMap f(final Hashtable ht) { return new java.util.TreeMap(ht); } @@ -1196,10 +1196,10 @@ public TreeSet f(final Array a) { * @param aa An arbitrary implementation for the type over which the vector is defined. * @return An arbitrary implementation for vectors. */ - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public static Arbitrary> arbVector(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.map(new F, Vector>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Vector f(final Array a) { return new Vector(a.toCollection()); } @@ -1217,7 +1217,7 @@ public Vector f(final Array a) { */ public static Arbitrary> arbWeakHashMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, WeakHashMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public WeakHashMap f(final Hashtable ht) { return new WeakHashMap(ht); } @@ -1265,7 +1265,7 @@ public ArrayBlockingQueue f(final Boolean fair) { public static Arbitrary> arbConcurrentHashMap(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbHashtable(ak, av).gen.map(new F, ConcurrentHashMap>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public ConcurrentHashMap f(final Hashtable ht) { return new ConcurrentHashMap(ht); } diff --git a/quickcheck/src/main/java/fj/test/CheckResult.java b/quickcheck/src/main/java/fj/test/CheckResult.java index fe3ca92a..dc0195d7 100644 --- a/quickcheck/src/main/java/fj/test/CheckResult.java +++ b/quickcheck/src/main/java/fj/test/CheckResult.java @@ -236,7 +236,7 @@ private String arguments(final CheckResult r) { return args.length() == 1 ? "argument: " + sa.showS(args.head()) : "arguments: " + listShow(sa).showS(args); } - @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public String f(final CheckResult r) { if (r.isProven()) return "OK, property proven with " + arguments(r); diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index 8b778188..bb607aa5 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -530,7 +530,7 @@ public String f(final Throwable t) { */ public static Coarbitrary> coarbArrayList(final Coarbitrary ca) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final ArrayList as, final Gen g) { return coarbArray(ca).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -580,7 +580,7 @@ public Gen coarbitrary(final Date d, final Gen g) { public static , V> Coarbitrary> coarbEnumMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final EnumMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -595,7 +595,7 @@ public Gen coarbitrary(final EnumMap m, final Gen g) { */ public static > Coarbitrary> coarbEnumSet(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final EnumSet as, final Gen g) { return coarbHashSet(c).coarbitrary(new HashSet(as), g); } @@ -620,7 +620,7 @@ public Gen coarbitrary(final GregorianCalendar c, final Gen g) { */ public static Coarbitrary> coarbHashMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final HashMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -635,7 +635,7 @@ public Gen coarbitrary(final HashMap m, final Gen g) { */ public static Coarbitrary> coarbHashSet(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final HashSet as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -651,7 +651,7 @@ public Gen coarbitrary(final HashSet as, final Gen g) { */ public static Coarbitrary> coarbHashtable(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final Hashtable h, final Gen g) { List> x = nil(); @@ -674,7 +674,7 @@ public Gen coarbitrary(final Hashtable h, final Gen g) { public static Coarbitrary> coarbIdentityHashMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final IdentityHashMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -691,7 +691,7 @@ public Gen coarbitrary(final IdentityHashMap m, final Gen g) { public static Coarbitrary> coarbLinkedHashMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final LinkedHashMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -706,7 +706,7 @@ public Gen coarbitrary(final LinkedHashMap m, final Gen g) { */ public static Coarbitrary> coarbLinkedHashSet(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedHashSet as, final Gen g) { return coarbHashSet(c).coarbitrary(new HashSet(as), g); } @@ -721,7 +721,7 @@ public Gen coarbitrary(final LinkedHashSet as, final Gen g) { */ public static Coarbitrary> coarbLinkedList(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedList as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -736,7 +736,7 @@ public Gen coarbitrary(final LinkedList as, final Gen g) { */ public static Coarbitrary> coarbPriorityQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final PriorityQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -747,7 +747,7 @@ public Gen coarbitrary(final PriorityQueue as, final Gen g) { * A coarbitrary for properties. */ public static final Coarbitrary coarbProperties = new Coarbitrary() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final Properties p, final Gen g) { final Hashtable t = new Hashtable(); @@ -767,7 +767,7 @@ public Gen coarbitrary(final Properties p, final Gen g) { */ public static Coarbitrary> coarbStack(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final Stack as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -783,7 +783,7 @@ public Gen coarbitrary(final Stack as, final Gen g) { */ public static Coarbitrary> coarbTreeMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final TreeMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -798,7 +798,7 @@ public Gen coarbitrary(final TreeMap m, final Gen g) { */ public static Coarbitrary> coarbTreeSet(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final TreeSet as, final Gen g) { return coarbHashSet(c).coarbitrary(new HashSet(as), g); } @@ -830,7 +830,7 @@ public Gen coarbitrary(final Vector as, final Gen g) { public static Coarbitrary> coarbWeakHashMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final WeakHashMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -849,7 +849,7 @@ public Gen coarbitrary(final WeakHashMap m, final Gen g) { */ public static Coarbitrary> coarbArrayBlockingQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final ArrayBlockingQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -866,7 +866,7 @@ public Gen coarbitrary(final ArrayBlockingQueue as, final Gen g) { public static Coarbitrary> coarbConcurrentHashMap(final Coarbitrary ck, final Coarbitrary cv) { return new Coarbitrary>() { - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final ConcurrentHashMap m, final Gen g) { return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); } @@ -881,7 +881,7 @@ public Gen coarbitrary(final ConcurrentHashMap m, final Gen g) { */ public static Coarbitrary> coarbConcurrentLinkedQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final ConcurrentLinkedQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -896,7 +896,7 @@ public Gen coarbitrary(final ConcurrentLinkedQueue as, final Gen g) */ public static Coarbitrary> coarbCopyOnWriteArrayList(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final CopyOnWriteArrayList as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -911,7 +911,7 @@ public Gen coarbitrary(final CopyOnWriteArrayList as, final Gen g) */ public static Coarbitrary> coarbCopyOnWriteArraySet(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final CopyOnWriteArraySet as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -926,7 +926,7 @@ public Gen coarbitrary(final CopyOnWriteArraySet as, final Gen g) { */ public static Coarbitrary> coarbDelayQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final DelayQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -941,7 +941,7 @@ public Gen coarbitrary(final DelayQueue as, final Gen g) { */ public static Coarbitrary> coarbLinkedBlockingQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedBlockingQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -956,7 +956,7 @@ public Gen coarbitrary(final LinkedBlockingQueue as, final Gen g) { */ public static Coarbitrary> coarbPriorityBlockingQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final PriorityBlockingQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } @@ -971,7 +971,7 @@ public Gen coarbitrary(final PriorityBlockingQueue as, final Gen g) */ public static Coarbitrary> coarbSynchronousQueue(final Coarbitrary c) { return new Coarbitrary>() { - @SuppressWarnings({"unchecked"}) + @SuppressWarnings("unchecked") public Gen coarbitrary(final SynchronousQueue as, final Gen g) { return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); } diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 18baccc3..3231cf2e 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -133,7 +133,7 @@ public Result f(final Result res2) { * @param maxSize The maximum size to use for checking. * @return A result after checking this property. */ - @SuppressWarnings({"ThrowableResultOfMethodCallIgnored"}) + @SuppressWarnings("ThrowableResultOfMethodCallIgnored") public CheckResult check(final Rand r, final int minSuccessful, final int maxDiscarded, @@ -453,7 +453,7 @@ public F f(final Integer i) { return new F() { public Result f(final Rand r) { final class Util { - @SuppressWarnings({"IfMayBeConditional"}) + @SuppressWarnings("IfMayBeConditional") Option> first(final Stream as, final int shrinks) { final Stream>> results = as.map(new F>>() { public Option> f(final A a) { diff --git a/quickcheck/src/main/java/fj/test/Result.java b/quickcheck/src/main/java/fj/test/Result.java index 40a388d6..eb6b973b 100644 --- a/quickcheck/src/main/java/fj/test/Result.java +++ b/quickcheck/src/main/java/fj/test/Result.java @@ -142,7 +142,7 @@ public Result addArg(final Arg a) { * * @return A potential result for this result. */ - @SuppressWarnings({"IfMayBeConditional"}) + @SuppressWarnings("IfMayBeConditional") public Option toOption() { if(isNoResult()) return none(); diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index d1403ee7..a9d1aa21 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -241,7 +241,7 @@ else if (as.tail().isEmpty()) } } - @SuppressWarnings({"IfMayBeConditional"}) + @SuppressWarnings("IfMayBeConditional") Stream> shrinkOne(final List as) { if (as.isEmpty()) return nil(); @@ -402,7 +402,7 @@ public static Shrink> shrinkHashSet(final Shrink sa) { * @param sv The shrink stratgey for values. * @return A shrink strategy for hash tables. */ - @SuppressWarnings({"UseOfObsoleteCollectionType"}) + @SuppressWarnings("UseOfObsoleteCollectionType") public static Shrink> shrinkHashtable(final Shrink sk, final Shrink sv) { return shrinkList(shrinkP2(sk, sv)).map(kvs -> { final Hashtable h = new Hashtable(); diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index 199f399a..079dcb22 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -260,14 +260,14 @@ private interface PropertyMember { AnnotatedElement element(); String name(); int modifiers(); - @SuppressWarnings({"ProhibitedExceptionDeclared"}) + @SuppressWarnings("ProhibitedExceptionDeclared") Property invoke(X x) throws Exception; boolean isProperty(); } private static Array>> properties(final Array ms, final java.lang.Class declaringClass, final String... categories) { final Option t = emptyCtor(declaringClass).map(new F, T>() { - @SuppressWarnings({"OverlyBroadCatchBlock"}) + @SuppressWarnings("OverlyBroadCatchBlock") public T f(final Constructor ctor) { try { ctor.setAccessible(true); From 673bfd6dc27f86dd9a8b764e70cf07cc6e8312ee Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 18:31:53 +0100 Subject: [PATCH 030/336] Fix non-sense in List_map demo --- demo/src/main/java/fj/demo/List_map.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/src/main/java/fj/demo/List_map.java b/demo/src/main/java/fj/demo/List_map.java index 55216810..a07f0015 100644 --- a/demo/src/main/java/fj/demo/List_map.java +++ b/demo/src/main/java/fj/demo/List_map.java @@ -9,8 +9,8 @@ public final class List_map { public static void main(final String[] args) { final List a = list(1, 2, 3); - final List b = a.map(add.f(42)); - final List c = a.map(i -> i = 42); + final List b = a.map(add.f(42)); // or equivalently: + final List c = a.map(i -> i + 42); listShow(intShow).println(b); // [43,44,45] } } From df48c32bf6ab51b8cef3f16ad4fe89ed756edb46 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 18:38:26 +0100 Subject: [PATCH 031/336] Use e.printStackTrace() instead of println(e) --- quickcheck/src/main/java/fj/test/reflect/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quickcheck/src/main/java/fj/test/reflect/Main.java b/quickcheck/src/main/java/fj/test/reflect/Main.java index a7e8be3c..b0b5fb95 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Main.java +++ b/quickcheck/src/main/java/fj/test/reflect/Main.java @@ -43,7 +43,7 @@ public void f(final P2 r) { } }); } catch(ClassNotFoundException e) { - System.err.println(e); + e.printStackTrace(); //noinspection CallToSystemExit exit(144); } From 2a27fa8203b241df29b8955e7d13916add709f4a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 19:47:50 +0100 Subject: [PATCH 032/336] Remove unnecessary qualification of static methods --- core/src/main/java/fj/Equal.java | 2 +- core/src/main/java/fj/F1Functions.java | 2 +- core/src/main/java/fj/Function.java | 2 +- core/src/main/java/fj/Hash.java | 2 +- core/src/main/java/fj/P.java | 4 +- core/src/main/java/fj/Show.java | 6 +-- core/src/main/java/fj/Try.java | 2 +- .../java/fj/control/parallel/Callables.java | 2 +- .../java/fj/control/parallel/Promise.java | 14 +++--- core/src/main/java/fj/data/Array.java | 10 ++-- core/src/main/java/fj/data/Conversions.java | 2 +- core/src/main/java/fj/data/DList.java | 4 +- core/src/main/java/fj/data/Either.java | 12 ++--- core/src/main/java/fj/data/Enumerator.java | 4 +- core/src/main/java/fj/data/HashMap.java | 2 +- core/src/main/java/fj/data/IOFunctions.java | 14 +++--- core/src/main/java/fj/data/IOW.java | 2 +- core/src/main/java/fj/data/IterableW.java | 2 +- core/src/main/java/fj/data/LazyString.java | 2 +- core/src/main/java/fj/data/List.java | 44 +++++++++--------- core/src/main/java/fj/data/Option.java | 2 +- core/src/main/java/fj/data/Seq.java | 2 +- core/src/main/java/fj/data/State.java | 2 +- core/src/main/java/fj/data/Stream.java | 24 +++++----- core/src/main/java/fj/data/Tree.java | 4 +- core/src/main/java/fj/data/TreeMap.java | 18 ++++---- core/src/main/java/fj/data/Validation.java | 46 +++++++++---------- core/src/main/java/fj/data/Writer.java | 2 +- .../java/fj/data/fingertrees/FingerTree.java | 2 +- .../main/java/fj/data/fingertrees/Single.java | 2 +- .../main/java/fj/demo/realworld/Chapter7.java | 2 +- .../src/main/java/fj/test/Arbitrary.java | 10 ++-- .../src/main/java/fj/test/Property.java | 4 +- 33 files changed, 127 insertions(+), 127 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 23ceffd3..27973afc 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -538,7 +538,7 @@ public static Equal> setEqual(final Equal e) { } public static Equal> treeMapEqual(Equal k, Equal v) { - return equal(t1 -> t2 -> Equal.streamEqual(p2Equal(k, v)).eq(t1.toStream(), t2.toStream())); + return equal(t1 -> t2 -> streamEqual(p2Equal(k, v)).eq(t1.toStream(), t2.toStream())); } public static Equal> writerEqual(Equal eq1, Equal eq2) { diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 12f565b2..3faf1b5e 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -330,7 +330,7 @@ public static F> iterableK(final F f) { */ @SuppressWarnings("unchecked") public static F, IterableW> mapIterable(final F f) { - return F1Functions.o(IterableW.map().f(f), IterableW.>wrap()); + return o(IterableW.map().f(f), IterableW.>wrap()); } /** diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index 4d4b14a2..b3b96870 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -60,7 +60,7 @@ public static F> compose2(final F f, final F F, F, F>> andThen() { - return g -> f -> Function.andThen(g, f); + return g -> f -> andThen(g, f); } /** diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 26f42049..61c5e1cd 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -268,7 +268,7 @@ public static Hash> treeHash(final Hash ha) { } public static Hash> treeMapHash(final Hash h, final Hash v) { - return hash(t -> streamHash(Hash.p2Hash(h, v)).hash(t.toStream())); + return hash(t -> streamHash(p2Hash(h, v)).hash(t.toStream())); } /** diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index 073de4f6..2826b6b0 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -234,7 +234,7 @@ public H _8() { } public static P2 lazyProduct(F0> f) { - return P.lazy(() -> f.f()._1(), () -> f.f()._2()); + return lazy(() -> f.f()._1(), () -> f.f()._2()); } /** @@ -552,7 +552,7 @@ public static P1 lazy(F f) { } public static P2 lazy(F fa, F fb) { - return P.lazy(() -> fa.f(unit()), () -> fb.f(unit())); + return lazy(() -> fa.f(unit()), () -> fb.f(unit())); } public static P3 lazy(F fa, F fb, F fc) { diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index b67f662a..7e832c6c 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -159,7 +159,7 @@ public static Show showS(final F f) { * @return A show instance that uses {@link Object#toString()} to perform the display rendering. */ public static Show anyShow() { - return show(a -> Stream.fromString((a == null) ? "null" : a.toString())); + return show(a -> fromString((a == null) ? "null" : a.toString())); } /** @@ -325,7 +325,7 @@ public static Show> setShow(final Show sa) { public static Show> treeMapShow(final Show sk, final Show sv) { return show(tm -> { Stream> stream = Stream.iteratorStream(tm.iterator()); - return streamShow(Show.p2MapShow(sk, sv), "TreeMap(", ",", ")").show(stream); + return streamShow(p2MapShow(sk, sv), "TreeMap(", ",", ")").show(stream); }); } @@ -425,7 +425,7 @@ public static Show> p1Show(final Show sa) { } public static Show> p1ShowLazy(final Show sa) { - return show(p -> Stream.fromString("(?)")); + return show(p -> fromString("(?)")); } public static Show> p1ShowEager(final Show sa) { diff --git a/core/src/main/java/fj/Try.java b/core/src/main/java/fj/Try.java index d18d7dbd..d8a30130 100644 --- a/core/src/main/java/fj/Try.java +++ b/core/src/main/java/fj/Try.java @@ -45,7 +45,7 @@ public static P1> f(final Try0 t public static F> f(final Try1 t) { return a -> { try { - return Validation.success(t.f(a)); + return success(t.f(a)); } catch (Exception e) { return fail((E) e); } diff --git a/core/src/main/java/fj/control/parallel/Callables.java b/core/src/main/java/fj/control/parallel/Callables.java index 1b6114fe..aeb9a312 100644 --- a/core/src/main/java/fj/control/parallel/Callables.java +++ b/core/src/main/java/fj/control/parallel/Callables.java @@ -93,7 +93,7 @@ public static Callable bind(final Callable a, final F F, Callable> fmap(final F f) { - return a -> Callables.bind(a, callable(f)); + return a -> bind(a, callable(f)); } /** diff --git a/core/src/main/java/fj/control/parallel/Promise.java b/core/src/main/java/fj/control/parallel/Promise.java index 100b50f6..42f9e3c2 100644 --- a/core/src/main/java/fj/control/parallel/Promise.java +++ b/core/src/main/java/fj/control/parallel/Promise.java @@ -75,7 +75,7 @@ public void f(final P2, Actor>, Promise> p) { */ public static Promise promise(final Strategy s, final P1 a) { final Promise p = mkPromise(s); - p.actor.act(P.p(Either., Actor>left(a), p)); + p.actor.act(p(Either., Actor>left(a), p)); return p; } @@ -118,7 +118,7 @@ public static F> promise(final Strategy s, final F a) { - actor.act(P.p(Either., Actor>right(a), this)); + actor.act(p(Either., Actor>right(a), this)); } /** @@ -176,7 +176,7 @@ public Promise bind(final F> f) { final Promise r = mkPromise(s); final Actor ab = actor(s, new Effect1() { public void f(final B b) { - r.actor.act(P.p(Either., Actor>left(P.p(b)), r)); + r.actor.act(p(Either., Actor>left(p(b)), r)); } }); to(ab.promise().contramap(f)); @@ -233,7 +233,7 @@ public static F, F, Promise>> liftM2(final F< * @return A single promise for the given List. */ public static Promise> sequence(final Strategy s, final List> as) { - return join(foldRight(s, liftM2(List.cons()), promise(s, P.p(List.nil()))).f(as)); + return join(foldRight(s, liftM2(List.cons()), promise(s, p(List.nil()))).f(as)); } /** @@ -254,7 +254,7 @@ public static F>, Promise>> sequence(final Strategy< * @return A single promise for the given Stream. */ public static Promise> sequence(final Strategy s, final Stream> as) { - return join(foldRightS(s, curry((Promise o, P1>> p) -> o.bind(a -> p._1().fmap(Stream.cons_().f(a)))), promise(s, P.p(Stream.nil()))).f(as)); + return join(foldRightS(s, curry((Promise o, P1>> p) -> o.bind(a -> p._1().fmap(Stream.cons_().f(a)))), promise(s, p(Stream.nil()))).f(as)); } /** @@ -289,7 +289,7 @@ public static Promise> sequence(final Strategy s, final P1 F, Promise> foldRight(final Strategy s, final F> f, final B b) { return new F, Promise>() { public Promise f(final List as) { - return as.isEmpty() ? promise(s, p(b)) : liftM2(f).f(promise(s, P.p(as.head()))).f( + return as.isEmpty() ? promise(s, p(b)) : liftM2(f).f(promise(s, p(as.head()))).f( join(s, P1.curry(this).f(as.tail()))); } }; @@ -307,7 +307,7 @@ public static F, Promise> foldRightS(final Strategy s, final B b) { return new F, Promise>() { public Promise f(final Stream as) { - return as.isEmpty() ? promise(s, P.p(b)) : liftM2(f).f(promise(s, P.p(as.head()))).f( + return as.isEmpty() ? promise(s, p(b)) : liftM2(f).f(promise(s, p(as.head()))).f( Promise.>join(s, P.lazy(() -> f(as.tail()._1()).fmap(P.p1())))); } }; diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index f9ed8abb..d9231cb8 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -859,7 +859,7 @@ public static P2, Array> unzip(final Array> xs) { aa.set(i, p._1()); ab.set(i, p._2()); } - return P.p(aa, ab); + return p(aa, ab); } /** @@ -1074,8 +1074,8 @@ public static T[] copyOf(final U[] a, final int len, final Class " + to); final char[] copy = new char[len]; - System.arraycopy(a, from, copy, 0, - Math.min(a.length - from, len)); + arraycopy(a, from, copy, 0, + min(a.length - from, len)); return copy; } } diff --git a/core/src/main/java/fj/data/Conversions.java b/core/src/main/java/fj/data/Conversions.java index f6cfb624..055da1dd 100644 --- a/core/src/main/java/fj/data/Conversions.java +++ b/core/src/main/java/fj/data/Conversions.java @@ -293,7 +293,7 @@ public static F, F> Effect1_F() { public static IO Effect_IO(Effect0 e) { return () ->{ e.f(); - return Unit.unit(); + return unit(); }; } diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index 3f7b2fe3..7e44ef9b 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -104,7 +104,7 @@ public static DList single(A a) { * @return the new DList. */ public DList cons(A a) { - return DList.single(a).append(this); + return single(a).append(this); } /** @@ -113,7 +113,7 @@ public DList cons(A a) { * @return the new DList. */ public DList snoc(A a) { - return this.append(DList.single(a)); + return this.append(single(a)); } /** diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 8581664f..6381ee78 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -417,7 +417,7 @@ public Collection toCollection() { public Option> traverseOption(F> f) { return isLeft() ? f.f(value()).map(x -> Either.left(x)) : - Option.some(Either.right(e.right().value())); + some(Either.right(e.right().value())); } public Stream> traverseStream(F> f) { @@ -561,7 +561,7 @@ public Either sequence(final Either e) { */ public List> traverseList(final F> f) { return isRight() ? - f.f(value()).map(x -> Either.right(x)) : + f.f(value()).map(x -> right(x)) : list(Either.left(e.left().value())); } @@ -580,13 +580,13 @@ public IO> traverseIO(final F> f) { public P1> traverseP1(final F> f) { return isRight() ? f.f(value()).map(x -> Either.right(x)) : - P.p(Either.left(e.left().value())); + p(Either.left(e.left().value())); } public Option> traverseOption(final F> f) { return isRight() ? f.f(value()).map(x -> Either.right(x)) : - Option.some(Either.left(e.left().value())); + some(Either.left(e.left().value())); } /** @@ -693,8 +693,8 @@ public Collection toCollection() { public Stream> traverseStream(F> f) { return isRight() ? - f.f(value()).map(x -> Either.right(x)) : - Stream.>single(Either.left(e.left().value())); + f.f(value()).map(x -> right(x)) : + Stream.>single(left(e.left().value())); } } diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index fe57a643..cc143f33 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -368,12 +368,12 @@ else if (l < 0L) { * An enumerator for Natural */ public static final Enumerator naturalEnumerator = enumerator( - n -> Option.some(n.succ()), + n -> some(n.succ()), n -> n.pred(), Option.none(), some(Natural.ZERO), naturalOrd, curry((n, l) -> some(n).apply( - Natural.natural(l).map(Function.curry((n1, n2) -> n1.add(n2))) + Natural.natural(l).map(curry((n1, n2) -> n1.add(n2))) ) ) ); diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index 3e6ff3b3..cde1e607 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -347,7 +347,7 @@ public static HashMap fromMap(java.util.Map map) { } public static HashMap fromMap(Equal eq, Hash h, java.util.Map map) { - HashMap m = HashMap.hashMap(eq, h); + HashMap m = hashMap(eq, h); for (Map.Entry e: map.entrySet()) { m.set(e.getKey(), e.getValue()); } diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 1a3e93ff..755ce9fa 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -126,7 +126,7 @@ public static IO> enumFileChars(final File f, final Opti } public static IO bufferedReader(final File f, final Option encoding) { - return IOFunctions.map(fileReader(f, encoding), a -> new BufferedReader(a)); + return map(fileReader(f, encoding), a -> new BufferedReader(a)); } public static IO fileReader(final File f, final Option encoding) { @@ -372,15 +372,15 @@ public static IO unless(final Boolean b, final IO io) { */ public static IO> sequence(List> list) { F2, IO>, IO>> f2 = (io, ioList) -> - IOFunctions.bind(ioList, (xs) -> map(io, x -> List.cons(x, xs))); - return list.foldRight(f2, IOFunctions.unit(List.nil())); + bind(ioList, (xs) -> map(io, x -> List.cons(x, xs))); + return list.foldRight(f2, unit(List.nil())); } public static IO> sequence(Stream> stream) { F2>, IO, IO>> f2 = (ioList, io) -> - IOFunctions.bind(ioList, (xs) -> map(io, x -> Stream.cons(x, () -> xs))); - return stream.foldLeft(f2, IOFunctions.unit(Stream.nil())); + bind(ioList, (xs) -> map(io, x -> Stream.cons(x, () -> xs))); + return stream.foldLeft(f2, unit(Stream.nil())); } @@ -418,7 +418,7 @@ public static IO flatMap(final IO io, final F> f) { * @param transform Function to change line value */ public static IO interactWhile(F condition, F transform) { - Stream> s1 = Stream.repeat(IOFunctions.stdinReadLine()); + Stream> s1 = Stream.repeat(stdinReadLine()); IO> io = sequenceWhile(s1, condition); return () -> runSafe(io).foreach(s -> runSafe(stdoutPrintln(transform.f(s)))); } @@ -507,7 +507,7 @@ public static IO stdoutPrint(final String s) { public static IO getContents() { Stream> s = Stream.>repeat(() -> (int) stdinBufferedReader.read()); - return IOFunctions.map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> { + return map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> { return (char) i.intValue(); }))); } diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index 8b1b2ac6..adb0c7af 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -40,6 +40,6 @@ public IOW getContents() { } public IOW interact(F f) { - return IOW.lift(() -> IOFunctions.interact(f).run()); + return lift(() -> IOFunctions.interact(f).run()); } } diff --git a/core/src/main/java/fj/data/IterableW.java b/core/src/main/java/fj/data/IterableW.java index 523b4152..9c701a98 100644 --- a/core/src/main/java/fj/data/IterableW.java +++ b/core/src/main/java/fj/data/IterableW.java @@ -420,7 +420,7 @@ public ListIterator listIterator(final int index) { } public List subList(final int fromIndex, final int toIndex) { - return wrap(Stream.iterableStream(IterableW.this).drop(fromIndex).take(toIndex - fromIndex)).toStandardList(); + return wrap(iterableStream(IterableW.this).drop(fromIndex).take(toIndex - fromIndex)).toStandardList(); } private ListIterator toListIterator(final Option> z) { diff --git a/core/src/main/java/fj/data/LazyString.java b/core/src/main/java/fj/data/LazyString.java index 95160de1..2583621f 100644 --- a/core/src/main/java/fj/data/LazyString.java +++ b/core/src/main/java/fj/data/LazyString.java @@ -224,7 +224,7 @@ public LazyString reverse() { * @return The first index of the given character in this lazy string, or None if the character is not present. */ public Option indexOf(final char c) { - return s.indexOf(Equal.charEqual.eq(c)); + return s.indexOf(charEqual.eq(c)); } /** diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 26ec5e33..f12d5a26 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -122,7 +122,7 @@ public final boolean isNotEmpty() { */ @Deprecated public final B list(final B nil, final F, B>> cons) { - return uncons(Function.uncurryF2(cons), nil); + return uncons(uncurryF2(cons), nil); } public final B uncons(final F2, B> cons, final B nil) { @@ -410,9 +410,9 @@ public final P2, List> span(final F p) { if (p.f(xs.head())) b.snoc(xs.head()); else - return P.p(b.toList(), xs); + return p(b.toList(), xs); } - return P.p(b.toList(), List.nil()); + return p(b.toList(), List.nil()); } /** @@ -614,7 +614,7 @@ public final List sequence(final List bs) { public Option> traverseOption(final F> f) { return foldRight( (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))), - Option.some(List.nil()) + some(List.nil()) ); } @@ -641,7 +641,7 @@ public Stream> traverseStream(final F> f) { public P1> traverseP1(final F> f){ return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - P.p(List.nil()) + p(List.nil()) ); } @@ -656,7 +656,7 @@ public F> traverseF(F> f) { return this.foldRight( (a, acc) -> Function.bind(acc, (bs) -> Function.> compose(b -> bs.cons(b), f.f(a))), - Function.constant(List. nil()) + constant(List. nil()) ); } @@ -675,7 +675,7 @@ public Promise> traversePromise(final F> f) { public List> traverseList(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - List.single(List. nil())); + single(List. nil())); } public Validation> traverseValidation(final F> f) { @@ -707,7 +707,7 @@ public final List apply(final List> lf) { * @return A new list that has appended the given list. */ public final List append(final List as) { - return Buffer.fromList(this).prependToList(as); + return fromList(this).prependToList(as); } /** @@ -830,7 +830,7 @@ public final A index(final int i) { * @return A new list with a length the same, or less than, this list. */ public final List take(final int i) { - Buffer result = Buffer.empty(); + Buffer result = empty(); List list = this; int index = i; while (index > 0 && list.isNotEmpty()) { @@ -868,7 +868,7 @@ public final List drop(final int i) { public final P2, List> splitAt(final int i) { int c = 0; List first = List.nil(); - List second = List.nil(); + List second = nil(); for (List xs = this; xs.isNotEmpty(); xs = xs.tail()) { final A h = xs.head(); if (c < i) { @@ -878,7 +878,7 @@ public final P2, List> splitAt(final int i) { } c++; } - return P.p(first.reverse(), second.reverse()); + return p(first.reverse(), second.reverse()); } /** @@ -906,10 +906,10 @@ public final List> partition(final int n) { */ public P2, List> partition(F f) { P2, List> p2 = foldLeft(acc -> a -> - f.f(a) ? P.p(acc._1().cons(a), acc._2()) : P.p(acc._1(), acc._2().cons(a)), - P.p(nil(), nil()) + f.f(a) ? p(acc._1().cons(a), acc._2()) : p(acc._1(), acc._2().cons(a)), + p(nil(), nil()) ); - return P.p(p2._1().reverse(), p2._2().reverse()); + return p(p2._1().reverse(), p2._2().reverse()); } /** @@ -1115,7 +1115,7 @@ public final Option find(final F f) { public final List intersperse(final A a) { return isEmpty() || tail().isEmpty() ? this : - cons(head(), tail().bind(a2 -> List.list(a, a2))); + cons(head(), tail().bind(a2 -> list(a, a2))); } /** @@ -1320,7 +1320,7 @@ public final TreeMap> groupBy(final F keyFunction) { * @return A TreeMap containing the keys with the accumulated list of matched elements. */ public final TreeMap> groupBy(final F keyFunction, final Ord keyOrd) { - return groupBy(keyFunction, Function.identity(), keyOrd); + return groupBy(keyFunction, identity(), keyOrd); } /** @@ -1372,7 +1372,7 @@ public final TreeMap groupBy( final Monoid monoid, final Ord keyOrd) { return groupBy(keyFunction, valueFunction, monoid.zero(), - Function.uncurryF2(monoid.sum()), keyOrd); + uncurryF2(monoid.sum()), keyOrd); } /** @@ -1709,7 +1709,7 @@ public static P2, List> unzip(final List> xs) { ba = ba.snoc(p._1()); bb = bb.snoc(p._2()); } - return P.p(ba.toList(), bb.toList()); + return p(ba.toList(), bb.toList()); } /** @@ -1720,7 +1720,7 @@ public static P2, List> unzip(final List> xs) { * @return A list of the given value replicated the given number of times. */ public static List replicate(final int n, final A a) { - List list = List.nil(); + List list = nil(); for (int i = 0; i < n; i++) { list = list.cons(a); } return list; } @@ -1735,7 +1735,7 @@ public static List replicate(final int n, final A a) { * to value (exclusive). */ public static List range(final int from, final int to) { - final Buffer buf = Buffer.empty(); + final Buffer buf = empty(); for (int i = from; i < to; i++) { buf.snoc(i); } @@ -1815,7 +1815,7 @@ public static List single(final A a) { */ public static List iterateWhile(final F f, final F p, final A a) { return unfold( - o -> Option.iif(p2 -> p.f(o), P.p(o, f.f(o))) + o -> Option.iif(p2 -> p.f(o), p(o, f.f(o))) , a); } @@ -2210,7 +2210,7 @@ public static Prism, Unit> nil() { * Cons prism */ public static Prism, P2>> cons() { - return prism(l -> l.>>> list(none(), h -> tail -> some(P.p(h, tail))), c -> List.cons(c._1(), c._2())); + return prism(l -> l.>>> list(none(), h -> tail -> some(p(h, tail))), c -> List.cons(c._1(), c._2())); } } diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index cb58e61f..5bec1ea4 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -432,7 +432,7 @@ public Stream> traverseStream(F> f) { } public P1> traverseP1(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(P.p(none())); + return map(a -> f.f(a).map(b -> some(b))).orSome(p(none())); } public Seq> traverseSeq(F> f) { diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index 00868ef3..84b26d6e 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -106,7 +106,7 @@ public static Seq listSeq(final List list) { * @return A sequence with the elements of the iterable. */ public static Seq iterableSeq(final Iterable i) { - Seq s = Seq.empty(); + Seq s = empty(); for (final A a: i) { s = s.snoc(a); } diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index c54d6cb7..2d87234f 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -79,7 +79,7 @@ public State gets() { } public static State put(S s) { - return State.unit((S z) -> p(s, Unit.unit())); + return unit((S z) -> p(s, Unit.unit())); } public A eval(S s) { diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index cb6fe8d0..485ca1ad 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -351,7 +351,7 @@ public final Stream removeAll(final F f) { * and returns a stream of the results. */ public static F> sequence_(final Stream> fs) { - return fs.foldRight((baf, p1) -> Function.bind(baf, p1._1(), Function.curry((a, stream) -> cons(a, p(stream)))), Function + return fs.foldRight((baf, p1) -> Function.bind(baf, p1._1(), curry((a, stream) -> cons(a, p(stream)))), Function .>constant(Stream.nil())); } @@ -531,7 +531,7 @@ public static Stream> sequence(final IO> io) { * @return The stream of (pre-calculated) lazy values after sequencing. */ public static Stream> sequence(final F0> p) { - return p.f().map(a -> P.p(a)); + return p.f().map(a -> p(a)); } /** @@ -541,7 +541,7 @@ public static Stream> sequence(final F0> p) { * @return The stream of options after sequencing. */ public static Stream> sequence(final Option> o) { - return o.isNone() ? Stream.nil() : o.some().map(a -> Option.some(a)); + return o.isNone() ? nil() : o.some().map(a -> some(a)); } /** @@ -566,9 +566,9 @@ public final Stream interleave(final Stream as) { public static Stream enumerationStream(Enumeration e) { if (e.hasMoreElements()) { - return Stream.cons(e.nextElement(), () -> enumerationStream(e)); + return cons(e.nextElement(), () -> enumerationStream(e)); } else { - return Stream.nil(); + return nil(); } } @@ -627,7 +627,7 @@ public final Stream sort(final Ord o, final Strategy s) { private Promise> qs(final Ord o, final Strategy s) { if (isEmpty()) - return promise(s, P.p(this)); + return promise(s, p(this)); else { final F id = identity(); final A x = head(); @@ -797,7 +797,7 @@ public static Stream range(final Enumerator e, final A from, final A t */ public static Stream range(final Enumerator e, final A from, final A to, final long step) { final Ordering o = e.order().compare(from, to); - return o == EQ || step > 0L && o == GT || step < 0L && o == LT ? single(from) : cons(from, () -> Stream.join(e.plus(from, step).filter(a -> !(o == LT + return o == EQ || step > 0L && o == GT || step < 0L && o == LT ? single(from) : cons(from, () -> join(e.plus(from, step).filter(a -> !(o == LT ? e.order().isLessThan(to, a) : e.order().isGreaterThan(to, a))).map(a1 -> range(e, a1, to, step)).toStream())); } @@ -1336,7 +1336,7 @@ public final Stream> tails() { * @return a stream of the prefixes of this stream, starting with the stream itself. */ public final Stream> inits() { - final Stream> nil = Stream.cons(Stream.nil(), () -> nil()); + final Stream> nil = cons(Stream.nil(), () -> nil()); return isEmpty() ? nil : nil.append(() -> tail()._1().inits().map(Stream.cons_().f(head()))); } @@ -1418,8 +1418,8 @@ public static Stream fromFunction(final Enumerator e, final F public static P2, Stream> unzip(final Stream> xs) { return xs.foldRight((p, ps) -> { final P2, Stream> pp = ps._1(); - return P.p(cons(p._1(), P.p(pp._1())), cons(p._2(), P.p(pp._2()))); - }, P.p(Stream.nil(), Stream.nil())); + return p(cons(p._1(), p(pp._1())), cons(p._2(), p(pp._2()))); + }, p(Stream.nil(), Stream.nil())); } /** @@ -1591,7 +1591,7 @@ public static Stream unfold(final F>> f, final B b) */ public static Stream iterateWhile(final F f, final F p, final A a) { return unfold( - o -> Option.iif(p2 -> p.f(o), P.p(o, f.f(o))) + o -> Option.iif(p2 -> p.f(o), p(o, f.f(o))) , a); } @@ -1609,7 +1609,7 @@ public static Stream iterableStream(final Iterable i) { public static Stream arrayStream(final A...as) { return as.length == 0 ? Stream.nil() : unfold(P2.tuple((as1, i) -> i >= as.length ? Option.>>none() - : some(P.p(as[i], P.p(as, i + 1)))), P.p(as, 0)); + : some(p(as[i], p(as, i + 1)))), p(as, 0)); } /** diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index f02a6e73..004e0910 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -252,7 +252,7 @@ private static Stream drawSubTrees(final Show s, final Stream shift(final String f, final String o, final Stream s) { - return Stream.repeat(o).cons(f).zipWith(s, Monoid.stringMonoid.sum()); + return repeat(o).cons(f).zipWith(s, Monoid.stringMonoid.sum()); } private Stream drawTree(final Show s) { @@ -328,7 +328,7 @@ public Tree zipWith(final Tree bs, final F> f) { public static Tree bottomUp(Tree t, final F>, B> f) { final F, Tree> recursiveCall = a -> bottomUp(a, f); final Stream> tbs = t.subForest()._1().map(recursiveCall); - return Tree.node(f.f(P.p(t.root(), tbs.map(Tree. getRoot()))), tbs); + return node(f.f(P.p(t.root(), tbs.map(Tree. getRoot()))), tbs); } /** diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index e35e6592..2bdf70a9 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -129,7 +129,7 @@ public static TreeMap arrayTreeMap(final Ord keyOrd, final P2 get(final K k) { - final Option>> x = tree.split(P.p(k, Option.none()))._2(); + final Option>> x = tree.split(p(k, Option.none()))._2(); return x.bind(P2.>__2()); } @@ -142,7 +142,7 @@ public Option get(final K k) { * @return A new tree map with the given value mapped to the given key. */ public TreeMap set(final K k, final V v) { - return new TreeMap(tree.insert(P.p(k, Option.some(v)))); + return new TreeMap(tree.insert(p(k, Option.some(v)))); } /** @@ -152,7 +152,7 @@ public TreeMap set(final K k, final V v) { * @return A new tree map with the entry corresponding to the given key removed. */ public TreeMap delete(final K k) { - return new TreeMap(tree.delete(P.p(k, Option.none()))); + return new TreeMap(tree.delete(p(k, Option.none()))); } /** @@ -198,7 +198,7 @@ public List keys() { * @return true if this tree map contains the given key, false otherwise. */ public boolean contains(final K k) { - return tree.member(P.p(k, Option.none())); + return tree.member(p(k, Option.none())); } /** @@ -218,7 +218,7 @@ public Iterator> iterator() { * @return A new mutable map isomorphic to this tree map. */ public Map toMutableMap() { - final F>> fakePair = k -> P.p(k, Option.none()); + final F>> fakePair = k -> p(k, Option.none()); final Comparator comparator = tree.ord().contramap(fakePair).toComparator(); final Map m = new java.util.TreeMap(comparator); for (final P2 e : this) { @@ -278,7 +278,7 @@ public F> get() { public P2> update(final K k, final F f) { final P2>>> up = tree.update(p(k, Option.none()), compose(P2.tuple(P.p2()), P2., Option>map2_(Option.map().f(f)))); - return P.p(up._1(), new TreeMap(up._2())); + return p(up._1(), new TreeMap(up._2())); } /** @@ -347,9 +347,9 @@ private static TreeMap treeMap(Ord ord, Set>> s) * given key if present, otherwise None. */ public P3, Option, TreeMap> splitLookup(final K k) { - P3>>, Option>>, Set>>> p3 = tree.split(P.p(k, get(k))); - Ord o = tree.ord().contramap(k2 -> P.p(k2, Option.none())); - return P.p(treeMap(o, p3._1()), get(k), treeMap(o, p3._3())); + P3>>, Option>>, Set>>> p3 = tree.split(p(k, get(k))); + Ord o = tree.ord().contramap(k2 -> p(k2, Option.none())); + return p(treeMap(o, p3._1()), get(k), treeMap(o, p3._3())); } /** diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index a87b4585..3e622f68 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -208,7 +208,7 @@ public static Validation> sequence(final Semigroup s, final if (list.exists(v -> v.isFail())) { return Validation.>fail(list.filter(v -> v.isFail()).map(v -> v.fail()).foldLeft1((e1, e2) -> s.sum(e1, e2))); } else { - return Validation.success(list.foldLeft((List acc, Validation v) -> acc.cons(v.success()), List.nil()).reverse()); + return success(list.foldLeft((List acc, Validation v) -> acc.cons(v.success()), List.nil()).reverse()); } } @@ -722,17 +722,17 @@ public Iterator iterator() { public Validation, T> accumulate() { if (isFail()) { - return Validation.fail(List.single(fail())); + return fail(List.single(fail())); } else { - return Validation.success(success()); + return success(success()); } } public Validation, B> accumulate(F f) { if (isFail()) { - return Validation.fail(List.single(fail())); + return fail(List.single(fail())); } else { - return Validation.success(f.f(success())); + return success(f.f(success())); } } @@ -746,9 +746,9 @@ public Validation, C> accumulate(Validation v2, F2 list = list.cons(v2.fail()); } if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success())); + return success(f.f(success(), v2.success())); } } @@ -757,27 +757,27 @@ public Validation, C> accumulate(Validation v2, F2 public Validation, D> accumulate(Validation v2, Validation v3, F3 f) { List list = fails(list(this, v2, v3)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success())); + return success(f.f(success(), v2.success(), v3.success())); } } public Validation, $E> accumulate(Validation v2, Validation v3, Validation v4, F4 f) { List list = fails(list(this, v2, v3, v4)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success(), v4.success())); + return success(f.f(success(), v2.success(), v3.success(), v4.success())); } } public Validation, $F> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, F5 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success())); + return success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success())); } } @@ -785,27 +785,27 @@ public Validation, D> accumulate(Validation v2, Validati public Validation, G> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, F6 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success())); + return success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success())); } } public Validation, H> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, F7 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success(), v7.success())); + return success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success(), v7.success())); } } public Validation, I> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, Validation v8, F8 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { - return Validation.fail(list); + return fail(list); } else { - return Validation.success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success(), v7.success(), v8.success())); + return success(f.f(success(), v2.success(), v3.success(), v4.success(), v5.success(), v6.success(), v7.success(), v8.success())); } } @@ -818,10 +818,10 @@ public Validation, D> accumulate(Validation v2, Validati public static Validation, List> sequenceNonCumulative(List> list) { if (list.exists(v -> v.isFail())) { F2, Validation, List> f = (acc, v) -> acc.cons(v.fail()); - return Validation.fail(list.filter(v -> v.isFail()).foldLeft(f, List.nil()).reverse()); + return fail(list.filter(v -> v.isFail()).foldLeft(f, List.nil()).reverse()); } else { F2, Validation, List> f = (acc, v) -> acc.cons(v.success()); - return Validation.success(list.filter(v -> v.isSuccess()).foldLeft(f, List.nil()).reverse()); + return success(list.filter(v -> v.isSuccess()).foldLeft(f, List.nil()).reverse()); } } @@ -852,7 +852,7 @@ public IO> traverseIO(F> f){ public P1> traverseP1(F> f){ return isSuccess() ? f.f(success()).map(Validation::success) : - P.p(fail(e.left().value())); + p(fail(e.left().value())); } @@ -1276,7 +1276,7 @@ public static Validation parseShort(final String s * Partitions the list into the list of fails and the list of successes */ public static P2, List> partition(List> list) { - return P.p( + return p( list.filter(v -> v.isFail()).map(v -> v.fail()), list.filter(v -> v.isSuccess()).map(v -> v.success()) ); diff --git a/core/src/main/java/fj/data/Writer.java b/core/src/main/java/fj/data/Writer.java index 7ff57d07..b384e259 100644 --- a/core/src/main/java/fj/data/Writer.java +++ b/core/src/main/java/fj/data/Writer.java @@ -59,7 +59,7 @@ public static Writer unit(B b) { } public static F> stringLogger() { - return a -> Writer.unit(a, Monoid.stringMonoid); + return a -> unit(a, Monoid.stringMonoid); } } diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index 9f86db45..1078374b 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -225,7 +225,7 @@ public final P3, A, FingerTree> split1(final F FingerTree emptyIntAddition() { - return FingerTree.mkTree(FingerTree.measured(intAdditionMonoid, Function.constant(1))).empty(); + return mkTree(FingerTree.measured(intAdditionMonoid, Function.constant(1))).empty(); } } diff --git a/core/src/main/java/fj/data/fingertrees/Single.java b/core/src/main/java/fj/data/fingertrees/Single.java index 410378f1..1bbe7884 100644 --- a/core/src/main/java/fj/data/fingertrees/Single.java +++ b/core/src/main/java/fj/data/fingertrees/Single.java @@ -81,7 +81,7 @@ public V measure() { @Override P3, A, FingerTree> split1(final F predicate, final V acc) { final Empty empty = new Empty<>(measured()); - return P.p(empty, a, empty); + return p(empty, a, empty); } @Override public P2 lookup(final F o, final int i) { return p(i, a); } diff --git a/demo/src/main/java/fj/demo/realworld/Chapter7.java b/demo/src/main/java/fj/demo/realworld/Chapter7.java index 2f6ed8a4..f9263683 100644 --- a/demo/src/main/java/fj/demo/realworld/Chapter7.java +++ b/demo/src/main/java/fj/demo/realworld/Chapter7.java @@ -36,7 +36,7 @@ public static void toUpperLazy() { * Read each line, convert to uppercase and print on stdout, until an empty line */ public static void toUpperByLine() { - Stream> s1 = Stream.repeat(IOFunctions.stdinReadLine()); + Stream> s1 = Stream.repeat(stdinReadLine()); IO> io = sequenceWhile(s1, s -> s.trim().length() > 0); runSafe(io).foreachDoEffect(s -> runSafe(stdoutPrintln(s.toUpperCase()))); } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 34a17ae1..5222df9e 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -128,7 +128,7 @@ public Gen f(final A x) { } public static Arbitrary> arbReader(Coarbitrary aa, Arbitrary ab) { - return arbitrary(Arbitrary.arbF(aa, ab).gen.map(f -> Reader.unit(f))); + return arbitrary(arbF(aa, ab).gen.map(f -> Reader.unit(f))); } /** @@ -819,7 +819,7 @@ public static Arbitrary> arbSet(Ord ord, final Arbitrary aa) { } public static Arbitrary> arbSet(Ord ord, final Arbitrary aa, int max) { - Gen> g = Gen.choose(0, max).bind(i -> Gen.sequenceN(i, aa.gen)).map(list -> Set.iterableSet(ord, list)); + Gen> g = choose(0, max).bind(i -> Gen.sequenceN(i, aa.gen)).map(list -> Set.iterableSet(ord, list)); return arbitrary(g); } @@ -902,7 +902,7 @@ public Date f(final Long i) { * @return An arbitrary for instances of the supplied enum type. */ public static > Arbitrary arbEnumValue(final Class clazz) { - return arbitrary(Gen.elements(clazz.getEnumConstants())); + return arbitrary(elements(clazz.getEnumConstants())); } /** @@ -1161,7 +1161,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb if (i < 0) { Bottom.error("Undefined: arbitrary natural is negative (" + i + ")"); } - return Gen.sequenceN(Math.max(i, 0), Arbitrary.arbP2(ak, av).gen); + return Gen.sequenceN(Math.max(i, 0), arbP2(ak, av).gen); }); return arbTreeMap(ord, arbitrary(gl2)); } @@ -1173,7 +1173,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb if (maxSize < 0) { Bottom.error("Undefined: arbitrary natural is negative (" + maxSize + ")"); } - return arbTreeMap(ord, ak, av, arbitrary(Gen.choose(0, maxSize))); + return arbTreeMap(ord, ak, av, arbitrary(choose(0, maxSize))); } /** diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 3231cf2e..1486a695 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -367,7 +367,7 @@ public Result f(final Rand r) { * will be taken from the given boolean b. */ public static Property impliesBoolean(final boolean a, final boolean b) { - return implies(a, () -> Property.prop(b)); + return implies(a, () -> prop(b)); } /** @@ -375,7 +375,7 @@ public static Property impliesBoolean(final boolean a, final boolean b) { * will be taken from the given lazy boolean b. */ public static Property impliesBoolean(final boolean a, final F0 b) { - return implies(a, () -> Property.prop(b.f())); + return implies(a, () -> prop(b.f())); } /** From 3655b4d143cb3a52d604ea41da110839684c9b74 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 20:17:43 +0100 Subject: [PATCH 033/336] Remove redundant public/abstract modifiers on interfaces --- core/src/main/java/fj/F.java | 2 +- core/src/main/java/fj/F0.java | 2 +- core/src/main/java/fj/F2.java | 2 +- core/src/main/java/fj/F3.java | 2 +- core/src/main/java/fj/F4.java | 2 +- core/src/main/java/fj/F5.java | 2 +- core/src/main/java/fj/F6.java | 2 +- core/src/main/java/fj/F7.java | 2 +- core/src/main/java/fj/F8.java | 2 +- core/src/main/java/fj/data/IO.java | 2 +- core/src/main/java/fj/data/SafeIO.java | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/fj/F.java b/core/src/main/java/fj/F.java index 1b524fdc..2a0136bf 100644 --- a/core/src/main/java/fj/F.java +++ b/core/src/main/java/fj/F.java @@ -45,6 +45,6 @@ public interface F { * @param a The A to transform. * @return The result of the transformation. */ - public abstract B f(A a); + B f(A a); } diff --git a/core/src/main/java/fj/F0.java b/core/src/main/java/fj/F0.java index e85689da..eab82a01 100644 --- a/core/src/main/java/fj/F0.java +++ b/core/src/main/java/fj/F0.java @@ -5,6 +5,6 @@ */ public interface F0 { - public A f(); + A f(); } diff --git a/core/src/main/java/fj/F2.java b/core/src/main/java/fj/F2.java index 0aa82585..1723927a 100644 --- a/core/src/main/java/fj/F2.java +++ b/core/src/main/java/fj/F2.java @@ -33,6 +33,6 @@ public interface F2 { * @param b The B to transform. * @return The result of the transformation. */ - public C f(A a, B b); + C f(A a, B b); } diff --git a/core/src/main/java/fj/F3.java b/core/src/main/java/fj/F3.java index 68e7627a..540afdaa 100644 --- a/core/src/main/java/fj/F3.java +++ b/core/src/main/java/fj/F3.java @@ -15,5 +15,5 @@ public interface F3 { * @param c The C to transform. * @return The result of the transformation. */ - public D f(A a, B b, C c); + D f(A a, B b, C c); } diff --git a/core/src/main/java/fj/F4.java b/core/src/main/java/fj/F4.java index 9447389a..84dcfafa 100644 --- a/core/src/main/java/fj/F4.java +++ b/core/src/main/java/fj/F4.java @@ -16,5 +16,5 @@ public interface F4 { * @param d The D to transform. * @return The result of the transformation. */ - public E f(A a, B b, C c, D d); + E f(A a, B b, C c, D d); } diff --git a/core/src/main/java/fj/F5.java b/core/src/main/java/fj/F5.java index ff7184f2..5fea676b 100644 --- a/core/src/main/java/fj/F5.java +++ b/core/src/main/java/fj/F5.java @@ -19,5 +19,5 @@ public interface F5 { * @param e The E to transform. * @return The result of the transformation. */ - public F$ f(A a, B b, C c, D d, E e); + F$ f(A a, B b, C c, D d, E e); } diff --git a/core/src/main/java/fj/F6.java b/core/src/main/java/fj/F6.java index f403eb0a..20101cf7 100644 --- a/core/src/main/java/fj/F6.java +++ b/core/src/main/java/fj/F6.java @@ -20,5 +20,5 @@ public interface F6 { * @param f The F$ to transform. * @return The result of the transformation. */ - public G f(A a, B b, C c, D d, E e, F$ f); + G f(A a, B b, C c, D d, E e, F$ f); } diff --git a/core/src/main/java/fj/F7.java b/core/src/main/java/fj/F7.java index be9d87e1..5a3ea1ef 100644 --- a/core/src/main/java/fj/F7.java +++ b/core/src/main/java/fj/F7.java @@ -21,5 +21,5 @@ public interface F7 { * @param g The G to transform. * @return The result of the transformation. */ - public H f(A a, B b, C c, D d, E e, F$ f, G g); + H f(A a, B b, C c, D d, E e, F$ f, G g); } diff --git a/core/src/main/java/fj/F8.java b/core/src/main/java/fj/F8.java index 5ad75489..8b986456 100644 --- a/core/src/main/java/fj/F8.java +++ b/core/src/main/java/fj/F8.java @@ -22,5 +22,5 @@ public interface F8 { * @param h The H to transform. * @return The result of the transformation. */ - public I f(A a, B b, C c, D d, E e, F$ f, G g, H h); + I f(A a, B b, C c, D d, E e, F$ f, G g, H h); } diff --git a/core/src/main/java/fj/data/IO.java b/core/src/main/java/fj/data/IO.java index eefd11b9..ee27bdb7 100644 --- a/core/src/main/java/fj/data/IO.java +++ b/core/src/main/java/fj/data/IO.java @@ -15,6 +15,6 @@ */ public interface IO { - public A run() throws IOException; + A run() throws IOException; } diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index 2935ca83..13bbbcc5 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -8,7 +8,7 @@ public interface SafeIO extends IO { @Override - public A run(); + A run(); } From a60afe9732d7a367fe8eabd3bd7fa9155f18addc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 20:39:49 +0100 Subject: [PATCH 034/336] Remove unnecessary parentheses --- core/src/main/java/fj/Semigroup.java | 2 +- core/src/main/java/fj/data/Stream.java | 2 +- core/src/main/java/fj/data/optic/PTraversal.java | 2 +- demo/src/main/java/fj/demo/Array_foldLeft.java | 2 +- demo/src/main/java/fj/demo/StateDemo_VendingMachine.java | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 18172990..5d4b995d 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -92,7 +92,7 @@ static A multiply1p(F> sum, int n, A a) { } } xTmp = sum.f(xTmp).f(xTmp); - yTmp = (yTmp) >>> 1; + yTmp = yTmp >>> 1; } } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 485ca1ad..fcb6c1d0 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -374,7 +374,7 @@ public final F> mapM(final F> f) { * @return A new stream after performing the map, then final join. */ public final Stream bind(final F> f) { - return foldRight(h -> (t -> f.f(h).append(t)), nil()); + return foldRight(h -> t -> f.f(h).append(t), nil()); } /** diff --git a/core/src/main/java/fj/data/optic/PTraversal.java b/core/src/main/java/fj/data/optic/PTraversal.java index 8e98cf2f..50c1e14c 100644 --- a/core/src/main/java/fj/data/optic/PTraversal.java +++ b/core/src/main/java/fj/data/optic/PTraversal.java @@ -533,7 +533,7 @@ public F foldMap(final Monoid monoid, final F f) { public static PTraversal pTraversal(final F get1, final F get2, final F get3, final F4 set) { - return fromCurried(pTraversal(get1, get2, (b1, b2, s) -> (b3 -> set.f(b1, b2, b3, s))), get3); + return fromCurried(pTraversal(get1, get2, (b1, b2, s) -> b3 -> set.f(b1, b2, b3, s)), get3); } public static PTraversal pTraversal(final F get1, final F get2, final F get3, diff --git a/demo/src/main/java/fj/demo/Array_foldLeft.java b/demo/src/main/java/fj/demo/Array_foldLeft.java index 9acb86be..f7f1ce58 100644 --- a/demo/src/main/java/fj/demo/Array_foldLeft.java +++ b/demo/src/main/java/fj/demo/Array_foldLeft.java @@ -12,7 +12,7 @@ public static void main(final String[] args) { // WARNING: In JDK 8, update 20 and 25 (current version) the following code triggers an internal JDK compiler error, likely due to https://bugs.openjdk.java.net/browse/JDK-8062253. The code below is a workaround for this compiler bug. // final int c = a.foldLeft(i -> (j -> i + j), 0); - F> add2 = i -> (j -> i + j); + F> add2 = i -> j -> i + j; final int c = a.foldLeft(add2, 0); System.out.println(b); // 1774 } diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index 0f09318a..e31c9f27 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -48,7 +48,7 @@ public boolean equals(Object o) { */ @Override public int hashCode() { - int result = (locked ? 1 : 0); + int result = locked ? 1 : 0; result = 31 * result + items; result = 31 * result + coins; return result; From 2b7633f5409c3d6a222bf70a3bb8476e61fb2b6e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 20:40:36 +0100 Subject: [PATCH 035/336] Remove unnecessary semicolon --- demo/src/main/java/fj/demo/StateDemo_VendingMachine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index e31c9f27..3178e37b 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -12,7 +12,7 @@ */ public class StateDemo_VendingMachine { - public enum Input { COIN, TURN }; + public enum Input { COIN, TURN } public static class VendingMachine { From 702202297bc4427556e94ffed84502aad01b52b3 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 16:49:36 +0100 Subject: [PATCH 036/336] Remove usage of deprecated API --- core/src/main/java/fj/P1.java | 4 ++-- core/src/main/java/fj/data/HashMap.java | 6 +++--- core/src/main/java/fj/data/List.java | 8 ++++---- core/src/test/java/fj/data/ListTest.java | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 1995352e..0cb92a89 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -86,7 +86,7 @@ public static F> curry(final F f) { */ public P1 apply(final P1> cf) { P1 self = this; - return cf.bind(f -> fmap(f).f(self)); + return cf.bind(f -> map_(f).f(self)); } /** @@ -97,7 +97,7 @@ public P1 apply(final P1> cf) { * @return A new P1 after performing the map, then final join. */ public P1 bind(final P1 cb, final F> f) { - return cb.apply(fmap(f).f(this)); + return cb.apply(map_(f).f(this)); } /** diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index cde1e607..e45d94a5 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -272,11 +272,11 @@ public HashMap map(F keyFunction, } public HashMap map(F, P2> function, Equal equal, Hash hash) { - return from(toStream().map(function), equal, hash); + return iterableHashMap(equal, hash, toStream().map(function)); } public HashMap map(F, P2> function) { - return from(toStream().map(function)); + return iterableHashMap(toStream().map(function)); } public HashMap mapKeys(F keyFunction, Equal equal, Hash hash) { @@ -339,7 +339,7 @@ public java.util.Map toMap() { */ @Deprecated public static HashMap from(final Iterable> entries) { - return iterableHashMap(Equal.anyEqual(), Hash.anyHash(), entries); + return iterableHashMap(entries); } public static HashMap fromMap(java.util.Map map) { diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index f12d5a26..31c4a4af 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -2188,15 +2188,15 @@ public static Traversal, A> traversal() { * Optional targeted on Cons head. */ public static Optional, A> head() { - return optional(l -> l.toOption(), a -> l -> l.>list(l, constant(cons_(a)))); + return optional(List::headOption, a -> l -> l.uncons((__, as) -> as.cons(a), l)); } /** * Optional targeted on Cons tail. */ public static Optional, List> tail() { - return optional(l -> l.>> list(none(), h -> tail -> some(tail)), - tail -> l -> l.list(l, h -> constant(List.cons(h, tail)))); + return optional(l -> l.uncons((__, tail) -> some(tail), none()), + tail -> l -> l.uncons((h, __) -> List.cons(h, tail), l)); } /** @@ -2210,7 +2210,7 @@ public static Prism, Unit> nil() { * Cons prism */ public static Prism, P2>> cons() { - return prism(l -> l.>>> list(none(), h -> tail -> some(p(h, tail))), c -> List.cons(c._1(), c._2())); + return prism(l -> l.>>> uncons((h, tail) -> some(p(h, tail)), none()), c -> List.cons(c._1(), c._2())); } } diff --git a/core/src/test/java/fj/data/ListTest.java b/core/src/test/java/fj/data/ListTest.java index 8725ef05..3b720fe6 100644 --- a/core/src/test/java/fj/data/ListTest.java +++ b/core/src/test/java/fj/data/ListTest.java @@ -82,13 +82,13 @@ public void listReduce() { } @Test - public void toJavaArray() { + public void array() { final int max = 3; Integer[] ints = new Integer[max]; for (int i = 0; i < max; i++) { ints[i] = i + 1; }; - assertThat(List.range(1, max + 1).toJavaArray(), equalTo(ints)); + assertThat(List.range(1, max + 1).array(Integer[].class), equalTo(ints)); } } From 9fa7b497d238f9be83fc23e9b544a9466f1fda29 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 20:59:47 +0100 Subject: [PATCH 037/336] simplify boolean expression --- core/src/main/java/fj/Semigroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 5d4b995d..6e091d7f 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -240,7 +240,7 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that XORs booleans. */ - public static final Semigroup exclusiveDisjunctionSemiGroup = semigroup((p, q) -> p && !q || !p && q); + public static final Semigroup exclusiveDisjunctionSemiGroup = semigroup((p, q) -> p ? !q : q); /** * A semigroup that ANDs booleans. From 00a5fdc34c5b97758a8a12f34cde4db3dd175f0f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 21:09:10 +0100 Subject: [PATCH 038/336] Add test for Ordering#reverse --- core/src/test/java/fj/OrderingTest.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 core/src/test/java/fj/OrderingTest.java diff --git a/core/src/test/java/fj/OrderingTest.java b/core/src/test/java/fj/OrderingTest.java new file mode 100644 index 00000000..9b980e67 --- /dev/null +++ b/core/src/test/java/fj/OrderingTest.java @@ -0,0 +1,21 @@ +package fj; + +import org.hamcrest.Matcher; +import org.hamcrest.core.Is; +import org.junit.Test; + +import static fj.Ordering.EQ; +import static fj.Ordering.GT; +import static fj.Ordering.LT; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class OrderingTest { + + @Test + public void reverse() throws Exception { + assertThat(GT.reverse(), is(LT)); + assertThat(LT.reverse(), is(GT)); + assertThat(EQ.reverse(), is(EQ)); + } +} \ No newline at end of file From a4fb2dfb6a7eb17db11f4d7f89a0442515fc1f43 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 21:19:46 +0100 Subject: [PATCH 039/336] More regular for loop --- core/src/main/java/fj/data/List.java | 4 +--- core/src/main/java/fj/data/Stream.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 31c4a4af..0b5a0d4c 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -848,11 +848,9 @@ public final List take(final int i) { * @return A list with a length the same, or less than, this list. */ public final List drop(final int i) { - int c = 0; - List xs = this; - for (; xs.isNotEmpty() && c < i; xs = xs.tail()) + for (int c = 0; xs.isNotEmpty() && c < i; xs = xs.tail()) c++; return xs; diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index fcb6c1d0..6dbcf778 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -1072,11 +1072,9 @@ public final Stream take(final int n) { * @return A stream with a length the same, or less than, this stream. */ public final Stream drop(final int i) { - int c = 0; - Stream xs = this; - for (; xs.isNotEmpty() && c < i; xs = xs.tail()._1()) + for (int c = 0; xs.isNotEmpty() && c < i; xs = xs.tail()._1()) c++; return xs; From f374e16989844354fc6dc252a1adb017157d45fe Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 21:50:08 +0100 Subject: [PATCH 040/336] Improve error handling in DbState#run --- core/src/main/java/fj/control/db/DbState.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/fj/control/db/DbState.java b/core/src/main/java/fj/control/db/DbState.java index 1243c309..228dff37 100644 --- a/core/src/main/java/fj/control/db/DbState.java +++ b/core/src/main/java/fj/control/db/DbState.java @@ -94,18 +94,21 @@ public Unit run(final Connection c) throws SQLException { * @throws SQLException in case of a database error. */ public A run(final DB dba) throws SQLException { - final Connection c = pc.connect(); - c.setAutoCommit(false); - try { - final A a = dba.run(c); + try (Connection c = pc.connect()) { + c.setAutoCommit(false); + final A a; + try { + a = dba.run(c); + } catch (RuntimeException | SQLException e) { + try { + c.rollback(); + } catch (Exception re) { + e.addSuppressed(re); + } + throw e; + } terminal.run(c); return a; - } catch (SQLException e) { - c.rollback(); - throw e; - } - finally { - c.close(); } } } From c45b0d64c66681d6779fa6ed021d263b2476b6f1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 22:01:17 +0100 Subject: [PATCH 041/336] Fix IOFunctions#bracket --- core/src/main/java/fj/data/IOFunctions.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 755ce9fa..6aa5db12 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -5,6 +5,7 @@ import static fj.Function.partialApply2; import java.io.BufferedReader; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -141,12 +142,8 @@ public static IO bracket(final IO init, final F> fin, f @Override public C run() throws IOException { final A a = init.run(); - try { + try(Closeable finAsCloseable = fin.f(a)::run) { return body.f(a).run(); - } catch (final IOException e) { - throw e; - } finally { - fin.f(a); } } }; From a069fa5e2ecdb8b7653bd1c40de0a1fb0a53a5a9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 22:08:58 +0100 Subject: [PATCH 042/336] Remove unused import statements --- core/src/main/java/fj/Class.java | 1 - core/src/main/java/fj/F.java | 32 ------------------- core/src/main/java/fj/F2.java | 19 ----------- core/src/main/java/fj/F2W.java | 7 ---- core/src/main/java/fj/F3Functions.java | 6 ---- core/src/main/java/fj/F4Functions.java | 3 -- core/src/main/java/fj/F5Functions.java | 3 -- core/src/main/java/fj/F6Functions.java | 3 -- core/src/main/java/fj/F7Functions.java | 3 -- core/src/main/java/fj/F8Functions.java | 3 -- core/src/main/java/fj/TryEffect.java | 4 --- core/src/main/java/fj/data/Enumerator.java | 2 +- core/src/main/java/fj/data/IterableW.java | 2 -- core/src/main/java/fj/data/Iteratee.java | 1 - core/src/main/java/fj/data/Java.java | 3 -- core/src/main/java/fj/data/Natural.java | 2 +- core/src/main/java/fj/data/SafeIO.java | 2 -- core/src/main/java/fj/data/State.java | 2 -- .../main/java/fj/data/fingertrees/Empty.java | 1 - .../main/java/fj/data/fingertrees/Node.java | 1 - core/src/main/java/fj/data/hlist/HPre.java | 1 - core/src/main/java/fj/data/vector/V.java | 1 - .../main/java/fj/function/BigIntegers.java | 1 - .../src/main/java/fj/function/Characters.java | 1 - core/src/main/java/fj/function/Doubles.java | 1 - core/src/main/java/fj/function/Integers.java | 2 +- core/src/main/java/fj/function/Longs.java | 2 +- core/src/main/java/fj/function/Visitor.java | 1 - core/src/main/java/fj/parser/Result.java | 2 +- demo/src/main/java/fj/demo/Array_bind.java | 1 - demo/src/main/java/fj/demo/ChequeWrite.java | 1 - .../main/java/fj/demo/Comonad_example.java | 1 - .../main/java/fj/demo/HList_foldRight.java | 2 -- demo/src/main/java/fj/demo/Primes2.java | 2 +- demo/src/main/java/fj/demo/Set_map.java | 1 - .../fj/demo/StateDemo_VendingMachine.java | 1 - .../main/java/fj/demo/concurrent/Fibs.java | 2 +- .../main/java/fj/demo/concurrent/Ping.java | 1 - .../java/fj/demo/concurrent/PingPong.java | 1 - .../main/java/fj/demo/concurrent/Pong.java | 1 - .../java/fj/demo/concurrent/WordCount.java | 1 - .../src/main/java/fj/demo/euler/Problem1.java | 1 - .../src/main/java/fj/demo/euler/Problem3.java | 2 -- .../src/main/java/fj/demo/euler/Problem4.java | 1 - .../java/fj/demo/test/AdditionCommutes.java | 1 - .../demo/test/AdditionCommutesParallel.java | 2 -- .../java/fj/demo/test/EqualsHashCode.java | 3 -- .../java/fj/demo/test/IntegerOverflow.java | 1 - .../java/fj/demo/test/JavaLinkedList.java | 1 - .../java/fj/demo/test/ListFunctorLaws.java | 2 -- .../fj/demo/test/OptionMonadFunctorLaw.java | 2 -- demo/src/main/java/fj/demo/test/Reflect.java | 2 -- .../fj/demo/test/StringBuilderReverse.java | 2 -- .../main/java/fj/demo/test/Triangulation.java | 1 - .../src/main/java/fj/test/Arbitrary.java | 1 - quickcheck/src/main/java/fj/test/Bool.java | 2 +- quickcheck/src/main/java/fj/test/Result.java | 1 - .../src/main/java/fj/test/reflect/Check.java | 1 - .../java/fj/test/reflect/CheckParams.java | 1 - 59 files changed, 8 insertions(+), 146 deletions(-) diff --git a/core/src/main/java/fj/Class.java b/core/src/main/java/fj/Class.java index e2630569..da214af1 100644 --- a/core/src/main/java/fj/Class.java +++ b/core/src/main/java/fj/Class.java @@ -2,7 +2,6 @@ import fj.data.List; import static fj.data.List.unfold; -import fj.data.Option; import static fj.data.Option.none; import static fj.data.Option.some; import fj.data.Tree; diff --git a/core/src/main/java/fj/F.java b/core/src/main/java/fj/F.java index 2a0136bf..e2db316e 100644 --- a/core/src/main/java/fj/F.java +++ b/core/src/main/java/fj/F.java @@ -1,37 +1,5 @@ package fj; -import fj.control.parallel.Actor; -import fj.control.parallel.Promise; -import fj.control.parallel.Strategy; -import fj.data.Array; -import fj.data.Either; -import fj.data.IterableW; -import fj.data.List; -import fj.data.NonEmptyList; -import fj.data.Option; -import fj.data.Set; -import fj.data.Stream; -import fj.data.Tree; -import fj.data.TreeZipper; -import fj.data.Validation; -import fj.data.Zipper; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.PriorityQueue; -import java.util.TreeSet; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.PriorityBlockingQueue; -import java.util.concurrent.SynchronousQueue; - -import static fj.data.Option.some; -import static fj.data.Stream.iterableStream; -import static fj.data.Zipper.fromStream; - /** * A transformation or function from A to B. This type can be represented * using the Java 7 closure syntax. diff --git a/core/src/main/java/fj/F2.java b/core/src/main/java/fj/F2.java index 1723927a..63555fd5 100644 --- a/core/src/main/java/fj/F2.java +++ b/core/src/main/java/fj/F2.java @@ -1,24 +1,5 @@ package fj; -import fj.control.parallel.Promise; -import fj.data.Array; -import fj.data.IterableW; -import fj.data.List; -import fj.data.NonEmptyList; -import fj.data.Option; -import fj.data.Set; -import fj.data.Stream; -import fj.data.Tree; -import fj.data.TreeZipper; -import fj.data.Zipper; - -import static fj.data.Tree.node; -import static fj.P.p; -import static fj.data.IterableW.wrap; -import static fj.data.Set.iterableSet; -import static fj.data.TreeZipper.treeZipper; -import static fj.data.Zipper.zipper; - /** * A transformation function of arity-2 from A and B to C. * This type can be represented using the Java 7 closure syntax. diff --git a/core/src/main/java/fj/F2W.java b/core/src/main/java/fj/F2W.java index 7a2f6e19..eb2fb590 100644 --- a/core/src/main/java/fj/F2W.java +++ b/core/src/main/java/fj/F2W.java @@ -3,13 +3,6 @@ import fj.control.parallel.Promise; import fj.data.*; -import static fj.P.p; -import static fj.data.IterableW.wrap; -import static fj.data.Set.iterableSet; -import static fj.data.Tree.node; -import static fj.data.TreeZipper.treeZipper; -import static fj.data.Zipper.zipper; - /** * Created by MarkPerry on 22/01/2015. */ diff --git a/core/src/main/java/fj/F3Functions.java b/core/src/main/java/fj/F3Functions.java index a1e0b8f7..18e811d9 100644 --- a/core/src/main/java/fj/F3Functions.java +++ b/core/src/main/java/fj/F3Functions.java @@ -1,11 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try3; - -import static fj.data.Validation.fail; -import static fj.data.Validation.success; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/F4Functions.java b/core/src/main/java/fj/F4Functions.java index 04525167..cb353764 100644 --- a/core/src/main/java/fj/F4Functions.java +++ b/core/src/main/java/fj/F4Functions.java @@ -1,8 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try4; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/F5Functions.java b/core/src/main/java/fj/F5Functions.java index d8dda4da..c39b228f 100644 --- a/core/src/main/java/fj/F5Functions.java +++ b/core/src/main/java/fj/F5Functions.java @@ -1,8 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try5; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/F6Functions.java b/core/src/main/java/fj/F6Functions.java index 69ce270a..320b95f4 100644 --- a/core/src/main/java/fj/F6Functions.java +++ b/core/src/main/java/fj/F6Functions.java @@ -1,8 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try6; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/F7Functions.java b/core/src/main/java/fj/F7Functions.java index 0f2f25ac..e583ba4b 100644 --- a/core/src/main/java/fj/F7Functions.java +++ b/core/src/main/java/fj/F7Functions.java @@ -1,8 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try7; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/F8Functions.java b/core/src/main/java/fj/F8Functions.java index 5eafe1f3..071cb6bc 100644 --- a/core/src/main/java/fj/F8Functions.java +++ b/core/src/main/java/fj/F8Functions.java @@ -1,8 +1,5 @@ package fj; -import fj.data.Validation; -import fj.function.Try8; - /** * Created by MarkPerry on 6/04/2014. */ diff --git a/core/src/main/java/fj/TryEffect.java b/core/src/main/java/fj/TryEffect.java index 90acaf06..cd1f75ab 100644 --- a/core/src/main/java/fj/TryEffect.java +++ b/core/src/main/java/fj/TryEffect.java @@ -1,12 +1,8 @@ package fj; -import fj.data.IO; -import fj.data.IOFunctions; import fj.data.Validation; import fj.function.*; -import java.io.IOException; - /** * Created by mperry on 29/08/2014. */ diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index cc143f33..14edff71 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -1,7 +1,7 @@ package fj.data; import fj.F; -import fj.F2; + import static fj.Function.*; import static fj.data.Option.none; import static fj.data.Option.some; diff --git a/core/src/main/java/fj/data/IterableW.java b/core/src/main/java/fj/data/IterableW.java index 9c701a98..9e36e710 100644 --- a/core/src/main/java/fj/data/IterableW.java +++ b/core/src/main/java/fj/data/IterableW.java @@ -5,8 +5,6 @@ import fj.Equal; import fj.F; import fj.F2; -import fj.F3; -import fj.P1; import fj.P2; import static fj.Function.curry; import static fj.Function.identity; diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index 7b413293..5912ec1b 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -5,7 +5,6 @@ import fj.F1Functions; import fj.Function; import fj.P; -import fj.P1; import fj.P2; import fj.Unit; diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 29c5714c..e2f9adfd 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -4,9 +4,6 @@ import static fj.P.p; -import fj.function.Effect1; - -import static fj.data.List.list; import static fj.data.Option.some; import java.util.Arrays; diff --git a/core/src/main/java/fj/data/Natural.java b/core/src/main/java/fj/data/Natural.java index 25cd11d5..396aa39c 100644 --- a/core/src/main/java/fj/data/Natural.java +++ b/core/src/main/java/fj/data/Natural.java @@ -2,7 +2,7 @@ import static fj.Bottom.error; import fj.F; -import fj.F2; + import static fj.Monoid.naturalAdditionMonoid; import static fj.Monoid.naturalMultiplicationMonoid; import static fj.Function.curry; diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index 13bbbcc5..ef4c608c 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -1,7 +1,5 @@ package fj.data; -import java.io.IOException; - /** * Created by MarkPerry on 3/07/2014. */ diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 2d87234f..81146f95 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -2,8 +2,6 @@ import fj.*; -import java.util.*; - import static fj.P.p; /** diff --git a/core/src/main/java/fj/data/fingertrees/Empty.java b/core/src/main/java/fj/data/fingertrees/Empty.java index 17ea5927..9f2b9bd2 100644 --- a/core/src/main/java/fj/data/fingertrees/Empty.java +++ b/core/src/main/java/fj/data/fingertrees/Empty.java @@ -1,7 +1,6 @@ package fj.data.fingertrees; import fj.F; -import fj.P; import fj.P2; import fj.P3; diff --git a/core/src/main/java/fj/data/fingertrees/Node.java b/core/src/main/java/fj/data/fingertrees/Node.java index 3e451766..d107c8d4 100644 --- a/core/src/main/java/fj/data/fingertrees/Node.java +++ b/core/src/main/java/fj/data/fingertrees/Node.java @@ -1,7 +1,6 @@ package fj.data.fingertrees; import fj.F; -import fj.F2; import fj.P2; import fj.P3; import fj.data.Option; diff --git a/core/src/main/java/fj/data/hlist/HPre.java b/core/src/main/java/fj/data/hlist/HPre.java index a37c3b78..6a2556de 100644 --- a/core/src/main/java/fj/data/hlist/HPre.java +++ b/core/src/main/java/fj/data/hlist/HPre.java @@ -1,6 +1,5 @@ package fj.data.hlist; -import fj.F; import fj.Show; /** diff --git a/core/src/main/java/fj/data/vector/V.java b/core/src/main/java/fj/data/vector/V.java index 84481d96..26a86462 100644 --- a/core/src/main/java/fj/data/vector/V.java +++ b/core/src/main/java/fj/data/vector/V.java @@ -7,7 +7,6 @@ import fj.F5; import fj.P; import fj.P1; -import fj.P2; /** * Functions across vectors. diff --git a/core/src/main/java/fj/function/BigIntegers.java b/core/src/main/java/fj/function/BigIntegers.java index b60d29f4..97f1a520 100644 --- a/core/src/main/java/fj/function/BigIntegers.java +++ b/core/src/main/java/fj/function/BigIntegers.java @@ -1,7 +1,6 @@ package fj.function; import fj.F; -import fj.F2; import fj.Monoid; import fj.data.List; import static fj.Function.curry; diff --git a/core/src/main/java/fj/function/Characters.java b/core/src/main/java/fj/function/Characters.java index 8aebde7b..9191bd5a 100644 --- a/core/src/main/java/fj/function/Characters.java +++ b/core/src/main/java/fj/function/Characters.java @@ -1,7 +1,6 @@ package fj.function; import fj.F; -import fj.F2; import static fj.Function.curry; diff --git a/core/src/main/java/fj/function/Doubles.java b/core/src/main/java/fj/function/Doubles.java index a15a4042..1a85a100 100644 --- a/core/src/main/java/fj/function/Doubles.java +++ b/core/src/main/java/fj/function/Doubles.java @@ -1,7 +1,6 @@ package fj.function; import fj.F; -import fj.F2; import fj.Monoid; import fj.data.List; import fj.data.Option; diff --git a/core/src/main/java/fj/function/Integers.java b/core/src/main/java/fj/function/Integers.java index 10fd3b15..c51359e4 100644 --- a/core/src/main/java/fj/function/Integers.java +++ b/core/src/main/java/fj/function/Integers.java @@ -1,7 +1,7 @@ package fj.function; import fj.F; -import fj.F2; + import static fj.Function.curry; import fj.Monoid; diff --git a/core/src/main/java/fj/function/Longs.java b/core/src/main/java/fj/function/Longs.java index 89c2babd..a1bd60eb 100644 --- a/core/src/main/java/fj/function/Longs.java +++ b/core/src/main/java/fj/function/Longs.java @@ -1,7 +1,7 @@ package fj.function; import fj.F; -import fj.F2; + import static fj.Function.curry; import static fj.Semigroup.longAdditionSemigroup; import static fj.Semigroup.longMultiplicationSemigroup; diff --git a/core/src/main/java/fj/function/Visitor.java b/core/src/main/java/fj/function/Visitor.java index ebd18c03..0f8c3846 100644 --- a/core/src/main/java/fj/function/Visitor.java +++ b/core/src/main/java/fj/function/Visitor.java @@ -3,7 +3,6 @@ import fj.Equal; import fj.F; import fj.F0; -import fj.F2; import fj.Function; import fj.Monoid; import fj.P1; diff --git a/core/src/main/java/fj/parser/Result.java b/core/src/main/java/fj/parser/Result.java index bcec7d8b..f450a054 100644 --- a/core/src/main/java/fj/parser/Result.java +++ b/core/src/main/java/fj/parser/Result.java @@ -1,7 +1,7 @@ package fj.parser; import fj.F; -import fj.F2; + import static fj.Function.curry; import java.util.Iterator; diff --git a/demo/src/main/java/fj/demo/Array_bind.java b/demo/src/main/java/fj/demo/Array_bind.java index a0182dd1..6048ce62 100644 --- a/demo/src/main/java/fj/demo/Array_bind.java +++ b/demo/src/main/java/fj/demo/Array_bind.java @@ -1,6 +1,5 @@ package fj.demo; -import fj.F; import fj.data.Array; import static fj.data.Array.array; import static fj.Show.arrayShow; diff --git a/demo/src/main/java/fj/demo/ChequeWrite.java b/demo/src/main/java/fj/demo/ChequeWrite.java index 44ee2956..d2d07d3d 100644 --- a/demo/src/main/java/fj/demo/ChequeWrite.java +++ b/demo/src/main/java/fj/demo/ChequeWrite.java @@ -1,7 +1,6 @@ package fj.demo; import fj.F; -import fj.F2; import fj.P2; import fj.data.List; import fj.data.Option; diff --git a/demo/src/main/java/fj/demo/Comonad_example.java b/demo/src/main/java/fj/demo/Comonad_example.java index 70230e1d..9a64c34e 100644 --- a/demo/src/main/java/fj/demo/Comonad_example.java +++ b/demo/src/main/java/fj/demo/Comonad_example.java @@ -1,6 +1,5 @@ package fj.demo; -import fj.F; import fj.F1Functions; import fj.P; import static fj.data.List.asString; diff --git a/demo/src/main/java/fj/demo/HList_foldRight.java b/demo/src/main/java/fj/demo/HList_foldRight.java index 4f5ee3e1..51f6f4c2 100644 --- a/demo/src/main/java/fj/demo/HList_foldRight.java +++ b/demo/src/main/java/fj/demo/HList_foldRight.java @@ -4,8 +4,6 @@ import static fj.Function.identity; import fj.P2; import fj.Unit; -import static fj.Unit.unit; -import static java.lang.System.out; import fj.data.hlist.HList; import static fj.data.hlist.HList.single; diff --git a/demo/src/main/java/fj/demo/Primes2.java b/demo/src/main/java/fj/demo/Primes2.java index 4a5b9dbd..96a852f3 100644 --- a/demo/src/main/java/fj/demo/Primes2.java +++ b/demo/src/main/java/fj/demo/Primes2.java @@ -1,7 +1,7 @@ package fj.demo; import fj.F1Functions; -import fj.P1; + import static fj.data.Enumerator.naturalEnumerator; import fj.Show; diff --git a/demo/src/main/java/fj/demo/Set_map.java b/demo/src/main/java/fj/demo/Set_map.java index ff5428df..054fbc15 100644 --- a/demo/src/main/java/fj/demo/Set_map.java +++ b/demo/src/main/java/fj/demo/Set_map.java @@ -1,6 +1,5 @@ package fj.demo; -import fj.F; import fj.data.Set; import static fj.data.Set.empty; import fj.Ord; diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index 3178e37b..167a08f5 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -1,6 +1,5 @@ package fj.demo; -import fj.F2; import fj.data.List; import fj.data.State; diff --git a/demo/src/main/java/fj/demo/concurrent/Fibs.java b/demo/src/main/java/fj/demo/concurrent/Fibs.java index b3aae799..5e95e597 100644 --- a/demo/src/main/java/fj/demo/concurrent/Fibs.java +++ b/demo/src/main/java/fj/demo/concurrent/Fibs.java @@ -1,7 +1,7 @@ package fj.demo.concurrent; import static fj.Bottom.error; -import fj.Effect; + import fj.F; import fj.P; import fj.P2; diff --git a/demo/src/main/java/fj/demo/concurrent/Ping.java b/demo/src/main/java/fj/demo/concurrent/Ping.java index 82aad6b3..3ba934fb 100644 --- a/demo/src/main/java/fj/demo/concurrent/Ping.java +++ b/demo/src/main/java/fj/demo/concurrent/Ping.java @@ -1,6 +1,5 @@ package fj.demo.concurrent; -import fj.Effect; import fj.Unit; import fj.P1; import fj.control.parallel.Actor; diff --git a/demo/src/main/java/fj/demo/concurrent/PingPong.java b/demo/src/main/java/fj/demo/concurrent/PingPong.java index d6bddbbf..b0b09011 100644 --- a/demo/src/main/java/fj/demo/concurrent/PingPong.java +++ b/demo/src/main/java/fj/demo/concurrent/PingPong.java @@ -2,7 +2,6 @@ import static fj.Bottom.error; import fj.Unit; -import fj.Effect; import fj.control.parallel.Strategy; import fj.control.parallel.Actor; import fj.function.Effect1; diff --git a/demo/src/main/java/fj/demo/concurrent/Pong.java b/demo/src/main/java/fj/demo/concurrent/Pong.java index d85eda7e..b0f0ad57 100644 --- a/demo/src/main/java/fj/demo/concurrent/Pong.java +++ b/demo/src/main/java/fj/demo/concurrent/Pong.java @@ -1,6 +1,5 @@ package fj.demo.concurrent; -import fj.Effect; import fj.Unit; import fj.P1; import fj.control.parallel.Actor; diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index 67fef136..b4d3dae2 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -19,7 +19,6 @@ import java.util.concurrent.ExecutorService; import fj.F; -import fj.F2; import fj.Monoid; import fj.P; import fj.P1; diff --git a/demo/src/main/java/fj/demo/euler/Problem1.java b/demo/src/main/java/fj/demo/euler/Problem1.java index 82dc53c0..e20f9a97 100644 --- a/demo/src/main/java/fj/demo/euler/Problem1.java +++ b/demo/src/main/java/fj/demo/euler/Problem1.java @@ -1,6 +1,5 @@ package fj.demo.euler; -import fj.F; import fj.data.Stream; import static fj.data.List.range; diff --git a/demo/src/main/java/fj/demo/euler/Problem3.java b/demo/src/main/java/fj/demo/euler/Problem3.java index bde87126..e429e0e9 100644 --- a/demo/src/main/java/fj/demo/euler/Problem3.java +++ b/demo/src/main/java/fj/demo/euler/Problem3.java @@ -1,7 +1,5 @@ package fj.demo.euler; -import fj.F; -import fj.P; import fj.P1; import static fj.data.Enumerator.naturalEnumerator; import fj.data.Natural; diff --git a/demo/src/main/java/fj/demo/euler/Problem4.java b/demo/src/main/java/fj/demo/euler/Problem4.java index f1947057..60c04d85 100644 --- a/demo/src/main/java/fj/demo/euler/Problem4.java +++ b/demo/src/main/java/fj/demo/euler/Problem4.java @@ -1,6 +1,5 @@ package fj.demo.euler; -import fj.F; import static fj.Function.flip; import fj.data.Stream; import static fj.data.Stream.iterate; diff --git a/demo/src/main/java/fj/demo/test/AdditionCommutes.java b/demo/src/main/java/fj/demo/test/AdditionCommutes.java index 8aea4f03..7b2a6571 100644 --- a/demo/src/main/java/fj/demo/test/AdditionCommutes.java +++ b/demo/src/main/java/fj/demo/test/AdditionCommutes.java @@ -1,6 +1,5 @@ package fj.demo.test; -import fj.F2; import static fj.test.Arbitrary.arbInteger; import static fj.test.CheckResult.summary; import fj.test.Property; diff --git a/demo/src/main/java/fj/demo/test/AdditionCommutesParallel.java b/demo/src/main/java/fj/demo/test/AdditionCommutesParallel.java index b1629c21..d61ffeb0 100644 --- a/demo/src/main/java/fj/demo/test/AdditionCommutesParallel.java +++ b/demo/src/main/java/fj/demo/test/AdditionCommutesParallel.java @@ -1,8 +1,6 @@ package fj.demo.test; -import fj.F2; import fj.P; -import fj.P1; import fj.control.parallel.Strategy; import static fj.test.Arbitrary.arbInteger; import static fj.test.CheckResult.summary; diff --git a/demo/src/main/java/fj/demo/test/EqualsHashCode.java b/demo/src/main/java/fj/demo/test/EqualsHashCode.java index 20a732a2..814f7112 100644 --- a/demo/src/main/java/fj/demo/test/EqualsHashCode.java +++ b/demo/src/main/java/fj/demo/test/EqualsHashCode.java @@ -1,8 +1,5 @@ package fj.demo.test; -import fj.F; -import fj.F2; -import fj.F3; import static fj.Function.curry; import fj.test.Arbitrary; import static fj.test.Arbitrary.arbByte; diff --git a/demo/src/main/java/fj/demo/test/IntegerOverflow.java b/demo/src/main/java/fj/demo/test/IntegerOverflow.java index 155f8495..48b9d2dc 100644 --- a/demo/src/main/java/fj/demo/test/IntegerOverflow.java +++ b/demo/src/main/java/fj/demo/test/IntegerOverflow.java @@ -1,6 +1,5 @@ package fj.demo.test; -import fj.F2; import static fj.test.Arbitrary.arbIntegerBoundaries; import static fj.test.Bool.bool; import static fj.test.CheckResult.summary; diff --git a/demo/src/main/java/fj/demo/test/JavaLinkedList.java b/demo/src/main/java/fj/demo/test/JavaLinkedList.java index 0954c705..5ce11fba 100644 --- a/demo/src/main/java/fj/demo/test/JavaLinkedList.java +++ b/demo/src/main/java/fj/demo/test/JavaLinkedList.java @@ -1,6 +1,5 @@ package fj.demo.test; -import fj.F2; import static fj.test.Arbitrary.arbInteger; import static fj.test.Arbitrary.arbLinkedList; import static fj.test.CheckResult.summary; diff --git a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java index e0c99f64..03095e80 100644 --- a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java +++ b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java @@ -1,7 +1,5 @@ package fj.demo.test; -import fj.F; -import fj.F3; import fj.Function; import static fj.Function.compose; import fj.P2; diff --git a/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java b/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java index 675c8eff..18d1b5d7 100644 --- a/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java +++ b/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java @@ -1,7 +1,5 @@ package fj.demo.test; -import fj.F; -import fj.F2; import static fj.Function.andThen; import fj.data.Option; import static fj.Equal.optionEqual; diff --git a/demo/src/main/java/fj/demo/test/Reflect.java b/demo/src/main/java/fj/demo/test/Reflect.java index 79d013dc..d5ebfd36 100644 --- a/demo/src/main/java/fj/demo/test/Reflect.java +++ b/demo/src/main/java/fj/demo/test/Reflect.java @@ -2,8 +2,6 @@ import static fj.Bottom.error; -import fj.F; -import fj.F2; import fj.P2; import fj.data.List; import static fj.data.List.list; diff --git a/demo/src/main/java/fj/demo/test/StringBuilderReverse.java b/demo/src/main/java/fj/demo/test/StringBuilderReverse.java index 9338065b..b0897044 100644 --- a/demo/src/main/java/fj/demo/test/StringBuilderReverse.java +++ b/demo/src/main/java/fj/demo/test/StringBuilderReverse.java @@ -1,7 +1,5 @@ package fj.demo.test; -import fj.F; -import fj.F2; import static fj.data.List.list; import static fj.Equal.stringBuilderEqual; import static fj.test.Arbitrary.arbCharacter; diff --git a/demo/src/main/java/fj/demo/test/Triangulation.java b/demo/src/main/java/fj/demo/test/Triangulation.java index 56d110f2..10de64ea 100644 --- a/demo/src/main/java/fj/demo/test/Triangulation.java +++ b/demo/src/main/java/fj/demo/test/Triangulation.java @@ -1,6 +1,5 @@ package fj.demo.test; -import fj.F; import static fj.test.Arbitrary.arbInteger; import static fj.test.CheckResult.summary; import fj.test.Property; diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 5222df9e..1e619f21 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -69,7 +69,6 @@ import java.util.PriorityQueue; import java.util.Properties; import java.util.Stack; -import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; import java.util.WeakHashMap; diff --git a/quickcheck/src/main/java/fj/test/Bool.java b/quickcheck/src/main/java/fj/test/Bool.java index deb072cf..18239fa6 100644 --- a/quickcheck/src/main/java/fj/test/Bool.java +++ b/quickcheck/src/main/java/fj/test/Bool.java @@ -1,7 +1,7 @@ package fj.test; import fj.F0; -import fj.P1; + import static fj.test.Property.prop; /** diff --git a/quickcheck/src/main/java/fj/test/Result.java b/quickcheck/src/main/java/fj/test/Result.java index eb6b973b..40130542 100644 --- a/quickcheck/src/main/java/fj/test/Result.java +++ b/quickcheck/src/main/java/fj/test/Result.java @@ -1,7 +1,6 @@ package fj.test; import fj.F; -import fj.P1; import fj.data.List; import fj.data.Option; import static fj.data.Option.none; diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index 079dcb22..5b7dbbb3 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -1,6 +1,5 @@ package fj.test.reflect; -import static fj.Bottom.error; import fj.Class; import static fj.Class.clas; import fj.F; diff --git a/quickcheck/src/main/java/fj/test/reflect/CheckParams.java b/quickcheck/src/main/java/fj/test/reflect/CheckParams.java index 725a7504..8c8445c1 100644 --- a/quickcheck/src/main/java/fj/test/reflect/CheckParams.java +++ b/quickcheck/src/main/java/fj/test/reflect/CheckParams.java @@ -1,6 +1,5 @@ package fj.test.reflect; -import fj.P1; import fj.test.Property; import java.lang.annotation.Documented; From 316d1d48768ed6c6730843393f799451c7e5cd68 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 22:29:38 +0100 Subject: [PATCH 043/336] Use method reference (over lambda) whenever possible --- core/src/main/java/fj/Bottom.java | 4 +- core/src/main/java/fj/Class.java | 2 +- core/src/main/java/fj/Digit.java | 8 +- core/src/main/java/fj/Effect.java | 2 +- core/src/main/java/fj/Equal.java | 4 +- core/src/main/java/fj/Function.java | 24 +-- core/src/main/java/fj/Hash.java | 2 +- core/src/main/java/fj/Monoid.java | 6 +- core/src/main/java/fj/Ord.java | 6 +- core/src/main/java/fj/P.java | 2 +- core/src/main/java/fj/P1.java | 16 +- core/src/main/java/fj/P2.java | 14 +- core/src/main/java/fj/P3.java | 6 +- core/src/main/java/fj/P4.java | 8 +- core/src/main/java/fj/P5.java | 10 +- core/src/main/java/fj/P6.java | 36 +--- core/src/main/java/fj/P7.java | 42 +--- core/src/main/java/fj/P8.java | 48 +---- core/src/main/java/fj/Semigroup.java | 20 +- core/src/main/java/fj/Show.java | 2 +- core/src/main/java/fj/control/Trampoline.java | 10 +- .../java/fj/control/parallel/Callables.java | 16 +- .../java/fj/control/parallel/ParModule.java | 18 +- .../java/fj/control/parallel/Promise.java | 2 +- .../java/fj/control/parallel/Strategy.java | 6 +- core/src/main/java/fj/data/Array.java | 6 +- core/src/main/java/fj/data/Conversions.java | 70 +++---- core/src/main/java/fj/data/Either.java | 26 +-- core/src/main/java/fj/data/Enumerator.java | 2 +- core/src/main/java/fj/data/HashMap.java | 2 +- core/src/main/java/fj/data/IOFunctions.java | 21 +- core/src/main/java/fj/data/IterableW.java | 10 +- core/src/main/java/fj/data/Java.java | 40 ++-- core/src/main/java/fj/data/List.java | 26 +-- core/src/main/java/fj/data/Natural.java | 12 +- core/src/main/java/fj/data/NonEmptyList.java | 6 +- core/src/main/java/fj/data/Option.java | 36 ++-- core/src/main/java/fj/data/Set.java | 8 +- core/src/main/java/fj/data/State.java | 6 +- core/src/main/java/fj/data/Stream.java | 42 ++-- core/src/main/java/fj/data/Tree.java | 10 +- core/src/main/java/fj/data/TreeMap.java | 6 +- core/src/main/java/fj/data/TreeZipper.java | 12 +- core/src/main/java/fj/data/Validation.java | 36 ++-- core/src/main/java/fj/data/Zipper.java | 8 +- .../main/java/fj/data/fingertrees/Digit.java | 4 +- .../java/fj/data/fingertrees/Measured.java | 4 +- .../main/java/fj/data/optic/POptional.java | 2 +- core/src/main/java/fj/data/optic/PPrism.java | 2 +- core/src/main/java/fj/data/vector/V.java | 10 +- core/src/main/java/fj/data/vector/V2.java | 10 +- core/src/main/java/fj/data/vector/V3.java | 14 +- core/src/main/java/fj/data/vector/V4.java | 16 +- core/src/main/java/fj/data/vector/V5.java | 18 +- core/src/main/java/fj/data/vector/V6.java | 20 +- core/src/main/java/fj/data/vector/V7.java | 22 +-- core/src/main/java/fj/data/vector/V8.java | 24 +-- .../main/java/fj/function/BigIntegers.java | 15 +- .../src/main/java/fj/function/Characters.java | 46 ++--- core/src/main/java/fj/function/Doubles.java | 4 +- core/src/main/java/fj/function/Integers.java | 2 +- core/src/main/java/fj/function/Longs.java | 2 +- core/src/main/java/fj/function/Strings.java | 8 +- core/src/main/java/fj/parser/Parser.java | 38 ++-- core/src/main/java/fj/parser/Result.java | 8 +- demo/src/main/java/fj/demo/IODemo.java | 2 +- .../java/fj/demo/concurrent/WordCount.java | 2 +- .../main/java/fj/demo/realworld/Chapter7.java | 4 +- .../java/fj/demo/test/EqualsHashCode.java | 2 +- java8/src/main/java/fj/data/Java8.java | 16 +- .../src/main/java/fj/test/Arbitrary.java | 184 ++++-------------- quickcheck/src/main/java/fj/test/Gen.java | 18 +- .../src/main/java/fj/test/Property.java | 6 +- quickcheck/src/main/java/fj/test/Result.java | 2 +- quickcheck/src/main/java/fj/test/Shrink.java | 30 +-- .../src/main/java/fj/test/reflect/Check.java | 6 +- 76 files changed, 514 insertions(+), 726 deletions(-) diff --git a/core/src/main/java/fj/Bottom.java b/core/src/main/java/fj/Bottom.java index 0f828102..a70629f1 100644 --- a/core/src/main/java/fj/Bottom.java +++ b/core/src/main/java/fj/Bottom.java @@ -83,7 +83,7 @@ public static Error decons(final java.lang.Class c) { * @return A function that returns the toString for a throwable. */ public static F eToString() { - return t -> t.toString(); + return Throwable::toString; } /** @@ -92,6 +92,6 @@ public static F eToString() { * @return A function that returns the getMessage for a throwable. */ public static F eMessage() { - return t -> t.getMessage(); + return Throwable::getMessage; } } diff --git a/core/src/main/java/fj/Class.java b/core/src/main/java/fj/Class.java index da214af1..d34aedb7 100644 --- a/core/src/main/java/fj/Class.java +++ b/core/src/main/java/fj/Class.java @@ -45,7 +45,7 @@ public java.lang.Class _2() { }; return some(p); } - }, c).map(c1 -> clas(c1)); + }, c).map(Class::clas); } /** diff --git a/core/src/main/java/fj/Digit.java b/core/src/main/java/fj/Digit.java index ba3c2245..7213e278 100644 --- a/core/src/main/java/fj/Digit.java +++ b/core/src/main/java/fj/Digit.java @@ -176,20 +176,20 @@ public static Option fromChar(final char c) { /** * First-class conversion from digit to a long. */ - public static final F toLong = d -> d.toLong(); + public static final F toLong = Digit::toLong; /** * First-class conversion from a long to a digit. */ - public static final F fromLong = i -> fromLong(i); + public static final F fromLong = Digit::fromLong; /** * First-class conversion from a digit to a character. */ - public static final F toChar = d -> d.toChar(); + public static final F toChar = Digit::toChar; /** * First-class conversion from a character to a digit. */ - public static final F> fromChar = c -> fromChar(c); + public static final F> fromChar = Digit::fromChar; } diff --git a/core/src/main/java/fj/Effect.java b/core/src/main/java/fj/Effect.java index 6e5e7b7f..80680cac 100644 --- a/core/src/main/java/fj/Effect.java +++ b/core/src/main/java/fj/Effect.java @@ -100,7 +100,7 @@ public static Effect1 contramap(Effect1 e1, final F f) { } public static Effect1 lazy(final F f) { - return a -> f.f(a); + return f::f; } diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 27973afc..f503d096 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -55,7 +55,7 @@ public boolean notEq(final A a1, final A a2) { * @return A function that returns true if the two given arguments are equal. */ public F2 eq() { - return (a, a1) -> eq(a, a1); + return this::eq; } /** @@ -96,7 +96,7 @@ public static Equal equal(final F> f) { * equality. */ public static Equal anyEqual() { - return equal(a1 -> a2 -> a1.equals(a2)); + return equal(a1 -> a1::equals); } /** diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index b3b96870..8d832798 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -89,7 +89,7 @@ public static F identity() { * @return A function that given an argument, returns a function that ignores its argument. */ public static F> constant() { - return b -> constant(b); + return Function::constant; } /** @@ -109,7 +109,7 @@ public static F constant(final B b) { * @return A co- and contravariant function that invokes f on its argument. */ public static F vary(final F f) { - return a -> f.f(a); + return f::f; } /** @@ -118,7 +118,7 @@ public static F vary(final F f) { * @return A function that varies and covaries a function. */ public static F, F> vary() { - return f -> Function.vary(f); + return Function::vary; } /** @@ -127,7 +127,7 @@ public static F, F> vary() { * @return A function that takes a function and flips its arguments. */ public static F>, F>> flip() { - return f -> flip(f); + return Function::flip; } /** @@ -156,7 +156,7 @@ public static F2 flip(final F2 f) { * @return A function that flips the arguments of a given function. */ public static F, F2> flip2() { - return f -> flip(f); + return Function::flip; } /** @@ -198,7 +198,7 @@ public static F curry(final F2 f, final A a) { * @return An uncurried function. */ public static F>, F2> uncurryF2() { - return f -> uncurryF2(f); + return Function::uncurryF2; } /** @@ -250,7 +250,7 @@ public static F curry(final F3 f, final A a, fina * @return An uncurried function. */ public static F>>, F3> uncurryF3() { - return f -> uncurryF3(f); + return Function::uncurryF3; } /** @@ -315,7 +315,7 @@ public static F curry(final F4 f, final A a * @return An uncurried function. */ public static F>>>, F4> uncurryF4() { - return f -> uncurryF4(f); + return Function::uncurryF4; } /** @@ -396,7 +396,7 @@ public static F4 uncurryF4(final F F>>>>, F5> uncurryF5() { - return f -> uncurryF5(f); + return Function::uncurryF5; } /** @@ -425,7 +425,7 @@ public static F4 uncurryF4(final F F>>>>>, F6> uncurryF6() { - return f -> uncurryF6(f); + return Function::uncurryF6; } /** @@ -543,7 +543,7 @@ public static F4 uncurryF4(final F F>>>>>>, F7> uncurryF7() { - return f -> uncurryF7(f); + return Function::uncurryF7; } /** @@ -682,7 +682,7 @@ public static F4 uncurryF4(final F F>>>>>>>, F8> uncurryF8() { - return f -> uncurryF8(f); + return Function::uncurryF8; } /** diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 61c5e1cd..acb2a62c 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -62,7 +62,7 @@ public static Hash hash(final F f) { * @return A hash that uses {@link Object#hashCode()}. */ public static Hash anyHash() { - return hash(a -> a.hashCode()); + return hash(Object::hashCode); } /** diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index a85a4712..be5215bb 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -156,7 +156,7 @@ public A sumLeft(final Stream as) { * @return a function that sums the given values with left-fold. */ public F, A> sumLeft() { - return as -> sumLeft(as); + return this::sumLeft; } /** @@ -165,7 +165,7 @@ public F, A> sumLeft() { * @return a function that sums the given values with right-fold. */ public F, A> sumRight() { - return as -> sumRight(as); + return this::sumRight; } /** @@ -174,7 +174,7 @@ public F, A> sumRight() { * @return a function that sums the given values with left-fold. */ public F, A> sumLeftS() { - return as -> sumLeft(as); + return this::sumLeft; } /** diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 780f5edf..57d7e389 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -150,12 +150,12 @@ public A min(final A a1, final A a2) { /** * A function that returns the greater of its two arguments. */ - public final F> max = curry((a, a1) -> max(a, a1)); + public final F> max = curry(this::max); /** * A function that returns the lesser of its two arguments. */ - public final F> min = curry((a, a1) -> min(a, a1)); + public final F> min = curry(this::min); public Ord reverse() { return ord(Function.flip(f)); } @@ -428,7 +428,7 @@ public static Ord> arrayOrd(final Ord oa) { * @return An order instance for the {@link Set} type. */ public static Ord> setOrd(final Ord oa) { - return streamOrd(oa).contramap(as -> as.toStream()); + return streamOrd(oa).contramap(Set::toStream); } /** diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index 2826b6b0..1ff82475 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -18,7 +18,7 @@ private P() { * @return A function that puts an element in a product-1. */ public static F> p1() { - return a -> p(a); + return P::p; } /** diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 0cb92a89..796daf22 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -33,7 +33,7 @@ public final A f() { * @return A function that returns the first element of a product. */ public static F, A> __1() { - return p -> p._1(); + return P1::_1; } /** @@ -147,7 +147,7 @@ public static P1> sequence(final List> as) { * @return A function from a List of P1s to a single P1 of a List. */ public static F>, P1>> sequenceList() { - return as -> sequence(as); + return P1::sequence; } /** @@ -164,7 +164,7 @@ public static P1> sequence(final Stream> as) { * Turns an optional P1 into a lazy option. */ public static P1> sequence(final Option> o) { - return P.lazy(() -> o.map(p -> p._1())); + return P.lazy(() -> o.map(P1::_1)); } /** @@ -184,7 +184,7 @@ public static P1> sequence(final Array> as) { * @return A List of P1 */ public List> traverseList(final F> f){ - return f.f(_1()).map(b -> P.p(b)); + return f.f(_1()).map(P::p); } /** @@ -194,7 +194,7 @@ public List> traverseList(final F> f){ * @return An Either of P1 */ public Either> traverseEither(final F> f){ - return f.f(_1()).right().map(b -> P.p(b)); + return f.f(_1()).right().map(P::p); } /** @@ -204,7 +204,7 @@ public Either> traverseEither(final F> f){ * @return An Option of P1 */ public Option> traverseOption(final F> f){ - return f.f(_1()).map(b -> P.p(b)); + return f.f(_1()).map(P::p); } /** @@ -214,7 +214,7 @@ public Option> traverseOption(final F> f){ * @return An Validation of P1 */ public Validation> traverseValidation(final F> f){ - return f.f(_1()).map(b -> P.p(b)); + return f.f(_1()).map(P::p); } /** @@ -224,7 +224,7 @@ public Validation> traverseValidation(final F */ public Stream> traverseStream(final F> f){ - return f.f(_1()).map(b -> P.p(b)); + return f.f(_1()).map(P::p); } /** diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index 3283f344..d564df35 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -42,7 +42,7 @@ public int hashCode() { * @return A new product-2 with the elements swapped. */ public final P2 swap() { - return P.lazy(() -> P2.this._2(), () -> P2.this._1()); + return P.lazy(P2.this::_2, P2.this::_1); } /** @@ -53,7 +53,7 @@ public final P2 swap() { */ public final P2 map1(final F f) { P2 self = this; - return P.lazy(() -> f.f(self._1()), () -> self._2()); + return P.lazy(() -> f.f(self._1()), self::_2); } /** @@ -63,7 +63,7 @@ public final P2 map1(final F f) { * @return A product with the given function applied. */ public final P2 map2(final F f) { - return P.lazy(() -> P2.this._1(), () -> f.f(P2.this._2())); + return P.lazy(P2.this::_1, () -> f.f(P2.this._2())); } @@ -90,7 +90,7 @@ public final P2 split(final F f, final F g) { */ public final P2 cobind(final F, C> k) { P2 self = this; - return P.lazy(() -> k.f(self), () -> self._2()); + return P.lazy(() -> k.f(self), self::_2); } /** @@ -258,7 +258,7 @@ public static P2 map(final F f, final P2 p) { * @return A curried form of {@link #swap()}. */ public static F, P2> swap_() { - return p -> p.swap(); + return P2::swap; } /** @@ -267,7 +267,7 @@ public static F, P2> swap_() { * @return A function that returns the first element of a product. */ public static F, A> __1() { - return p -> p._1(); + return P2::_1; } /** @@ -276,7 +276,7 @@ public static F, A> __1() { * @return A function that returns the second element of a product. */ public static F, B> __2() { - return p -> p._2(); + return P2::_2; } /** diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index 9f473f56..8760562b 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -152,7 +152,7 @@ public C _3() { * @return A function that returns the first element of a product. */ public static F, A> __1() { - return p -> p._1(); + return P3::_1; } /** @@ -161,7 +161,7 @@ public static F, A> __1() { * @return A function that returns the second element of a product. */ public static F, B> __2() { - return p -> p._2(); + return P3::_2; } /** @@ -170,7 +170,7 @@ public static F, B> __2() { * @return A function that returns the third element of a product. */ public static F, C> __3() { - return p -> p._3(); + return P3::_3; } @Override diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index 7ba55b5d..7f71943e 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -212,7 +212,7 @@ public D _4() { * @return A function that returns the first element of a product. */ public static F, A> __1() { - return p -> p._1(); + return P4::_1; } /** @@ -221,7 +221,7 @@ public static F, A> __1() { * @return A function that returns the second element of a product. */ public static F, B> __2() { - return p -> p._2(); + return P4::_2; } /** @@ -230,7 +230,7 @@ public static F, B> __2() { * @return A function that returns the third element of a product. */ public static F, C> __3() { - return p -> p._3(); + return P4::_3; } /** @@ -239,7 +239,7 @@ public static F, C> __3() { * @return A function that returns the fourth element of a product. */ public static F, D> __4() { - return p -> p._4(); + return P4::_4; } @Override diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 6059e22a..57199302 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -278,7 +278,7 @@ public E _5() { * @return A function that returns the first element of a product. */ public static F, A> __1() { - return p -> p._1(); + return P5::_1; } /** @@ -287,7 +287,7 @@ public static F, A> __1() { * @return A function that returns the second element of a product. */ public static F, B> __2() { - return p -> p._2(); + return P5::_2; } /** @@ -296,7 +296,7 @@ public static F, B> __2() { * @return A function that returns the third element of a product. */ public static F, C> __3() { - return p -> p._3(); + return P5::_3; } /** @@ -305,7 +305,7 @@ public static F, C> __3() { * @return A function that returns the fourth element of a product. */ public static F, D> __4() { - return p -> p._4(); + return P5::_4; } /** @@ -314,7 +314,7 @@ public static F, D> __4() { * @return A function that returns the fifth element of a product. */ public static F, E> __5() { - return p -> p._5(); + return P5::_5; } @Override diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index c2983298..d1f32b87 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -355,11 +355,7 @@ public F _6() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return new fj.F, A>() { - public A f(final P6 p) { - return p._1(); - } - }; + return P6::_1; } /** @@ -368,11 +364,7 @@ public A f(final P6 p) { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return new fj.F, B>() { - public B f(final P6 p) { - return p._2(); - } - }; + return P6::_2; } /** @@ -381,11 +373,7 @@ public B f(final P6 p) { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return new fj.F, C>() { - public C f(final P6 p) { - return p._3(); - } - }; + return P6::_3; } /** @@ -394,11 +382,7 @@ public C f(final P6 p) { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return new fj.F, D>() { - public D f(final P6 p) { - return p._4(); - } - }; + return P6::_4; } /** @@ -407,11 +391,7 @@ public D f(final P6 p) { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return new fj.F, E>() { - public E f(final P6 p) { - return p._5(); - } - }; + return P6::_5; } /** @@ -420,11 +400,7 @@ public E f(final P6 p) { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return new fj.F, F$>() { - public F$ f(final P6 p) { - return p._6(); - } - }; + return P6::_6; } @Override diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index 478e3d87..e81a2480 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -437,11 +437,7 @@ public G _7() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return new fj.F, A>() { - public A f(final P7 p) { - return p._1(); - } - }; + return P7::_1; } /** @@ -450,11 +446,7 @@ public A f(final P7 p) { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return new fj.F, B>() { - public B f(final P7 p) { - return p._2(); - } - }; + return P7::_2; } /** @@ -463,11 +455,7 @@ public B f(final P7 p) { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return new fj.F, C>() { - public C f(final P7 p) { - return p._3(); - } - }; + return P7::_3; } /** @@ -476,11 +464,7 @@ public C f(final P7 p) { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return new fj.F, D>() { - public D f(final P7 p) { - return p._4(); - } - }; + return P7::_4; } /** @@ -489,11 +473,7 @@ public D f(final P7 p) { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return new fj.F, E>() { - public E f(final P7 p) { - return p._5(); - } - }; + return P7::_5; } /** @@ -502,11 +482,7 @@ public E f(final P7 p) { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return new fj.F, F$>() { - public F$ f(final P7 p) { - return p._6(); - } - }; + return P7::_6; } /** @@ -515,11 +491,7 @@ public E f(final P7 p) { * @return A function that returns the seventh element of a product. */ public static fj.F, G> __7() { - return new fj.F, G>() { - public G f(final P7 p) { - return p._7(); - } - }; + return P7::_7; } @Override diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index 62fef46e..982dca58 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -530,11 +530,7 @@ public H _8() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return new fj.F, A>() { - public A f(final P8 p) { - return p._1(); - } - }; + return P8::_1; } /** @@ -543,11 +539,7 @@ public A f(final P8 p) { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return new fj.F, B>() { - public B f(final P8 p) { - return p._2(); - } - }; + return P8::_2; } /** @@ -556,11 +548,7 @@ public B f(final P8 p) { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return new fj.F, C>() { - public C f(final P8 p) { - return p._3(); - } - }; + return P8::_3; } /** @@ -569,11 +557,7 @@ public C f(final P8 p) { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return new fj.F, D>() { - public D f(final P8 p) { - return p._4(); - } - }; + return P8::_4; } /** @@ -582,11 +566,7 @@ public D f(final P8 p) { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return new fj.F, E>() { - public E f(final P8 p) { - return p._5(); - } - }; + return P8::_5; } /** @@ -595,11 +575,7 @@ public E f(final P8 p) { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return new fj.F, F$>() { - public F$ f(final P8 p) { - return p._6(); - } - }; + return P8::_6; } /** @@ -608,11 +584,7 @@ public E f(final P8 p) { * @return A function that returns the seventh element of a product. */ public static fj.F, G> __7() { - return new fj.F, G>() { - public G f(final P8 p) { - return p._7(); - } - }; + return P8::_7; } /** @@ -621,11 +593,7 @@ public G f(final P8 p) { * @return A function that returns the eighth element of a product. */ public static fj.F, H> __8() { - return new fj.F, H>() { - public H f(final P8 p) { - return p._8(); - } - }; + return P8::_8; } @Override diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 6e091d7f..e7cd4c35 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -150,13 +150,13 @@ public static Semigroup semigroup(final F2 sum) { * A semigroup that adds big integers. */ public static final Semigroup bigintAdditionSemigroup = - semigroup((i1, i2) -> i1.add(i2)); + semigroup(BigInteger::add); /** * A semigroup that multiplies big integers. */ public static final Semigroup bigintMultiplicationSemigroup = - semigroup((i1, i2) -> i1.multiply(i2)); + semigroup(BigInteger::multiply); /** * A semigroup that yields the maximum of big integers. @@ -172,13 +172,13 @@ public static Semigroup semigroup(final F2 sum) { * A semigroup that adds big decimals. */ public static final Semigroup bigdecimalAdditionSemigroup = - semigroup((i1, i2) -> i1.add(i2)); + semigroup(BigDecimal::add); /** * A semigroup that multiplies big decimals. */ public static final Semigroup bigdecimalMultiplicationSemigroup = - semigroup((i1, i2) -> i1.multiply(i2)); + semigroup(BigDecimal::multiply); /** * A semigroup that yields the maximum of big decimals. @@ -194,13 +194,13 @@ public static Semigroup semigroup(final F2 sum) { * A semigroup that multiplies natural numbers. */ public static final Semigroup naturalMultiplicationSemigroup = - semigroup((n1, n2) -> n1.multiply(n2)); + semigroup(Natural::multiply); /** * A semigroup that multiplies natural numbers. */ public static final Semigroup naturalAdditionSemigroup = - semigroup((n1, n2) -> n1.add(n2)); + semigroup(Natural::add); /** * A semigroup that yields the maximum of natural numbers. @@ -294,7 +294,7 @@ public static Semigroup> functionSemigroup(final Semigroup sb) * @return A semigroup for lists. */ public static Semigroup> listSemigroup() { - return semigroup((a1, a2) -> a1.append(a2)); + return semigroup(List::append); } /** @@ -303,7 +303,7 @@ public static Semigroup> listSemigroup() { * @return A semigroup for non-empty lists. */ public static Semigroup> nonEmptyListSemigroup() { - return semigroup((a1, a2) -> a1.append(a2)); + return semigroup(NonEmptyList::append); } /** @@ -347,7 +347,7 @@ public static Semigroup> streamSemigroup() { * @return A semigroup for arrays. */ public static Semigroup> arraySemigroup() { - return semigroup((a1, a2) -> a1.append(a2)); + return semigroup(Array::append); } /** @@ -389,7 +389,7 @@ public static Semigroup> ioSemigroup(final Semigroup sa) { * @return a semigroup for sets. */ public static Semigroup> setSemigroup() { - return semigroup((a, b) -> a.union(b)); + return semigroup(Set::union); } } diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 7e832c6c..5e6fd8b0 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -79,7 +79,7 @@ public String showS(final A a) { * @return the transformation equivalent to this show. */ public F showS_() { - return a -> showS(a); + return this::showS; } /** diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 49b6bb61..140deeaa 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -57,7 +57,7 @@ public Either>, A> resume() { // WARNING: In JDK 8, update 25 (current version) the following code is a // workaround for an internal JDK compiler error, likely due to // https:bugs.openjdk.java.net/browse/JDK-8062253. - F, Trampoline> f = o -> o.foldNormal(o1 -> cont.f(o1), t -> t._1().bind(cont)); + F, Trampoline> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont)); F, Trampoline> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont)); return ot.fold(f, g); }); @@ -117,7 +117,7 @@ protected static Codense codense(final Normal a, final F F> pure() { - return a -> pure(a); + return Trampoline::pure; } /** @@ -144,7 +144,7 @@ public static Trampoline suspend(final P1> a) { * @return The first-class version of `suspend`. */ public static F>, Trampoline> suspend_() { - return trampolineP1 -> suspend(trampolineP1); + return Trampoline::suspend; } protected abstract R fold(final F, R> n, final F, R> gs); @@ -185,7 +185,7 @@ public static F, F, Trampoline>> map_() { * @return The first-class version of `resume`. */ public static F, Either>, A>> resume_() { - return aTrampoline -> aTrampoline.resume(); + return Trampoline::resume; } /** @@ -221,7 +221,7 @@ public A run() { * @return A new Trampoline after applying the given function through this Trampoline. */ public final Trampoline apply(final Trampoline> lf) { - return lf.bind(f -> map(f)); + return lf.bind(this::map); } /** diff --git a/core/src/main/java/fj/control/parallel/Callables.java b/core/src/main/java/fj/control/parallel/Callables.java index aeb9a312..40c8e746 100644 --- a/core/src/main/java/fj/control/parallel/Callables.java +++ b/core/src/main/java/fj/control/parallel/Callables.java @@ -51,7 +51,7 @@ public static Callable callable(final Exception e) { * @return A function from a value to a Callable that completely preserves that value. */ public static F> callable() { - return a -> callable(a); + return Callables::callable; } /** @@ -72,7 +72,7 @@ public static F> callable(final F f) { * @return A transformation from a function to the equivalent Callable-valued function. */ public static F, F>> arrow() { - return f -> callable(f); + return Callables::callable; } /** @@ -156,7 +156,7 @@ public static Callable> sequence(final List> as) { * @return A function from a List of Callables to a single Callable of a List. */ public static F>, Callable>> sequence_() { - return as -> sequence(as); + return Callables::sequence; } /** @@ -181,7 +181,7 @@ public static P1> option(final Callable a) { * @return a function that turns a Callable into an optional value. */ public static F, P1>> option() { - return a -> option(a); + return Callables::option; } /** @@ -206,7 +206,7 @@ public static P1> either(final Callable a) { * @return a function that turns a Callable into an Either. */ public static F, P1>> either() { - return a -> either(a); + return Callables::either; } /** @@ -233,7 +233,7 @@ public A call() throws Exception { * @return a function that turns an Either into a Callable. */ public static F>, Callable> fromEither() { - return e -> fromEither(e); + return Callables::fromEither; } /** @@ -261,7 +261,7 @@ public A call() throws Exception { * or throws an exception in the case of no value. */ public static F>, Callable> fromOption() { - return o -> fromOption(o); + return Callables::fromOption; } /** @@ -285,7 +285,7 @@ public static Callable normalise(final Callable a) { * @return A function that normalises the given Callable by calling it and wrapping the result in a new Callable. */ public static F, Callable> normalise() { - return a -> normalise(a); + return Callables::normalise; } } diff --git a/core/src/main/java/fj/control/parallel/ParModule.java b/core/src/main/java/fj/control/parallel/ParModule.java index 7d01139a..7e0fdb59 100644 --- a/core/src/main/java/fj/control/parallel/ParModule.java +++ b/core/src/main/java/fj/control/parallel/ParModule.java @@ -56,7 +56,7 @@ public Promise promise(final P1 p) { * @return a function that evaluates a given product concurrently and returns a Promise of the result. */ public F, Promise> promise() { - return ap1 -> promise(ap1); + return this::promise; } /** @@ -77,7 +77,7 @@ public F> promise(final F f) { * @return A higher-order function that takes pure functions to promise-valued functions. */ public F, F>> promisePure() { - return abf -> promise(abf); + return this::promise; } /** @@ -110,7 +110,7 @@ public Actor effect(final Effect1 e) { * @return A function that takes an effect and returns a concurrent effect. */ public F, Actor> effect() { - return effect -> effect(effect); + return this::effect; } /** @@ -129,7 +129,7 @@ public Actor actor(final Effect1 e) { * @return A function that takes an effect and returns an actor that processes messages in some order. */ public F, Actor> actor() { - return effect -> actor(effect); + return this::actor; } /** @@ -148,7 +148,7 @@ public Promise> sequence(final List> ps) { * @return A first-class function that traverses a list inside a promise. */ public F>, Promise>> sequenceList() { - return list -> sequence(list); + return this::sequence; } /** @@ -167,7 +167,7 @@ public Promise> sequence(final Stream> ps) { * @return A first-class function that traverses a stream inside a promise. */ public F>, Promise>> sequenceStream() { - return stream -> sequence(stream); + return this::sequence; } /** @@ -313,7 +313,7 @@ public F, F, Promise>>> parMapIterable() * @return A Promise of a new Array with the given function applied to each element. */ public Promise> parMap(final Array as, final F f) { - return parMap(as.toStream(), f).fmap(stream -> stream.toArray()); + return parMap(as.toStream(), f).fmap(Stream::toArray); } /** @@ -452,7 +452,7 @@ public Promise> parZipWith(final Stream as, final Stream< * @return A Promise of a new array with the results of applying the given function across the two arrays, stepwise. */ public Promise> parZipWith(final Array as, final Array bs, final F> f) { - return parZipWith(as.toStream(), bs.toStream(), f).fmap(stream -> stream.toArray()); + return parZipWith(as.toStream(), bs.toStream(), f).fmap(Stream::toArray); } /** @@ -515,7 +515,7 @@ public Promise parFoldMap(final Stream as, final F map, final public Promise parFoldMap(final Iterable as, final F map, final Monoid reduce, final F, P2, Iterable>> chunking) { return parFoldMap(iterableStream(as), map, reduce, (Stream stream) -> { - final F, Stream> is = iterable -> iterableStream(iterable); + final F, Stream> is = Stream::iterableStream; return chunking.f(stream).map1(is).map2(is); }); } diff --git a/core/src/main/java/fj/control/parallel/Promise.java b/core/src/main/java/fj/control/parallel/Promise.java index 42f9e3c2..fc20f491 100644 --- a/core/src/main/java/fj/control/parallel/Promise.java +++ b/core/src/main/java/fj/control/parallel/Promise.java @@ -190,7 +190,7 @@ public void f(final B b) { * @return A new promise after applying the given promised function to this promise. */ public Promise apply(final Promise> pf) { - return pf.bind(f -> fmap(f)); + return pf.bind(this::fmap); } /** diff --git a/core/src/main/java/fj/control/parallel/Strategy.java b/core/src/main/java/fj/control/parallel/Strategy.java index 28bd6d32..79e698b9 100644 --- a/core/src/main/java/fj/control/parallel/Strategy.java +++ b/core/src/main/java/fj/control/parallel/Strategy.java @@ -168,7 +168,7 @@ public F, P1>> parMapList(final F f) { * @return A function that promotes another function to a parallel function on lists. */ public F, F, P1>>> parMapList() { - return f1 -> parMapList(f1); + return this::parMapList; } /** @@ -196,7 +196,7 @@ public F, P1>> parMapArray(final F f) { * @return A function that promotes another function to a parallel function on arrays. */ public F, F, P1>>> parMapArray() { - return f1 -> parMapArray(f1); + return this::parMapArray; } /** @@ -311,7 +311,7 @@ public F2, Array, P1>> parZipArrayWith(final F2 F, P1> obtain() { - return t -> obtain(t); + return Strategy::obtain; } /** diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index d9231cb8..7890a0c8 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -527,7 +527,7 @@ public Array bind(final Array sb, final F2 f) { * @return A new array after applying the given array of functions through this array. */ public Array apply(final Array> lf) { - return lf.bind(f -> map(a -> f.f(a))); + return lf.bind(f -> map(f::f)); } /** @@ -606,7 +606,7 @@ public static Array single(final A a) { * @return A function that wraps a given array. */ public static F> wrap() { - return as -> array(as); + return Array::array; } /** @@ -635,7 +635,7 @@ public static Array join(final Array> o) { * @return A function that joins a array of arrays using a bind operation. */ public static F>, Array> join() { - return as -> join(as); + return Array::join; } /** diff --git a/core/src/main/java/fj/data/Conversions.java b/core/src/main/java/fj/data/Conversions.java index 055da1dd..35cf68be 100644 --- a/core/src/main/java/fj/data/Conversions.java +++ b/core/src/main/java/fj/data/Conversions.java @@ -36,7 +36,7 @@ private Conversions() { * @return A function that converts lists to arrays. */ public static F, Array> List_Array() { - return as -> as.toArray(); + return List::toArray; } /** @@ -45,7 +45,7 @@ public static F, Array> List_Array() { * @return A function that converts lists to streams. */ public static F, Stream> List_Stream() { - return as -> as.toStream(); + return List::toStream; } /** @@ -54,7 +54,7 @@ public static F, Stream> List_Stream() { * @return A function that converts lists to options. */ public static F, Option> List_Option() { - return as -> as.headOption(); + return List::headOption; } /** @@ -69,7 +69,7 @@ public static F, F, Either>> List_Either() { /** * A function that converts lists to strings. */ - public static final F, String> List_String = cs -> asString(cs); + public static final F, String> List_String = List::asString; /** * A function that converts lists to string buffers. @@ -91,7 +91,7 @@ public static F, F, Either>> List_Either() { * @return A function that converts arrays to lists. */ public static F, List> Array_List() { - return as -> as.toList(); + return Array::toList; } /** @@ -100,7 +100,7 @@ public static F, List> Array_List() { * @return A function that converts arrays to streams. */ public static F, Stream> Array_Stream() { - return as -> as.toStream(); + return Array::toStream; } /** @@ -109,7 +109,7 @@ public static F, Stream> Array_Stream() { * @return A function that converts arrays to options. */ public static F, Option> Array_Option() { - return as -> as.toOption(); + return Array::toOption; } /** @@ -126,7 +126,7 @@ public static F, F, Either>> Array_Either() { */ public static final F, String> Array_String = cs -> { final StringBuilder sb = new StringBuilder(); - cs.foreachDoEffect(c -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb.toString(); }; @@ -135,7 +135,7 @@ public static F, F, Either>> Array_Either() { */ public static final F, StringBuffer> Array_StringBuffer = cs -> { final StringBuffer sb = new StringBuffer(); - cs.foreachDoEffect(c -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb; }; @@ -144,7 +144,7 @@ public static F, F, Either>> Array_Either() { */ public static final F, StringBuilder> Array_StringBuilder = cs -> { final StringBuilder sb = new StringBuilder(); - cs.foreachDoEffect((Character c) -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb; }; @@ -158,7 +158,7 @@ public static F, F, Either>> Array_Either() { * @return A function that converts streams to lists. */ public static F, List> Stream_List() { - return as -> as.toList(); + return Stream::toList; } /** @@ -167,7 +167,7 @@ public static F, List> Stream_List() { * @return A function that converts streams to arrays. */ public static F, Array> Stream_Array() { - return as -> as.toArray(); + return Stream::toArray; } /** @@ -176,7 +176,7 @@ public static F, Array> Stream_Array() { * @return A function that converts streams to options. */ public static F, Option> Stream_Option() { - return as -> as.toOption(); + return Stream::toOption; } /** @@ -193,7 +193,7 @@ public static F, F, Either>> Stream_Either() { */ public static final F, String> Stream_String = cs -> { final StringBuilder sb = new StringBuilder(); - cs.foreachDoEffect((Character c) -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb.toString(); }; @@ -202,7 +202,7 @@ public static F, F, Either>> Stream_Either() { */ public static final F, StringBuffer> Stream_StringBuffer = cs -> { final StringBuffer sb = new StringBuffer(); - cs.foreachDoEffect((Character c) -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb; }; @@ -211,7 +211,7 @@ public static F, F, Either>> Stream_Either() { */ public static final F, StringBuilder> Stream_StringBuilder = cs -> { final StringBuilder sb = new StringBuilder(); - cs.foreachDoEffect((Character c) -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb; }; @@ -225,7 +225,7 @@ public static F, F, Either>> Stream_Either() { * @return A function that converts options to lists. */ public static F, List> Option_List() { - return o -> o.toList(); + return Option::toList; } /** @@ -234,7 +234,7 @@ public static F, List> Option_List() { * @return A function that converts options to arrays. */ public static F, Array> Option_Array() { - return o -> o.toArray(); + return Option::toArray; } /** @@ -243,7 +243,7 @@ public static F, Array> Option_Array() { * @return A function that converts options to streams. */ public static F, Stream> Option_Stream() { - return o -> o.toStream(); + return Option::toStream; } /** @@ -275,7 +275,7 @@ public static F, F, Either>> Option_Either() { // BEGIN Effect public static F> Effect0_P1() { - return e -> Effect0_P1(e); + return Conversions::Effect0_P1; } public static P1 Effect0_P1(Effect0 e) { @@ -287,7 +287,7 @@ public static F Effect1_F(Effect1 e) { } public static F, F> Effect1_F() { - return e -> Effect1_F(e); + return Conversions::Effect1_F; } public static IO Effect_IO(Effect0 e) { @@ -298,7 +298,7 @@ public static IO Effect_IO(Effect0 e) { } public static F> Effect_IO() { - return e -> Effect_IO(e); + return Conversions::Effect_IO; } public static SafeIO Effect_SafeIO(Effect0 e) { @@ -309,7 +309,7 @@ public static SafeIO Effect_SafeIO(Effect0 e) { } public static F> Effect_SafeIO() { - return e -> Effect_SafeIO(e); + return Conversions::Effect_SafeIO; } // END Effect @@ -451,7 +451,7 @@ public static SafeIO F_SafeIO(F f) { } public static F, SafeIO> F_SafeIO() { - return f -> F_SafeIO(f); + return Conversions::F_SafeIO; } // END F @@ -461,7 +461,7 @@ public static F, SafeIO> F_SafeIO() { /** * A function that converts strings to lists. */ - public static final F> String_List = s -> fromString(s); + public static final F> String_List = List::fromString; /** * A function that converts strings to arrays. @@ -490,12 +490,12 @@ public static F, F>> String_Either() { /** * A function that converts strings to string buffers. */ - public static final F String_StringBuffer = s -> new StringBuffer(s); + public static final F String_StringBuffer = StringBuffer::new; /** * A function that converts strings to string builders. */ - public static final F String_StringBuilder = s -> new StringBuilder(s); + public static final F String_StringBuilder = StringBuilder::new; // END String -> @@ -533,12 +533,12 @@ public static F, F>> StringBuffer_E /** * A function that converts string buffers to strings. */ - public static final F StringBuffer_String = s -> s.toString(); + public static final F StringBuffer_String = StringBuffer::toString; /** * A function that converts string buffers to string builders. */ - public static final F StringBuffer_StringBuilder = s -> new StringBuilder(s); + public static final F StringBuffer_StringBuilder = StringBuilder::new; // END StringBuffer -> @@ -576,12 +576,12 @@ public static F, F>> StringBuilder /** * A function that converts string builders to strings. */ - public static final F StringBuilder_String = s -> s.toString(); + public static final F StringBuilder_String = StringBuilder::toString; /** * A function that converts string builders to string buffers. */ - public static final F StringBuilder_StringBuffer = s -> new StringBuffer(s); + public static final F StringBuilder_StringBuffer = StringBuffer::new; // END StringBuilder -> @@ -593,15 +593,15 @@ public static SafeIO> Try_SafeIO(Tr } public static F, SafeIO>> Try_SafeIO() { - return t -> Try_SafeIO(t); + return Conversions::Try_SafeIO; } public static IO Try_IO(Try0 t) { - return () -> t.f(); + return t::f; } public static F, IO> Try_IO() { - return t -> Try_IO(t); + return Conversions::Try_IO; } public static F> Try_F(Try1 t) { @@ -609,7 +609,7 @@ public static F> Try_F(Try1 F, F>> Try_F() { - return t -> Try_F(t); + return Conversions::Try_F; } // END Try diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 6381ee78..1cbecb5d 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -296,7 +296,7 @@ public Either sequence(final Either e) { */ public List> traverseList(final F> f) { return isLeft() ? - f.f(value()).map(x -> Either.left(x)) : + f.f(value()).map(Either::left) : list(Either.right(e.right().value())); } @@ -308,7 +308,7 @@ public List> traverseList(final F> f) { */ public IO> traverseIO(final F> f) { return isRight() ? - IOFunctions.map(f.f(value()), x -> Either.left(x)) : + IOFunctions.map(f.f(value()), Either::left) : IOFunctions.unit(Either.right(e.right().value())); } @@ -335,7 +335,7 @@ public Option> filter(final F f) { * @return The result of function application within either. */ public Either apply(final Either, B> e) { - return e.left().bind(f -> map(f)); + return e.left().bind(this::map); } /** @@ -416,13 +416,13 @@ public Collection toCollection() { public Option> traverseOption(F> f) { return isLeft() ? - f.f(value()).map(x -> Either.left(x)) : + f.f(value()).map(Either::left) : some(Either.right(e.right().value())); } public Stream> traverseStream(F> f) { return isLeft() ? - f.f(value()).map(c -> Either.left(c)) : + f.f(value()).map(Either::left) : Stream.single(Either.right(e.right().value())); } } @@ -561,7 +561,7 @@ public Either sequence(final Either e) { */ public List> traverseList(final F> f) { return isRight() ? - f.f(value()).map(x -> right(x)) : + f.f(value()).map(Either::right) : list(Either.left(e.left().value())); } @@ -573,19 +573,19 @@ public List> traverseList(final F> f) { */ public IO> traverseIO(final F> f) { return isRight() ? - IOFunctions.map(f.f(value()), x -> Either.right(x)) : + IOFunctions.map(f.f(value()), Either::right) : IOFunctions.lazy(() -> Either.left(e.left().value())); } public P1> traverseP1(final F> f) { return isRight() ? - f.f(value()).map(x -> Either.right(x)) : + f.f(value()).map(Either::right) : p(Either.left(e.left().value())); } public Option> traverseOption(final F> f) { return isRight() ? - f.f(value()).map(x -> Either.right(x)) : + f.f(value()).map(Either::right) : some(Either.left(e.left().value())); } @@ -612,7 +612,7 @@ public Option> filter(final F f) { * @return The result of function application within either. */ public Either apply(final Either> e) { - return e.right().bind(f -> map(f)); + return e.right().bind(this::map); } /** @@ -693,7 +693,7 @@ public Collection toCollection() { public Stream> traverseStream(F> f) { return isRight() ? - f.f(value()).map(x -> right(x)) : + f.f(value()).map(Either::right) : Stream.>single(left(e.left().value())); } @@ -715,7 +715,7 @@ public static Either left(final A a) { * @return A function that constructs a left value of either. */ public static F> left_() { - return a -> left(a); + return Either::left; } /** @@ -724,7 +724,7 @@ public static F> left_() { * @return A function that constructs a right value of either. */ public static F> right_() { - return b -> right(b); + return Either::right; } /** diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index 14edff71..b7533ffd 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -369,7 +369,7 @@ else if (l < 0L) { */ public static final Enumerator naturalEnumerator = enumerator( n -> some(n.succ()), - n -> n.pred(), + Natural::pred, Option.none(), some(Natural.ZERO), naturalOrd, curry((n, l) -> some(n).apply( diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index e45d94a5..6b03a96a 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -161,7 +161,7 @@ public Option get(final K k) { * @return A curried version of {@link #get(Object)}. */ public F> get() { - return k -> get(k); + return this::get; } /** diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 6aa5db12..b62bb60e 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -18,6 +18,7 @@ import fj.data.Iteratee.Input; import fj.data.Iteratee.IterV; import fj.function.Try0; +import fj.function.Try1; /** * IO monad for processing files, with main methods {@link #enumFileLines }, @@ -35,7 +36,7 @@ private IOFunctions() { } public static Try0 toTry(IO io) { - return () -> io.run(); + return io::run; } public static P1> p(IO io) { @@ -47,10 +48,10 @@ public static IO fromF(F0 p) { } public static IO fromTry(Try0 t) { - return () -> t.f(); + return t::f; } - public static final F> closeReader = r -> closeReader(r); + public static final F> closeReader = IOFunctions::closeReader; /** * Convert io to a SafeIO, throwing any IOException wrapped inside a RuntimeException @@ -127,7 +128,7 @@ public static IO> enumFileChars(final File f, final Opti } public static IO bufferedReader(final File f, final Option encoding) { - return map(fileReader(f, encoding), a -> new BufferedReader(a)); + return map(fileReader(f, encoding), BufferedReader::new); } public static IO fileReader(final File f, final Option encoding) { @@ -386,7 +387,7 @@ public static IO join(IO> io1) { } public static SafeIO> toSafeValidation(IO io) { - return () -> Try.f(() -> io.run())._1(); + return () -> Try.f(io::run)._1(); } public static IO append(final IO io1, final IO io2) { @@ -458,8 +459,8 @@ public Stream run() throws IOException { return Stream.nil(); } else { IO> io2 = sequenceWhile(stream.tail()._1(), f); - SafeIO> s3 = toSafe(() -> io2.run()); - return Stream.cons(a, () -> s3.run()); + SafeIO> s3 = toSafe(io2::run); + return Stream.cons(a, s3::run); } } } @@ -467,7 +468,7 @@ public Stream run() throws IOException { } public static IO apply(IO io, IO> iof) { - return bind(iof, f -> map(io, a -> f.f(a))); + return bind(iof, f -> map(io, f::f)); } public static IO liftM2(IO ioa, IO iob, F2 f) { @@ -479,13 +480,13 @@ public static IO> replicateM(IO ioa, int n) { } public static IO>> readerState() { - return () -> State.unit((BufferedReader r) -> P.p(r, Try.f((BufferedReader r2) -> r2.readLine()).f(r))); + return () -> State.unit((BufferedReader r) -> P.p(r, Try.f((Try1) BufferedReader::readLine).f(r))); } public static final BufferedReader stdinBufferedReader = new BufferedReader(new InputStreamReader(System.in)); public static IO stdinReadLine() { - return () -> stdinBufferedReader.readLine(); + return stdinBufferedReader::readLine; } public static IO stdoutPrintln(final String s) { diff --git a/core/src/main/java/fj/data/IterableW.java b/core/src/main/java/fj/data/IterableW.java index 9e36e710..0633ffd4 100644 --- a/core/src/main/java/fj/data/IterableW.java +++ b/core/src/main/java/fj/data/IterableW.java @@ -42,7 +42,7 @@ public static IterableW wrap(final Iterable a) { * @return A function that returns the given iterable, wrapped. */ public static > F> wrap() { - return a -> wrap(a); + return IterableW::wrap; } /** @@ -73,7 +73,7 @@ public static F> iterable(final F f) { * @return A transformation from a function to the equivalent Iterable-valued function. */ public static F, F>> arrow() { - return f -> iterable(f); + return IterableW::iterable; } /** @@ -93,7 +93,7 @@ public > IterableW bind(final F f) { * @return A new iterable after applying the given iterable function to the wrapped iterable. */ public IterableW apply(final Iterable> f) { - return wrap(f).bind(f1 -> map(f1)); + return wrap(f).bind(this::map); } /** @@ -143,7 +143,7 @@ public static > IterableW> sequence(final * @return a function that binds a given function across a given iterable. */ public static > F, F, IterableW>> bind() { - return a -> f -> a.bind(f); + return a -> a::bind; } /** @@ -163,7 +163,7 @@ public static > IterableW join(final Iterable as) * @return a function that joins an Iterable of Iterables into a single Iterable. */ public static > F, IterableW> join() { - return a -> join(a); + return IterableW::join; } /** diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index e2f9adfd..8836fe2f 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -1433,7 +1433,7 @@ public static F> StringBuilder_Synchr * @return A function that converts array lists to lists. */ public static F, List> ArrayList_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1447,11 +1447,11 @@ public static F, List> ArrayList_List() { * @return A function that converts Java lists to lists. */ public static F, List> JUList_List() { - return as -> JavaList_List(as); + return Java::JavaList_List; } public static F, List> JavaList_List() { - return as -> JavaList_List(as); + return Java::JavaList_List; } public static List JavaList_List(java.util.List list) { @@ -1479,7 +1479,7 @@ public static List JavaList_List(java.util.List list) { * @return A function that converts enum sets to lists. */ public static > F, List> EnumSet_List() { - return as -> Collection_List(as); + return Java::Collection_List; } public static List Collection_List(Collection c) { @@ -1507,7 +1507,7 @@ private static E[] array(int length, E... array) { * @return A function that converts hash sets to lists. */ public static F, List> HashSet_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1522,7 +1522,7 @@ public static F, List> HashSet_List() { * @return A function that converts linked hash sets to lists. */ public static F, List> LinkedHashSet_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1537,7 +1537,7 @@ public static F, List> LinkedHashSet_List() { * @return A function that converts linked lists to lists. */ public static F, List> LinkedList_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1552,7 +1552,7 @@ public static F, List> LinkedList_List() { * @return A function that converts priority queues to lists. */ public static F, List> PriorityQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1567,7 +1567,7 @@ public static F, List> PriorityQueue_List() { * @return A function that converts stacks to lists. */ public static F, List> Stack_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1582,7 +1582,7 @@ public static F, List> Stack_List() { * @return A function that converts tree sets to lists. */ public static F, List> TreeSet_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1597,7 +1597,7 @@ public static F, List> TreeSet_List() { * @return A function that converts vectors to lists. */ public static F, List> Vector_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1612,7 +1612,7 @@ public static F, List> Vector_List() { * @return A function that converts array blocking queues to lists. */ public static F, List> ArrayBlockingQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1627,7 +1627,7 @@ public static F, List> ArrayBlockingQueue_List() { * @return A function that converts concurrent linked queues to lists. */ public static F, List> ConcurrentLinkedQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1642,7 +1642,7 @@ public static F, List> ConcurrentLinkedQueue_Lis * @return A function that converts copy on write array lists to lists. */ public static F, List> CopyOnWriteArrayList_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1657,7 +1657,7 @@ public static F, List> CopyOnWriteArrayList_List( * @return A function that converts copy on write array sets to lists. */ public static F, List> CopyOnWriteArraySet_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1672,7 +1672,7 @@ public static F, List> CopyOnWriteArraySet_List() * @return A function that converts delay queues to lists. */ public static F, List> DelayQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1687,7 +1687,7 @@ public static F, List> DelayQueue_List() { * @return A function that converts linked blocking queues to lists. */ public static F, List> LinkedBlockingQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1702,7 +1702,7 @@ public static F, List> LinkedBlockingQueue_List() * @return A function that converts priority blocking queues to lists. */ public static F, List> PriorityBlockingQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1717,7 +1717,7 @@ public static F, List> PriorityBlockingQueue_Lis * @return A function that converts synchronous queues to lists. */ public static F, List> SynchronousQueue_List() { - return as -> Collection_List(as); + return Java::Collection_List; } // todo @@ -1727,7 +1727,7 @@ public static F, List> SynchronousQueue_List() { // BEGIN Callable -> public static F, Callable> P1_Callable() { - return a -> () -> a._1(); + return a -> a::_1; } // END Callable -> diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 0b5a0d4c..5a2e2504 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -655,7 +655,7 @@ public IO> traverseIO(F> f) { public F> traverseF(F> f) { return this.foldRight( (a, acc) -> Function.bind(acc, - (bs) -> Function.> compose(b -> bs.cons(b), f.f(a))), + (bs) -> Function.> compose(bs::cons, f.f(a))), constant(List. nil()) ); } @@ -697,7 +697,7 @@ public V2> traverseV2(final F> f) { * @return A new list after applying the given list of functions through this list. */ public final List apply(final List> lf) { - return lf.bind(f -> map(f)); + return lf.bind(this::map); } /** @@ -1041,7 +1041,7 @@ public final List> zip(final List bs) { * @return A function that zips the given lists to produce a list of pairs. */ public static F, F, List>>> zip() { - return curry((as, bs) -> as.zip(bs)); + return curry(List::zip); } /** @@ -1164,7 +1164,7 @@ public final List nub(final Ord o) { * @return A function that gets the head of a given list. */ public static F, A> head_() { - return list -> list.head(); + return List::head; } @@ -1182,7 +1182,7 @@ public Option> tailOption() { * @return A function that gets the tail of a given list. */ public static F, List> tail_() { - return list -> list.tail(); + return List::tail; } /** @@ -1446,7 +1446,7 @@ public final boolean isSuffixOf(final Equal eq, final List xs) { * @return A function that gets the length of a given list. */ public static F, Integer> length_() { - return a -> a.length(); + return List::length; } /** @@ -1607,7 +1607,7 @@ public static F, List>> cons() { } public static F2, List> cons_() { - return (a, listA) -> cons(a, listA); + return List::cons; } /** @@ -1617,7 +1617,7 @@ public static F2, List> cons_() { * @return A function that prepends a value to the given list. */ public static F> cons(final List tail) { - return a -> tail.cons(a); + return tail::cons; } /** @@ -1647,7 +1647,7 @@ public static List cons(final A head, final List tail) { * @return A function that determines whether a given list is empty. */ public static F, Boolean> isEmpty_() { - return as -> as.isEmpty(); + return List::isEmpty; } /** @@ -1656,7 +1656,7 @@ public static F, Boolean> isEmpty_() { * @return A function that determines whether a given list is not empty. */ public static F, Boolean> isNotEmpty_() { - return as -> as.isNotEmpty(); + return List::isNotEmpty; } /** @@ -1676,7 +1676,7 @@ public static List join(final List> o) { * @return A function that joins a list of lists using a bind operation. */ public static F>, List> join() { - return as -> join(as); + return List::join; } /** @@ -1762,7 +1762,7 @@ public static List fromString(final String s) { * @return A first-class fromString. */ public static F> fromString() { - return s -> fromString(s); + return List::fromString; } /** @@ -1788,7 +1788,7 @@ public static String asString(final List cs) { * @return A first-class asString. */ public static F, String> asString() { - return cs -> asString(cs); + return List::asString; } /** diff --git a/core/src/main/java/fj/data/Natural.java b/core/src/main/java/fj/data/Natural.java index 396aa39c..1779d8c7 100644 --- a/core/src/main/java/fj/data/Natural.java +++ b/core/src/main/java/fj/data/Natural.java @@ -40,7 +40,7 @@ public static Option natural(final BigInteger i) { * A function that returns the natural number equal to a given BigInteger */ public static final F> fromBigInt = - i -> natural(i); + Natural::natural; /** * Returns the natural number equal to the given long @@ -77,7 +77,7 @@ public Natural succ() { * @return A function that returns the successor of a given natural number. */ public static F succ_() { - return natural -> natural.succ(); + return Natural::succ; } /** @@ -95,7 +95,7 @@ public Option pred() { * @return A function that returns the predecessor of a given natural number, or None if it's zero. */ public static F> pred_() { - return natural -> natural.pred(); + return Natural::pred; } /** @@ -111,7 +111,7 @@ public Natural add(final Natural n) { /** * A function that adds two natural numbers. */ - public static final F> add = curry((n1, n2) -> n1.add(n2)); + public static final F> add = curry(Natural::add); /** @@ -143,7 +143,7 @@ public Natural multiply(final Natural n) { /** * A function that multiplies a natural number by another. */ - public static final F> multiply = curry((n1, n2) -> n1.multiply(n2)); + public static final F> multiply = curry(Natural::multiply); /** @@ -245,7 +245,7 @@ public int intValue() { /** * A function that returns the BigInteger value of a given Natural. */ - public static final F bigIntegerValue = n -> n.bigIntegerValue(); + public static final F bigIntegerValue = Natural::bigIntegerValue; /** * Sums a stream of natural numbers. diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index 0ebffc11..611bef93 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -127,7 +127,7 @@ public void f(final A a) { public NonEmptyList> sublists() { return fromList( somes(toList().toStream().substreams() - .map(F1Functions.o(list -> fromList(list), Conversions.Stream_List())).toList())).some(); + .map(F1Functions.o(NonEmptyList::fromList, Conversions.Stream_List())).toList())).some(); } /** @@ -137,7 +137,7 @@ public NonEmptyList> sublists() { * @return A NonEmptyList of the tails of this list. */ public NonEmptyList> tails() { - return fromList(somes(toList().tails().map(list -> fromList(list)))).some(); + return fromList(somes(toList().tails().map(NonEmptyList::fromList))).some(); } /** @@ -268,7 +268,7 @@ public Collection toCollection() { * @return A function that takes a non-empty list to a list. */ public static F, List> toList_() { - return as -> as.toList(); + return NonEmptyList::toList; } /** diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 5bec1ea4..5c8dca74 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -95,7 +95,7 @@ public final boolean isNone() { * @return A function that returns true if a given optional value has a value, otherwise false. */ public static F, Boolean> isSome_() { - return a -> a.isSome(); + return Option::isSome; } /** @@ -104,7 +104,7 @@ public static F, Boolean> isSome_() { * @return A function that returns false if a given optional value has a value, otherwise true. */ public static F, Boolean> isNone_() { - return a -> a.isNone(); + return Option::isNone; } /** @@ -412,15 +412,15 @@ public final Option sequence(final Option o) { } public Either> traverseEither(F> f) { - return map(a -> f.f(a).right().map(b -> some(b))).orSome(Either.right(none())); + return map(a -> f.f(a).right().map(Option::some)).orSome(Either.right(none())); } public IO> traverseIO(F> f) { - return map(a -> IOFunctions.map(f.f(a), b -> some(b))).orSome(IOFunctions.lazy(() -> none())); + return map(a -> IOFunctions.map(f.f(a), Option::some)).orSome(IOFunctions.lazy(Option::none)); } public List> traverseList(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(List.list()); + return map(a -> f.f(a).map(Option::some)).orSome(List.list()); } public Option> traverseOption(F> f) { @@ -428,28 +428,28 @@ public Option> traverseOption(F> f) { } public Stream> traverseStream(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(Stream.nil()); + return map(a -> f.f(a).map(Option::some)).orSome(Stream.nil()); } public P1> traverseP1(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(p(none())); + return map(a -> f.f(a).map(Option::some)).orSome(p(none())); } public Seq> traverseSeq(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(Seq.empty()); + return map(a -> f.f(a).map(Option::some)).orSome(Seq.empty()); } public Set> traverseSet(Ord ord, F> f) { Ord> optOrd = Ord.optionOrd(ord); - return map(a -> f.f(a).map(optOrd, b -> some(b))).orSome(Set.empty(optOrd)); + return map(a -> f.f(a).map(optOrd, Option::some)).orSome(Set.empty(optOrd)); } public F2, F>, Set>> traverseSet() { - return (o, f) -> traverseSet(o, f); + return this::traverseSet; } public Validation> traverseValidation(F> f) { - return map(a -> f.f(a).map(b -> some(b))).orSome(Validation.success(none())); + return map(a -> f.f(a).map(Option::some)).orSome(Validation.success(none())); } /** @@ -460,7 +460,7 @@ public Validation> traverseValidation(F> * optional value. */ public final Option apply(final Option> of) { - return of.bind(f -> map(a -> f.f(a))); + return of.bind(f -> map(f::f)); } /** @@ -516,7 +516,7 @@ public final Validation toValidation(final X x) { * return in left. */ public static F, F>> toEither() { - return curry((a, x) -> a.toEither(x)); + return curry(Option::toEither); } /** @@ -641,7 +641,7 @@ public A some() { public static F> some_() { - return t -> some(t); + return Option::some; } /** @@ -685,7 +685,7 @@ public static Option fromNull(final T t) { * @return If t == null then return none, otherwise, return it in some. */ public static F> fromNull() { - return t -> fromNull(t); + return Option::fromNull; } /** @@ -758,7 +758,7 @@ public static Option iif(final boolean p, final A a) { * holds on that argument, or no value otherwise. */ public static F2, A, Option> iif() { - return (p, a) -> iif(p, a); + return Option::iif; } /** @@ -808,7 +808,7 @@ public int hashCode() { * or no value if the string is empty. */ public static F> fromString() { - return s -> fromString(s); + return Option::fromString; } /** @@ -855,7 +855,7 @@ public static F>, F, Option>> bind() { * @return A function that joins an Option of an Option to make a single Option. */ public static F>, Option> join() { - return option -> join(option); + return Option::join; } /** diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 09d80279..4dcd10de 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -173,7 +173,7 @@ public final boolean member(final A x) { * @return A function that returns true if the given element if a member of the given set. */ public static F, F> member() { - return curry((s, a) -> s.member(a)); + return curry(Set::member); } /** @@ -394,7 +394,7 @@ public final Set union(final Set s) { * @see #union(Set) */ public static F, F, Set>> union() { - return curry((s1, s2) -> s1.union(s2)); + return curry(Set::union); } /** @@ -444,7 +444,7 @@ public final Set intersect(final Set s) { * @see #intersect(Set) */ public static F, F, Set>> intersect() { - return curry((s1, s2) -> s1.intersect(s2)); + return curry(Set::intersect); } /** @@ -464,7 +464,7 @@ public final Set minus(final Set s) { * @see #minus(Set) */ public static F, F, Set>> minus() { - return curry((s1, s2) -> s1.minus(s2)); + return curry(Set::minus); } public Option min() { diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 81146f95..47703e7b 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -93,7 +93,7 @@ public State withs(F f) { } public static State gets(F f) { - return State.init().map(s -> f.f(s)); + return State.init().map(f::f); } /** @@ -101,7 +101,7 @@ public static State gets(F f) { */ public static State> sequence(List> list) { return list.foldLeft((State> acc, State ma) -> - acc.flatMap((List xs) -> ma.map((A x) -> xs.snoc(x)) + acc.flatMap((List xs) -> ma.map(xs::snoc) ), constant(List.nil())); } @@ -111,7 +111,7 @@ public static State> sequence(List> list) { */ public static State> traverse(List list, F> f) { return list.foldLeft((State> acc, A a) -> - acc.flatMap(bs -> f.f(a).map(b -> bs.snoc(b)) + acc.flatMap(bs -> f.f(a).map(bs::snoc) ), constant(List.nil())); } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 6dbcf778..8e04e499 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -2,6 +2,7 @@ import fj.Equal; import fj.F0; +import fj.F3; import fj.Hash; import fj.Show; import fj.F; @@ -521,7 +522,7 @@ public final Stream sequence(final Stream bs) { * @return The stream of IOs after sequencing. */ public static Stream> sequence(final IO> io) { - return IOFunctions.runSafe(io).map(a -> IOFunctions.unit(a)); + return IOFunctions.runSafe(io).map(IOFunctions::unit); } /** @@ -531,7 +532,7 @@ public static Stream> sequence(final IO> io) { * @return The stream of (pre-calculated) lazy values after sequencing. */ public static Stream> sequence(final F0> p) { - return p.f().map(a -> p(a)); + return p.f().map(P::p); } /** @@ -541,7 +542,7 @@ public static Stream> sequence(final F0> p) { * @return The stream of options after sequencing. */ public static Stream> sequence(final Option> o) { - return o.isNone() ? nil() : o.some().map(a -> some(a)); + return o.isNone() ? nil() : o.some().map(Option::some); } /** @@ -551,7 +552,7 @@ public static Stream> sequence(final Option> o) { * @return A new stream after applying the given stream of functions through this stream. */ public final Stream apply(final Stream> sf) { - return sf.bind(f -> map(f)); + return sf.bind(this::map); } /** @@ -892,7 +893,7 @@ public final Stream> zip(final Stream bs) { * @return A new stream with the same length as this stream. */ public final Stream> zipIndex() { - return zipWith(range(0), (a, i) -> p(a, i)); + return zipWith(range(0), (F2>) P::p); } /** @@ -941,7 +942,7 @@ public final A[] toJavaArray() { */ public final List toList() { List.Buffer buf = List.Buffer.empty(); - foreachDoEffect(a -> buf.snoc(a)); + foreachDoEffect(buf::snoc); return buf.toList(); } @@ -1018,7 +1019,7 @@ public final Stream cons(final A a) { */ public static String asString(final Stream cs) { StringBuilder sb = new StringBuilder(); - cs.foreachDoEffect(c -> sb.append(c)); + cs.foreachDoEffect(sb::append); return sb.toString(); } @@ -1103,8 +1104,7 @@ public final Stream takeWhile(final F f) { public final IO> traverseIO(F> f) { return this.foldRight1((a, acc) -> IOFunctions.bind(acc, (Stream bs) -> - IOFunctions.map(f.f(a), b -> - bs.cons(b))), IOFunctions.unit(Stream.nil())); + IOFunctions.map(f.f(a), bs::cons)), IOFunctions.unit(Stream.nil())); } @@ -1114,7 +1114,7 @@ public final IO> traverseIO(F> f) { * @return traversed value */ public final Option> traverseOption(F> f) { - return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(b -> bs.cons(b))), some(Stream.nil())); + return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil())); } /** @@ -1334,7 +1334,7 @@ public final Stream> tails() { * @return a stream of the prefixes of this stream, starting with the stream itself. */ public final Stream> inits() { - final Stream> nil = cons(Stream.nil(), () -> nil()); + final Stream> nil = cons(Stream.nil(), Stream::nil); return isEmpty() ? nil : nil.append(() -> tail()._1().inits().map(Stream.cons_().f(head()))); } @@ -1344,7 +1344,7 @@ public final Stream> inits() { * @return a stream of the infixes of this stream. */ public final Stream> substreams() { - return tails().bind(stream -> stream.inits()); + return tails().bind(Stream::inits); } /** @@ -1375,7 +1375,7 @@ public final Stream sequenceW(final Stream, B>> fs) { * @return A function from natural numbers to values with the corresponding position in this stream. */ public final F toFunction() { - return i -> index(i); + return this::index; } /** @@ -1426,7 +1426,7 @@ public static P2, Stream> unzip(final Stream> xs) { * @return a function that zips two given streams with a given function. */ public static F, F, F>, Stream>>> zipWith() { - return curry((as, bs, f) -> as.zipWith(bs, f)); + return curry((F3, Stream, F>, Stream>) Stream::zipWith); } private static final class Nil extends Stream { @@ -1491,7 +1491,7 @@ public static Stream nil() { * @return An empty stream. */ public static P1> nil_() { - return P.lazy(() -> new Nil()); + return P.lazy(Nil::new); } /** @@ -1500,7 +1500,7 @@ public static P1> nil_() { * @return A function that determines whether a given stream is empty. */ public static F, Boolean> isEmpty_() { - return as -> as.isEmpty(); + return Stream::isEmpty; } /** @@ -1509,7 +1509,7 @@ public static F, Boolean> isEmpty_() { * @return A function that determines whether a given stream is not empty. */ public static F, Boolean> isNotEmpty_() { - return as -> as.isNotEmpty(); + return Stream::isNotEmpty; } /** @@ -1519,7 +1519,7 @@ public static F, Boolean> isNotEmpty_() { * @return A stream of one element containing the given value. */ public static Stream single(final A a) { - return cons(a, () -> nil()); + return cons(a, Stream::nil); } /** @@ -1528,7 +1528,7 @@ public static Stream single(final A a) { * @return a function that yields a stream containing its argument. */ public static F> single() { - return a -> single(a); + return Stream::single; } /** @@ -1556,7 +1556,7 @@ public static Stream cons(final A head, final F0> tail) { * @return A function that joins a stream of streams using a bind operation. */ public static F>, Stream> join() { - return as -> join(as); + return Stream::join; } /** @@ -1651,7 +1651,7 @@ public static Stream iterate(final F f, final A a) { * starting at a given value. */ public static F, F>> iterate() { - return curry((f, a) -> iterate(f, a)); + return curry(Stream::iterate); } /** diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index 004e0910..82e682bc 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -107,7 +107,7 @@ public P1>> subForest() { * @return A transformation from a tree to its root. */ public static F, A> root_() { - return a -> a.root(); + return Tree::root; } /** @@ -116,7 +116,7 @@ public static F, A> root_() { * @return A transformation from a tree to its subforest. */ public static F, P1>>> subForest_() { - return a -> a.subForest(); + return Tree::subForest; } /** @@ -142,7 +142,7 @@ public Stream f(final Tree t, final P1> xs) { * @return The elements of the tree in pre-order. */ public static F, Stream> flatten_() { - return t -> t.flatten(); + return Tree::flatten; } /** @@ -335,7 +335,7 @@ public static Tree bottomUp(Tree t, final F>, B> f) * @return a function getting the root of a Tree */ private static F, A> getRoot() { - return a -> a.root(); + return Tree::root; } public boolean isLeaf() { @@ -343,7 +343,7 @@ public boolean isLeaf() { } public int length() { - return 1 + subForest._1().map(t -> t.length()).foldLeft((acc, i) -> acc + i, 0); + return 1 + subForest._1().map(Tree::length).foldLeft((acc, i) -> acc + i, 0); } } \ No newline at end of file diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index 2bdf70a9..de4876ec 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -264,7 +264,7 @@ public static TreeMap fromMutableMap(final Ord ord, final Map> get() { - return k -> get(k); + return this::get; } /** @@ -377,7 +377,7 @@ public Option> min() { * Returns the minimum key in the tree if the tree is not empty. */ public Option minKey() { - return tree.min().map(p -> p._1()); + return tree.min().map(P2::_1); } /** @@ -391,7 +391,7 @@ public Option> max() { * Returns the maximum key in the tree if the tree is not empty. */ public Option maxKey() { - return tree.max().map(p -> p._1()); + return tree.max().map(P2::_1); } /** diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index 959de5a7..3cfeff7c 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -81,7 +81,7 @@ public static TreeZipper treeZipper(final Tree tree, F, F>, F>, F>, A, Stream>>>, TreeZipper>>>> treeZipper() { return curry( - (tree, lefts, rights, parents) -> treeZipper(tree, lefts, rights, parents)); + TreeZipper::treeZipper); } /** @@ -100,7 +100,7 @@ public P4, Stream>, Stream>, Stream>, */ public static F, P4, Stream>, Stream>, Stream>, A, Stream>>>>> p_() { - return a -> a.p(); + return TreeZipper::p; } /** @@ -167,7 +167,7 @@ public TreeZipper root() { * @return A function that returns a new tree-zipper focused on the root of the given tree zipper's tree. */ public static F, TreeZipper> root_() { - return a -> a.root(); + return TreeZipper::root; } /** @@ -553,7 +553,7 @@ public TreeZipper map(final F f) { * @return A function that takes a tree to its tree zipper representation. */ public static F, TreeZipper> fromTree() { - return t -> fromTree(t); + return TreeZipper::fromTree; } /** @@ -562,7 +562,7 @@ public static F, TreeZipper> fromTree() { * @return A function that focuses the given tree zipper on its left sibling. */ public static F, Option>> left_() { - return z -> z.left(); + return TreeZipper::left; } /** @@ -571,7 +571,7 @@ public static F, Option>> left_() { * @return A function that focuses the given tree zipper on its right sibling. */ public static F, Option>> right_() { - return z -> z.right(); + return TreeZipper::right; } /** diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 3e622f68..8328590f 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -205,8 +205,8 @@ public Validation sequence(final Validation v) { * all the failures using the semigroup, otherwise returns the successful list. */ public static Validation> sequence(final Semigroup s, final List> list) { - if (list.exists(v -> v.isFail())) { - return Validation.>fail(list.filter(v -> v.isFail()).map(v -> v.fail()).foldLeft1((e1, e2) -> s.sum(e1, e2))); + if (list.exists(Validation::isFail)) { + return Validation.>fail(list.filter(Validation::isFail).map(v -> v.fail()).foldLeft1((F2) s::sum)); } else { return success(list.foldLeft((List acc, Validation v) -> acc.cons(v.success()), List.nil()).reverse()); } @@ -816,12 +816,12 @@ public Validation, D> accumulate(Validation v2, Validati * single failure using a semigroup. */ public static Validation, List> sequenceNonCumulative(List> list) { - if (list.exists(v -> v.isFail())) { + if (list.exists(Validation::isFail)) { F2, Validation, List> f = (acc, v) -> acc.cons(v.fail()); - return fail(list.filter(v -> v.isFail()).foldLeft(f, List.nil()).reverse()); + return fail(list.filter(Validation::isFail).foldLeft(f, List.nil()).reverse()); } else { F2, Validation, List> f = (acc, v) -> acc.cons(v.success()); - return success(list.filter(v -> v.isSuccess()).foldLeft(f, List.nil()).reverse()); + return success(list.filter(Validation::isSuccess).foldLeft(f, List.nil()).reverse()); } } @@ -857,11 +857,11 @@ public P1> traverseP1(F> f){ public static List fails(List> list) { - return list.filter(v -> v.isFail()).map(v -> v.fail()); + return list.filter(Validation::isFail).map(v -> v.fail()); } public static List successes(List> list) { - return list.filter(v -> v.isSuccess()).map(v -> v.success()); + return list.filter(Validation::isSuccess).map(v -> v.success()); } /** @@ -1002,7 +1002,7 @@ public Option> filter(final F f) { * @return The result of function application in validation. */ public Validation apply(final Validation, T> v) { - return v.f().bind(f -> map(f)); + return v.f().bind(this::map); } /** @@ -1103,7 +1103,7 @@ public static Validation validation(final Either e) { * @return A function that constructs a validation with an either. */ public static F, Validation> validation() { - return e1 -> validation(e1); + return Validation::validation; } /** @@ -1112,7 +1112,7 @@ public static F, Validation> validation() { * @return A function that constructs an either with a validation. */ public static F, Either> either() { - return v -> v.toEither(); + return Validation::toEither; } /** @@ -1175,7 +1175,7 @@ public static Validation parseByte(final String s) /** * A function that parses a string into a byte. */ - public static final F> parseByte = s -> parseByte(s); + public static final F> parseByte = Validation::parseByte; /** * Parses the given string into a double. @@ -1194,7 +1194,7 @@ public static Validation parseDouble(final String /** * A function that parses a string into a double. */ - public static final F> parseDouble = s -> parseDouble(s); + public static final F> parseDouble = Validation::parseDouble; /** * Parses the given string into a float. @@ -1213,7 +1213,7 @@ public static Validation parseFloat(final String s /** * A function that parses a string into a float. */ - public static final F> parseFloat = s -> parseFloat(s); + public static final F> parseFloat = Validation::parseFloat; /** * Parses the given string into a integer. @@ -1232,7 +1232,7 @@ public static Validation parseInt(final String s /** * A function that parses a string into an integer. */ - public static final F> parseInt = s -> parseInt(s); + public static final F> parseInt = Validation::parseInt; /** * Parses the given string into a long. @@ -1251,7 +1251,7 @@ public static Validation parseLong(final String s) /** * A function that parses a string into a long. */ - public static final F> parseLong = s -> parseLong(s); + public static final F> parseLong = Validation::parseLong; /** * Parses the given string into a short. @@ -1270,15 +1270,15 @@ public static Validation parseShort(final String s /** * A function that parses a string into a short. */ - public static final F> parseShort = s -> parseShort(s); + public static final F> parseShort = Validation::parseShort; /** * Partitions the list into the list of fails and the list of successes */ public static P2, List> partition(List> list) { return p( - list.filter(v -> v.isFail()).map(v -> v.fail()), - list.filter(v -> v.isSuccess()).map(v -> v.success()) + list.filter(Validation::isFail).map(v -> v.fail()), + list.filter(Validation::isSuccess).map(v -> v.success()) ); } diff --git a/core/src/main/java/fj/data/Zipper.java b/core/src/main/java/fj/data/Zipper.java index 6de0d39c..f24ecf01 100644 --- a/core/src/main/java/fj/data/Zipper.java +++ b/core/src/main/java/fj/data/Zipper.java @@ -74,7 +74,7 @@ public static Zipper zipper(final P3, A, Stream> p) { * @return A function that yields a new zipper given streams on the left and right and a focus element. */ public static F3, A, Stream, Zipper> zipper() { - return (l, a, r) -> zipper(l, a, r); + return Zipper::zipper; } /** @@ -92,7 +92,7 @@ public P3, A, Stream> p() { * @return A first-class function that yields the product-3 representation of a given Zipper. */ public static F, P3, A, Stream>> p_() { - return a -> a.p(); + return Zipper::p; } /** @@ -255,7 +255,7 @@ public Zipper tryPrevious() { * @return A function that moves the given zipper's focus to the next element. */ public static F, Option>> next_() { - return as -> as.next(); + return Zipper::next; } /** @@ -264,7 +264,7 @@ public static F, Option>> next_() { * @return A function that moves the given zipper's focus to the previous element. */ public static F, Option>> previous_() { - return as -> as.previous(); + return Zipper::previous; } /** diff --git a/core/src/main/java/fj/data/fingertrees/Digit.java b/core/src/main/java/fj/data/fingertrees/Digit.java index debf2635..2b51f7a7 100644 --- a/core/src/main/java/fj/data/fingertrees/Digit.java +++ b/core/src/main/java/fj/data/fingertrees/Digit.java @@ -38,7 +38,7 @@ public abstract class Digit { */ public final A reduceRight(final F> f) { return match( - one -> one.value(), + One::value, two -> { final V2 v = two.values(); return f.f(v._1()).f(v._2()); @@ -62,7 +62,7 @@ public final A reduceRight(final F> f) { */ public final A reduceLeft(final F> f) { return match( - one -> one.value(), + One::value, two -> { final V2 v = two.values(); return f.f(v._1()).f(v._2()); diff --git a/core/src/main/java/fj/data/fingertrees/Measured.java b/core/src/main/java/fj/data/fingertrees/Measured.java index 777eb369..d33b5726 100644 --- a/core/src/main/java/fj/data/fingertrees/Measured.java +++ b/core/src/main/java/fj/data/fingertrees/Measured.java @@ -74,7 +74,7 @@ public V zero() { * @return A measured instance for nodes. */ public Measured> nodeMeasured() { - return new Measured>(m, node -> node.measure()); + return new Measured>(m, Node::measure); } /** @@ -83,7 +83,7 @@ public Measured> nodeMeasured() { * @return A measured instance for digits. */ public Measured> digitMeasured() { - return new Measured>(m, d -> d.measure()); + return new Measured>(m, Digit::measure); } } diff --git a/core/src/main/java/fj/data/optic/POptional.java b/core/src/main/java/fj/data/optic/POptional.java index 92e4edf0..5c0bdd8c 100644 --- a/core/src/main/java/fj/data/optic/POptional.java +++ b/core/src/main/java/fj/data/optic/POptional.java @@ -458,7 +458,7 @@ public F> modifyP1F(final F> f) { @Override public F> modifyValidationF(final F> f) { return s -> getOrModify.f(s).either( - t -> Validation. success(t), + Validation::success, t -> f.f(t).map(b -> set.f(b).f(s)) ); } diff --git a/core/src/main/java/fj/data/optic/PPrism.java b/core/src/main/java/fj/data/optic/PPrism.java index 476758a7..f6712989 100644 --- a/core/src/main/java/fj/data/optic/PPrism.java +++ b/core/src/main/java/fj/data/optic/PPrism.java @@ -126,7 +126,7 @@ public final F> modifyP1F(final F> f) { /** modify polymorphically the target of a {@link PPrism} with an Applicative function */ public final F> modifyValidationF(final F> f) { return s -> getOrModify(s).either( - t -> Validation. success(t), + Validation::success, t -> f.f(t).map(this::reverseGet) ); } diff --git a/core/src/main/java/fj/data/vector/V.java b/core/src/main/java/fj/data/vector/V.java index 26a86462..57249ac8 100644 --- a/core/src/main/java/fj/data/vector/V.java +++ b/core/src/main/java/fj/data/vector/V.java @@ -35,7 +35,7 @@ public static V2 v(final A a1, final A a2) { * @return The vector-2. */ public static V2 v(final F0 a1, final F0 a2) { - return V2.p(P.lazy(() -> a1.f(), () -> a2.f())); + return V2.p(P.lazy(a1::f, a2::f)); } /** @@ -44,7 +44,7 @@ public static V2 v(final F0 a1, final F0 a2) { * @return A function that puts elements in a vector-2. */ public static F2> v2() { - return (a, a1) -> v(a, a1); + return V::v; } /** @@ -77,7 +77,7 @@ public static V3 v(final P1 a1, final F0 a2, final F0 a3) { * @return A function that puts elements in a vector-3. */ public static F3> v3() { - return (a, a1, a2) -> v(a, a1, a2); + return V::v; } /** @@ -112,7 +112,7 @@ public static V4 v(final P1 a1, final P1 a2, final F0 a3, final * @return A function that puts elements in a vector-4. */ public static F4> v4() { - return (a, a1, a2, a3) -> v(a, a1, a2, a3); + return V::v; } @@ -150,7 +150,7 @@ public static V5 v(final P1 a1, final P1 a2, final P1 a3, final * @return A function that puts elements in a vector-5. */ public static F5> v5() { - return (a, a1, a2, a3, a4) -> v(a, a1, a2, a3, a4); + return V::v; } } diff --git a/core/src/main/java/fj/data/vector/V2.java b/core/src/main/java/fj/data/vector/V2.java index e5bf7bc1..700a8409 100644 --- a/core/src/main/java/fj/data/vector/V2.java +++ b/core/src/main/java/fj/data/vector/V2.java @@ -57,7 +57,7 @@ public A _2() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V2::_1; } /** @@ -66,7 +66,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V2::_2; } /** @@ -111,7 +111,7 @@ public Stream toStream() { * @return a function that transforms a vector-2 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V2::toStream; } /** @@ -120,7 +120,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-2 to the equivalent product-2. */ public static F, P2> p_() { - return v -> v.p(); + return V2::p; } /** @@ -193,7 +193,7 @@ public V2> vzip(final V2 bs) { * @return the first element of this vector as a product-1. */ public P1 head() { - return P.lazy(() -> V2.this._1()); + return P.lazy(V2.this::_1); } } diff --git a/core/src/main/java/fj/data/vector/V3.java b/core/src/main/java/fj/data/vector/V3.java index 22e11946..ceb492bc 100644 --- a/core/src/main/java/fj/data/vector/V3.java +++ b/core/src/main/java/fj/data/vector/V3.java @@ -31,8 +31,8 @@ private V3(final P1 head, final V2 tail) { */ public static V3 p(final P3 p) { return new V3( - P.lazy(() -> p._1()), - V2.p(P.lazy(() -> p._2(), () -> p._3())) + P.lazy(p::_1), + V2.p(P.lazy(p::_2, p::_3)) ); } @@ -211,7 +211,7 @@ public V3 map(final F f) { * @return a function that transforms a vector-3 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V3::toStream; } /** @@ -220,7 +220,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-3 to the equivalent product-3. */ public static F, P3> p_() { - return v -> v.p(); + return V3::p; } /** @@ -229,7 +229,7 @@ public static F, P3> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V3::_1; } /** @@ -238,7 +238,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V3::_2; } /** @@ -247,7 +247,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V3::_3; } } \ No newline at end of file diff --git a/core/src/main/java/fj/data/vector/V4.java b/core/src/main/java/fj/data/vector/V4.java index 19ea2648..8e142023 100644 --- a/core/src/main/java/fj/data/vector/V4.java +++ b/core/src/main/java/fj/data/vector/V4.java @@ -30,7 +30,7 @@ private V4(final P1 head, final V3 tail) { * @return A new vector-4. */ public static V4 p(final P4 p) { - return new V4(P.lazy(() -> p._1()), + return new V4(P.lazy(p::_1), V3.p(new P3() { public A _1() { return p._2(); @@ -160,7 +160,7 @@ public NonEmptyList toNonEmptyList() { * @return a stream of the elements of this vector. */ public Stream toStream() { - return Stream.cons(head._1(), () -> tail.toStream()); + return Stream.cons(head._1(), tail::toStream); } /** @@ -233,7 +233,7 @@ public V4> vzip(final V4 bs) { * @return a function that transforms a vector-4 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V4::toStream; } /** @@ -242,7 +242,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-4 to the equivalent product-4. */ public static F, P4> p_() { - return v -> v.p(); + return V4::p; } /** @@ -251,7 +251,7 @@ public static F, P4> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V4::_1; } /** @@ -260,7 +260,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V4::_2; } /** @@ -269,7 +269,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V4::_3; } /** @@ -278,6 +278,6 @@ public static F, A> __3() { * @return a function that gets the fourth element of a given vector. */ public static F, A> __4() { - return v -> v._4(); + return V4::_4; } } diff --git a/core/src/main/java/fj/data/vector/V5.java b/core/src/main/java/fj/data/vector/V5.java index 3aab13e3..d386cb32 100644 --- a/core/src/main/java/fj/data/vector/V5.java +++ b/core/src/main/java/fj/data/vector/V5.java @@ -30,7 +30,7 @@ private V5(final P1 head, final V4 tail) { * @return A new vector-5. */ public static V5 p(final P5 p) { - return new V5(P.lazy(() -> p._1()), + return new V5(P.lazy(p::_1), V4.p(new P4() { public A _1() { return p._2(); @@ -177,7 +177,7 @@ public NonEmptyList toNonEmptyList() { * @return a stream of the elements of this vector. */ public Stream toStream() { - return Stream.cons(head._1(), () -> tail.toStream()); + return Stream.cons(head._1(), tail::toStream); } /** @@ -250,7 +250,7 @@ public V5> vzip(final V5 bs) { * @return a function that transforms a vector-5 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V5::toStream; } /** @@ -259,7 +259,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-5 to the equivalent product-5. */ public static F, P5> p_() { - return v -> v.p(); + return V5::p; } /** @@ -268,7 +268,7 @@ public static F, P5> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V5::_1; } /** @@ -277,7 +277,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V5::_2; } /** @@ -286,7 +286,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V5::_3; } /** @@ -295,7 +295,7 @@ public static F, A> __3() { * @return a function that gets the fourth element of a given vector. */ public static F, A> __4() { - return v -> v._4(); + return V5::_4; } /** @@ -304,6 +304,6 @@ public static F, A> __4() { * @return a function that gets the fifth element of a given vector. */ public static F, A> __5() { - return v -> v._5(); + return V5::_5; } } diff --git a/core/src/main/java/fj/data/vector/V6.java b/core/src/main/java/fj/data/vector/V6.java index 66a5afca..107c01a5 100644 --- a/core/src/main/java/fj/data/vector/V6.java +++ b/core/src/main/java/fj/data/vector/V6.java @@ -30,7 +30,7 @@ private V6(final P1 head, final V5 tail) { * @return A new vector-6. */ public static V6 p(final P6 p) { - return new V6(P.lazy(() -> p._1()), + return new V6(P.lazy(p::_1), V5.p(new P5() { public A _1() { return p._2(); @@ -194,7 +194,7 @@ public NonEmptyList toNonEmptyList() { * @return a stream of the elements of this vector. */ public Stream toStream() { - return Stream.cons(head._1(), () -> tail.toStream()); + return Stream.cons(head._1(), tail::toStream); } /** @@ -267,7 +267,7 @@ public V6> vzip(final V6 bs) { * @return a function that transforms a vector-6 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V6::toStream; } /** @@ -276,7 +276,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-6 to the equivalent product-6. */ public static F, P6> p_() { - return v -> v.p(); + return V6::p; } /** @@ -285,7 +285,7 @@ public static F, P6> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V6::_1; } /** @@ -294,7 +294,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V6::_2; } /** @@ -303,7 +303,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V6::_3; } /** @@ -312,7 +312,7 @@ public static F, A> __3() { * @return a function that gets the fourth element of a given vector. */ public static F, A> __4() { - return v -> v._4(); + return V6::_4; } /** @@ -321,7 +321,7 @@ public static F, A> __4() { * @return a function that gets the fifth element of a given vector. */ public static F, A> __5() { - return v -> v._5(); + return V6::_5; } /** @@ -330,7 +330,7 @@ public static F, A> __5() { * @return a function that gets the sixth element of a given vector. */ public static F, A> __6() { - return v -> v._6(); + return V6::_6; } } diff --git a/core/src/main/java/fj/data/vector/V7.java b/core/src/main/java/fj/data/vector/V7.java index c57e3551..52699481 100644 --- a/core/src/main/java/fj/data/vector/V7.java +++ b/core/src/main/java/fj/data/vector/V7.java @@ -30,7 +30,7 @@ private V7(final P1 head, final V6 tail) { * @return A new vector-7. */ public static V7 p(final P7 p) { - return new V7(P.lazy(() -> p._1()), + return new V7(P.lazy(p::_1), V6.p(new P6() { public A _1() { return p._2(); @@ -211,7 +211,7 @@ public NonEmptyList toNonEmptyList() { * @return a stream of the elements of this vector. */ public Stream toStream() { - return Stream.cons(head._1(), () -> tail.toStream()); + return Stream.cons(head._1(), tail::toStream); } /** @@ -284,7 +284,7 @@ public V7> vzip(final V7 bs) { * @return a function that transforms a vector-7 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V7::toStream; } /** @@ -293,7 +293,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-7 to the equivalent product-7. */ public static F, P7> p_() { - return v -> v.p(); + return V7::p; } /** @@ -302,7 +302,7 @@ public static F, P7> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V7::_1; } /** @@ -311,7 +311,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V7::_2; } /** @@ -320,7 +320,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V7::_3; } /** @@ -329,7 +329,7 @@ public static F, A> __3() { * @return a function that gets the fourth element of a given vector. */ public static F, A> __4() { - return v -> v._4(); + return V7::_4; } /** @@ -338,7 +338,7 @@ public static F, A> __4() { * @return a function that gets the fifth element of a given vector. */ public static F, A> __5() { - return v -> v._5(); + return V7::_5; } /** @@ -347,7 +347,7 @@ public static F, A> __5() { * @return a function that gets the sixth element of a given vector. */ public static F, A> __6() { - return v -> v._6(); + return V7::_6; } /** @@ -356,7 +356,7 @@ public static F, A> __6() { * @return a function that gets the seventh element of a given vector. */ public static F, A> __7() { - return v -> v._7(); + return V7::_7; } } diff --git a/core/src/main/java/fj/data/vector/V8.java b/core/src/main/java/fj/data/vector/V8.java index 72af03f1..8ad96cdd 100644 --- a/core/src/main/java/fj/data/vector/V8.java +++ b/core/src/main/java/fj/data/vector/V8.java @@ -30,7 +30,7 @@ private V8(final P1 head, final V7 tail) { * @return A new vector-8. */ public static V8 p(final P8 p) { - return new V8(P.lazy(() -> p._1()), + return new V8(P.lazy(p::_1), V7.p(new P7() { public A _1() { return p._2(); @@ -228,7 +228,7 @@ public NonEmptyList toNonEmptyList() { * @return a stream of the elements of this vector. */ public Stream toStream() { - return Stream.cons(head._1(), () -> tail.toStream()); + return Stream.cons(head._1(), tail::toStream); } /** @@ -301,7 +301,7 @@ public V8> vzip(final V8 bs) { * @return a function that transforms a vector-8 to a stream of its elements. */ public static F, Stream> toStream_() { - return v -> v.toStream(); + return V8::toStream; } /** @@ -310,7 +310,7 @@ public static F, Stream> toStream_() { * @return a function that transforms a vector-8 to the equivalent product-8. */ public static F, P8> p_() { - return v -> v.p(); + return V8::p; } @@ -320,7 +320,7 @@ public static F, P8> p_() { * @return a function that gets the first element of a given vector. */ public static F, A> __1() { - return v -> v._1(); + return V8::_1; } /** @@ -329,7 +329,7 @@ public static F, A> __1() { * @return a function that gets the second element of a given vector. */ public static F, A> __2() { - return v -> v._2(); + return V8::_2; } /** @@ -338,7 +338,7 @@ public static F, A> __2() { * @return a function that gets the third element of a given vector. */ public static F, A> __3() { - return v -> v._3(); + return V8::_3; } /** @@ -347,7 +347,7 @@ public static F, A> __3() { * @return a function that gets the fourth element of a given vector. */ public static F, A> __4() { - return v -> v._4(); + return V8::_4; } /** @@ -356,7 +356,7 @@ public static F, A> __4() { * @return a function that gets the fifth element of a given vector. */ public static F, A> __5() { - return v -> v._5(); + return V8::_5; } /** @@ -365,7 +365,7 @@ public static F, A> __5() { * @return a function that gets the sixth element of a given vector. */ public static F, A> __6() { - return v -> v._6(); + return V8::_6; } /** @@ -374,7 +374,7 @@ public static F, A> __6() { * @return a function that gets the seventh element of a given vector. */ public static F, A> __7() { - return v -> v._7(); + return V8::_7; } /** @@ -383,7 +383,7 @@ public static F, A> __7() { * @return a function that gets the eighth element of a given vector. */ public static F, A> __8() { - return v -> v._8(); + return V8::_8; } } diff --git a/core/src/main/java/fj/function/BigIntegers.java b/core/src/main/java/fj/function/BigIntegers.java index 97f1a520..30d07a10 100644 --- a/core/src/main/java/fj/function/BigIntegers.java +++ b/core/src/main/java/fj/function/BigIntegers.java @@ -1,6 +1,7 @@ package fj.function; import fj.F; +import fj.F2; import fj.Monoid; import fj.data.List; import static fj.Function.curry; @@ -21,40 +22,40 @@ private BigIntegers() { * Curried Integer addition. */ public static final F> add = - curry((a1, a2) -> a1.add(a2)); + curry((F2) BigInteger::add); /** * Curried Integer multiplication. */ public static final F> multiply = - curry((a1, a2) -> a1.multiply(a2)); + curry(BigInteger::multiply); /** * Curried Integer subtraction. */ public static final F> subtract = - curry((a1, a2) -> a1.subtract(a2)); + curry((F2) BigInteger::subtract); /** * Negation. */ - public static final F negate = i -> i.negate(); + public static final F negate = BigInteger::negate; /** * Absolute value. */ - public static final F abs = i -> i.abs(); + public static final F abs = BigInteger::abs; /** * Remainder. */ public static final F> remainder = - curry((a1, a2) -> a1.remainder(a2)); + curry(BigInteger::remainder); /** * Power. */ - public static final F> power = curry((a1, a2) -> a1.pow(a2)); + public static final F> power = curry(BigInteger::pow); /** * Sums a list of big integers. diff --git a/core/src/main/java/fj/function/Characters.java b/core/src/main/java/fj/function/Characters.java index 9191bd5a..220bea7a 100644 --- a/core/src/main/java/fj/function/Characters.java +++ b/core/src/main/java/fj/function/Characters.java @@ -12,30 +12,30 @@ private Characters() { throw new UnsupportedOperationException(); } public static final F toString = c -> Character.toString(c); - public static final F isLowerCase = ch -> Character.isLowerCase(ch); - public static final F isUpperCase = ch -> Character.isUpperCase(ch); - public static final F isTitleCase = ch -> Character.isTitleCase(ch); - public static final F isDigit = ch -> Character.isDigit(ch); - public static final F isDefined = ch -> Character.isDefined(ch); - public static final F isLetter = ch -> Character.isLetter(ch); - public static final F isLetterOrDigit = ch -> Character.isLetterOrDigit(ch); - public static final F isJavaIdentifierStart = ch -> Character.isJavaIdentifierStart(ch); - public static final F isJavaIdentifierPart = ch -> Character.isJavaIdentifierPart(ch); - public static final F isUnicodeIdentifierStart = ch -> Character.isUnicodeIdentifierStart(ch); - public static final F isUnicodeIdentifierPart = ch -> Character.isUnicodeIdentifierPart(ch); - public static final F isIdentifierIgnorable = ch -> Character.isIdentifierIgnorable(ch); - public static final F toLowerCase = ch -> Character.toLowerCase(ch); - public static final F toUpperCase = ch -> Character.toUpperCase(ch); - public static final F toTitleCase = ch -> Character.toTitleCase(ch); + public static final F isLowerCase = Character::isLowerCase; + public static final F isUpperCase = Character::isUpperCase; + public static final F isTitleCase = Character::isTitleCase; + public static final F isDigit = Character::isDigit; + public static final F isDefined = Character::isDefined; + public static final F isLetter = Character::isLetter; + public static final F isLetterOrDigit = Character::isLetterOrDigit; + public static final F isJavaIdentifierStart = Character::isJavaIdentifierStart; + public static final F isJavaIdentifierPart = Character::isJavaIdentifierPart; + public static final F isUnicodeIdentifierStart = Character::isUnicodeIdentifierStart; + public static final F isUnicodeIdentifierPart = Character::isUnicodeIdentifierPart; + public static final F isIdentifierIgnorable = Character::isIdentifierIgnorable; + public static final F toLowerCase = Character::toLowerCase; + public static final F toUpperCase = Character::toUpperCase; + public static final F toTitleCase = Character::toTitleCase; public static final F> digit = curry((ch, radix) -> Character.digit(ch, radix)); - public static final F getNumericValue = ch -> Character.getNumericValue(ch); - public static final F isSpaceChar = ch -> Character.isSpaceChar(ch); - public static final F isWhitespace = ch -> Character.isWhitespace(ch); - public static final F isISOControl = ch -> Character.isISOControl(ch); - public static final F getType = ch -> Character.getType(ch); - public static final F getDirectionality = ch -> Character.getDirectionality(ch); - public static final F isMirrored = ch -> Character.isMirrored(ch); - public static final F reverseBytes = ch -> Character.reverseBytes(ch); + public static final F getNumericValue = Character::getNumericValue; + public static final F isSpaceChar = Character::isSpaceChar; + public static final F isWhitespace = Character::isWhitespace; + public static final F isISOControl = Character::isISOControl; + public static final F getType = Character::getType; + public static final F getDirectionality = Character::getDirectionality; + public static final F isMirrored = Character::isMirrored; + public static final F reverseBytes = Character::reverseBytes; public static final F isNewLine = c -> c == '\n'; } diff --git a/core/src/main/java/fj/function/Doubles.java b/core/src/main/java/fj/function/Doubles.java index 1a85a100..7bff2409 100644 --- a/core/src/main/java/fj/function/Doubles.java +++ b/core/src/main/java/fj/function/Doubles.java @@ -45,7 +45,7 @@ private Doubles() { /** * Absolute value. */ - public static final F abs = x -> abs(x); + public static final F abs = Math::abs; /** * Remainder. @@ -55,7 +55,7 @@ private Doubles() { /** * Power. */ - public static final F> power = curry((a, b) -> StrictMath.pow(a, b)); + public static final F> power = curry(StrictMath::pow); /** * Evenness. diff --git a/core/src/main/java/fj/function/Integers.java b/core/src/main/java/fj/function/Integers.java index c51359e4..4b1b14b5 100644 --- a/core/src/main/java/fj/function/Integers.java +++ b/core/src/main/java/fj/function/Integers.java @@ -47,7 +47,7 @@ private Integers() { /** * Absolute value. */ - public static final F abs = x -> abs(x); + public static final F abs = Math::abs; /** * Remainder. diff --git a/core/src/main/java/fj/function/Longs.java b/core/src/main/java/fj/function/Longs.java index a1bd60eb..18667699 100644 --- a/core/src/main/java/fj/function/Longs.java +++ b/core/src/main/java/fj/function/Longs.java @@ -41,7 +41,7 @@ private Longs() { /** * Absolute value. */ - public static final F abs = x -> abs(x); + public static final F abs = Math::abs; /** * Remainder. diff --git a/core/src/main/java/fj/function/Strings.java b/core/src/main/java/fj/function/Strings.java index 88e9cc2f..c64db043 100644 --- a/core/src/main/java/fj/function/Strings.java +++ b/core/src/main/java/fj/function/Strings.java @@ -61,7 +61,7 @@ private Strings() { /** * A curried version of {@link String#length()}. */ - public static final F length = s -> s.length(); + public static final F length = String::length; /** * A curried version of {@link String#contains(CharSequence)}. @@ -80,17 +80,17 @@ public static List lines(String s) { } public static F> lines() { - return s -> lines(s); + return Strings::lines; } public static String unlines(List list) { StringBuilder sb = new StringBuilder(); - list.intersperse(lineSeparator).foreachDoEffect(s -> sb.append(s)); + list.intersperse(lineSeparator).foreachDoEffect(sb::append); return sb.toString(); } public static F, String> unlines() { - return l -> unlines(l); + return Strings::unlines; } } diff --git a/core/src/main/java/fj/parser/Parser.java b/core/src/main/java/fj/parser/Parser.java index e5ce04c9..605125f0 100644 --- a/core/src/main/java/fj/parser/Parser.java +++ b/core/src/main/java/fj/parser/Parser.java @@ -210,7 +210,7 @@ public Parser sequence(final Parser p) { * @return A new parser after function application. */ public Parser apply(final Parser, E> p) { - return p.bind((F, Parser>) f1 -> map(f1)); + return p.bind((F, Parser>) this::map); } /** @@ -549,7 +549,7 @@ public static Parser, String, E> string(final E missing, f * @return A parser that produces a digit (0 to 9). */ public static Parser, Digit, E> digit(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isDigit(c)).map(c1 -> Digit.fromChar(c1).some()); + return StreamParser.satisfy(missing, sat, Character::isDigit).map(c1 -> Digit.fromChar(c1).some()); } /** @@ -572,7 +572,7 @@ public static Parser, Digit, E> digit(final E missing, fin * @see Character#isLowerCase(char) */ public static Parser, Character, E> lower(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isLowerCase(c)); + return StreamParser.satisfy(missing, sat, Character::isLowerCase); } /** @@ -596,7 +596,7 @@ public static Parser, Character, E> lower(final E missing, * @see Character#isUpperCase(char) */ public static Parser, Character, E> upper(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isUpperCase(c)); + return StreamParser.satisfy(missing, sat, Character::isUpperCase); } /** @@ -620,7 +620,7 @@ public static Parser, Character, E> upper(final E missing, * @see Character#isDefined(char) */ public static Parser, Character, E> defined(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isDefined(c)); + return StreamParser.satisfy(missing, sat, Character::isDefined); } /** @@ -645,7 +645,7 @@ public static Parser, Character, E> defined(final E missin */ public static Parser, Character, E> highSurrogate(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isHighSurrogate(c)); + return StreamParser.satisfy(missing, sat, Character::isHighSurrogate); } /** @@ -671,7 +671,7 @@ public static Parser, Character, E> highSurrogate(final E */ public static Parser, Character, E> identifierIgnorable(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isIdentifierIgnorable(c)); + return StreamParser.satisfy(missing, sat, Character::isIdentifierIgnorable); } /** @@ -697,7 +697,7 @@ public static Parser, Character, E> identifierIgnorable(fi */ public static Parser, Character, E> isoControl(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isISOControl(c)); + return StreamParser.satisfy(missing, sat, Character::isISOControl); } /** @@ -722,7 +722,7 @@ public static Parser, Character, E> isoControl(final E mis */ public static Parser, Character, E> javaIdentifierPart(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isJavaIdentifierPart(c)); + return StreamParser.satisfy(missing, sat, Character::isJavaIdentifierPart); } /** @@ -748,7 +748,7 @@ public static Parser, Character, E> javaIdentifierPart(fin */ public static Parser, Character, E> javaIdentifierStart(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isJavaIdentifierStart(c)); + return StreamParser.satisfy(missing, sat, Character::isJavaIdentifierStart); } /** @@ -773,7 +773,7 @@ public static Parser, Character, E> javaIdentifierStart(fi * @see Character#isLetter(char) */ public static Parser, Character, E> alpha(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isLetter(c)); + return StreamParser.satisfy(missing, sat, Character::isLetter); } /** @@ -797,7 +797,7 @@ public static Parser, Character, E> alpha(final E missing, * @see Character#isLetterOrDigit(char) */ public static Parser, Character, E> alphaNum(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isLetterOrDigit(c)); + return StreamParser.satisfy(missing, sat, Character::isLetterOrDigit); } /** @@ -822,7 +822,7 @@ public static Parser, Character, E> alphaNum(final E missi */ public static Parser, Character, E> lowSurrogate(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isLowSurrogate(c)); + return StreamParser.satisfy(missing, sat, Character::isLowSurrogate); } /** @@ -846,7 +846,7 @@ public static Parser, Character, E> lowSurrogate(final E m * @see Character#isMirrored(char) */ public static Parser, Character, E> mirrored(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isMirrored(c)); + return StreamParser.satisfy(missing, sat, Character::isMirrored); } /** @@ -870,7 +870,7 @@ public static Parser, Character, E> mirrored(final E missi * @see Character#isSpace(char) */ public static Parser, Character, E> space(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isSpaceChar(c)); + return StreamParser.satisfy(missing, sat, Character::isSpaceChar); } /** @@ -895,7 +895,7 @@ public static Parser, Character, E> space(final E missing, */ public static Parser, Character, E> titleCase(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isTitleCase(c)); + return StreamParser.satisfy(missing, sat, Character::isTitleCase); } /** @@ -920,7 +920,7 @@ public static Parser, Character, E> titleCase(final E miss */ public static Parser, Character, E> unicodeIdentiferPart(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isUnicodeIdentifierPart(c)); + return StreamParser.satisfy(missing, sat, Character::isUnicodeIdentifierPart); } /** @@ -946,7 +946,7 @@ public static Parser, Character, E> unicodeIdentiferPart(f */ public static Parser, Character, E> unicodeIdentiferStart(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isUnicodeIdentifierStart(c)); + return StreamParser.satisfy(missing, sat, Character::isUnicodeIdentifierStart); } /** @@ -972,7 +972,7 @@ public static Parser, Character, E> unicodeIdentiferStart( */ public static Parser, Character, E> whitespace(final F0 missing, final F sat) { - return StreamParser.satisfy(missing, sat, c -> Character.isWhitespace(c)); + return StreamParser.satisfy(missing, sat, Character::isWhitespace); } /** diff --git a/core/src/main/java/fj/parser/Result.java b/core/src/main/java/fj/parser/Result.java index f450a054..8f5a4b78 100644 --- a/core/src/main/java/fj/parser/Result.java +++ b/core/src/main/java/fj/parser/Result.java @@ -55,7 +55,7 @@ public Result mapRest(final F f) { * @return A first-class function mapping across the remainder of the parse input. */ public F, Result> mapRest() { - return f -> mapRest(f); + return this::mapRest; } /** @@ -74,7 +74,7 @@ public Result mapValue(final F f) { * @return A first-class function mapping across the parse value. */ public F, Result> mapValue() { - return f -> mapValue(f); + return this::mapValue; } /** @@ -94,7 +94,7 @@ public Result bimap(final F f, final F g) { * @return A first-class bifunctor map. */ public F, F, Result>> bimap() { - return curry((f, g) -> bimap(f, g)); + return curry(this::bimap); } /** @@ -142,7 +142,7 @@ public static Result result(final I i, final A a) { * @return A first-class function for construction of a result. */ public static F>> result() { - return curry((i, a) -> result(i, a)); + return curry(Result::result); } } diff --git a/demo/src/main/java/fj/demo/IODemo.java b/demo/src/main/java/fj/demo/IODemo.java index 316eafc4..0bc7db12 100644 --- a/demo/src/main/java/fj/demo/IODemo.java +++ b/demo/src/main/java/fj/demo/IODemo.java @@ -37,7 +37,7 @@ public void readFirstShortLine() { * Read a stream of input lazily using interact, in effect reading the first line */ public void readFirstLine() { - F f = lift((LazyString s) -> s.lines()).andThen(unlines_()); + F f = lift(LazyString::lines).andThen(unlines_()); runSafe(interact(f)); } diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index b4d3dae2..69b27202 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -298,7 +298,7 @@ private static P2, Map> writeSampleFiles( public static Map getWordsAndCountsFromFilesWithIteratee(final List fileNames, final F> fileNameToWordsAndCountsWithIteratee) { final List> maps = fileNames.map(fileNameToWordsAndCountsWithIteratee); - return maps.foldLeft((Map a, Map b) -> plus(a, b), new HashMap()); + return maps.foldLeft(WordCount::plus, new HashMap()); } public static Map getWordsAndCountsFromFilesInParallel( diff --git a/demo/src/main/java/fj/demo/realworld/Chapter7.java b/demo/src/main/java/fj/demo/realworld/Chapter7.java index f9263683..c239a5bf 100644 --- a/demo/src/main/java/fj/demo/realworld/Chapter7.java +++ b/demo/src/main/java/fj/demo/realworld/Chapter7.java @@ -28,7 +28,7 @@ public static void main(String[] args) { public static void toUpperLazy() { runSafe(interact(ls -> { Stream stream = ls.lines().map((LazyString ls2) -> ls2.eval().toUpperCase()); - return LazyString.unlines(stream.map(s -> LazyString.str(s))); + return LazyString.unlines(stream.map(LazyString::str)); })); } @@ -46,7 +46,7 @@ public static void toUpperByLine() { * uppercase line to stdout */ public static void toUpperInteract() { - runSafe(interactWhile(s -> s.trim().length() > 0, s -> s.toUpperCase())); + runSafe(interactWhile(s -> s.trim().length() > 0, String::toUpperCase)); } } diff --git a/demo/src/main/java/fj/demo/test/EqualsHashCode.java b/demo/src/main/java/fj/demo/test/EqualsHashCode.java index 814f7112..c5b0a898 100644 --- a/demo/src/main/java/fj/demo/test/EqualsHashCode.java +++ b/demo/src/main/java/fj/demo/test/EqualsHashCode.java @@ -62,7 +62,7 @@ public static void main(final String[] args) { // Arbitrary for MyClass that uses the restrictive arbitraries above. // We are using the monad pattern (bind) to make this a trivial exercise. - final Arbitrary arbMyClass = arbitrary(arbByteR.gen.bind(arbStringR.gen, curry((b, s) -> new MyClass(b, s)))); + final Arbitrary arbMyClass = arbitrary(arbByteR.gen.bind(arbStringR.gen, curry(MyClass::new))); // Finally the property. // if m1 equals m2, then this implies that m1's hashCode is equal to m2's hashCode. diff --git a/java8/src/main/java/fj/data/Java8.java b/java8/src/main/java/fj/data/Java8.java index 93fd1e9e..d893a370 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/java8/src/main/java/fj/data/Java8.java @@ -32,7 +32,7 @@ public static P1 Supplier_P1(final Supplier s) { } public static F, P1> Supplier_P1() { - return s -> P.lazy(() -> s.get()); + return s -> P.lazy(s::get); } public static Supplier P1_Supplier(final P1 p) { @@ -40,7 +40,7 @@ public static Supplier P1_Supplier(final P1 p) { } public static F, Supplier> P1_Supplier() { - return (p) -> () -> p._1(); + return (p) -> p::_1; } public static F Function_F(final Function f) { @@ -48,7 +48,7 @@ public static F Function_F(final Function f) { } public static F, F> Function_F() { - return f -> a -> f.apply(a); + return f -> f::apply; } public static Function F_Function(final F f) { @@ -56,7 +56,7 @@ public static Function F_Function(final F f) { } public static F, Function> F_Function() { - return f -> a -> f.f(a); + return f -> f::f; } public static F2 BiFunction_F2(final BiFunction f) { @@ -64,7 +64,7 @@ public static F2 BiFunction_F2(final BiFunction f) { } public static F, F2> BiFunction_F2() { - return f -> (a, b) -> f.apply(a, b); + return f -> f::apply; } public static BiFunction F2_BiFunction(final F2 f) { @@ -72,7 +72,7 @@ public static BiFunction F2_BiFunction(final F2 f) { } public static F, BiFunction> F2_BiFunction() { - return f -> (a, b) -> f.f(a, b); + return f -> f::f; } public static Supplier> TryCatch0_Supplier(final Try0 t) { @@ -120,7 +120,7 @@ public static F, Optional> Option_Optional() { } public static F, F> Consumer_F() { - return c -> Consumer_F(c); + return Java8::Consumer_F; } public static F Consumer_F(final Consumer c) { @@ -143,7 +143,7 @@ public static java.util.stream.Stream Iterator_JavaStream(final Iterator< } public static F, java.util.stream.Stream> Stream_JavaStream() { - return s -> Stream_JavaStream(s); + return Java8::Stream_JavaStream; } public static Stream JavaStream_Stream(final java.util.stream.Stream s) { diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 1e619f21..7b96d299 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -13,6 +13,8 @@ import static fj.Function.compose; import static fj.P.p; + +import fj.P; import fj.P1; import fj.P2; import fj.P3; @@ -32,6 +34,9 @@ import static fj.data.List.list; import static fj.data.Option.some; +import fj.data.List; +import fj.data.Set; +import fj.data.TreeMap; import fj.function.Effect1; import static fj.data.Stream.range; @@ -50,29 +55,13 @@ import java.math.BigInteger; import java.sql.Time; import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.BitSet; -import java.util.Calendar; -import java.util.Date; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.IdentityHashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Locale; +import java.util.*; + import static java.util.Locale.getAvailableLocales; -import java.util.PriorityQueue; -import java.util.Properties; -import java.util.Stack; -import java.util.TreeSet; -import java.util.Vector; -import java.util.WeakHashMap; import static java.util.EnumSet.copyOf; + +import java.util.HashMap; +import java.util.HashSet; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -127,21 +116,21 @@ public Gen f(final A x) { } public static Arbitrary> arbReader(Coarbitrary aa, Arbitrary ab) { - return arbitrary(arbF(aa, ab).gen.map(f -> Reader.unit(f))); + return arbitrary(arbF(aa, ab).gen.map(Reader::unit)); } /** * An arbitrary for state. */ public static Arbitrary> arbState(Arbitrary as, Coarbitrary cs, Arbitrary aa) { - return arbitrary(arbF(cs, arbP2(as, aa)).gen.map(f -> State.unit(f))); + return arbitrary(arbF(cs, arbP2(as, aa)).gen.map(State::unit)); } /** * An arbitrary for the LcgRng. */ public static Arbitrary arbLcgRng() { - return arbitrary(Arbitrary.arbLong.gen.map(l -> new LcgRng(l))); + return arbitrary(Arbitrary.arbLong.gen.map(LcgRng::new)); } /** @@ -611,11 +600,7 @@ public Gen f(final Integer i) { * An arbitrary implementation for string values. */ public static final Arbitrary arbString = - arbitrary(arbList(arbCharacter).gen.map(new F, String>() { - public String f(final List cs) { - return asString(cs); - } - })); + arbitrary(arbList(arbCharacter).gen.map(List::asString)); /** * An arbitrary implementation for string values with characters in the US-ASCII range. @@ -643,21 +628,13 @@ public Character f(final Character c) { * An arbitrary implementation for string buffer values. */ public static final Arbitrary arbStringBuffer = - arbitrary(arbString.gen.map(new F() { - public StringBuffer f(final String s) { - return new StringBuffer(s); - } - })); + arbitrary(arbString.gen.map(StringBuffer::new)); /** * An arbitrary implementation for string builder values. */ public static final Arbitrary arbStringBuilder = - arbitrary(arbString.gen.map(new F() { - public StringBuilder f(final String s) { - return new StringBuilder(s); - } - })); + arbitrary(arbString.gen.map(StringBuilder::new)); /** * Returns an arbitrary implementation for generators. @@ -672,11 +649,7 @@ public Gen> f(final Integer i) { if (i == 0) return fail(); else - return aa.gen.map(new F>() { - public Gen f(final A a) { - return value(a); - } - }).resize(i - 1); + return aa.gen.map(Gen::value).resize(i - 1); } })); } @@ -692,11 +665,7 @@ public static Arbitrary> arbOption(final Arbitrary aa) { public Gen> f(final Integer i) { return i == 0 ? value(Option.none()) : - aa.gen.map(new F>() { - public Option f(final A a) { - return some(a); - } - }).resize(i - 1); + aa.gen.map(Option::some).resize(i - 1); } })); } @@ -712,16 +681,8 @@ public Option f(final A a) { */ @SuppressWarnings("unchecked") public static Arbitrary> arbEither(final Arbitrary aa, final Arbitrary ab) { - final Gen> left = aa.gen.map(new F>() { - public Either f(final A a) { - return left(a); - } - }); - final Gen> right = ab.gen.map(new F>() { - public Either f(final B b) { - return right(b); - } - }); + final Gen> left = aa.gen.map(Either::left); + final Gen> right = ab.gen.map(Either::right); return arbitrary(oneOf(list(left, right))); } @@ -771,7 +732,7 @@ public static Arbitrary> arbNonEmptyList(final Arbitrary * Returns an arbitrary Validation for the given arbitrary parameters. */ public static Arbitrary> arbValidation(final Arbitrary aa, final Arbitrary ab) { - return arbitrary(arbBoolean.gen.bind(bool -> bool ? ab.gen.map(b -> Validation.success(b)) : aa.gen.map(a -> Validation.fail(a)))); + return arbitrary(arbBoolean.gen.bind(bool -> bool ? ab.gen.map(Validation::success) : aa.gen.map(Validation::fail))); } /** @@ -781,11 +742,7 @@ public static Arbitrary> arbValidation(final Arbitrary Arbitrary> arbStream(final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(new F, Stream>() { - public Stream f(final List as) { - return as.toStream(); - } - })); + return arbitrary(arbList(aa).gen.map(List::toStream)); } /** @@ -795,11 +752,7 @@ public Stream f(final List as) { * @return An arbitrary implementation for arrays. */ public static Arbitrary> arbArray(final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(new F, Array>() { - public Array f(final List as) { - return as.toArray(); - } - })); + return arbitrary(arbList(aa).gen.map(List::toArray)); } /** @@ -830,11 +783,7 @@ public static Arbitrary> arbSet(Ord ord, final Arbitrary aa, in * @return An arbitrary implementation for throwables. */ public static Arbitrary arbThrowable(final Arbitrary as) { - return arbitrary(as.gen.map(new F() { - public Throwable f(final String msg) { - return new Throwable(msg); - } - })); + return arbitrary(as.gen.map(Throwable::new)); } /** @@ -888,11 +837,7 @@ public Calendar f(final Long i) { /** * An arbitrary implementation for dates. */ - public static final Arbitrary arbDate = arbitrary(arbLong.gen.map(new F() { - public Date f(final Long i) { - return new Date(i); - } - })); + public static final Arbitrary arbDate = arbitrary(arbLong.gen.map(Date::new)); /** * Returns an arbitrary implementation for a Java enumeration. @@ -914,12 +859,7 @@ public static > Arbitrary arbEnumValue(final Class clazz */ public static , V> Arbitrary> arbEnumMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, EnumMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public EnumMap f(final Hashtable ht) { - return new EnumMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(EnumMap::new)); } /** @@ -957,12 +897,7 @@ public GregorianCalendar f(final Long i) { * @return An arbitrary implementation for hash maps. */ public static Arbitrary> arbHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, HashMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public HashMap f(final Hashtable ht) { - return new HashMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(HashMap::new)); } /** @@ -1020,12 +955,7 @@ public void f(final P2 kv) { */ public static Arbitrary> arbIdentityHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, IdentityHashMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public IdentityHashMap f(final Hashtable ht) { - return new IdentityHashMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(IdentityHashMap::new)); } /** @@ -1038,12 +968,7 @@ public IdentityHashMap f(final Hashtable ht) { * @return An arbitrary implementation for linked hash maps. */ public static Arbitrary> arbLinkedHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, LinkedHashMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public LinkedHashMap f(final Hashtable ht) { - return new LinkedHashMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(LinkedHashMap::new)); } /** @@ -1130,12 +1055,7 @@ public Stack f(final Array a) { * @return An arbitrary implementation for tree maps. */ public static Arbitrary> arbJavaTreeMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, java.util.TreeMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public java.util.TreeMap f(final Hashtable ht) { - return new java.util.TreeMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(java.util.TreeMap::new)); } /** @@ -1215,12 +1135,7 @@ public Vector f(final Array a) { * @return An arbitrary implementation for weak hash maps. */ public static Arbitrary> arbWeakHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, WeakHashMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public WeakHashMap f(final Hashtable ht) { - return new WeakHashMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(WeakHashMap::new)); } // END java.util @@ -1263,12 +1178,7 @@ public ArrayBlockingQueue f(final Boolean fair) { */ public static Arbitrary> arbConcurrentHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(new F, ConcurrentHashMap>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public ConcurrentHashMap f(final Hashtable ht) { - return new ConcurrentHashMap(ht); - } - })); + return arbitrary(arbHashtable(ak, av).gen.map(ConcurrentHashMap::new)); } /** @@ -1388,29 +1298,17 @@ public SynchronousQueue f(final Boolean fair) { /** * An arbitrary implementation for SQL dates. */ - public static final Arbitrary arbSQLDate = arbitrary(arbLong.gen.map(new F() { - public java.sql.Date f(final Long i) { - return new java.sql.Date(i); - } - })); + public static final Arbitrary arbSQLDate = arbitrary(arbLong.gen.map(java.sql.Date::new)); /** * An arbitrary implementation for SQL times. */ - public static final Arbitrary Arbitrary> arbP1(final Arbitrary aa) { - return arbitrary(aa.gen.map(new F>() { - public P1 f(final A a) { - return p(a); - } - })); + return arbitrary(aa.gen.map(P::p)); } /** diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 0aa11adb..b3bb1371 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -294,11 +294,7 @@ public Gen bind(final Gen gb, final Gen gc, final Gen g public Gen apply(final Gen> gf) { return gf.bind(new F, Gen>() { public Gen f(final F f) { - return map(new F() { - public B f(final A a) { - return f.f(a); - } - }); + return map(f::f); } }); } @@ -492,11 +488,7 @@ public Gen f(final Integer i) { public static Gen elemFrequency(final List> as) { return frequency(as.map(new F, P2>>() { public P2> f(final P2 p) { - return p.map2(new F>() { - public Gen f(final A a) { - return value(a); - } - }); + return p.map2(Gen::value); } })); } @@ -525,11 +517,7 @@ public A f(final Integer i) { * requests. */ public static Gen oneOf(final List> gs) { - return gs.isEmpty() ? Gen.fail() : choose(0, gs.length() - 1).bind(new F>() { - public Gen f(final Integer i) { - return gs.index(i); - } - }); + return gs.isEmpty() ? Gen.fail() : choose(0, gs.length() - 1).bind(gs::index); } /** diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 1486a695..d0eeb5ae 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -469,11 +469,7 @@ public P2 f(final Result result) { if (results.isEmpty()) return none(); - else return results.find(new F>, Boolean>() { - public Boolean f(final Option> o) { - return failed(o); - } - }).orSome(() -> results.head()); + else return results.find(this::failed).orSome(results::head); } public boolean failed(final Option> o) { diff --git a/quickcheck/src/main/java/fj/test/Result.java b/quickcheck/src/main/java/fj/test/Result.java index 40130542..467e2ae2 100644 --- a/quickcheck/src/main/java/fj/test/Result.java +++ b/quickcheck/src/main/java/fj/test/Result.java @@ -156,7 +156,7 @@ public Option toOption() { * @return The result that may be {@link #noResult() noResult()}. */ public static Result noResult(final Option r) { - return r.orSome(() -> noResult()); + return r.orSome(Result::noResult); } /** diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index a9d1aa21..751a1307 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -235,7 +235,7 @@ else if (as.tail().isEmpty()) .map(aas1 -> aas1.append(as2)) .interleave(removeChunks(n2, as2) .filter(isNotEmpty) - .map(aas -> as1.append(aas))))); + .map(as1::append)))); }) ); } @@ -301,7 +301,7 @@ public static Shrink> shrinkStream(final Shrink sa) { * @return A shrink strategy for throwables. */ public static Shrink shrinkThrowable(final Shrink ss) { - return ss.map(s -> new Throwable(s), t -> t.getMessage()); + return ss.map(Throwable::new, Throwable::getMessage); } /** @@ -341,7 +341,7 @@ public static Shrink> shrinkArrayList(final Shrink sa) { * A shrink strategy for dates. */ public static final Shrink shrinkDate = - shrinkLong.map(i -> new Date(i), d -> d.getTime()); + shrinkLong.map(Date::new, Date::getTime); /** * A shrink strategy for enum maps. @@ -351,7 +351,7 @@ public static Shrink> shrinkArrayList(final Shrink sa) { * @return A shrink strategy for enum maps. */ public static , V> Shrink> shrinkEnumMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new EnumMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(EnumMap::new, Hashtable::new); } /** @@ -382,7 +382,7 @@ public static > Shrink> shrinkEnumSet(final Shrink< * @return A shrink strategy for hash maps. */ public static Shrink> shrinkHashMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new HashMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(HashMap::new, Hashtable::new); } /** @@ -427,7 +427,7 @@ public static Shrink> shrinkHashtable(final Shrink sk, * @return A shrink strategy for identity hash maps. */ public static Shrink> shrinkIdentityHashMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new IdentityHashMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(IdentityHashMap::new, Hashtable::new); } /** @@ -438,7 +438,7 @@ public static Shrink> shrinkIdentityHashMap(final S * @return A shrink strategy for linked hash maps. */ public static Shrink> shrinkLinkedHashMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new LinkedHashMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(LinkedHashMap::new, Hashtable::new); } /** @@ -511,7 +511,7 @@ public static Shrink> shrinkStack(final Shrink sa) { * @return A shrink strategy for tree maps. */ public static Shrink> shrinkTreeMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new TreeMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(TreeMap::new, Hashtable::new); } /** @@ -542,7 +542,7 @@ public static Shrink> shrinkVector(final Shrink sa) { * @return A shrink strategy for weak hash maps. */ public static Shrink> shrinkWeakHashMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new WeakHashMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(WeakHashMap::new, Hashtable::new); } // END java.util @@ -567,7 +567,7 @@ public static Shrink> shrinkArrayBlockingQueue(final S * @return A shrink strategy for concurrent hash maps. */ public static Shrink> shrinkConcurrentHashMap(final Shrink sk, final Shrink sv) { - return shrinkHashtable(sk, sv).map(h -> new ConcurrentHashMap(h), m -> new Hashtable(m)); + return shrinkHashtable(sk, sv).map(ConcurrentHashMap::new, Hashtable::new); } /** @@ -648,19 +648,19 @@ public static Shrink> shrinkSynchronousQueue(final Shrin * A shrink strategy for SQL dates. */ public static final Shrink shrinkSQLDate = - shrinkLong.map(i -> new java.sql.Date(i), c -> c.getTime()); + shrinkLong.map(java.sql.Date::new, Date::getTime); /** * A shrink strategy for SQL times. */ public static final Shrink Shrink> shrinkSynchronousQueue(final Shrin * A shrink strategy for big decimals. */ public static final Shrink shrinkBigDecimal = - shrinkBigInteger.map(i -> new BigDecimal(i), d -> d.toBigInteger()); + shrinkBigInteger.map(BigDecimal::new, BigDecimal::toBigInteger); // END java.math @@ -702,7 +702,7 @@ public static Shrink> shrinkSynchronousQueue(final Shrin * @return a shrinking strategy for product-1 values. */ public static Shrink> shrinkP1(final Shrink sa) { - return shrink(p -> sa.shrink(p._1()).map(a -> p(a))); + return shrink(p -> sa.shrink(p._1()).map(P::p)); } /** diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index 5b7dbbb3..a4994bcb 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -300,11 +300,7 @@ public Boolean f(final String cs) { } }; - final F nameS = new F() { - public String f(final Name name) { - return name.value(); - } - }; + final F nameS = Name::value; return ms.filter(new F() { public Boolean f(final PropertyMember m) { From a93c54c2d274b731c57b3fce6791e9e996b6b9ac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 22:39:50 +0100 Subject: [PATCH 044/336] Use lambda syntax instead of anonymous class whenever possible --- core/src/main/java/fj/control/Trampoline.java | 18 +- .../java/fj/control/parallel/Callables.java | 28 +- .../java/fj/control/parallel/Strategy.java | 4 +- core/src/main/java/fj/data/IOFunctions.java | 245 +++--- core/src/main/java/fj/data/Iteratee.java | 11 +- core/src/main/java/fj/data/Java.java | 12 +- core/src/main/java/fj/data/NonEmptyList.java | 10 +- core/src/main/java/fj/data/TreeZipper.java | 19 +- .../main/java/fj/data/fingertrees/Deep.java | 712 +++++------------- demo/src/main/java/fj/demo/ChequeWrite.java | 24 +- demo/src/main/java/fj/demo/List_groupBy.java | 12 +- .../java/fj/demo/concurrent/PingPong.java | 16 +- .../java/fj/demo/concurrent/WordCount.java | 70 +- .../src/main/java/fj/demo/euler/Problem2.java | 5 +- .../java/fj/demo/test/ListFunctorLaws.java | 8 +- demo/src/main/java/fj/demo/test/Reflect.java | 8 +- .../fj/demo/test/StringBuilderReverse.java | 6 +- .../src/main/java/fj/test/Arbitrary.java | 454 ++--------- .../src/main/java/fj/test/Coarbitrary.java | 12 +- quickcheck/src/main/java/fj/test/Gen.java | 98 +-- .../src/main/java/fj/test/Property.java | 488 ++---------- .../src/main/java/fj/test/reflect/Check.java | 211 +++--- .../src/main/java/fj/test/reflect/Main.java | 8 +- 23 files changed, 640 insertions(+), 1839 deletions(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 140deeaa..a41c7a03 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -52,16 +52,14 @@ public Trampoline bind(final F> f) { // The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result // gets shifted into the continuation. public Either>, A> resume() { - return left(sub.resume().either(p -> { - return p.map(ot -> { - // WARNING: In JDK 8, update 25 (current version) the following code is a - // workaround for an internal JDK compiler error, likely due to - // https:bugs.openjdk.java.net/browse/JDK-8062253. - F, Trampoline> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont)); - F, Trampoline> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont)); - return ot.fold(f, g); - }); - }, o -> P.lazy(() -> cont.f(o)))); + return left(sub.resume().either(p -> p.map(ot -> { + // WARNING: In JDK 8, update 25 (current version) the following code is a + // workaround for an internal JDK compiler error, likely due to + // https:bugs.openjdk.java.net/browse/JDK-8062253. + F, Trampoline> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont)); + F, Trampoline> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont)); + return ot.fold(f, g); + }), o -> P.lazy(() -> cont.f(o)))); } } diff --git a/core/src/main/java/fj/control/parallel/Callables.java b/core/src/main/java/fj/control/parallel/Callables.java index 40c8e746..7c2a7221 100644 --- a/core/src/main/java/fj/control/parallel/Callables.java +++ b/core/src/main/java/fj/control/parallel/Callables.java @@ -216,14 +216,12 @@ public static F, P1>> either() { * @return A Callable equivalent to the given Either value. */ public static Callable fromEither(final F0> e) { - return new Callable() { - public A call() throws Exception { - final Either e1 = e.f(); - if (e1.isLeft()) - throw e1.left().value(); - else - return e1.right().value(); - } + return () -> { + final Either e1 = e.f(); + if (e1.isLeft()) + throw e1.left().value(); + else + return e1.right().value(); }; } @@ -243,14 +241,12 @@ public static F>, Callable> fromEither() { * @return A Callable that yields some value or throws an exception in the case of no value. */ public static Callable fromOption(final F0> o) { - return new Callable() { - public A call() throws Exception { - final Option o1 = o.f(); - if (o1.isSome()) - return o1.some(); - else - throw new Exception("No value."); - } + return () -> { + final Option o1 = o.f(); + if (o1.isSome()) + return o1.some(); + else + throw new Exception("No value."); }; } diff --git a/core/src/main/java/fj/control/parallel/Strategy.java b/core/src/main/java/fj/control/parallel/Strategy.java index 79e698b9..94e1f148 100644 --- a/core/src/main/java/fj/control/parallel/Strategy.java +++ b/core/src/main/java/fj/control/parallel/Strategy.java @@ -339,9 +339,7 @@ public static P1 obtain(final Future t) { * @return An effect, which, given a Future, waits for it to obtain a value, discarding the value. */ public static Effect1> discard() { - return a -> { - Strategy.obtain().f(a)._1(); - }; + return a -> Strategy.obtain().f(a)._1(); } /** diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index b62bb60e..c3d5fe01 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -76,12 +76,9 @@ public static A runSafe(IO io) { } public static IO closeReader(final Reader r) { - return new IO() { - @Override - public Unit run() throws IOException { - r.close(); - return Unit.unit(); - } + return () -> { + r.close(); + return Unit.unit(); }; } @@ -139,24 +136,16 @@ public static IO fileReader(final File f, final Option encoding } public static IO bracket(final IO init, final F> fin, final F> body) { - return new IO() { - @Override - public C run() throws IOException { - final A a = init.run(); - try(Closeable finAsCloseable = fin.f(a)::run) { - return body.f(a).run(); - } + return () -> { + final A a = init.run(); + try(Closeable finAsCloseable = fin.f(a)::run) { + return body.f(a).run(); } }; } public static IO unit(final A a) { - return new IO() { - @Override - public A run() throws IOException { - return a; - } - }; + return () -> a; } public static final IO ioUnit = unit(Unit.unit()); @@ -192,32 +181,24 @@ public Boolean f(final IterV i) { } }; - return new F, IO>>>() { - @Override - public F, IO>> f(final BufferedReader r) { - return new F, IO>>() { - final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ + return r -> new F, IO>>() { + final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return new IO>() { - @Override - public IterV run() throws IOException { - IterV i = it; - while (!isDone.f(i)) { - final String s = r.readLine(); - if (s == null) { - return i; - } - final Input input = Input.el(s); - final F, IterV>, P1>> cont = F1Functions.lazy(Function., IterV>apply(input)); - i = i.fold(done, cont)._1(); - } - return i; - } - }; + @Override + public IO> f(final IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + IterV i = it; + while (!isDone.f(i)) { + final String s = r.readLine(); + if (s == null) { + return i; + } + final Input input = Input.el(s); + final F, IterV>, P1>> cont = F1Functions.lazy(Function., IterV>apply(input)); + i = i.fold(done, cont)._1(); } + return i; }; } }; @@ -239,38 +220,30 @@ public Boolean f(final IterV i) { } }; - return new F, IO>>>() { - @Override - public F, IO>> f(final Reader r) { - return new F, IO>>() { - final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ + return r -> new F, IO>>() { + final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return new IO>() { - @Override - public IterV run() throws IOException { - - IterV i = it; - while (!isDone.f(i)) { - char[] buffer = new char[DEFAULT_BUFFER_SIZE]; - final int numRead = r.read(buffer); - if (numRead == -1) { - return i; - } - if (numRead < buffer.length) { - buffer = Arrays.copyOfRange(buffer, 0, numRead); - } - final Input input = Input.el(buffer); - final F, IterV>, P1>> cont = - F1Functions.lazy(Function., IterV>apply(input)); - i = i.fold(done, cont)._1(); - } - return i; - } - }; + @Override + public IO> f(final IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + + IterV i = it; + while (!isDone.f(i)) { + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + final int numRead = r.read(buffer); + if (numRead == -1) { + return i; + } + if (numRead < buffer.length) { + buffer = Arrays.copyOfRange(buffer, 0, numRead); + } + final Input input = Input.el(buffer); + final F, IterV>, P1>> cont = + F1Functions.lazy(Function., IterV>apply(input)); + i = i.fold(done, cont)._1(); } + return i; }; } }; @@ -292,52 +265,39 @@ public Boolean f(final IterV i) { } }; - return new F, IO>>>() { - @Override - public F, IO>> f(final Reader r) { - return new F, IO>>() { - final F>, IterV> done = errorF("iteratee is done"); //$NON-NLS-1$ + return r -> new F, IO>>() { + final F>, IterV> done = errorF("iteratee is done"); //$NON-NLS-1$ - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return new IO>() { - @Override - public IterV run() throws IOException { - - IterV i = it; - while (!isDone.f(i)) { - char[] buffer = new char[DEFAULT_BUFFER_SIZE]; - final int numRead = r.read(buffer); - if (numRead == -1) { - return i; - } - if (numRead < buffer.length) { - buffer = Arrays.copyOfRange(buffer, 0, numRead); - } - for (int c = 0; c < buffer.length; c++) { - final Input input = Input.el(buffer[c]); - final F, IterV>, IterV> cont = - Function., IterV>apply(input); - i = i.fold(done, cont); - } - } - return i; - } - }; + @Override + public IO> f(final IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + + IterV i = it; + while (!isDone.f(i)) { + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + final int numRead = r.read(buffer); + if (numRead == -1) { + return i; + } + if (numRead < buffer.length) { + buffer = Arrays.copyOfRange(buffer, 0, numRead); + } + for (int c = 0; c < buffer.length; c++) { + final Input input = Input.el(buffer[c]); + final F, IterV>, IterV> cont = + Function., IterV>apply(input); + i = i.fold(done, cont); + } } + return i; }; } }; } public static IO map(final IO io, final F f) { - return new IO() { - @Override - public B run() throws IOException { - return f.f(io.run()); - } - }; + return () -> f.f(io.run()); } public static IO as(final IO io, final B b) { @@ -349,12 +309,7 @@ public static IO voided(final IO io) { } public static IO bind(final IO io, final F> f) { - return new IO() { - @Override - public B run() throws IOException { - return f.f(io.run()).run(); - } - }; + return () -> f.f(io.run()).run(); } public static IO when(final Boolean b, final IO io) { @@ -422,46 +377,40 @@ public static IO interactWhile(F condition, F IO> sequenceWhileEager(final Stream> stream, final F f) { - return new IO>() { - @Override - public Stream run() throws IOException { - boolean loop = true; - Stream> input = stream; - Stream result = Stream.nil(); - while (loop) { - if (input.isEmpty()) { + return () -> { + boolean loop = true; + Stream> input = stream; + Stream result = Stream.nil(); + while (loop) { + if (input.isEmpty()) { + loop = false; + } else { + A a = input.head().run(); + if (!f.f(a)) { loop = false; } else { - A a = input.head().run(); - if (!f.f(a)) { - loop = false; - } else { - input = input.tail()._1(); - result = result.cons(a); - } + input = input.tail()._1(); + result = result.cons(a); } } - return result.reverse(); } + return result.reverse(); }; } public static IO> sequenceWhile(final Stream> stream, final F f) { - return new IO>() { - @Override - public Stream run() throws IOException { - if (stream.isEmpty()) { + return () -> { + if (stream.isEmpty()) { + return Stream.nil(); + } else { + IO io = stream.head(); + A a = io.run(); + if (!f.f(a)) { return Stream.nil(); } else { - IO io = stream.head(); - A a = io.run(); - if (!f.f(a)) { - return Stream.nil(); - } else { - IO> io2 = sequenceWhile(stream.tail()._1(), f); - SafeIO> s3 = toSafe(io2::run); - return Stream.cons(a, s3::run); - } + IO> io2 = sequenceWhile(stream.tail()._1(), f); + SafeIO> s3 = toSafe(io2::run); + return Stream.cons(a, s3::run); } } }; @@ -505,9 +454,7 @@ public static IO stdoutPrint(final String s) { public static IO getContents() { Stream> s = Stream.>repeat(() -> (int) stdinBufferedReader.read()); - return map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> { - return (char) i.intValue(); - }))); + return map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> (char) i.intValue()))); } public static IO interact(F f) { diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index 5912ec1b..391c4087 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -99,11 +99,9 @@ public Option f(final IterV i) { /** TODO more documentation */ public final IterV bind(final F> f) { final F>, IterV> done = - new F>, IterV>() { - @Override - public IterV f(final P2> xe) { + xe -> { final Input e = xe._2(); - final F>, IterV> done = + final F>, IterV> done1 = y_ -> { final B y = y_._1(); return done(y, e); @@ -111,9 +109,8 @@ public IterV f(final P2> xe) { final F, IterV>, IterV> cont = k -> k.f(e); final A x = xe._1(); - return f.f(x).fold(done, cont); - } - }; + return f.f(x).fold(done1, cont); + }; final F, IterV>, IterV> cont = k -> cont(e -> k.f(e).bind(f)); return this.fold(done, cont); diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 8836fe2f..0be648f2 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -59,9 +59,7 @@ public static F, ArrayList> List_ArrayList() { */ public static final F, BitSet> List_BitSet = bs -> { final BitSet s = new BitSet(bs.length()); - bs.zipIndex().foreachDoEffect(bi -> { - s.set(bi._2(), bi._1()); - }); + bs.zipIndex().foreachDoEffect(bi -> s.set(bi._2(), bi._1())); return s; }; @@ -238,9 +236,7 @@ public static F, ArrayList> Array_ArrayList() { public static final F, BitSet> Array_BitSet = bs -> { final BitSet s = new BitSet(bs.length()); - bs.zipIndex().foreachDoEffect(bi -> { - s.set(bi._2(), bi._1()); - }); + bs.zipIndex().foreachDoEffect(bi -> s.set(bi._2(), bi._1())); return s; }; @@ -445,9 +441,7 @@ public static F, ArrayList> Stream_ArrayList() { */ public static final F, BitSet> Stream_BitSet = bs -> { final BitSet s = new BitSet(bs.length()); - bs.zipIndex().foreachDoEffect(bi -> { - s.set(bi._2(), bi._1()); - }); + bs.zipIndex().foreachDoEffect(bi -> s.set(bi._2(), bi._1())); return s; }; diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index 611bef93..c8dd4cca 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -108,12 +108,10 @@ public NonEmptyList bind(final F> f) { final NonEmptyList p = f.f(head); b.snoc(p.head); b.append(p.tail); - tail.foreachDoEffect(new Effect1() { - public void f(final A a) { - final NonEmptyList p = f.f(a); - b.snoc(p.head); - b.append(p.tail); - } + tail.foreachDoEffect(a -> { + final NonEmptyList p1 = f.f(a); + b.snoc(p1.head); + b.append(p1.tail); }); final List bb = b.toList(); return nel(bb.head(), bb.tail()); diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index 3cfeff7c..a9d92b5a 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -585,21 +585,14 @@ public TreeZipper> positions() { final Stream>> l = uf(TreeZipper.left_()); final Stream>> r = uf(TreeZipper.right_()); final Stream>>, TreeZipper, Stream>>>> p = unfold( - new F>, - Option>>, TreeZipper, Stream>>>, - Option>>>>() { - public Option { + Option>>, TreeZipper, Stream>>>, - Option>>> f(final Option> o) { - Option>>, TreeZipper, Stream>>>, - Option>>> r = none(); - for (final TreeZipper z : o) { - r = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); - } - return r; + Option>>> r1 = none(); + for (final TreeZipper z : o) { + r1 = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); } + return r1; }, parent()); return treeZipper(t, l, r, p); } diff --git a/core/src/main/java/fj/data/fingertrees/Deep.java b/core/src/main/java/fj/data/fingertrees/Deep.java index a33637d8..17e775e6 100644 --- a/core/src/main/java/fj/data/fingertrees/Deep.java +++ b/core/src/main/java/fj/data/fingertrees/Deep.java @@ -208,23 +208,21 @@ private static FingerTree> addDigits0( final MakeTree mk = mkTree(m); return s1.match( - one1 -> { - return p2.match( - one2 -> append1(m, m1, mk.node2(one1.value(), one2.value()), m2), - two2 -> { - final V2 vs = two2.values(); - return append1(m, m1, mk.node3(one1.value(), vs._1(), vs._2()), m2); - }, - three -> { - final V3 vs = three.values(); - return append2(m, m1, mk.node2(one1.value(), vs._1()), mk.node2(vs._2(), vs._3()), m2); - }, - four -> { - final V4 vs = four.values(); - return append2(m, m1, mk.node3(one1.value(), vs._1(), vs._2()), mk.node2(vs._3(), vs._4()), m2); - } - ); - }, + one1 -> p2.match( + one2 -> append1(m, m1, mk.node2(one1.value(), one2.value()), m2), + two2 -> { + final V2 vs = two2.values(); + return append1(m, m1, mk.node3(one1.value(), vs._1(), vs._2()), m2); + }, + three -> { + final V3 vs = three.values(); + return append2(m, m1, mk.node2(one1.value(), vs._1()), mk.node2(vs._2(), vs._3()), m2); + }, + four -> { + final V4 vs = four.values(); + return append2(m, m1, mk.node3(one1.value(), vs._1(), vs._2()), mk.node2(vs._3(), vs._4()), m2); + } + ), two1 -> { final V2 v1 = two1.values(); return p2.match( @@ -281,34 +279,12 @@ private static FingerTree> addDigits0( private static FingerTree> append1(final Measured m, final FingerTree> xs, final Node a, final FingerTree> ys) { - return xs.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return ys.cons(a); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return ys.cons(a).cons(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep1) { - return ys.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return xs.snoc(a); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return xs.snoc(a).snoc(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep2) { - final Measured> nm = m.nodeMeasured(); - return new Deep>(nm, m.sum(m.sum(deep1.v, nm.measure(a)), deep2.v), deep1.prefix, - addDigits1(nm, deep1.middle, deep1.suffix, a, deep2.prefix, deep2.middle), - deep2.suffix); - } - }); - } - }); + return xs.match(empty -> ys.cons(a), single -> ys.cons(a).cons(single.value()), deep1 -> ys.match(empty -> xs.snoc(a), single -> xs.snoc(a).snoc(single.value()), deep2 -> { + final Measured> nm = m.nodeMeasured(); + return new Deep>(nm, m.sum(m.sum(deep1.v, nm.measure(a)), deep2.v), deep1.prefix, + addDigits1(nm, deep1.middle, deep1.suffix, a, deep2.prefix, deep2.middle), + deep2.suffix); + })); } private static FingerTree>> addDigits1(final Measured> m, @@ -317,136 +293,54 @@ private static FingerTree>> addDigits1(final Measur final Digit> y, final FingerTree>> m2) { final MakeTree> mk = mkTree(m); - return x.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one1) { - return y.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one2) { - return append1(m, m1, mk.node3(one1.value(), n, one2.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append2(m, m1, mk.node2(one1.value(), n), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append2(m, m1, mk.node3(one1.value(), n, v2._1()), mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append2(m, m1, mk.node3(one1.value(), n, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two1) { - final V2> v1 = two1.values(); - return y.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node2(v1), mk.node2(n, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append2(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - return append2(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node3(three.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), - m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v1 = three.values(); - return y.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node3(v1), mk.node2(n, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v2 = two.values(); - return append2(m, m1, mk.node3(v1), mk.node3(n, v2._1(), v2._2()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(v1), mk.node2(n, v2._1()), mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1), mk.node3(n, v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v1 = four.values(); - return y.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node2(v1._4(), n), mk.node2(two.values()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, v2._1()), - mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, v2._1()), - mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } + return x.match(one1 -> y.match(one2 -> append1(m, m1, mk.node3(one1.value(), n, one2.value()), m2), two -> append2(m, m1, mk.node2(one1.value(), n), mk.node2(two.values()), m2), three -> { + final V3> v2 = three.values(); + return append2(m, m1, mk.node3(one1.value(), n, v2._1()), mk.node2(v2._2(), v2._3()), m2); + }, four -> { + final V4> v2 = four.values(); + return append2(m, m1, mk.node3(one1.value(), n, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); + }), two1 -> { + final V2> v1 = two1.values(); + return y.match(one -> append2(m, m1, mk.node2(v1), mk.node2(n, one.value()), m2), two -> append2(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node2(two.values()), m2), three -> append2(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node3(three.values()), m2), four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), n), mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), + m2); + }); + }, three -> { + final V3> v1 = three.values(); + return y.match(one -> append2(m, m1, mk.node3(v1), mk.node2(n, one.value()), m2), two -> { + final V2> v2 = two.values(); + return append2(m, m1, mk.node3(v1), mk.node3(n, v2._1(), v2._2()), m2); + }, three1 -> { + final V3> v2 = three1.values(); + return append3(m, m1, mk.node3(v1), mk.node2(n, v2._1()), mk.node2(v2._2(), v2._3()), m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(v1), mk.node3(n, v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); + }); + }, four -> { + final V4> v1 = four.values(); + return y.match(one -> append2(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, one.value()), m2), two -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node2(v1._4(), n), mk.node2(two.values()), + m2), three -> { + final V3> v2 = three.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, v2._1()), + mk.node2(v2._2(), v2._3()), m2); + }, four1 -> { + final V4> v2 = four1.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n, v2._1()), + mk.node3(v2._2(), v2._3(), v2._4()), m2); + }); }); } private static FingerTree> append2(final Measured m, final FingerTree> t1, final Node n1, final Node n2, final FingerTree> t2) { - return t1.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return t2.cons(n2).cons(n1); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return t2.cons(n2).cons(n1).cons(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep) { - return t2.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return deep.snoc(n1).snoc(n2); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return deep.snoc(n1).snoc(n2).snoc(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep2) { - return new Deep>(m.nodeMeasured(), - m.sum(m.sum(m.sum(deep.measure(), n1.measure()), n2.measure()), - deep2.measure()), deep.prefix, - addDigits2(m.nodeMeasured(), deep.middle, deep.suffix, n1, n2, deep2.prefix, - deep2.middle), deep2.suffix); - } - }); - } - }); + return t1.match(empty -> t2.cons(n2).cons(n1), single -> t2.cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2), single -> deep.snoc(n1).snoc(n2).snoc(single.value()), deep2 -> new Deep>(m.nodeMeasured(), + m.sum(m.sum(m.sum(deep.measure(), n1.measure()), n2.measure()), + deep2.measure()), deep.prefix, + addDigits2(m.nodeMeasured(), deep.middle, deep.suffix, n1, n2, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits2(final Measured> m, @@ -456,103 +350,43 @@ private static FingerTree>> addDigits2(final Measur final Digit> prefix, final FingerTree>> m2) { final MakeTree> mk = mkTree(m); - return suffix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one2) { - return append2(m, m1, mk.node2(one.value(), n1), mk.node2(n2, one2.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(three.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), - m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v1 = two.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two2) { - final V2> v2 = two2.values(); - return append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, v2._1(), v2._2()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, v2._1()), mk.node2(v2._2(), v2._3()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, v2._1(), v2._2()), - mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v1 = three.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node3(v1), mk.node3(n1, n2, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(v1), mk.node2(n1, n2), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three2) { - final V3> v2 = three2.values(); - return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, v2._1()), mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v1 = four.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node2(v1._4(), n1), mk.node2(n2, one.value()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(three.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four2) { - final V4> v2 = four2.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); - } - }); - } + return suffix.match(one -> prefix.match(one2 -> append2(m, m1, mk.node2(one.value(), n1), mk.node2(n2, one2.value()), m2), two -> append2(m, m1, mk.node3(one.value(), n1, n2), mk.node2(two.values()), m2), three -> append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(three.values()), m2), four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), + m2); + }), two -> { + final V2> v1 = two.values(); + return prefix.match(one -> append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, one.value()), m2), two2 -> { + final V2> v2 = two2.values(); + return append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, v2._1(), v2._2()), m2); + }, three -> { + final V3> v2 = three.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, v2._1()), mk.node2(v2._2(), v2._3()), + m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, v2._1(), v2._2()), + mk.node2(v2._3(), v2._4()), m2); + }); + }, three -> { + final V3> v1 = three.values(); + return prefix.match(one -> append2(m, m1, mk.node3(v1), mk.node3(n1, n2, one.value()), m2), two -> append3(m, m1, mk.node3(v1), mk.node2(n1, n2), mk.node2(two.values()), m2), three2 -> { + final V3> v2 = three2.values(); + return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, v2._1()), mk.node2(v2._2(), v2._3()), m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); + }); + }, four -> { + final V4> v1 = four.values(); + return prefix.match(one -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node2(v1._4(), n1), mk.node2(n2, one.value()), + m2), two -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node2(two.values()), m2), three -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(three.values()), m2), four2 -> { + final V4> v2 = four2.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node2(v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); + }); }); } @@ -561,34 +395,10 @@ private static FingerTree> append3(final Measured m, final Node n1, final Node n2, final Node n3, final FingerTree> t2) { final Measured> nm = m.nodeMeasured(); - return t1.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return t2.cons(n3).cons(n2).cons(n1); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return t2.cons(n3).cons(n2).cons(n1).cons(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep) { - return t2.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return deep.snoc(n1).snoc(n2).snoc(n3); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return deep.snoc(n1).snoc(n2).snoc(n3).snoc(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep2) { - return new Deep>(nm, nm.monoid().sumLeft( - list(deep.v, n1.measure(), n2.measure(), n3.measure(), deep2.v)), deep.prefix, - addDigits3(nm, deep.middle, deep.suffix, n1, n2, n3, deep2.prefix, - deep2.middle), deep2.suffix); - } - }); - } - }); + return t1.match(empty -> t2.cons(n3).cons(n2).cons(n1), single -> t2.cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2).snoc(n3), single -> deep.snoc(n1).snoc(n2).snoc(n3).snoc(single.value()), deep2 -> new Deep>(nm, nm.monoid().sumLeft( + list(deep.v, n1.measure(), n2.measure(), n3.measure(), deep2.v)), deep.prefix, + addDigits3(nm, deep.middle, deep.suffix, n1, n2, n3, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits3(final Measured> m, @@ -599,105 +409,47 @@ private static FingerTree>> addDigits3(final Measur final Digit> prefix, final FingerTree>> m2) { final MakeTree> mk = mkTree(m); - return suffix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one2) { - return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, one2.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v2 = two.values(); - return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, v2._1(), v2._2()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, v2._1()), mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, v2._1(), v2._2()), - mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v1 = two.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, n3), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, v2._1()), mk.node2(v2._2(), v2._3()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, v2._1()), - mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(three.values()), mk.node2(n1, n2), mk.node2(n3, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three2) { - return append3(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node3(three2.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append4(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node2(v2._1(), v2._2()), - mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v1 = four.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node2(n3, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v2 = two.values(); - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(n3, v2._1(), v2._2()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), mk.node2(n3, v2._1()), - mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four2) { - final V4> v2 = four2.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(n3, v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); - } - }); - } + return suffix.match(one -> prefix.match(one2 -> append2(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, one2.value()), m2), two -> { + final V2> v2 = two.values(); + return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, v2._1(), v2._2()), m2); + }, three -> { + final V3> v2 = three.values(); + return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, v2._1()), mk.node2(v2._2(), v2._3()), m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, v2._1(), v2._2()), + mk.node2(v2._3(), v2._4()), m2); + }), two -> { + final V2> v1 = two.values(); + return prefix.match(one -> append2(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, one.value()), m2), two1 -> append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, n3), mk.node2(two1.values()), m2), three -> { + final V3> v2 = three.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, v2._1()), mk.node2(v2._2(), v2._3()), + m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, v2._1()), + mk.node3(v2._2(), v2._3(), v2._4()), m2); + }); + }, three -> prefix.match(one -> append3(m, m1, mk.node3(three.values()), mk.node2(n1, n2), mk.node2(n3, one.value()), m2), two -> append3(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node2(two.values()), m2), three2 -> append3(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node3(three2.values()), m2), four -> { + final V4> v2 = four.values(); + return append4(m, m1, mk.node3(three.values()), mk.node3(n1, n2, n3), mk.node2(v2._1(), v2._2()), + mk.node2(v2._3(), v2._4()), m2); + }), four -> { + final V4> v1 = four.values(); + return prefix.match(one -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node2(n3, one.value()), m2), two -> { + final V2> v2 = two.values(); + return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(n3, v2._1(), v2._2()), m2); + }, three -> { + final V3> v2 = three.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), mk.node2(n3, v2._1()), + mk.node2(v2._2(), v2._3()), m2); + }, four2 -> { + final V4> v2 = four2.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(n3, v2._1(), v2._2()), mk.node2(v2._3(), v2._4()), m2); + }); }); } @@ -710,34 +462,10 @@ private static FingerTree> append4(final Measured m, final Node n4, final FingerTree> t2) { final Measured> nm = m.nodeMeasured(); - return t1.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return t2.cons(n4).cons(n3).cons(n2).cons(n1); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return t2.cons(n4).cons(n3).cons(n2).cons(n1).cons(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep) { - return t2.match(new F>, FingerTree>>() { - public FingerTree> f(final Empty> empty) { - return t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Single> single) { - return t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4).snoc(single.value()); - } - }, new F>, FingerTree>>() { - public FingerTree> f(final Deep> deep2) { - return new Deep>(nm, m.monoid().sumLeft( - list(deep.v, n1.measure(), n2.measure(), n3.measure(), n4.measure(), deep2.v)), deep.prefix, - addDigits4(nm, deep.middle, deep.suffix, n1, n2, n3, n4, deep2.prefix, - deep2.middle), deep2.suffix); - } - }); - } - }); + return t1.match(empty -> t2.cons(n4).cons(n3).cons(n2).cons(n1), single -> t2.cons(n4).cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4), single -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4).snoc(single.value()), deep2 -> new Deep>(nm, m.monoid().sumLeft( + list(deep.v, n1.measure(), n2.measure(), n3.measure(), n4.measure(), deep2.v)), deep.prefix, + addDigits4(nm, deep.middle, deep.suffix, n1, n2, n3, n4, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits4(final Measured> m, @@ -748,106 +476,48 @@ private static FingerTree>> addDigits4(final Measur final Digit> prefix, final FingerTree>> m2) { final MakeTree> mk = mkTree(m); - return suffix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one2) { - return append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, one2.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, n4), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, v2._1()), mk.node2(v2._2(), v2._3()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, v2._1()), - mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v1 = two.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, n3), mk.node2(n4, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two2) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node2(two2.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node3(three.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node2(v2._1(), v2._2()), - mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v1 = three.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node2(n4, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - final V2> v2 = two.values(); - return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node3(n4, v2._1(), v2._2()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append4(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node2(n4, v2._1()), mk.node2(v2._2(), v2._3()), - m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append4(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node3(n4, v2._1(), v2._2()), - mk.node2(v2._3(), v2._4()), m2); - } - }); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v1 = four.values(); - return prefix.match(new F>, FingerTree>>>() { - public FingerTree>> f(final One> one) { - return append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(n3, n4, one.value()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Two> two) { - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node2(n3, n4), mk.node2(two.values()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Three> three) { - final V3> v2 = three.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(n3, n4, v2._1()), mk.node2(v2._2(), v2._3()), m2); - } - }, new F>, FingerTree>>>() { - public FingerTree>> f(final Four> four) { - final V4> v2 = four.values(); - return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), - mk.node3(n3, n4, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); - } - }); - } + return suffix.match(one -> prefix.match(one2 -> append2(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, one2.value()), m2), two -> append3(m, m1, mk.node3(one.value(), n1, n2), mk.node2(n3, n4), mk.node2(two.values()), m2), three -> { + final V3> v2 = three.values(); + return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, v2._1()), mk.node2(v2._2(), v2._3()), + m2); + }, four -> { + final V4> v2 = four.values(); + return append3(m, m1, mk.node3(one.value(), n1, n2), mk.node3(n3, n4, v2._1()), + mk.node3(v2._2(), v2._3(), v2._4()), m2); + }), two -> { + final V2> v1 = two.values(); + return prefix.match(one -> append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node2(n2, n3), mk.node2(n4, one.value()), m2), two2 -> append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node2(two2.values()), m2), three -> append3(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node3(three.values()), m2), four -> { + final V4> v2 = four.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), n1), mk.node3(n2, n3, n4), mk.node2(v2._1(), v2._2()), + mk.node2(v2._3(), v2._4()), m2); + }); + }, three -> { + final V3> v1 = three.values(); + return prefix.match(one -> append3(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node2(n4, one.value()), m2), two -> { + final V2> v2 = two.values(); + return append3(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node3(n4, v2._1(), v2._2()), m2); + }, three1 -> { + final V3> v2 = three1.values(); + return append4(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node2(n4, v2._1()), mk.node2(v2._2(), v2._3()), + m2); + }, four -> { + final V4> v2 = four.values(); + return append4(m, m1, mk.node3(v1), mk.node3(n1, n2, n3), mk.node3(n4, v2._1(), v2._2()), + mk.node2(v2._3(), v2._4()), m2); + }); + }, four -> { + final V4> v1 = four.values(); + return prefix.match(one -> append3(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(n3, n4, one.value()), m2), two -> append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node2(n3, n4), mk.node2(two.values()), m2), three -> { + final V3> v2 = three.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(n3, n4, v2._1()), mk.node2(v2._2(), v2._3()), m2); + }, four1 -> { + final V4> v2 = four1.values(); + return append4(m, m1, mk.node3(v1._1(), v1._2(), v1._3()), mk.node3(v1._4(), n1, n2), + mk.node3(n3, n4, v2._1()), mk.node3(v2._2(), v2._3(), v2._4()), m2); + }); }); } } diff --git a/demo/src/main/java/fj/demo/ChequeWrite.java b/demo/src/main/java/fj/demo/ChequeWrite.java index d2d07d3d..ee958fc9 100644 --- a/demo/src/main/java/fj/demo/ChequeWrite.java +++ b/demo/src/main/java/fj/demo/ChequeWrite.java @@ -111,19 +111,17 @@ static boolean eq(final List a, final List b) { final List, Integer>> k = split(cs); final int c = k.head()._2(); - k.foreachDoEffect(new Effect1, Integer>>() { - public void f(final P2, Integer> z) { - final List w = z._1(); - final int i = z._2(); - - if (i == 0 && c > 0 && and(w)) - x.snoc(fromString("and")); - - if (existsNotZero(w)) { - x.snoc(show(w)); - if (i != 0) - x.snoc(illion(i - 1)); - } + k.foreachDoEffect(z -> { + final List w = z._1(); + final int i = z._2(); + + if (i == 0 && c > 0 && and(w)) + x.snoc(fromString("and")); + + if (existsNotZero(w)) { + x.snoc(show(w)); + if (i != 0) + x.snoc(illion(i - 1)); } }); diff --git a/demo/src/main/java/fj/demo/List_groupBy.java b/demo/src/main/java/fj/demo/List_groupBy.java index 1dc8866d..f557ec74 100644 --- a/demo/src/main/java/fj/demo/List_groupBy.java +++ b/demo/src/main/java/fj/demo/List_groupBy.java @@ -20,9 +20,7 @@ private static void keyDemo() { final List words = list("Hello", "World", "how", "are", "your", "doing"); final TreeMap> lengthMap = words.groupBy(String::length); - lengthMap.forEach(entry -> { - System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2())); - }); + lengthMap.forEach(entry -> System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2()))); } private static void keyValueDemo() { @@ -30,9 +28,7 @@ private static void keyValueDemo() { final List xs = list(1, 2, 3, 4, 5, 6, 7, 8, 9); final TreeMap> result = xs.groupBy(x -> x % 3, Integer::toBinaryString); - result.forEach(entry -> { - System.out.println(String.format("Numbers with reminder %d are %s", entry._1(), entry._2())); - }); + result.forEach(entry -> System.out.println(String.format("Numbers with reminder %d are %s", entry._1(), entry._2()))); } private static void keyValueAccDemo() { @@ -41,8 +37,6 @@ private static void keyValueAccDemo() { final TreeMap lengthCounts = words.groupBy(String::length, Function.identity(), 0, (word, sum) -> sum + 1, Ord.hashOrd()); - lengthCounts.forEach(entry -> { - System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2())); - }); + lengthCounts.forEach(entry -> System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2()))); } } diff --git a/demo/src/main/java/fj/demo/concurrent/PingPong.java b/demo/src/main/java/fj/demo/concurrent/PingPong.java index b0b09011..a9109585 100644 --- a/demo/src/main/java/fj/demo/concurrent/PingPong.java +++ b/demo/src/main/java/fj/demo/concurrent/PingPong.java @@ -30,15 +30,13 @@ public PingPong(final ExecutorService pool, final int actors, final int pings) { // This actor gives feedback to the user that work is being done // and also terminates the program when all work has been completed. - callback = Actor.queueActor(s, new Effect1() { - public void f(final Integer i) { - done++; - if (done >= actors) { - System.out.println("All done."); - pool.shutdown(); - } else if (actors < 10 || done % (actors / 10) == 0) - System.out.println(MessageFormat.format("{0} actors done ({1} total pongs).", done, pings * done)); - } + callback = Actor.queueActor(s, i -> { + done++; + if (done >= actors) { + System.out.println("All done."); + pool.shutdown(); + } else if (actors < 10 || done % (actors / 10) == 0) + System.out.println(MessageFormat.format("{0} actors done ({1} total pongs).", done, pings * done)); }); } diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index 69b27202..dbbd035c 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -92,24 +92,21 @@ public F, IterV>> f(final P2>>>() { @Override public F>> _1() { - return new F>>() { - @Override - public IterV> f(final char[] e) { - StringBuilder sb = acc._1(); - Map map = acc._2(); - for(char c : e) { - if(Character.isWhitespace(c)) { - if(sb.length() > 0) { - map = update(map, sb.toString(), addOne, Integer.valueOf(0)); - sb = new StringBuilder(); - } - } - else { - sb.append(c); + return e -> { + StringBuilder sb = acc._1(); + Map map = acc._2(); + for(char c : e) { + if(Character.isWhitespace(c)) { + if(sb.length() > 0) { + map = update(map, sb.toString(), addOne, Integer.valueOf(0)); + sb = new StringBuilder(); } } - return IterV.cont(step.f(P.p(sb, map))); + else { + sb.append(c); + } } + return IterV.cont(step.f(P.p(sb, map))); }; } }; @@ -139,25 +136,23 @@ public static final IterV> wordCountsFromCha public F, IterV>> f(final P2> acc) { final P1>> empty = P.lazy(() -> IterV.cont(step.f(acc))); final P1>>> el = - P.lazy(() -> { - return e -> { - if(Character.isWhitespace(e.charValue())) { - final StringBuilder sb = acc._1(); - if(sb.length() > 0) { - final Map map = update(acc._2(), sb.toString(), addOne, Integer.valueOf(0)); - return IterV.cont(step.f(P.p(new StringBuilder(), map))); - } - else { - // another whitespace char, no word to push to the map - return IterV.cont(step.f(acc)); - } - } - else { - acc._1().append(e); - return IterV.cont(step.f(acc)); - } - }; - }); + P.lazy(() -> e -> { + if(Character.isWhitespace(e.charValue())) { + final StringBuilder sb = acc._1(); + if(sb.length() > 0) { + final Map map = update(acc._2(), sb.toString(), addOne, Integer.valueOf(0)); + return IterV.cont(step.f(P.p(new StringBuilder(), map))); + } + else { + // another whitespace char, no word to push to the map + return IterV.cont(step.f(acc)); + } + } + else { + acc._1().append(e); + return IterV.cont(step.f(acc)); + } + }); final P1>> eof = P.lazy(() -> { final StringBuilder sb = acc._1(); if(sb.length() > 0) { @@ -261,12 +256,7 @@ public static void main(String[] args) throws IOException { assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); // we have tmpfiles, but still want to be sure not to leave rubbish - fileNames.foreachDoEffect(new Effect1() { - @Override - public void f(final String a) { - new File(a).delete(); - } - }); + fileNames.foreachDoEffect(a -> new File(a).delete()); } @SuppressWarnings("unused") diff --git a/demo/src/main/java/fj/demo/euler/Problem2.java b/demo/src/main/java/fj/demo/euler/Problem2.java index 321a34b7..eda4a72d 100644 --- a/demo/src/main/java/fj/demo/euler/Problem2.java +++ b/demo/src/main/java/fj/demo/euler/Problem2.java @@ -29,10 +29,7 @@ public Stream f(final Integer a, final Integer b) { out.println(sum(fibs.filter(even).takeWhile(intOrd.isLessThan(4000001)).toList())); } - static F2> fibsJava8 = (a, b) -> { - - return cons(a, F1Functions.lazy(F2Functions.curry(Problem2.fibsJava8).f(b)).f(a + b)); - }; + static F2> fibsJava8 = (a, b) -> cons(a, F1Functions.lazy(F2Functions.curry(Problem2.fibsJava8).f(b)).f(a + b)); static void java8() { out.println(sum(fibsJava8.f(1, 2).filter(even).takeWhile(intOrd.isLessThan(4000001)).toList())); diff --git a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java index 03095e80..8ed7a306 100644 --- a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java +++ b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java @@ -52,11 +52,9 @@ public final class ListFunctorLaws { // composition: OK, passed 1000 tests. @SuppressWarnings("unchecked") public static void main(final String[] args) { - check(ListFunctorLaws.class).foreachDoEffect(new Effect1>() { - public void f(final P2 r) { - System.out.print(r._1() + ": "); - summary.println(r._2()); - } + check(ListFunctorLaws.class).foreachDoEffect(r -> { + System.out.print(r._1() + ": "); + summary.println(r._2()); }); } } diff --git a/demo/src/main/java/fj/demo/test/Reflect.java b/demo/src/main/java/fj/demo/test/Reflect.java index d5ebfd36..78084b47 100644 --- a/demo/src/main/java/fj/demo/test/Reflect.java +++ b/demo/src/main/java/fj/demo/test/Reflect.java @@ -119,11 +119,9 @@ public static void main(final String[] args) { } private static void printResults(final List> results) { - results.foreachDoEffect(new Effect1>() { - public void f(final P2 result) { - summary.print(result._2()); - out.println(" (" + result._1() + ')'); - } + results.foreachDoEffect(result -> { + summary.print(result._2()); + out.println(" (" + result._1() + ')'); }); out.println("--------------------------------------------------------------------------------"); } diff --git a/demo/src/main/java/fj/demo/test/StringBuilderReverse.java b/demo/src/main/java/fj/demo/test/StringBuilderReverse.java index b0897044..78a4cc82 100644 --- a/demo/src/main/java/fj/demo/test/StringBuilderReverse.java +++ b/demo/src/main/java/fj/demo/test/StringBuilderReverse.java @@ -34,10 +34,6 @@ public static void main(final String[] args) { //OK, passed 100 tests. //OK, passed 100 tests. //OK, passed 100 tests. - list(p1, p2, p3).foreachDoEffect(new Effect1() { - public void f(final Property p) { - summary.println(p.check()); - } - }); + list(p1, p2, p3).foreachDoEffect(p -> summary.println(p.check())); } } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 7b96d299..a9f05549 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -397,11 +397,7 @@ public static Arbitrary> arbF4Invariant(final /** * An arbitrary implementation for integer values. */ - public static final Arbitrary arbInteger = arbitrary(sized(new F>() { - public Gen f(final Integer i) { - return choose(-i, i); - } - })); + public static final Arbitrary arbInteger = arbitrary(sized(i -> choose(-i, i))); /** * An arbitrary implementation for integer values that checks boundary values (0, 1, -1, @@ -426,15 +422,7 @@ public Gen f(final Integer i) { * An arbitrary implementation for long values. */ public static final Arbitrary arbLong = - arbitrary(arbInteger.gen.bind(arbInteger.gen, new F>() { - public F f(final Integer i1) { - return new F() { - public Long f(final Integer i2) { - return (long) i1 << 32L & i2; - } - }; - } - })); + arbitrary(arbInteger.gen.bind(arbInteger.gen, i1 -> i2 -> (long) i1 << 32L & i2)); /** * An arbitrary implementation for long values that checks boundary values (0, 1, -1, max, @@ -458,11 +446,7 @@ public Gen f(final Integer i) { /** * An arbitrary implementation for byte values. */ - public static final Arbitrary arbByte = arbitrary(arbInteger.gen.map(new F() { - public Byte f(final Integer i) { - return (byte) i.intValue(); - } - })); + public static final Arbitrary arbByte = arbitrary(arbInteger.gen.map(i -> (byte) i.intValue())); /** * An arbitrary implementation for byte values that checks boundary values (0, 1, -1, max, @@ -486,11 +470,7 @@ public Gen f(final Integer i) { /** * An arbitrary implementation for short values. */ - public static final Arbitrary arbShort = arbitrary(arbInteger.gen.map(new F() { - public Short f(final Integer i) { - return (short) i.intValue(); - } - })); + public static final Arbitrary arbShort = arbitrary(arbInteger.gen.map(i -> (short) i.intValue())); /** * An arbitrary implementation for short values that checks boundary values (0, 1, -1, max, @@ -514,11 +494,7 @@ public Gen f(final Integer i) { /** * An arbitrary implementation for character values. */ - public static final Arbitrary arbCharacter = arbitrary(choose(0, 65536).map(new F() { - public Character f(final Integer i) { - return (char) i.intValue(); - } - })); + public static final Arbitrary arbCharacter = arbitrary(choose(0, 65536).map(i -> (char) i.intValue())); /** * An arbitrary implementation for character values that checks boundary values (max, min, @@ -539,11 +515,7 @@ public Gen f(final Integer i) { /** * An arbitrary implementation for double values. */ - public static final Arbitrary arbDouble = arbitrary(sized(new F>() { - public Gen f(final Integer i) { - return choose((double) -i, i); - } - })); + public static final Arbitrary arbDouble = arbitrary(sized(i -> choose((double) -i, i))); /** * An arbitrary implementation for double values that checks boundary values (0, 1, -1, max, @@ -569,11 +541,7 @@ public Gen f(final Integer i) { /** * An arbitrary implementation for float values. */ - public static final Arbitrary arbFloat = arbitrary(arbDouble.gen.map(new F() { - public Float f(final Double d) { - return (float) d.doubleValue(); - } - })); + public static final Arbitrary arbFloat = arbitrary(arbDouble.gen.map(d -> (float) d.doubleValue())); /** * An arbitrary implementation for float values that checks boundary values (0, 1, -1, max, @@ -606,15 +574,7 @@ public Gen f(final Integer i) { * An arbitrary implementation for string values with characters in the US-ASCII range. */ public static final Arbitrary arbUSASCIIString = - arbitrary(arbList(arbCharacter).gen.map(new F, String>() { - public String f(final List cs) { - return asString(cs.map(new F() { - public Character f(final Character c) { - return (char) (c % 128); - } - })); - } - })); + arbitrary(arbList(arbCharacter).gen.map(cs -> asString(cs.map(c -> (char) (c % 128))))); /** * An arbitrary implementation for string values with alpha-numeric characters. @@ -643,14 +603,11 @@ public Character f(final Character c) { * @return An arbitrary implementation for generators. */ public static Arbitrary> arbGen(final Arbitrary aa) { - return arbitrary(sized(new F>>() { - @SuppressWarnings("IfMayBeConditional") - public Gen> f(final Integer i) { - if (i == 0) - return fail(); - else - return aa.gen.map(Gen::value).resize(i - 1); - } + return arbitrary(sized(i -> { + if (i == 0) + return fail(); + else + return aa.gen.map(Gen::value).resize(i - 1); })); } @@ -661,13 +618,9 @@ public Gen> f(final Integer i) { * @return An arbitrary implementation for optional values. */ public static Arbitrary> arbOption(final Arbitrary aa) { - return arbitrary(sized(new F>>() { - public Gen> f(final Integer i) { - return i == 0 ? - value(Option.none()) : - aa.gen.map(Option::some).resize(i - 1); - } - })); + return arbitrary(sized(i -> i == 0 ? + value(Option.none()) : + aa.gen.map(Option::some).resize(i - 1))); } /** @@ -800,38 +753,26 @@ public static Arbitrary arbThrowable(final Arbitrary as) { * @return An arbitrary implementation for array lists. */ public static Arbitrary> arbArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, ArrayList>() { - public ArrayList f(final Array a) { - return new ArrayList(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new ArrayList(a.toCollection()))); } /** * An arbitrary implementation for bit sets. */ public static final Arbitrary arbBitSet = - arbitrary(arbList(arbBoolean).gen.map(new F, BitSet>() { - public BitSet f(final List bs) { - final BitSet s = new BitSet(bs.length()); - bs.zipIndex().foreachDoEffect(new Effect1>() { - public void f(final P2 bi) { - s.set(bi._2(), bi._1()); - } - }); - return s; - } + arbitrary(arbList(arbBoolean).gen.map(bs -> { + final BitSet s = new BitSet(bs.length()); + bs.zipIndex().foreachDoEffect(bi -> s.set(bi._2(), bi._1())); + return s; })); /** * An arbitrary implementation for calendars. */ - public static final Arbitrary arbCalendar = arbitrary(arbLong.gen.map(new F() { - public Calendar f(final Long i) { - final Calendar c = Calendar.getInstance(); - c.setTimeInMillis(i); - return c; - } + public static final Arbitrary arbCalendar = arbitrary(arbLong.gen.map(i -> { + final Calendar c = Calendar.getInstance(); + c.setTimeInMillis(i); + return c; })); /** @@ -869,23 +810,17 @@ public static , V> Arbitrary> arbEnumMap(final A * @return An arbitrary implementation for enum sets. */ public static > Arbitrary> arbEnumSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, EnumSet>() { - public EnumSet f(final Array a) { - return copyOf(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> copyOf(a.toCollection()))); } /** * An arbitrary implementation for gregorian calendars. */ public static final Arbitrary arbGregorianCalendar = - arbitrary(arbLong.gen.map(new F() { - public GregorianCalendar f(final Long i) { - final GregorianCalendar c = new GregorianCalendar(); - c.setTimeInMillis(i); - return c; - } + arbitrary(arbLong.gen.map(i -> { + final GregorianCalendar c = new GregorianCalendar(); + c.setTimeInMillis(i); + return c; })); /** @@ -907,11 +842,7 @@ public static Arbitrary> arbHashMap(final Arbitrary ak, * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, HashSet>() { - public HashSet f(final Array a) { - return new HashSet(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new HashSet(a.toCollection()))); } /** @@ -924,23 +855,12 @@ public HashSet f(final Array a) { * @return An arbitrary implementation for hash tables. */ public static Arbitrary> arbHashtable(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbList(ak).gen.bind(arbList(av).gen, new F, F, Hashtable>>() { - public F, Hashtable> f(final List ks) { - return new F, Hashtable>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Hashtable f(final List vs) { - final Hashtable t = new Hashtable(); - - ks.zip(vs).foreachDoEffect(new Effect1>() { - public void f(final P2 kv) { - t.put(kv._1(), kv._2()); - } - }); - - return t; - } - }; - } + return arbitrary(arbList(ak).gen.bind(arbList(av).gen, ks -> vs -> { + final Hashtable t = new Hashtable(); + + ks.zip(vs).foreachDoEffect(kv -> t.put(kv._1(), kv._2())); + + return t; })); } @@ -978,11 +898,7 @@ public static Arbitrary> arbLinkedHashMap(final Arbit * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbLinkedHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, LinkedHashSet>() { - public LinkedHashSet f(final Array a) { - return new LinkedHashSet(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet(a.toCollection()))); } /** @@ -992,11 +908,7 @@ public LinkedHashSet f(final Array a) { * @return An arbitrary implementation for linked lists. */ public static Arbitrary> arbLinkedList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, LinkedList>() { - public LinkedList f(final Array a) { - return new LinkedList(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedList(a.toCollection()))); } /** @@ -1006,28 +918,21 @@ public LinkedList f(final Array a) { * @return An arbitrary implementation for priority queues. */ public static Arbitrary> arbPriorityQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, PriorityQueue>() { - public PriorityQueue f(final Array a) { - return new PriorityQueue(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue(a.toCollection()))); } /** * An arbitrary implementation for properties. */ public static final Arbitrary arbProperties = - arbitrary(arbHashtable(arbString, arbString).gen.map(new F, Properties>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Properties f(final Hashtable ht) { - final Properties p = new Properties(); + arbitrary(arbHashtable(arbString, arbString).gen.map(ht -> { + final Properties p = new Properties(); - for (final String k : ht.keySet()) { - p.setProperty(k, ht.get(k)); - } - - return p; + for (final String k : ht.keySet()) { + p.setProperty(k, ht.get(k)); } + + return p; })); /** @@ -1037,12 +942,10 @@ public Properties f(final Hashtable ht) { * @return An arbitrary implementation for stacks. */ public static Arbitrary> arbStack(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, Stack>() { - public Stack f(final Array a) { - final Stack s = new Stack(); - s.addAll(a.toCollection()); - return s; - } + return arbitrary(arbArray(aa).gen.map(a -> { + final Stack s = new Stack(); + s.addAll(a.toCollection()); + return s; })); } @@ -1102,11 +1005,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb * @return An arbitrary implementation for tree sets. */ public static Arbitrary> arbTreeSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, TreeSet>() { - public TreeSet f(final Array a) { - return new TreeSet(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new TreeSet(a.toCollection()))); } /** @@ -1117,12 +1016,7 @@ public TreeSet f(final Array a) { */ @SuppressWarnings("UseOfObsoleteCollectionType") public static Arbitrary> arbVector(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, Vector>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Vector f(final Array a) { - return new Vector(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new Vector(a.toCollection()))); } /** @@ -1151,20 +1045,8 @@ public static Arbitrary> arbWeakHashMap(final Arbitrary */ public static Arbitrary> arbArrayBlockingQueue(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.bind(arbInteger.gen, arbBoolean.gen, - new F, F>>>() { - public F>> f(final Array a) { - return new F>>() { - public F> f(final Integer capacity) { - return new F>() { - public ArrayBlockingQueue f(final Boolean fair) { - return new ArrayBlockingQueue(a.length() + abs(capacity), - fair, a.toCollection()); - } - }; - } - }; - } - })); + a -> capacity -> fair -> new ArrayBlockingQueue(a.length() + abs(capacity), + fair, a.toCollection()))); } /** @@ -1189,11 +1071,7 @@ public static Arbitrary> arbConcurrentHashMap(fin * @return An arbitrary implementation for concurrent linked queues. */ public static Arbitrary> arbConcurrentLinkedQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, ConcurrentLinkedQueue>() { - public ConcurrentLinkedQueue f(final Array a) { - return new ConcurrentLinkedQueue(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue(a.toCollection()))); } /** @@ -1204,11 +1082,7 @@ public ConcurrentLinkedQueue f(final Array a) { * @return An arbitrary implementation for copy-on-write array lists. */ public static Arbitrary> arbCopyOnWriteArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, CopyOnWriteArrayList>() { - public CopyOnWriteArrayList f(final Array a) { - return new CopyOnWriteArrayList(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList(a.toCollection()))); } /** @@ -1219,11 +1093,7 @@ public CopyOnWriteArrayList f(final Array a) { * @return An arbitrary implementation for copy-on-write array sets. */ public static Arbitrary> arbCopyOnWriteArraySet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, CopyOnWriteArraySet>() { - public CopyOnWriteArraySet f(final Array a) { - return new CopyOnWriteArraySet(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet(a.toCollection()))); } /** @@ -1233,11 +1103,7 @@ public CopyOnWriteArraySet f(final Array a) { * @return An arbitrary implementation for delay queues. */ public static Arbitrary> arbDelayQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, DelayQueue>() { - public DelayQueue f(final Array a) { - return new DelayQueue(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue(a.toCollection()))); } /** @@ -1248,11 +1114,7 @@ public DelayQueue f(final Array a) { * @return An arbitrary implementation for linked blocking queues. */ public static Arbitrary> arbLinkedBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, LinkedBlockingQueue>() { - public LinkedBlockingQueue f(final Array a) { - return new LinkedBlockingQueue(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue(a.toCollection()))); } /** @@ -1263,11 +1125,7 @@ public LinkedBlockingQueue f(final Array a) { * @return An arbitrary implementation for priority blocking queues. */ public static Arbitrary> arbPriorityBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(new F, PriorityBlockingQueue>() { - public PriorityBlockingQueue f(final Array a) { - return new PriorityBlockingQueue(a.toCollection()); - } - })); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue(a.toCollection()))); } /** @@ -1278,16 +1136,10 @@ public PriorityBlockingQueue f(final Array a) { * @return An arbitrary implementation for priority blocking queues. */ public static Arbitrary> arbSynchronousQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.bind(arbBoolean.gen, new F, F>>() { - public F> f(final Array a) { - return new F>() { - public SynchronousQueue f(final Boolean fair) { - final SynchronousQueue q = new SynchronousQueue(fair); - q.addAll(a.toCollection()); - return q; - } - }; - } + return arbitrary(arbArray(aa).gen.bind(arbBoolean.gen, a -> fair -> { + final SynchronousQueue q = new SynchronousQueue(fair); + q.addAll(a.toCollection()); + return q; })); } @@ -1318,22 +1170,16 @@ public SynchronousQueue f(final Boolean fair) { * An arbitrary implementation for big integers. */ public static final Arbitrary arbBigInteger = - arbitrary(arbArray(arbByte).gen.bind(arbByte.gen, new F, F>() { - public F f(final Array a) { - return new F() { - public BigInteger f(final Byte b) { - final byte[] x = new byte[a.length() + 1]; + arbitrary(arbArray(arbByte).gen.bind(arbByte.gen, a -> b -> { + final byte[] x = new byte[a.length() + 1]; - for (int i = 0; i < a.array().length; i++) { - x[i] = a.get(i); - } + for (int i = 0; i < a.array().length; i++) { + x[i] = a.get(i); + } - x[a.length()] = b; + x[a.length()] = b; - return new BigInteger(x); - } - }; - } + return new BigInteger(x); })); /** @@ -1369,15 +1215,7 @@ public static Arbitrary> arbP1(final Arbitrary aa) { * @return An arbitrary implementation for product-2 values. */ public static Arbitrary> arbP2(final Arbitrary aa, final Arbitrary ab) { - return arbitrary(aa.gen.bind(ab.gen, new F>>() { - public F> f(final A a) { - return new F>() { - public P2 f(final B b) { - return p(a, b); - } - }; - } - })); + return arbitrary(aa.gen.bind(ab.gen, a -> b -> p(a, b))); } /** @@ -1393,19 +1231,7 @@ public P2 f(final B b) { */ public static Arbitrary> arbP3(final Arbitrary aa, final Arbitrary ab, final Arbitrary ac) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, new F>>>() { - public F>> f(final A a) { - return new F>>() { - public F> f(final B b) { - return new F>() { - public P3 f(final C c) { - return p(a, b, c); - } - }; - } - }; - } - })); + return arbitrary(aa.gen.bind(ab.gen, ac.gen, a -> b -> c -> p(a, b, c))); } /** @@ -1423,23 +1249,7 @@ public P3 f(final C c) { */ public static Arbitrary> arbP4(final Arbitrary aa, final Arbitrary ab, final Arbitrary ac, final Arbitrary ad) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, new F>>>>() { - public F>>> f(final A a) { - return new F>>>() { - public F>> f(final B b) { - return new F>>() { - public F> f(final C c) { - return new F>() { - public P4 f(final D d) { - return p(a, b, c, d); - } - }; - } - }; - } - }; - } - })); + return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, a -> b -> c -> d -> p(a, b, c, d))); } /** @@ -1460,27 +1270,7 @@ public P4 f(final D d) { public static Arbitrary> arbP5(final Arbitrary aa, final Arbitrary ab, final Arbitrary ac, final Arbitrary ad, final Arbitrary ae) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, new F>>>>>() { - public F>>>> f(final A a) { - return new F>>>>() { - public F>>> f(final B b) { - return new F>>>() { - public F>> f(final C c) { - return new F>>() { - public F> f(final D d) { - return new F>() { - public P5 f(final E e) { - return p(a, b, c, d, e); - } - }; - } - }; - } - }; - } - }; - } - })); + return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, a -> b -> c -> d -> e -> p(a, b, c, d, e))); } /** @@ -1505,31 +1295,7 @@ public P5 f(final E e) { final Arbitrary ae, final Arbitrary af) { return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, - new F>>>>>>() { - public F>>>>> f(final A a) { - return new F>>>>>() { - public F>>>> f(final B b) { - return new F>>>>() { - public F>>> f(final C c) { - return new F>>>() { - public F>> f(final D d) { - return new F>>() { - public F> f(final E e) { - return new F>() { - public P6 f(final F$ f) { - return p(a, b, c, d, e, f); - } - }; - } - }; - } - }; - } - }; - } - }; - } - })); + a -> b -> c -> d -> e -> f -> p(a, b, c, d, e, f))); } /** @@ -1559,35 +1325,7 @@ public P5 f(final E e) { final Arbitrary af, final Arbitrary ag) { return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, ag.gen, - new F>>>>>>>() { - public F>>>>>> f(final A a) { - return new F>>>>>>() { - public F>>>>> f(final B b) { - return new F>>>>>() { - public F>>>> f(final C c) { - return new F>>>>() { - public F>>> f(final D d) { - return new F>>>() { - public F>> f(final E e) { - return new F>>() { - public F> f(final F$ f) { - return new F>() { - public P7 f(final G g) { - return p(a, b, c, d, e, f, g); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }; - } - })); + a -> b -> c -> d -> e -> f -> g -> p(a, b, c, d, e, f, g))); } /** @@ -1620,42 +1358,6 @@ public P5 f(final E e) { final Arbitrary ag, final Arbitrary ah) { return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, ag.gen, ah.gen, - new F>>>>>>>>() { - public F>>>>>>> f( - final A a) { - return new F>>>>>>>() { - public F>>>>>> f( - final B b) { - return new F>>>>>>() { - public F>>>>> f( - final C c) { - return new F>>>>>() { - public F>>>> f( - final D d) { - return new F>>>>() { - public F>>> f(final E e) { - return new F>>>() { - public F>> f(final F$ f) { - return new F>>() { - public F> f(final G g) { - return new F>() { - public P8 f(final H h) { - return p(a, b, c, d, e, f, g, h); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }; - } - }; - } - })); + a -> b -> c -> d -> e -> f -> g -> h -> p(a, b, c, d, e, f, g, h))); } } diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index bb607aa5..9655aec2 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -76,11 +76,7 @@ public abstract class Coarbitrary { * @return A curried version of {@link #coarbitrary(Object, Gen)}. */ public final F, Gen> coarbitrary(final A a) { - return new F, Gen>() { - public Gen f(final Gen g) { - return coarbitrary(a, g); - } - }; + return g -> coarbitrary(a, g); } /** @@ -121,11 +117,7 @@ public Gen coarbitrary(final B b, final Gen g) { public static Coarbitrary> coarbF(final Arbitrary a, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F f, final Gen g) { - return a.gen.bind(new F>() { - public Gen f(final A a) { - return c.coarbitrary(f.f(a), g); - } - }); + return a.gen.bind(a1 -> c.coarbitrary(f.f(a1), g)); } }; } diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index b3bb1371..45a4429a 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -110,15 +110,7 @@ public A gen(final int i, final Rand r) { * @return A new generator after applying the mapping function. */ public Gen map(final F f) { - return new Gen(new F>() { - public F f(final Integer i) { - return new F() { - public B f(final Rand r) { - return f.f(gen(i, r)); - } - }; - } - }); + return new Gen(i -> r -> f.f(gen(i, r))); } /** @@ -169,15 +161,7 @@ public void foreachDoEffect(final Integer i, final Rand r, final Effect1 f) { * @return A new generator after binding the given function. */ public Gen bind(final F> f) { - return new Gen(new F>() { - public F f(final Integer i) { - return new F() { - public B f(final Rand r) { - return f.f(gen(i, r)).f.f(i).f(r); - } - }; - } - }); + return new Gen(i -> r -> f.f(gen(i, r)).f.f(i).f(r)); } /** @@ -292,11 +276,7 @@ public Gen bind(final Gen gb, final Gen gc, final Gen g * @return A new generator after function application. */ public Gen apply(final Gen> gf) { - return gf.bind(new F, Gen>() { - public Gen f(final F f) { - return map(f::f); - } - }); + return gf.bind(f1 -> map(f1::f)); } /** @@ -306,15 +286,7 @@ public Gen f(final F f) { * @return A new generator that uses the given size. */ public Gen resize(final int s) { - return new Gen(new F>() { - public F f(final Integer i) { - return new F() { - public A f(final Rand r) { - return f.f(s).f(r); - } - }; - } - }); + return new Gen(i -> r -> f.f(s).f(r)); } /** @@ -376,15 +348,7 @@ public static Gen sized(final F> f) { * @return A generator that always produces the given value. */ public static Gen value(final A a) { - return new Gen(new F>() { - public F f(final Integer i) { - return new F() { - public A f(final Rand r) { - return a; - } - }; - } - }); + return new Gen(i -> r -> a); } /** @@ -410,15 +374,7 @@ public static Gen choose(final int from, final int to) { public static Gen choose(final double from, final double to) { final double f = min(from, to); final double t = max(from, to); - return parameterised(new F>>() { - public F> f(final Integer i) { - return new F>() { - public Gen f(final Rand r) { - return value(r.choose(f, t)); - } - }; - } - }); + return parameterised(i -> r -> value(r.choose(f, t))); } /** @@ -427,14 +383,8 @@ public Gen f(final Rand r) { * @return A generator that never returns a value. */ public static Gen fail() { - return new Gen(new F>() { - public F f(final Integer i) { - return new F() { - public A f(final Rand r) { - throw error("Failing generator"); - } - }; - } + return new Gen(i -> r -> { + throw error("Failing generator"); }); } @@ -471,11 +421,7 @@ Gen pick(final int n, final List>> gs) { final F>, Integer> f = __1(); - return choose(1, intAdditionMonoid.sumLeft(gs.map(f))).bind(new F>() { - public Gen f(final Integer i) { - return new Pick().pick(i, gs); - } - }); + return choose(1, intAdditionMonoid.sumLeft(gs.map(f))).bind(i -> new Pick().pick(i, gs)); } /** @@ -486,11 +432,7 @@ public Gen f(final Integer i) { * @return A new generator that uses the given pairs of frequency and value. */ public static Gen elemFrequency(final List> as) { - return frequency(as.map(new F, P2>>() { - public P2> f(final P2 p) { - return p.map2(Gen::value); - } - })); + return frequency(as.map(p -> p.map2(Gen::value))); } /** @@ -501,11 +443,7 @@ public P2> f(final P2 p) { */ @SafeVarargs public static Gen elements(final A... as) { - return array(as).isEmpty() ? Gen.fail() : choose(0, as.length - 1).map(new F() { - public A f(final Integer i) { - return as[i]; - } - }); + return array(as).isEmpty() ? Gen.fail() : choose(0, as.length - 1).map(i -> as[i]); } /** @@ -785,18 +723,6 @@ public static Gen> someWordOf(int maxLength, List as) { * @return A generator for functions. */ public static Gen> promote(final F> f) { - return new Gen>(new F>>() { - public F> f(final Integer i) { - return new F>() { - public F f(final Rand r) { - return new F() { - public B f(final A a) { - return f.f(a).f.f(i).f(r); - } - }; - } - }; - } - }); + return new Gen>(i -> r -> a -> f.f(a).f.f(i).f(r)); } } diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index d0eeb5ae..d69d0c65 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -54,15 +54,7 @@ public Result prop(final int i, final Rand r) { * @return A generator of results from this property. */ public Gen gen() { - return Gen.gen(new F>() { - public F f(final Integer i) { - return new F() { - public Result f(final Rand r) { - return f.f(i).f(r); - } - }; - } - }); + return Gen.gen(i -> r -> f.f(i).f(r)); } /** @@ -72,15 +64,7 @@ public Result f(final Rand r) { * @return A conjunction of this property with the given property. */ public Property and(final Property p) { - return fromGen(gen().bind(p.gen(), new F>() { - public F f(final Result res1) { - return new F() { - public Result f(final Result res2) { - return res1.isException() || res1.isFalsified() ? res1 : res2.isException() || res2.isFalsified() ? res2 : res1.isProven() || res1.isUnfalsified() ? res2 : res2.isProven() || res2.isUnfalsified() ? res1 : noResult(); - } - }; - } - })); + return fromGen(gen().bind(p.gen(), res1 -> res2 -> res1.isException() || res1.isFalsified() ? res1 : res2.isException() || res2.isFalsified() ? res2 : res1.isProven() || res1.isUnfalsified() ? res2 : res2.isProven() || res2.isUnfalsified() ? res1 : noResult())); } /** @@ -90,15 +74,7 @@ public Result f(final Result res2) { * @return A disjunction of this property with the given property. */ public Property or(final Property p) { - return fromGen(gen().bind(p.gen(), new F>() { - public F f(final Result res1) { - return new F() { - public Result f(final Result res2) { - return res1.isException() || res1.isFalsified() ? res1 : res2.isException() || res2.isFalsified() ? res2 : res1.isProven() || res1.isUnfalsified() ? res1 : res2.isProven() || res2.isUnfalsified() ? res2 : noResult(); - } - }; - } - })); + return fromGen(gen().bind(p.gen(), res1 -> res2 -> res1.isException() || res1.isFalsified() ? res1 : res2.isException() || res2.isFalsified() ? res2 : res1.isProven() || res1.isUnfalsified() ? res1 : res2.isProven() || res2.isUnfalsified() ? res2 : noResult())); } /** @@ -111,15 +87,7 @@ public Result f(final Result res2) { * @return A sequence of this property with the given property. */ public Property sequence(final Property p) { - return fromGen(gen().bind(p.gen(), new F>() { - public F f(final Result res1) { - return new F() { - public Result f(final Result res2) { - return res1.isException() || res1.isProven() || res1.isUnfalsified() ? res1 : res2.isException() || res2.isProven() || res2.isUnfalsified() ? res2 : res1.isFalsified() ? res2 : res2.isFalsified() ? res1 : noResult(); - } - }; - } - })); + return fromGen(gen().bind(p.gen(), res1 -> res2 -> res1.isException() || res1.isProven() || res1.isUnfalsified() ? res1 : res2.isException() || res2.isProven() || res2.isUnfalsified() ? res2 : res1.isFalsified() ? res2 : res2.isFalsified() ? res1 : noResult())); } /** @@ -351,15 +319,7 @@ public CheckResult maxSize(final Rand r, final int maxSize) { * @return A property that produces a result only if the given condition satisfies. */ public static Property implies(final boolean b, final F0 p) { - return b ? p.f() : new Property(new F>() { - public F f(final Integer i) { - return new F() { - public Result f(final Rand r) { - return noResult(); - } - }; - } - }); + return b ? p.f() : new Property(i -> r -> noResult()); } /** @@ -395,15 +355,7 @@ public static Property prop(final F> f) { * @return A property that always has the given result. */ public static Property prop(final Result r) { - return new Property(new F>() { - public F f(final Integer integer) { - return new F() { - public Result f(final Rand x) { - return r; - } - }; - } - }); + return new Property(integer -> x -> r); } /** @@ -426,15 +378,7 @@ public static Property prop(final boolean b) { * @return A property from a generator of results. */ public static Property fromGen(final Gen g) { - return prop(new F>() { - public F f(final Integer i) { - return new F() { - public Result f(final Rand r) { - return g.gen(i, r); - } - }; - } - }); + return prop(i -> r -> g.gen(i, r)); } /** @@ -448,56 +392,44 @@ public Result f(final Rand r) { * application of its arguments. */ public static Property forall(final Gen g, final Shrink shrink, final F> f) { - return prop(new F>() { - public F f(final Integer i) { - return new F() { - public Result f(final Rand r) { - final class Util { - @SuppressWarnings("IfMayBeConditional") - Option> first(final Stream as, final int shrinks) { - final Stream>> results = as.map(new F>>() { - public Option> f(final A a) { - final Result result = exception(f.f(a)).prop(i, r); - - return result.toOption().map(new F>() { - public P2 f(final Result result) { - return p(a, result.provenAsUnfalsified().addArg(arg(a, shrinks))); - } - }); - } - }); - - if (results.isEmpty()) - return none(); - else return results.find(this::failed).orSome(results::head); - } - - public boolean failed(final Option> o) { - return o.isSome() && o.some()._2().failed(); - } - } - - final Util u = new Util(); - - Option> x = u.first(Stream.single(g.gen(i, r)), 0); - final F, Result> __2 = __2(); - if (u.failed(x)) { - Option or; - int shrinks = 0; - - do { - shrinks++; - or = x.map(__2); - x = u.first(shrink.shrink(x.some()._1()), shrinks); - } - while (u.failed(x)); - - return noResult(or); - } else - return noResult(x.map(__2)); - } - }; + return prop(i -> r -> { + final class Util { + @SuppressWarnings("IfMayBeConditional") + Option> first(final Stream as, final int shrinks) { + final Stream>> results = as.map(a -> { + final Result result = exception(f.f(a)).prop(i, r); + + return result.toOption().map(result1 -> p(a, result1.provenAsUnfalsified().addArg(arg(a, shrinks)))); + }); + + if (results.isEmpty()) + return none(); + else return results.find(this::failed).orSome(results::head); + } + + public boolean failed(final Option> o) { + return o.isSome() && o.some()._2().failed(); + } } + + final Util u = new Util(); + + Option> x = u.first(Stream.single(g.gen(i, r)), 0); + final F, Result> __2 = __2(); + if (u.failed(x)) { + Option or; + int shrinks = 0; + + do { + shrinks++; + or = x.map(__2); + x = u.first(shrink.shrink(x.some()._1()), shrinks); + } + while (u.failed(x)); + + return noResult(or); + } else + return noResult(x.map(__2)); }); } @@ -569,14 +501,10 @@ public static Property property(final Arbitrary aa, final F * application of its arguments. */ public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F>> f) { - return property(aa, sa, new F() { - public Property f(final A a) { - return propertyP(ab, sb, new F>() { - public P1 f(final B b) { - return f.f(a).f(b); - } - }); - } + return property(aa, sa, a -> { + return propertyP(ab, sb, b -> { + return f.f(a).f(b); + }); }); } @@ -607,15 +535,7 @@ public static Property property(final Arbitrary aa, final Arbitrary * application of its arguments. */ public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final F>> f) { - return property(aa, new F() { - public Property f(final A a) { - return propertyP(ab, new F>() { - public P1 f(final B b) { - return f.f(a).f(b); - } - }); - } - }); + return property(aa, a -> propertyP(ab, b -> f.f(a).f(b))); } /** @@ -713,19 +633,9 @@ public static Property property(final Arbitrary aa, final Shrink sb, final Shrink sc, final F>> f) { - return property(aa, ab, sa, sb, new F>() { - public F f(final A a) { - return new F() { - public Property f(final B b) { - return property(ac, sc, new F() { - public Property f(final C c) { - return f.f(a).f(b).f(c); - } - }); - } - }; - } - }); + return property(aa, ab, sa, sb, a -> b -> property(ac, sc, c -> { + return f.f(a).f(b).f(c); + })); } /** @@ -743,19 +653,7 @@ public static Property property(final Arbitrary aa, final Arbitrary ab, final Arbitrary ac, final F>> f) { - return property(aa, ab, new F>() { - public F f(final A a) { - return new F() { - public Property f(final B b) { - return property(ac, new F() { - public Property f(final C c) { - return f.f(a).f(b).f(c); - } - }); - } - }; - } - }); + return property(aa, ab, a -> b -> property(ac, c -> f.f(a).f(b).f(c))); } /** @@ -825,23 +723,9 @@ public static Property property(final Arbitrary aa, final Shrink sc, final Shrink sd, final F>>> f) { - return property(aa, ab, ac, sa, sb, sc, new F>>() { - public F> f(final A a) { - return new F>() { - public F f(final B b) { - return new F() { - public Property f(final C c) { - return property(ad, sd, new F() { - public Property f(final D d) { - return f.f(a).f(b).f(c).f(d); - } - }); - } - }; - } - }; - } - }); + return property(aa, ab, ac, sa, sb, sc, a -> b -> c -> property(ad, sd, d -> { + return f.f(a).f(b).f(c).f(d); + })); } /** @@ -861,23 +745,7 @@ public static Property property(final Arbitrary aa, final Arbitrary ac, final Arbitrary ad, final F>>> f) { - return property(aa, ab, ac, new F>>() { - public F> f(final A a) { - return new F>() { - public F f(final B b) { - return new F() { - public Property f(final C c) { - return property(ad, new F() { - public Property f(final D d) { - return f.f(a).f(b).f(c).f(d); - } - }); - } - }; - } - }; - } - }); + return property(aa, ab, ac, a -> b -> c -> property(ad, d -> f.f(a).f(b).f(c).f(d))); } /** @@ -957,27 +825,9 @@ public static Property property(final Arbitrary aa, final Shrink sd, final Shrink se, final F>>>> f) { - return property(aa, ab, ac, ad, sa, sb, sc, sd, new F>>>() { - public F>> f(final A a) { - return new F>>() { - public F> f(final B b) { - return new F>() { - public F f(final C c) { - return new F() { - public Property f(final D d) { - return property(ae, se, new F() { - public Property f(final E e) { - return f.f(a).f(b).f(c).f(d).f(e); - } - }); - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, sa, sb, sc, sd, a -> b -> c -> d -> property(ae, se, e -> { + return f.f(a).f(b).f(c).f(d).f(e); + })); } /** @@ -999,27 +849,7 @@ public static Property property(final Arbitrary aa, final Arbitrary ad, final Arbitrary ae, final F>>>> f) { - return property(aa, ab, ac, ad, new F>>>() { - public F>> f(final A a) { - return new F>>() { - public F> f(final B b) { - return new F>() { - public F f(final C c) { - return new F() { - public Property f(final D d) { - return property(ae, new F() { - public Property f(final E e) { - return f.f(a).f(b).f(c).f(d).f(e); - } - }); - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, a -> b -> c -> d -> property(ae, e -> f.f(a).f(b).f(c).f(d).f(e))); } /** @@ -1109,31 +939,9 @@ public static Property property(final Arbitrary aa, final Shrink se, final Shrink sf, final F>>>>> f) { - return property(aa, ab, ac, ad, ae, sa, sb, sc, sd, se, new F>>>>() { - public F>>> f(final A a) { - return new F>>>() { - public F>> f(final B b) { - return new F>>() { - public F> f(final C c) { - return new F>() { - public F f(final D d) { - return new F() { - public Property f(final E e) { - return property(af, sf, new F() { - public Property f(final F$ f$) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, sa, sb, sc, sd, se, a -> b -> c -> d -> e -> property(af, sf, f$ -> { + return f.f(a).f(b).f(c).f(d).f(e).f(f$); + })); } /** @@ -1157,31 +965,7 @@ public Property f(final F$ f$) { final Arbitrary ae, final Arbitrary af, final F>>>>> f) { - return property(aa, ab, ac, ad, ae, new F>>>>() { - public F>>> f(final A a) { - return new F>>>() { - public F>> f(final B b) { - return new F>>() { - public F> f(final C c) { - return new F>() { - public F f(final D d) { - return new F() { - public Property f(final E e) { - return property(af, new F() { - public Property f(final F$ f$) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, a -> b -> c -> d -> e -> property(af, f$ -> f.f(a).f(b).f(c).f(d).f(e).f(f$))); } /** @@ -1281,35 +1065,9 @@ public Property f(final F$ f$) { final Shrink sf, final Shrink sg, final F>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, sa, sb, sc, sd, se, sf, new F>>>>>() { - public F>>>> f(final A a) { - return new F>>>>() { - public F>>> f(final B b) { - return new F>>>() { - public F>> f(final C c) { - return new F>>() { - public F> f(final D d) { - return new F>() { - public F f(final E e) { - return new F() { - public Property f(final F$ f$) { - return property(ag, sg, new F() { - public Property f(final G g) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, af, sa, sb, sc, sd, se, sf, a -> b -> c -> d -> e -> f$ -> property(ag, sg, g -> { + return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g); + })); } /** @@ -1335,35 +1093,7 @@ public Property f(final G g) { final Arbitrary af, final Arbitrary ag, final F>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, new F>>>>>() { - public F>>>> f(final A a) { - return new F>>>>() { - public F>>> f(final B b) { - return new F>>>() { - public F>> f(final C c) { - return new F>>() { - public F> f(final D d) { - return new F>() { - public F f(final E e) { - return new F() { - public Property f(final F$ f$) { - return property(ag, new F() { - public Property f(final G g) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, af, a -> b -> c -> d -> e -> f$ -> property(ag, g -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g))); } /** @@ -1473,39 +1203,9 @@ public Property f(final G g) { final Shrink sg, final Shrink sh, final F>>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, ag, sa, sb, sc, sd, se, sf, sg, new F>>>>>>() { - public F>>>>> f(final A a) { - return new F>>>>>() { - public F>>>> f(final B b) { - return new F>>>>() { - public F>>> f(final C c) { - return new F>>>() { - public F>> f(final D d) { - return new F>>() { - public F> f(final E e) { - return new F>() { - public F f(final F$ f$) { - return new F() { - public Property f(final G g) { - return property(ah, sh, new F() { - public Property f(final H h) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, af, ag, sa, sb, sc, sd, se, sf, sg, a -> b -> c -> d -> e -> f$ -> g -> property(ah, sh, h -> { + return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h); + })); } /** @@ -1533,39 +1233,7 @@ public Property f(final H h) { final Arbitrary ag, final Arbitrary ah, final F>>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, ag, new F>>>>>>() { - public F>>>>> f(final A a) { - return new F>>>>>() { - public F>>>> f(final B b) { - return new F>>>>() { - public F>>> f(final C c) { - return new F>>>() { - public F>> f(final D d) { - return new F>>() { - public F> f(final E e) { - return new F>() { - public F f(final F$ f$) { - return new F() { - public Property f(final G g) { - return property(ah, new F() { - public Property f(final H h) { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h); - } - }); - } - }; - } - }; - } - }; - } - }; - } - }; - } - }; - } - }); + return property(aa, ab, ac, ad, ae, af, ag, a -> b -> c -> d -> e -> f$ -> g -> property(ah, h -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h))); } /** @@ -1652,15 +1320,7 @@ public static Property exception(final F0 p) { try { return p.f(); } catch (final Throwable t) { - return new Property(new F>() { - public F f(final Integer i) { - return new F() { - public Result f(final Rand r) { - return Result.exception(List.>nil(), t); - } - }; - } - }); + return new Property(i -> r -> Result.exception(List.>nil(), t)); } } diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index a4994bcb..f4da2459 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -80,11 +80,7 @@ public static List> check(final List List> check(final List> c, final Rand r, final String... categories) { - return join(c.map(new F, List>>() { - public List> f(final java.lang.Class c) { - return check(c, r, categories); - } - })); + return join(c.map(c1 -> check(c1, r, categories))); } /** @@ -142,18 +138,12 @@ public static List> check(final java.lang.Class c * @return The results of checking the properties on the given class. */ public static List> check(final java.lang.Class c, final Rand r, final String... categories) { - return join(clas(c).inheritance().map(new F, List>>>() { - public List>> f(final Class c) { - return properties(c.clas(), categories); - } - })).map(new F>, P2>() { - public P2 f(final P3> p) { - if(p._3().isSome()) { - final CheckParams ps = p._3().some(); - return p(p._2(), p._1().check(r, ps.minSuccessful(), ps.maxDiscarded(), ps.minSize(), ps.maxSize())); - } else - return p(p._2(), p._1().check(r)); - } + return join(clas(c).inheritance().map(c1 -> properties(c1.clas(), categories))).map(p -> { + if(p._3().isSome()) { + final CheckParams ps = p._3().some(); + return p(p._2(), p._1().check(r, ps.minSuccessful(), ps.maxDiscarded(), ps.minSize(), ps.maxSize())); + } else + return p(p._2(), p._1().check(r)); }); } @@ -187,68 +177,62 @@ public static List> check(final java.lang.Class c */ public static List>> properties(final java.lang.Class c, final String... categories) { //noinspection ClassEscapesDefinedScope - final Array>> propFields = properties(array(c.getDeclaredFields()).map(new F() { - public PropertyMember f(final Field f) { - return new PropertyMember() { - public java.lang.Class type() { - return f.getType(); - } - - public AnnotatedElement element() { - return f; - } - - public String name() { - return f.getName(); - } - - public int modifiers() { - return f.getModifiers(); - } - - public Property invoke(final X x) throws IllegalAccessException { - f.setAccessible(true); - return (Property)f.get(x); - } - - public boolean isProperty() { - return true; - } - }; + final Array>> propFields = properties(array(c.getDeclaredFields()).map((F) f -> new PropertyMember() { + public java.lang.Class type() { + return f.getType(); + } + + public AnnotatedElement element() { + return f; + } + + public String name() { + return f.getName(); + } + + public int modifiers() { + return f.getModifiers(); + } + + public Property invoke(final X x) throws IllegalAccessException { + f.setAccessible(true); + return (Property)f.get(x); + } + + public boolean isProperty() { + return true; } }), c, categories); //noinspection ClassEscapesDefinedScope - final Array>> propMethods = properties(array(c.getDeclaredMethods()).map(new F() { - public PropertyMember f(final Method m) { - //noinspection ProhibitedExceptionDeclared - return new PropertyMember() { - public java.lang.Class type() { - return m.getReturnType(); - } - - public AnnotatedElement element() { - return m; - } - - public String name() { - return m.getName(); - } - - public int modifiers() { - return m.getModifiers(); - } - - public Property invoke(final X x) throws Exception { - m.setAccessible(true); - return (Property)m.invoke(x); - } - - public boolean isProperty() { - return m.getParameterTypes().length == 0; - } - }; - } + final Array>> propMethods = properties(array(c.getDeclaredMethods()).map((F) m -> { + //noinspection ProhibitedExceptionDeclared + return new PropertyMember() { + public java.lang.Class type() { + return m.getReturnType(); + } + + public AnnotatedElement element() { + return m; + } + + public String name() { + return m.getName(); + } + + public int modifiers() { + return m.getModifiers(); + } + + public Property invoke(final X x) throws Exception { + m.setAccessible(true); + return (Property)m.invoke(x); + } + + public boolean isProperty() { + return m.getParameterTypes().length == 0; + } + }; }), c, categories); return propFields.append(propMethods).toList(); @@ -265,62 +249,41 @@ private interface PropertyMember { } private static Array>> properties(final Array ms, final java.lang.Class declaringClass, final String... categories) { - final Option t = emptyCtor(declaringClass).map(new F, T>() { - @SuppressWarnings("OverlyBroadCatchBlock") - public T f(final Constructor ctor) { - try { - ctor.setAccessible(true); - return ctor.newInstance(); - } catch(Exception e) { - throw new Error(e.getMessage(), e); - } + final Option t = emptyCtor(declaringClass).map(ctor -> { + try { + ctor.setAccessible(true); + return ctor.newInstance(); + } catch(Exception e) { + throw new Error(e.getMessage(), e); } }); - final F> p = new F>() { - public F f(final AnnotatedElement e) { - return new F() { - public Boolean f(final String s) { - final F p = new F() { - public Boolean f(final Category c) { - return array(c.value()).exists(new F() { - public Boolean f(final String cs) { - return cs.equals(s); - } - }); - } - }; - - @SuppressWarnings("unchecked") - final List bss = somes(list(fromNull(e.getAnnotation(Category.class)).map(p), - fromNull(declaringClass.getAnnotation(Category.class)).map(p))); - return bss.exists(Function.identity()); - } - }; - } + final F> p = e -> s -> { + final F p1 = c -> array(c.value()).exists(cs -> cs.equals(s)); + + @SuppressWarnings("unchecked") + final List bss = somes(list(fromNull(e.getAnnotation(Category.class)).map(p1), + fromNull(declaringClass.getAnnotation(Category.class)).map(p1))); + return bss.exists(Function.identity()); }; final F nameS = Name::value; - return ms.filter(new F() { - public Boolean f(final PropertyMember m) { - //noinspection ObjectEquality - return m.isProperty() && - m.type() == Property.class && - !m.element().isAnnotationPresent(NoCheck.class) && - !declaringClass.isAnnotationPresent(NoCheck.class) && - (categories.length == 0 || array(categories).exists(p.f(m.element()))) && - (t.isSome() || isStatic(m.modifiers())); - } - }).map(new F>>() { - public P3> f(final PropertyMember m) { - try { - final Option params = fromNull(m.element().getAnnotation(CheckParams.class)).orElse(fromNull(declaringClass.getAnnotation(CheckParams.class))); - final String name = fromNull(m.element().getAnnotation(Name.class)).map(nameS).orSome(m.name()); - return p(m.invoke(t.orSome(P.p(null))), name, params); - } catch(Exception e) { - throw new Error(e.getMessage(), e); - } + return ms.filter(m -> { + //noinspection ObjectEquality + return m.isProperty() && + m.type() == Property.class && + !m.element().isAnnotationPresent(NoCheck.class) && + !declaringClass.isAnnotationPresent(NoCheck.class) && + (categories.length == 0 || array(categories).exists(p.f(m.element()))) && + (t.isSome() || isStatic(m.modifiers())); + }).map(m -> { + try { + final Option params = fromNull(m.element().getAnnotation(CheckParams.class)).orElse(fromNull(declaringClass.getAnnotation(CheckParams.class))); + final String name = fromNull(m.element().getAnnotation(Name.class)).map(nameS).orSome(m.name()); + return p(m.invoke(t.orSome(P.p(null))), name, params); + } catch(Exception e) { + throw new Error(e.getMessage(), e); } }); } diff --git a/quickcheck/src/main/java/fj/test/reflect/Main.java b/quickcheck/src/main/java/fj/test/reflect/Main.java index b0b5fb95..5f6f3dfc 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Main.java +++ b/quickcheck/src/main/java/fj/test/reflect/Main.java @@ -36,11 +36,9 @@ public static void main(final String... args) { exit(441); } else { try { - check(forName(args[0]), array(args).toList().tail()).foreachDoEffect(new Effect1>() { - public void f(final P2 r) { - summary.print(r._2()); - out.println(" (" + r._1() + ')'); - } + check(forName(args[0]), array(args).toList().tail()).foreachDoEffect(r -> { + summary.print(r._2()); + out.println(" (" + r._1() + ')'); }); } catch(ClassNotFoundException e) { e.printStackTrace(); From 4b053ca403df1469db25c8d17cf7049460516c0a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 5 Mar 2016 23:16:42 +0100 Subject: [PATCH 045/336] Make use of type inference --- core/src/main/java/fj/Class.java | 4 +- core/src/main/java/fj/Equal.java | 24 +- core/src/main/java/fj/F1Functions.java | 32 +- core/src/main/java/fj/F1W.java | 2 +- core/src/main/java/fj/Function.java | 4 +- core/src/main/java/fj/Hash.java | 22 +- core/src/main/java/fj/LcgRng.java | 2 +- core/src/main/java/fj/Monoid.java | 22 +- core/src/main/java/fj/Ord.java | 12 +- core/src/main/java/fj/P1.java | 10 +- core/src/main/java/fj/P2.java | 4 +- core/src/main/java/fj/P3.java | 2 +- core/src/main/java/fj/P4.java | 2 +- core/src/main/java/fj/P5.java | 2 +- core/src/main/java/fj/P6.java | 14 +- core/src/main/java/fj/P7.java | 16 +- core/src/main/java/fj/P8.java | 18 +- core/src/main/java/fj/Semigroup.java | 4 +- core/src/main/java/fj/Show.java | 18 +- core/src/main/java/fj/control/Trampoline.java | 10 +- core/src/main/java/fj/control/db/DB.java | 2 +- .../main/java/fj/control/parallel/Actor.java | 8 +- .../java/fj/control/parallel/Callables.java | 5 +- .../java/fj/control/parallel/ParModule.java | 30 +- .../java/fj/control/parallel/Promise.java | 18 +- .../java/fj/control/parallel/Strategy.java | 20 +- core/src/main/java/fj/data/$.java | 2 +- core/src/main/java/fj/data/Array.java | 44 +-- core/src/main/java/fj/data/DList.java | 4 +- core/src/main/java/fj/data/Either.java | 88 +++--- core/src/main/java/fj/data/Enumerator.java | 90 +++--- core/src/main/java/fj/data/HashMap.java | 40 +-- core/src/main/java/fj/data/HashSet.java | 10 +- core/src/main/java/fj/data/IOFunctions.java | 32 +- core/src/main/java/fj/data/IterableW.java | 6 +- core/src/main/java/fj/data/Iteratee.java | 16 +- core/src/main/java/fj/data/Java.java | 290 +++++++++--------- core/src/main/java/fj/data/LazyString.java | 2 +- core/src/main/java/fj/data/List.java | 78 ++--- core/src/main/java/fj/data/Natural.java | 2 +- core/src/main/java/fj/data/NonEmptyList.java | 12 +- core/src/main/java/fj/data/Option.java | 48 +-- core/src/main/java/fj/data/Reader.java | 2 +- core/src/main/java/fj/data/Seq.java | 16 +- core/src/main/java/fj/data/Set.java | 38 +-- core/src/main/java/fj/data/State.java | 6 +- core/src/main/java/fj/data/Stream.java | 60 ++-- core/src/main/java/fj/data/Tree.java | 20 +- core/src/main/java/fj/data/TreeMap.java | 44 +-- core/src/main/java/fj/data/TreeZipper.java | 54 ++-- core/src/main/java/fj/data/Validation.java | 38 +-- core/src/main/java/fj/data/Writer.java | 4 +- core/src/main/java/fj/data/Zipper.java | 44 +-- .../main/java/fj/data/fingertrees/Deep.java | 40 +-- .../main/java/fj/data/fingertrees/Digit.java | 30 +- .../main/java/fj/data/fingertrees/Empty.java | 4 +- .../java/fj/data/fingertrees/FingerTree.java | 6 +- .../java/fj/data/fingertrees/MakeTree.java | 22 +- .../java/fj/data/fingertrees/Measured.java | 6 +- .../main/java/fj/data/fingertrees/Node.java | 4 +- .../main/java/fj/data/fingertrees/Node2.java | 2 +- .../main/java/fj/data/fingertrees/Node3.java | 2 +- .../main/java/fj/data/fingertrees/Single.java | 6 +- core/src/main/java/fj/data/hlist/HList.java | 10 +- core/src/main/java/fj/data/optic/Fold.java | 2 +- .../src/main/java/fj/data/optic/Optional.java | 4 +- .../main/java/fj/data/optic/POptional.java | 2 +- core/src/main/java/fj/data/optic/Prism.java | 2 +- core/src/main/java/fj/data/vector/V2.java | 2 +- core/src/main/java/fj/data/vector/V3.java | 8 +- core/src/main/java/fj/data/vector/V4.java | 34 +- core/src/main/java/fj/data/vector/V5.java | 42 +-- core/src/main/java/fj/data/vector/V6.java | 50 +-- core/src/main/java/fj/data/vector/V7.java | 58 ++-- core/src/main/java/fj/data/vector/V8.java | 54 ++-- core/src/main/java/fj/function/Visitor.java | 6 +- core/src/main/java/fj/parser/Parser.java | 26 +- core/src/main/java/fj/parser/Result.java | 2 +- demo/src/main/java/fj/demo/ChequeWrite.java | 10 +- .../main/java/fj/demo/Comonad_example.java | 4 +- demo/src/main/java/fj/demo/Option_bind.java | 6 +- .../fj/demo/StateDemo_VendingMachine.java | 2 +- .../main/java/fj/demo/concurrent/Fibs.java | 2 +- .../java/fj/demo/concurrent/MapReduce.java | 2 +- .../java/fj/demo/concurrent/WordCount.java | 20 +- .../java/fj/demo/test/JavaLinkedList.java | 2 +- .../java/fj/demo/test/ListFunctorLaws.java | 2 +- .../fj/demo/test/OptionMonadFunctorLaw.java | 2 +- .../src/main/java/fj/test/Arbitrary.java | 130 ++++---- quickcheck/src/main/java/fj/test/Arg.java | 2 +- .../src/main/java/fj/test/CheckResult.java | 10 +- .../src/main/java/fj/test/Coarbitrary.java | 22 +- quickcheck/src/main/java/fj/test/Gen.java | 24 +- .../src/main/java/fj/test/Property.java | 14 +- quickcheck/src/main/java/fj/test/Rand.java | 4 +- quickcheck/src/main/java/fj/test/Result.java | 8 +- quickcheck/src/main/java/fj/test/Shrink.java | 56 ++-- quickcheck/src/main/java/fj/test/Variant.java | 2 +- .../src/main/java/fj/test/reflect/Check.java | 4 +- 99 files changed, 1074 insertions(+), 1075 deletions(-) diff --git a/core/src/main/java/fj/Class.java b/core/src/main/java/fj/Class.java index d34aedb7..56222de1 100644 --- a/core/src/main/java/fj/Class.java +++ b/core/src/main/java/fj/Class.java @@ -101,7 +101,7 @@ public static Tree typeParameterTree(final Type t) { } types = Tree.node(pt.getRawType(), typeArgs); } else { - types = Tree.node(t, List.>nil()); + types = Tree.node(t, List.nil()); } return types; } @@ -122,6 +122,6 @@ public java.lang.Class clas() { * @return A class from the given argument. */ public static Class clas(final java.lang.Class c) { - return new Class(c); + return new Class<>(c); } } diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index f503d096..2282b04e 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -75,7 +75,7 @@ public F eq(final A a) { * @return A new equal. */ public Equal contramap(final F f) { - return equal(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); + return equal(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); } /** @@ -85,7 +85,7 @@ public Equal contramap(final F f) { * @return An equal instance from the given function. */ public static Equal equal(final F> f) { - return new Equal(f); + return new Equal<>(f); } /** @@ -202,7 +202,7 @@ public static Equal> eitherEqual(final Equal ea, final Eq * @return An equal instance for the {@link Validation} type. */ public static Equal> validationEqual(final Equal ea, final Equal eb) { - return eitherEqual(ea, eb).contramap(Validation.either()); + return eitherEqual(ea, eb).contramap(Validation.either()); } /** @@ -235,7 +235,7 @@ public static Equal> listEqual(final Equal ea) { * @return An equal instance for the {@link NonEmptyList} type. */ public static Equal> nonEmptyListEqual(final Equal ea) { - return listEqual(ea).contramap(NonEmptyList.toList_()); + return listEqual(ea).contramap(NonEmptyList.toList_()); } /** @@ -302,7 +302,7 @@ public static Equal> arrayEqual(final Equal ea) { * @return An equal instance for the {@link Tree} type. */ public static Equal> treeEqual(final Equal ea) { - return Equal.>equal(curry((t1, t2) -> ea.eq(t1.root(), t2.root()) && p1Equal(streamEqual(Equal.treeEqual(ea))).eq(t2.subForest(), t1.subForest()))); + return Equal.equal(curry((t1, t2) -> ea.eq(t1.root(), t2.root()) && p1Equal(streamEqual(Equal.treeEqual(ea))).eq(t2.subForest(), t1.subForest()))); } /** @@ -443,7 +443,7 @@ public static Equal> p5Equal(final Equal ea * @return An equal instance for a vector-2. */ public static Equal> v2Equal(final Equal ea) { - return streamEqual(ea).contramap(V2.toStream_()); + return streamEqual(ea).contramap(V2.toStream_()); } /** @@ -453,7 +453,7 @@ public static Equal> v2Equal(final Equal ea) { * @return An equal instance for a vector-3. */ public static Equal> v3Equal(final Equal ea) { - return streamEqual(ea).contramap(V3.toStream_()); + return streamEqual(ea).contramap(V3.toStream_()); } /** @@ -463,7 +463,7 @@ public static Equal> v3Equal(final Equal ea) { * @return An equal instance for a vector-4. */ public static Equal> v4Equal(final Equal ea) { - return streamEqual(ea).contramap(V4.toStream_()); + return streamEqual(ea).contramap(V4.toStream_()); } /** @@ -473,7 +473,7 @@ public static Equal> v4Equal(final Equal ea) { * @return An equal instance for a vector-5. */ public static Equal> v5Equal(final Equal ea) { - return streamEqual(ea).contramap(V5.toStream_()); + return streamEqual(ea).contramap(V5.toStream_()); } /** @@ -483,7 +483,7 @@ public static Equal> v5Equal(final Equal ea) { * @return An equal instance for a vector-6. */ public static Equal> v6Equal(final Equal ea) { - return streamEqual(ea).contramap(V6.toStream_()); + return streamEqual(ea).contramap(V6.toStream_()); } /** @@ -493,7 +493,7 @@ public static Equal> v6Equal(final Equal ea) { * @return An equal instance for a vector-7. */ public static Equal> v7Equal(final Equal ea) { - return streamEqual(ea).contramap(V7.toStream_()); + return streamEqual(ea).contramap(V7.toStream_()); } /** @@ -503,7 +503,7 @@ public static Equal> v7Equal(final Equal ea) { * @return An equal instance for a vector-8. */ public static Equal> v8Equal(final Equal ea) { - return streamEqual(ea).contramap(V8.toStream_()); + return streamEqual(ea).contramap(V8.toStream_()); } /** diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 3faf1b5e..7b97675a 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -261,7 +261,7 @@ public static F, Promise> mapPromise(final F f) { */ @SuppressWarnings("unchecked") public static F> eitherLeftK(final F f) { - return o(Either.left_(), f); + return o(Either.left_(), f); } /** @@ -272,7 +272,7 @@ public static F> eitherLeftK(final F f) { */ @SuppressWarnings("unchecked") public static F> eitherRightK(final F f) { - return o(Either.right_(), f); + return o(Either.right_(), f); } /** @@ -330,7 +330,7 @@ public static F> iterableK(final F f) { */ @SuppressWarnings("unchecked") public static F, IterableW> mapIterable(final F f) { - return o(IterableW.map().f(f), IterableW.>wrap()); + return o(IterableW.map().f(f), IterableW.wrap()); } /** @@ -340,7 +340,7 @@ public static F, IterableW> mapIterable(final F f) { */ @SuppressWarnings("unchecked") public static F> nelK(final F f) { - return o(NonEmptyList.nel(), f); + return o(NonEmptyList.nel(), f); } /** @@ -408,7 +408,7 @@ public static F, B> foldMapTree(final F f, final Monoid * @return This function promoted to return its value in a TreeZipper. */ public static F> treeZipperK(final F f) { - return andThen(treeK(f), TreeZipper.fromTree()); + return andThen(treeK(f), TreeZipper.fromTree()); } /** @@ -560,7 +560,7 @@ public static F, P2> mapBoth(final F f) { * @return A new SynchronousQueue with this function applied to each element. */ public static SynchronousQueue mapJ(final F f, final SynchronousQueue as) { - final SynchronousQueue bs = new SynchronousQueue(); + final SynchronousQueue bs = new SynchronousQueue<>(); bs.addAll(iterableStream(as).map(f).toCollection()); return bs; } @@ -573,7 +573,7 @@ public static SynchronousQueue mapJ(final F f, final Synchronous * @return A new PriorityBlockingQueue with this function applied to each element. */ public static PriorityBlockingQueue mapJ(final F f, final PriorityBlockingQueue as) { - return new PriorityBlockingQueue(iterableStream(as).map(f).toCollection()); + return new PriorityBlockingQueue<>(iterableStream(as).map(f).toCollection()); } /** @@ -583,7 +583,7 @@ public static PriorityBlockingQueue mapJ(final F f, final Priori * @return A new LinkedBlockingQueue with this function applied to each element. */ public static LinkedBlockingQueue mapJ(final F f, final LinkedBlockingQueue as) { - return new LinkedBlockingQueue(iterableStream(as).map(f).toCollection()); + return new LinkedBlockingQueue<>(iterableStream(as).map(f).toCollection()); } /** @@ -593,7 +593,7 @@ public static LinkedBlockingQueue mapJ(final F f, final LinkedBl * @return A new CopyOnWriteArraySet with this function applied to each element. */ public static CopyOnWriteArraySet mapJ(final F f, final CopyOnWriteArraySet as) { - return new CopyOnWriteArraySet(iterableStream(as).map(f).toCollection()); + return new CopyOnWriteArraySet<>(iterableStream(as).map(f).toCollection()); } /** @@ -603,7 +603,7 @@ public static CopyOnWriteArraySet mapJ(final F f, final CopyOnWr * @return A new CopyOnWriteArrayList with this function applied to each element. */ public static CopyOnWriteArrayList mapJ(final F f, final CopyOnWriteArrayList as) { - return new CopyOnWriteArrayList(iterableStream(as).map(f).toCollection()); + return new CopyOnWriteArrayList<>(iterableStream(as).map(f).toCollection()); } /** @@ -613,7 +613,7 @@ public static CopyOnWriteArrayList mapJ(final F f, final CopyOnW * @return A new ConcurrentLinkedQueue with this function applied to each element. */ public static ConcurrentLinkedQueue mapJ(final F f, final ConcurrentLinkedQueue as) { - return new ConcurrentLinkedQueue(iterableStream(as).map(f).toCollection()); + return new ConcurrentLinkedQueue<>(iterableStream(as).map(f).toCollection()); } /** @@ -623,7 +623,7 @@ public static ConcurrentLinkedQueue mapJ(final F f, final Concur * @return A new ArrayBlockingQueue with this function applied to each element. */ public static ArrayBlockingQueue mapJ(final F f, final ArrayBlockingQueue as) { - final ArrayBlockingQueue bs = new ArrayBlockingQueue(as.size()); + final ArrayBlockingQueue bs = new ArrayBlockingQueue<>(as.size()); bs.addAll(iterableStream(as).map(f).toCollection()); return bs; } @@ -636,7 +636,7 @@ public static ArrayBlockingQueue mapJ(final F f, final ArrayBloc * @return A new TreeSet with this function applied to each element. */ public static TreeSet mapJ(final F f, final TreeSet as) { - return new TreeSet(iterableStream(as).map(f).toCollection()); + return new TreeSet<>(iterableStream(as).map(f).toCollection()); } /** @@ -646,7 +646,7 @@ public static TreeSet mapJ(final F f, final TreeSet as) { * @return A new PriorityQueue with this function applied to each element. */ public static PriorityQueue mapJ(final F f, final PriorityQueue as) { - return new PriorityQueue(iterableStream(as).map(f).toCollection()); + return new PriorityQueue<>(iterableStream(as).map(f).toCollection()); } /** @@ -656,7 +656,7 @@ public static PriorityQueue mapJ(final F f, final PriorityQueue< * @return A new LinkedList with this function applied to each element. */ public static LinkedList mapJ(final F f, final LinkedList as) { - return new LinkedList(iterableStream(as).map(f).toCollection()); + return new LinkedList<>(iterableStream(as).map(f).toCollection()); } /** @@ -666,7 +666,7 @@ public static LinkedList mapJ(final F f, final LinkedList as) * @return A new ArrayList with this function applied to each element. */ public static ArrayList mapJ(final F f, final ArrayList as) { - return new ArrayList(iterableStream(as).map(f).toCollection()); + return new ArrayList<>(iterableStream(as).map(f).toCollection()); } public static F map(F target, F f) { diff --git a/core/src/main/java/fj/F1W.java b/core/src/main/java/fj/F1W.java index 7fe50e35..19a978dc 100644 --- a/core/src/main/java/fj/F1W.java +++ b/core/src/main/java/fj/F1W.java @@ -682,6 +682,6 @@ public B f(A a) { * Lifts the function into the fully featured function wrapper */ public static F1W lift(final F f) { - return new F1WFunc(f); + return new F1WFunc<>(f); } } diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index 8d832798..87888fad 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -168,7 +168,7 @@ public static F, F2> flip2() { * not apply the value, instead returning an empty optional value. */ public static F> nullable(final F f) { - return a -> a == null ? Option.none() : Option.some(f.f(a)); + return a -> a == null ? Option.none() : Option.some(f.f(a)); } /** @@ -761,7 +761,7 @@ public static F, F, F>> lift(final Ff. */ public static F join(final F> f) { - return bind(f, Function.>identity()); + return bind(f, Function.identity()); } diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index acb2a62c..3e6c0ae8 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -165,7 +165,7 @@ public static Hash> eitherHash(final Hash ha, final Hash< * @return A hash instance for the {@link Validation} type. */ public static Hash> validationHash(final Hash ha, final Hash hb) { - return eitherHash(ha, hb).contramap(Validation.either()); + return eitherHash(ha, hb).contramap(Validation.either()); } /** @@ -196,7 +196,7 @@ public static Hash> listHash(final Hash ha) { * @return A hash instance for the {@link NonEmptyList} type. */ public static Hash> nonEmptyListHash(final Hash ha) { - return listHash(ha).contramap(NonEmptyList.toList_()); + return listHash(ha).contramap(NonEmptyList.toList_()); } /** @@ -264,7 +264,7 @@ public static Hash> arrayHash(final Hash ha) { * @return A hash instance for the {@link Tree} type. */ public static Hash> treeHash(final Hash ha) { - return streamHash(ha).contramap(Tree.flatten_()); + return streamHash(ha).contramap(Tree.flatten_()); } public static Hash> treeMapHash(final Hash h, final Hash v) { @@ -278,7 +278,7 @@ public static Hash> treeMapHash(final Hash h, final Hash * @return A hash instance for a product-1. */ public static Hash> p1Hash(final Hash ha) { - return ha.contramap(P1.__1()); + return ha.contramap(P1.__1()); } /** @@ -473,7 +473,7 @@ public static Hash> p5Hash(final Hash ha, f * @return A hash instance for a vector-2. */ public static Hash> v2Hash(final Hash ea) { - return streamHash(ea).contramap(V2.toStream_()); + return streamHash(ea).contramap(V2.toStream_()); } /** @@ -483,7 +483,7 @@ public static Hash> v2Hash(final Hash ea) { * @return A hash instance for a vector-3. */ public static Hash> v3Hash(final Hash ea) { - return streamHash(ea).contramap(V3.toStream_()); + return streamHash(ea).contramap(V3.toStream_()); } /** @@ -493,7 +493,7 @@ public static Hash> v3Hash(final Hash ea) { * @return A hash instance for a vector-4. */ public static Hash> v4Hash(final Hash ea) { - return streamHash(ea).contramap(V4.toStream_()); + return streamHash(ea).contramap(V4.toStream_()); } /** @@ -503,7 +503,7 @@ public static Hash> v4Hash(final Hash ea) { * @return A hash instance for a vector-5. */ public static Hash> v5Hash(final Hash ea) { - return streamHash(ea).contramap(V5.toStream_()); + return streamHash(ea).contramap(V5.toStream_()); } /** @@ -513,7 +513,7 @@ public static Hash> v5Hash(final Hash ea) { * @return A hash instance for a vector-6. */ public static Hash> v6Hash(final Hash ea) { - return streamHash(ea).contramap(V6.toStream_()); + return streamHash(ea).contramap(V6.toStream_()); } /** @@ -523,7 +523,7 @@ public static Hash> v6Hash(final Hash ea) { * @return A hash instance for a vector-7. */ public static Hash> v7Hash(final Hash ea) { - return streamHash(ea).contramap(V7.toStream_()); + return streamHash(ea).contramap(V7.toStream_()); } /** @@ -533,6 +533,6 @@ public static Hash> v7Hash(final Hash ea) { * @return A hash instance for a vector-8. */ public static Hash> v8Hash(final Hash ea) { - return streamHash(ea).contramap(V8.toStream_()); + return streamHash(ea).contramap(V8.toStream_()); } } diff --git a/core/src/main/java/fj/LcgRng.java b/core/src/main/java/fj/LcgRng.java index d2c244b6..50ee9e03 100644 --- a/core/src/main/java/fj/LcgRng.java +++ b/core/src/main/java/fj/LcgRng.java @@ -40,7 +40,7 @@ public P2 nextLong() { */ static P2 nextLong(long seed) { long newSeed = (seed * 0x5DEECE66DL + 0xBL) & 0xFFFFFFFFFFFFL; - long n = (Long) (newSeed >>> 16); + long n = newSeed >>> 16; return P.p(newSeed, n); } diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index be5215bb..af6d95f9 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -200,7 +200,7 @@ public A join(final Iterable as, final A a) { * @return A monoid instance that uses the given sun function and zero value. */ public static Monoid monoid(final F> sum, final A zero) { - return new Monoid(sum, zero); + return new Monoid<>(sum, zero); } /** @@ -212,7 +212,7 @@ public static Monoid monoid(final F> sum, final A zero) { * @return A monoid instance that uses the given sun function and zero value. */ public static Monoid monoid(final F2 sum, final A zero) { - return new Monoid(curry(sum), zero); + return new Monoid<>(curry(sum), zero); } /** @@ -223,7 +223,7 @@ public static Monoid monoid(final F2 sum, final A zero) { * @return A monoid instance that uses the given sun function and zero value. */ public static Monoid monoid(final Semigroup s, final A zero) { - return new Monoid(s.sum(), zero); + return new Monoid<>(s.sum(), zero); } /** @@ -328,7 +328,7 @@ public static Monoid monoid(final Semigroup s, final A zero) { * @return A monoid for functions. */ public static Monoid> functionMonoid(final Monoid mb) { - return monoid(Semigroup.functionSemigroup(mb.semigroup()), Function.constant(mb.zero)); + return monoid(Semigroup.functionSemigroup(mb.semigroup()), Function.constant(mb.zero)); } /** @@ -337,7 +337,7 @@ public static Monoid> functionMonoid(final Monoid mb) { * @return A monoid for lists. */ public static Monoid> listMonoid() { - return monoid(Semigroup.listSemigroup(), List.nil()); + return monoid(Semigroup.listSemigroup(), List.nil()); } /** @@ -346,7 +346,7 @@ public static Monoid> listMonoid() { * @return A monoid for options. */ public static Monoid> optionMonoid() { - return monoid(Semigroup.optionSemigroup(), Option.none()); + return monoid(Semigroup.optionSemigroup(), Option.none()); } /** @@ -355,7 +355,7 @@ public static Monoid> optionMonoid() { * @return A monoid for options that take the first available value. */ public static Monoid> firstOptionMonoid() { - return monoid(Semigroup.firstOptionSemigroup(), Option.none()); + return monoid(Semigroup.firstOptionSemigroup(), Option.none()); } /** @@ -364,7 +364,7 @@ public static Monoid> firstOptionMonoid() { * @return A monoid for options that take the last available value. */ public static Monoid> lastOptionMonoid() { - return monoid(Semigroup.lastOptionSemigroup(), Option.none()); + return monoid(Semigroup.lastOptionSemigroup(), Option.none()); } /** @@ -373,7 +373,7 @@ public static Monoid> lastOptionMonoid() { * @return A monoid for streams. */ public static Monoid> streamMonoid() { - return monoid(Semigroup.streamSemigroup(), Stream.nil()); + return monoid(Semigroup.streamSemigroup(), Stream.nil()); } /** @@ -383,7 +383,7 @@ public static Monoid> streamMonoid() { */ @SuppressWarnings("unchecked") public static Monoid> arrayMonoid() { - return monoid(Semigroup.arraySemigroup(), Array.empty()); + return monoid(Semigroup.arraySemigroup(), Array.empty()); } /** @@ -405,7 +405,7 @@ public static Monoid> ioMonoid(final Monoid ma) { * @return A monoid for sets whose elements have the given order. */ public static Monoid> setMonoid(final Ord o) { - return monoid(Semigroup.setSemigroup(), Set.empty(o)); + return monoid(Semigroup.setSemigroup(), Set.empty(o)); } } diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 57d7e389..471c110f 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -75,7 +75,7 @@ public Equal equal() { * @return A new ord. */ public Ord contramap(final F f) { - return ord(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); + return ord(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); } /** @@ -166,7 +166,7 @@ public A min(final A a1, final A a2) { * @return An order instance. */ public static Ord ord(final F> f) { - return new Ord(f); + return new Ord<>(f); } /** @@ -262,7 +262,7 @@ public static Ord ord(final F> f) { /** * An order instance for the {@link Ordering} type. */ - public static final Ord orderingOrd = Ord.ord(curry((o1, o2) -> o1 == o2 ? + public static final Ord orderingOrd = Ord.ord(curry((o1, o2) -> o1 == o2 ? Ordering.EQ : o1 == Ordering.LT ? Ordering.LT : @@ -334,7 +334,7 @@ public static Ord> eitherOrd(final Ord oa, final Ord o * @return An order instance for the {@link Validation} type. */ public static Ord> validationOrd(final Ord oa, final Ord ob) { - return eitherOrd(oa, ob).contramap(Validation.either()); + return eitherOrd(oa, ob).contramap(Validation.either()); } /** @@ -374,7 +374,7 @@ public static Ord> listOrd(final Ord oa) { * @return An order instance for the {@link NonEmptyList} type. */ public static Ord> nonEmptyListOrd(final Ord oa) { - return listOrd(oa).contramap(NonEmptyList.toList_()); + return listOrd(oa).contramap(NonEmptyList.toList_()); } /** @@ -443,7 +443,7 @@ public static Ord> setOrd(final Ord oa) { * @return An order instance for a product-1. */ public static Ord> p1Ord(final Ord oa) { - return oa.contramap(P1.__1()); + return oa.contramap(P1.__1()); } diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 796daf22..5a1d9b8a 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -114,7 +114,7 @@ public P1 bind(final P1 cb, final F2 f) { * @return A new P1 that is the join of the given P1. */ public static P1 join(final P1> a) { - return a.bind(Function.>identity()); + return a.bind(Function.identity()); } /** @@ -138,7 +138,7 @@ public P1 liftM2(P1 pb, F2 f) { * @return A single P1 for the given List. */ public static P1> sequence(final List> as) { - return as.foldRight(liftM2(List.cons()), P.p(List.nil())); + return as.foldRight(liftM2(List.cons()), P.p(List.nil())); } /** @@ -157,7 +157,7 @@ public static F>, P1>> sequenceList() { * @return A single P1 for the given stream. */ public static P1> sequence(final Stream> as) { - return as.foldRight(liftM2(Stream.cons()), P.p(Stream.nil())); + return as.foldRight(liftM2(Stream.cons()), P.p(Stream.nil())); } /** @@ -174,7 +174,7 @@ public static P1> sequence(final Option> o) { * @return A single P1 for the given array. */ public static P1> sequence(final Array> as) { - return P.lazy(() -> as.map(P1.__1())); + return P.lazy(() -> as.map(P1.__1())); } /** @@ -341,7 +341,7 @@ public String toString() { @Override public boolean equals(Object other) { - return Equal.equals0(P1.class, this, other, () -> Equal.p1Equal(Equal.anyEqual())); + return Equal.equals0(P1.class, this, other, () -> Equal.p1Equal(Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index d564df35..be3be69b 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -28,7 +28,7 @@ public abstract class P2 { @Override public boolean equals(Object other) { - return Equal.equals0(P2.class, this, other, () -> Equal.p2Equal(Equal.anyEqual(), Equal.anyEqual())); + return Equal.equals0(P2.class, this, other, () -> Equal.p2Equal(Equal.anyEqual(), Equal.anyEqual())); } @Override @@ -155,7 +155,7 @@ public final Either> traverseEither(final F> */ public final Stream sequenceW(final Stream, C>> fs) { return fs.isEmpty() - ? Stream.nil() + ? Stream.nil() : Stream.cons(fs.head().f(this), () -> sequenceW(fs.tail()._1())); } diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index 8760562b..c6bc38a9 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -181,7 +181,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P3.class, this, other, - () -> Equal.p3Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p3Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index 7f71943e..6181b75e 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -250,7 +250,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P4.class, this, other, - () -> Equal.p4Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p4Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 57199302..2fd74ebe 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -325,7 +325,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P5.class, this, other, - () -> Equal.p5Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p5Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index d1f32b87..5c679a2c 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -355,7 +355,7 @@ public F _6() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return P6::_1; + return P6::_1; } /** @@ -364,7 +364,7 @@ public F _6() { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return P6::_2; + return P6::_2; } /** @@ -373,7 +373,7 @@ public F _6() { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return P6::_3; + return P6::_3; } /** @@ -382,7 +382,7 @@ public F _6() { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return P6::_4; + return P6::_4; } /** @@ -391,7 +391,7 @@ public F _6() { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return P6::_5; + return P6::_5; } /** @@ -400,7 +400,7 @@ public F _6() { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return P6::_6; + return P6::_6; } @Override @@ -412,7 +412,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P6.class, this, other, - () -> Equal.p6Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p6Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index e81a2480..eb0cb913 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -437,7 +437,7 @@ public G _7() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return P7::_1; + return P7::_1; } /** @@ -446,7 +446,7 @@ public G _7() { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return P7::_2; + return P7::_2; } /** @@ -455,7 +455,7 @@ public G _7() { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return P7::_3; + return P7::_3; } /** @@ -464,7 +464,7 @@ public G _7() { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return P7::_4; + return P7::_4; } /** @@ -473,7 +473,7 @@ public G _7() { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return P7::_5; + return P7::_5; } /** @@ -482,7 +482,7 @@ public G _7() { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return P7::_6; + return P7::_6; } /** @@ -491,7 +491,7 @@ public G _7() { * @return A function that returns the seventh element of a product. */ public static fj.F, G> __7() { - return P7::_7; + return P7::_7; } @Override @@ -502,7 +502,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P7.class, this, other, - () -> Equal.p7Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p7Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index 982dca58..de13749b 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -530,7 +530,7 @@ public H _8() { * @return A function that returns the first element of a product. */ public static fj.F, A> __1() { - return P8::_1; + return P8::_1; } /** @@ -539,7 +539,7 @@ public H _8() { * @return A function that returns the second element of a product. */ public static fj.F, B> __2() { - return P8::_2; + return P8::_2; } /** @@ -548,7 +548,7 @@ public H _8() { * @return A function that returns the third element of a product. */ public static fj.F, C> __3() { - return P8::_3; + return P8::_3; } /** @@ -557,7 +557,7 @@ public H _8() { * @return A function that returns the fourth element of a product. */ public static fj.F, D> __4() { - return P8::_4; + return P8::_4; } /** @@ -566,7 +566,7 @@ public H _8() { * @return A function that returns the fifth element of a product. */ public static fj.F, E> __5() { - return P8::_5; + return P8::_5; } /** @@ -575,7 +575,7 @@ public H _8() { * @return A function that returns the sixth element of a product. */ public static fj.F, F$> __6() { - return P8::_6; + return P8::_6; } /** @@ -584,7 +584,7 @@ public H _8() { * @return A function that returns the seventh element of a product. */ public static fj.F, G> __7() { - return P8::_7; + return P8::_7; } /** @@ -593,7 +593,7 @@ public H _8() { * @return A function that returns the eighth element of a product. */ public static fj.F, H> __8() { - return P8::_8; + return P8::_8; } @Override @@ -604,7 +604,7 @@ public String toString() { @Override public boolean equals(Object other) { return Equal.equals0(P8.class, this, other, - () -> Equal.p8Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + () -> Equal.p8Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index e7cd4c35..057596f5 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -103,7 +103,7 @@ static A multiply1p(F> sum, int n, A a) { * @return A semigroup from the given function. */ public static Semigroup semigroup(final F> sum) { - return new Semigroup(sum); + return new Semigroup<>(sum); } /** @@ -113,7 +113,7 @@ public static Semigroup semigroup(final F> sum) { * @return A semigroup from the given function. */ public static Semigroup semigroup(final F2 sum) { - return new Semigroup(curry(sum)); + return new Semigroup<>(curry(sum)); } /** diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 5e6fd8b0..4d599693 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -282,7 +282,7 @@ public static Show> listShow(final Show sa) { * @return A show instance for the {@link NonEmptyList} type. */ public static Show> nonEmptyListShow(final Show sa) { - return listShow(sa).contramap(NonEmptyList.toList_()); + return listShow(sa).contramap(NonEmptyList.toList_()); } /** @@ -557,7 +557,7 @@ public static Show> p5Show(final Show sa, f * @return A show instance for a vector-2. */ public static Show> v2Show(final Show ea) { - return streamShow(ea, "V2(", ",", ")").contramap(V2.toStream_()); + return streamShow(ea, "V2(", ",", ")").contramap(V2.toStream_()); } /** @@ -567,7 +567,7 @@ public static Show> v2Show(final Show ea) { * @return A show instance for a vector-3. */ public static Show> v3Show(final Show ea) { - return streamShow(ea, "V3(", ",", ")").contramap(V3.toStream_()); + return streamShow(ea, "V3(", ",", ")").contramap(V3.toStream_()); } /** @@ -577,7 +577,7 @@ public static Show> v3Show(final Show ea) { * @return A show instance for a vector-4. */ public static Show> v4Show(final Show ea) { - return streamShow(ea, "V4(", ",", ")").contramap(V4.toStream_()); + return streamShow(ea, "V4(", ",", ")").contramap(V4.toStream_()); } /** @@ -587,7 +587,7 @@ public static Show> v4Show(final Show ea) { * @return A show instance for a vector-5. */ public static Show> v5Show(final Show ea) { - return streamShow(ea, "V5(", ",", ")").contramap(V5.toStream_()); + return streamShow(ea, "V5(", ",", ")").contramap(V5.toStream_()); } /** @@ -597,7 +597,7 @@ public static Show> v5Show(final Show ea) { * @return A show instance for a vector-6. */ public static Show> v6Show(final Show ea) { - return streamShow(ea, "V6(", ",", ")").contramap(V6.toStream_()); + return streamShow(ea, "V6(", ",", ")").contramap(V6.toStream_()); } /** @@ -607,7 +607,7 @@ public static Show> v6Show(final Show ea) { * @return A show instance for a vector-7. */ public static Show> v7Show(final Show ea) { - return streamShow(ea, "V7(", ",", ")").contramap(V7.toStream_()); + return streamShow(ea, "V7(", ",", ")").contramap(V7.toStream_()); } /** @@ -617,7 +617,7 @@ public static Show> v7Show(final Show ea) { * @return A show instance for a vector-8. */ public static Show> v8Show(final Show ea) { - return streamShow(ea, "V8(", ",", ")").contramap(V8.toStream_()); + return streamShow(ea, "V8(", ",", ")").contramap(V8.toStream_()); } /** @@ -643,7 +643,7 @@ public static Show> unlineShow(final Show sa) { /** * A show instance for the empty heterogeneous Stream. */ - public static final Show HListShow = showS(Function.constant("Nil")); + public static final Show HListShow = showS(Function.constant("Nil")); /** * A show instance for heterogeneous Streams. diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index a41c7a03..fa07df3c 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -108,7 +108,7 @@ public Either>, A> resume() { @SuppressWarnings("unchecked") protected static Codense codense(final Normal a, final F> k) { - return new Codense((Normal) a, (F>) k); + return new Codense<>((Normal) a, (F>) k); } /** @@ -125,7 +125,7 @@ public static F> pure() { * @return A trampoline that results in the given value. */ public static Trampoline pure(final A a) { - return new Pure(a); + return new Pure<>(a); } /** @@ -135,7 +135,7 @@ public static Trampoline pure(final A a) { * @return A trampoline whose next step runs the given thunk. */ public static Trampoline suspend(final P1> a) { - return new Suspend(a); + return new Suspend<>(a); } /** @@ -162,7 +162,7 @@ public static F>, Trampoline> suspend_() { * @return A new trampoline that runs this trampoline, then applies the given function to the result. */ public final Trampoline map(final F f) { - return bind(F1Functions.o(Trampoline.pure(), f)); + return bind(F1Functions.o(Trampoline.pure(), f)); } /** @@ -257,7 +257,7 @@ public Trampoline zipWith(final Trampoline b, final F2 f) final Either>, B> eb = b.resume(); for (final P1> x : ea.left()) { for (final P1> y : eb.left()) { - return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(P.>lazy(() -> ta.zipWith(tb, f)))))); + return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(P.lazy(() -> ta.zipWith(tb, f)))))); } for (final B y : eb.right()) { return suspend(x.map(ta -> ta.map(F2Functions.f(F2Functions.flip(f), y)))); diff --git a/core/src/main/java/fj/control/db/DB.java b/core/src/main/java/fj/control/db/DB.java index 8e8590b6..a7ba6a7f 100644 --- a/core/src/main/java/fj/control/db/DB.java +++ b/core/src/main/java/fj/control/db/DB.java @@ -103,6 +103,6 @@ public B run(final Connection c) throws SQLException { * @return A new database action equivalent to the result of the given action. */ public static DB join(final DB> a) { - return a.bind(Function.>identity()); + return a.bind(Function.identity()); } } diff --git a/core/src/main/java/fj/control/parallel/Actor.java b/core/src/main/java/fj/control/parallel/Actor.java index bd1956bd..c5985c7c 100644 --- a/core/src/main/java/fj/control/parallel/Actor.java +++ b/core/src/main/java/fj/control/parallel/Actor.java @@ -33,13 +33,13 @@ public final class Actor { * as they are sent. */ public static Actor queueActor(final Strategy s, final Effect1 ea) { - return actor(Strategy.seqStrategy(), new Effect1() { + return actor(Strategy.seqStrategy(), new Effect1() { // Lock to ensure the actor only acts on one message at a time final AtomicBoolean suspended = new AtomicBoolean(true); // Queue to hold pending messages - final ConcurrentLinkedQueue mbox = new ConcurrentLinkedQueue(); + final ConcurrentLinkedQueue mbox = new ConcurrentLinkedQueue<>(); // Product so the actor can use its strategy (to act on messages in other threads, // to handle exceptions, etc.) @@ -90,7 +90,7 @@ private Actor(final Strategy s, final F> e) { * @return A new actor that uses the given parallelization strategy and has the given side-effect. */ public static Actor actor(final Strategy s, final Effect1 e) { - return new Actor(s, P1.curry(Effect.f(e))); + return new Actor<>(s, P1.curry(Effect.f(e))); } /** @@ -101,7 +101,7 @@ public static Actor actor(final Strategy s, final Effect1 e) { * @return A new actor that uses the given parallelization strategy and has the given side-effect. */ public static Actor actor(final Strategy s, final F> e) { - return new Actor(s, e); + return new Actor<>(s, e); } /** diff --git a/core/src/main/java/fj/control/parallel/Callables.java b/core/src/main/java/fj/control/parallel/Callables.java index 7c2a7221..995780c4 100644 --- a/core/src/main/java/fj/control/parallel/Callables.java +++ b/core/src/main/java/fj/control/parallel/Callables.java @@ -126,7 +126,7 @@ public static Callable bind(final Callable ca, final Callable * @return A new Callable that is the join of the given Callable. */ public static Callable join(final Callable> a) { - return bind(a, Function.>identity()); + return bind(a, Function.identity()); } /** @@ -146,8 +146,7 @@ public static F, F, Callable>> liftM2(final * @return A single callable for the given List. */ public static Callable> sequence(final List> as) { - return as.foldRight(Callables., - List>liftM2(List.cons()), callable(List.nil())); + return as.foldRight(Callables.liftM2(List.cons()), callable(List.nil())); } /** diff --git a/core/src/main/java/fj/control/parallel/ParModule.java b/core/src/main/java/fj/control/parallel/ParModule.java index 7e0fdb59..514988aa 100644 --- a/core/src/main/java/fj/control/parallel/ParModule.java +++ b/core/src/main/java/fj/control/parallel/ParModule.java @@ -261,7 +261,7 @@ public F, F, Promise>>> parMapList() { * @return A Promise of a new NonEmptyList with the given function applied to each element. */ public Promise> parMap(final NonEmptyList as, final F f) { - return mapM(as.toList(), promise(f)).fmap((F, NonEmptyList>) list -> NonEmptyList.fromList(list).some()); + return mapM(as.toList(), promise(f)).fmap(list -> NonEmptyList.fromList(list).some()); } /** @@ -293,7 +293,7 @@ public F, F, Promise>>> parMapStream() { */ public Promise> parMap(final Iterable as, final F f) { return parMap(iterableStream(as), f) - .fmap(Function., Iterable>vary(Function.>identity())); + .fmap(Function.vary(Function.identity())); } /** @@ -334,7 +334,7 @@ public F, F, Promise>>> parMapArray() { */ public Promise> parMap(final Zipper za, final F f) { return parMap(za.rights(), f) - .apply(promise(f).f(za.focus()).apply(parMap(za.lefts(), f).fmap(curry(Zipper.zipper())))); + .apply(promise(f).f(za.focus()).apply(parMap(za.lefts(), f).fmap(curry(Zipper.zipper())))); } /** @@ -346,7 +346,7 @@ public Promise> parMap(final Zipper za, final F f) { */ public Promise> parMap(final Tree ta, final F f) { return mapM(ta.subForest(), this., Tree>mapStream().f(this.parMapTree().f(f))) - .apply(promise(f).f(ta.root()).fmap(Tree.node())); + .apply(promise(f).f(ta.root()).fmap(Tree.node())); } /** @@ -370,8 +370,8 @@ public Promise> parMap(final TreeZipper za, final F, Stream>, Stream>, Stream>, A, Stream>>>> p = za.p(); return mapM(p._4(), p3 -> parMap(p3._3(), tf).apply(promise(f).f(p3._2()).apply( - parMap(p3._1(), tf).fmap(P.>, B, Stream>>p3())))).apply(parMap(za.rights(), tf).apply( - parMap(za.lefts(), tf).apply(parMap(p._1(), f).fmap(TreeZipper.treeZipper())))); + parMap(p3._1(), tf).fmap(P.p3())))).apply(parMap(za.rights(), tf).apply( + parMap(za.lefts(), tf).apply(parMap(p._1(), f).fmap(TreeZipper.treeZipper())))); } /** @@ -382,7 +382,7 @@ public Promise> parMap(final TreeZipper za, final F Promise> parFlatMap(final List as, final F> f) { - return parFoldMap(as, f, Monoid.listMonoid()); + return parFoldMap(as, f, Monoid.listMonoid()); } /** @@ -393,7 +393,7 @@ public Promise> parFlatMap(final List as, final F> * @return A promise of a new Stream with the given function bound across its elements. */ public Promise> parFlatMap(final Stream as, final F> f) { - return parFoldMap(as, f, Monoid.streamMonoid()); + return parFoldMap(as, f, Monoid.streamMonoid()); } /** @@ -404,7 +404,7 @@ public Promise> parFlatMap(final Stream as, final F Promise> parFlatMap(final Array as, final F> f) { - return parMap(as, f).fmap(Array.join()); + return parMap(as, f).fmap(Array.join()); } /** @@ -415,8 +415,8 @@ public Promise> parFlatMap(final Array as, final F Promise> parFlatMap(final Iterable as, final F> f) { - return parMap(as, f).fmap(IterableW.>join()) - .fmap(Function., Iterable>vary(Function.>identity())); + return parMap(as, f).fmap(IterableW.join()) + .fmap(Function.vary(Function.>identity())); } /** @@ -428,7 +428,7 @@ public Promise> parFlatMap(final Iterable as, final F Promise> parZipWith(final List as, final List bs, final F> f) { - return sequence(as.>zipWith(bs, promise(uncurryF2(f)))); + return sequence(as.zipWith(bs, promise(uncurryF2(f)))); } /** @@ -440,7 +440,7 @@ public Promise> parZipWith(final List as, final List bs, * @return A Promise of a new stream with the results of applying the given function across the two streams, stepwise. */ public Promise> parZipWith(final Stream as, final Stream bs, final F> f) { - return sequence(as.>zipWith(bs, promise(uncurryF2(f)))); + return sequence(as.zipWith(bs, promise(uncurryF2(f)))); } /** @@ -465,7 +465,7 @@ public Promise> parZipWith(final Array as, final Array */ public Promise> parZipWith(final Iterable as, final Iterable bs, final F> f) { return parZipWith(iterableStream(as), iterableStream(bs), f).fmap( - Function., Iterable>vary(Function.>identity())); + Function.vary(Function.>identity())); } /** @@ -496,7 +496,7 @@ public Promise parFoldMap(final Stream as, final F map, final */ public Promise parFoldMap(final Stream as, final F map, final Monoid reduce, final F, P2, Stream>> chunking) { - return parMap(Stream.unfold(stream -> stream.isEmpty() ? Option., Stream>>none() : some(chunking.f(stream)), as), Stream.map_().f(map)).bind(stream -> parMap(stream, reduce.sumLeftS()).fmap(reduce.sumLeftS())); + return parMap(Stream.unfold(stream -> stream.isEmpty() ? Option.none() : some(chunking.f(stream)), as), Stream.map_().f(map)).bind(stream -> parMap(stream, reduce.sumLeftS()).fmap(reduce.sumLeftS())); } /** diff --git a/core/src/main/java/fj/control/parallel/Promise.java b/core/src/main/java/fj/control/parallel/Promise.java index fc20f491..3689c286 100644 --- a/core/src/main/java/fj/control/parallel/Promise.java +++ b/core/src/main/java/fj/control/parallel/Promise.java @@ -37,7 +37,7 @@ public final class Promise { private final CountDownLatch l = new CountDownLatch(1); private volatile Option v = none(); - private final Queue> waiting = new LinkedList>(); + private final Queue> waiting = new LinkedList<>(); private Promise(final Strategy s, final Actor, Actor>, Promise>> qa) { this.s = s; @@ -62,7 +62,7 @@ public void f(final P2, Actor>, Promise> p) { p._1().right().value().act(snd.v.some()); } }); - return new Promise(s, q); + return new Promise<>(s, q); } /** @@ -75,7 +75,7 @@ public void f(final P2, Actor>, Promise> p) { */ public static Promise promise(final Strategy s, final P1 a) { final Promise p = mkPromise(s); - p.actor.act(p(Either., Actor>left(a), p)); + p.actor.act(p(Either.left(a), p)); return p; } @@ -118,7 +118,7 @@ public static F> promise(final Strategy s, final F a) { - actor.act(p(Either., Actor>right(a), this)); + actor.act(p(Either.right(a), this)); } /** @@ -176,7 +176,7 @@ public Promise bind(final F> f) { final Promise r = mkPromise(s); final Actor ab = actor(s, new Effect1() { public void f(final B b) { - r.actor.act(p(Either., Actor>left(p(b)), r)); + r.actor.act(p(Either.left(p(b)), r)); } }); to(ab.promise().contramap(f)); @@ -254,7 +254,7 @@ public static F>, Promise>> sequence(final Strategy< * @return A single promise for the given Stream. */ public static Promise> sequence(final Strategy s, final Stream> as) { - return join(foldRightS(s, curry((Promise o, P1>> p) -> o.bind(a -> p._1().fmap(Stream.cons_().f(a)))), promise(s, p(Stream.nil()))).f(as)); + return join(foldRightS(s, curry((Promise o, P1>> p) -> o.bind(a -> p._1().fmap(Stream.cons_().f(a)))), promise(s, p(Stream.nil()))).f(as)); } /** @@ -275,7 +275,7 @@ public static F>, Promise>> sequenceS(final Strategy * @return A promised product. */ public static Promise> sequence(final Strategy s, final P1> p) { - return join(promise(s, p)).fmap(P.p1()); + return join(promise(s, p)).fmap(P.p1()); } /** @@ -308,7 +308,7 @@ public static F, Promise> foldRightS(final Strategy s, return new F, Promise>() { public Promise f(final Stream as) { return as.isEmpty() ? promise(s, p(b)) : liftM2(f).f(promise(s, p(as.head()))).f( - Promise.>join(s, P.lazy(() -> f(as.tail()._1()).fmap(P.p1())))); + Promise.join(s, P.lazy(() -> f(as.tail()._1()).fmap(P.p1())))); } }; } @@ -381,7 +381,7 @@ public Promise> cojoin() { */ public Stream sequenceW(final Stream, B>> fs) { return fs.isEmpty() - ? Stream.nil() + ? Stream.nil() : Stream.cons(fs.head().f(this), () -> sequenceW(fs.tail()._1())); } diff --git a/core/src/main/java/fj/control/parallel/Strategy.java b/core/src/main/java/fj/control/parallel/Strategy.java index 94e1f148..2b77a9e8 100644 --- a/core/src/main/java/fj/control/parallel/Strategy.java +++ b/core/src/main/java/fj/control/parallel/Strategy.java @@ -51,7 +51,7 @@ public F, P1> f() { * @return A strategy that uses the given function to evaluate product-1s. */ public static Strategy strategy(final F, P1> f) { - return new Strategy(f); + return new Strategy<>(f); } /** @@ -71,7 +71,7 @@ public P1 par(final P1 a) { * @return A function that executes concurrently when called, yielding a Future value. */ public F> concurry(final F f) { - return compose(f(), P1.curry(f)); + return compose(f(), P1.curry(f)); } /** @@ -91,7 +91,7 @@ public F>> concurry(final F2 f) { * @return A list of values extracted from the Futures in the argument list. */ public static List> mergeAll(final List> xs) { - return xs.map(Strategy.obtain()); + return xs.map(Strategy.obtain()); } /** @@ -136,7 +136,7 @@ public P1> parMap(final F f, final Array bs) { * @return A list with all of its elements transformed by the given function. */ public List parMap1(final F f, final List bs) { - return compose(P1.>__1(), parMapList(f)).f(bs); + return compose(P1.__1(), parMapList(f)).f(bs); } /** @@ -149,7 +149,7 @@ public List parMap1(final F f, final List bs) { * @return An array with all of its elements transformed by the given function. */ public Array parMap1(final F f, final Array bs) { - return compose(P1.>__1(), parMapArray(f)).f(bs); + return compose(P1.__1(), parMapArray(f)).f(bs); } /** @@ -248,7 +248,7 @@ public static P1> parFlatMap(final Strategy> s, public static P1> parListChunk(final Strategy> s, final int chunkLength, final List> as) { - return P1.map_(List.join()).f(s.parList(as.partition(chunkLength).map(P1.sequenceList()))); + return P1.map_(List.join()).f(s.parList(as.partition(chunkLength).map(P1.sequenceList()))); } /** @@ -351,7 +351,7 @@ public static Effect1> discard() { */ public static Strategy simpleThreadStrategy() { return strategy(p -> { - final FutureTask t = new FutureTask(Java.P1_Callable().f(p)); + final FutureTask t = new FutureTask<>(Java.P1_Callable().f(p)); new Thread(t).start(); return obtain(t); }); @@ -396,7 +396,7 @@ public static Strategy seqStrategy() { * @return A strategy that performs no evaluation of its argument. */ public static Strategy idStrategy() { - return strategy(Function.>identity()); + return strategy(Function.identity()); } /** @@ -417,7 +417,7 @@ public Strategy xmap(final F, P1> f, final F, P1> g) { * @return A new strategy that applies the given transformation after each application of this strategy. */ public Strategy map(final F, P1> f) { - return xmap(f, Function.>identity()); + return xmap(f, Function.identity()); } /** @@ -427,7 +427,7 @@ public Strategy map(final F, P1> f) { * @return A new strategy that applies the given transformation before each application of this strategy. */ public Strategy contramap(final F, P1> f) { - return xmap(Function.>identity(), f); + return xmap(Function.identity(), f); } /** diff --git a/core/src/main/java/fj/data/$.java b/core/src/main/java/fj/data/$.java index 212216bc..17b2ac9e 100644 --- a/core/src/main/java/fj/data/$.java +++ b/core/src/main/java/fj/data/$.java @@ -30,7 +30,7 @@ public final class $ extends P1 { } public static $ constant(final B b) { - return new $(b); + return new $<>(b); } diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index 7890a0c8..09b56f9a 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -88,7 +88,7 @@ public int length() { } public ImmutableProjection immutable() { - return new ImmutableProjection(this); + return new ImmutableProjection<>(this); } /** @@ -148,7 +148,7 @@ public A[] toJavaArray() { */ @SuppressWarnings("unchecked") public Option toOption() { - return a.length == 0 ? Option.none() : some((A) a[0]); + return a.length == 0 ? Option.none() : some((A) a[0]); } /** @@ -160,7 +160,7 @@ public Option toOption() { */ @SuppressWarnings("unchecked") public Either toEither(final F0 x) { - return a.length == 0 ? Either. left(x.f()) : Either. right((A) a[0]); + return a.length == 0 ? Either.left(x.f()) : Either.right((A) a[0]); } /** @@ -187,7 +187,7 @@ public List toList() { @SuppressWarnings("unchecked") public Stream toStream() { return Stream.unfold(o -> - a.length > o ? some(p((A) a[o], o + 1)) : Option.>none(), 0 + a.length > o ? some(p((A) a[o], o + 1)) : Option.none(), 0 ); } @@ -210,7 +210,7 @@ public Array map(final F f) { bs[i] = f.f((A) a[i]); } - return new Array(bs); + return new Array<>(bs); } /** @@ -333,7 +333,7 @@ public Array scanLeft(final F> f, final B b) { bs[i] = x; } - return new Array(bs); + return new Array<>(bs); } /** @@ -368,7 +368,7 @@ public Array scanLeft1(final F> f) { bs[i] = x; } - return new Array(bs); + return new Array<>(bs); } /** @@ -402,7 +402,7 @@ public Array scanRight(final F>f, final B b) { bs[i] = x; } - return new Array(bs); + return new Array<>(bs); } /** @@ -437,7 +437,7 @@ public Array scanRight1(final F>f) { bs[i] = x; } - return new Array(bs); + return new Array<>(bs); } /** @@ -482,7 +482,7 @@ public Unit f(final Array x) { } }); - return new Array(bs); + return new Array<>(bs); } /** @@ -542,7 +542,7 @@ public Array reverse() { x[a.length - 1 - i] = a[i]; } - return new Array(x); + return new Array<>(x); } /** @@ -557,7 +557,7 @@ public Array append(final Array aas) { arraycopy(a, 0, x, 0, a.length); arraycopy(aas.a, 0, x, a.length, aas.a.length); - return new Array(x); + return new Array<>(x); } /** @@ -566,7 +566,7 @@ public Array append(final Array aas) { * @return An empty array. */ public static Array empty() { - return new Array(new Object[0]); + return new Array<>(new Object[0]); } /** @@ -587,7 +587,7 @@ public static Array array(final A...as) { * @return A wrapped array. */ static Array mkArray(final Object[] a) { - return new Array(a); + return new Array<>(a); } /** @@ -597,7 +597,7 @@ static Array mkArray(final Object[] a) { * @return An array with the given single element. */ public static Array single(final A a) { - return new Array(new Object[]{a}); + return new Array<>(new Object[]{a}); } /** @@ -674,7 +674,7 @@ public boolean exists(final F f) { @Override public boolean equals(Object o) { - return Equal.equals0(Array.class, this, o, () -> Equal.arrayEqual(Equal.anyEqual())); + return Equal.equals0(Array.class, this, o, () -> Equal.arrayEqual(Equal.anyEqual())); } /** @@ -707,7 +707,7 @@ public static Array range(final int from, final int to) { if (from >= to) return empty(); else { - final Array a = new Array(new Integer[to - from]); + final Array a = new Array<>(new Integer[to - from]); for (int i = from; i < to; i++) a.set(i - from, i); @@ -727,7 +727,7 @@ public static Array range(final int from, final int to) { */ public Array zipWith(final Array bs, final F> f) { final int len = min(a.length, bs.length()); - final Array x = new Array(new Object[len]); + final Array x = new Array<>(new Object[len]); for (int i = 0; i < len; i++) { x.set(i, f.f(get(i)).f(bs.get(i))); @@ -812,7 +812,7 @@ public int size() { * Returns a standard java.util.List projection of this array. */ java.util.List toJavaList() { - return new ArrayList(toCollection()); + return new ArrayList<>(toCollection()); } /** @@ -840,7 +840,7 @@ public static Array iteratorArray(final Iterator i) { */ @SafeVarargs public static Array arrayArray(final A...as) { - return new Array(as); + return new Array<>(as); } /** @@ -852,8 +852,8 @@ public static Array arrayArray(final A...as) { @SuppressWarnings("unchecked") public static P2, Array> unzip(final Array> xs) { final int len = xs.length(); - final Array aa = new Array(new Object[len]); - final Array ab = new Array(new Object[len]); + final Array aa = new Array<>(new Object[len]); + final Array ab = new Array<>(new Object[len]); for (int i = len - 1; i >= 0; i--) { final P2 p = xs.get(i); aa.set(i, p._1()); diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index 7e44ef9b..cf2f0af5 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -69,7 +69,7 @@ public static DList arrayDList(final A...as) { * @return the final List */ public List run() { - return appendFn.f(List.nil()).run(); + return appendFn.f(List.nil()).run(); } /** @@ -85,7 +85,7 @@ public java.util.List toJavaList() { * @return a empty DList. */ public static DList nil() { - return new DList<>(Trampoline.>pure()); + return new DList<>(Trampoline.pure()); } /** diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 1cbecb5d..0d944415 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -39,7 +39,7 @@ private Either() { * @return A left projection of this either. */ public final LeftProjection left() { - return new LeftProjection(this); + return new LeftProjection<>(this); } /** @@ -48,7 +48,7 @@ public final LeftProjection left() { * @return A right projection of this either. */ public final RightProjection right() { - return new RightProjection(this); + return new RightProjection<>(this); } /** @@ -93,7 +93,7 @@ public final Either bimap(final F left, final F right) @Override public boolean equals(Object other) { - return Equal.equals0(Either.class, this, other, () -> Equal.eitherEqual(Equal.anyEqual(), Equal.anyEqual())); + return Equal.equals0(Either.class, this, other, () -> Equal.eitherEqual(Equal.anyEqual(), Equal.anyEqual())); } @Override @@ -107,7 +107,7 @@ public int hashCode() { * @return The value of this either swapped to the opposing side. */ public final Either swap() { - return isLeft() ? new Right(((Left) this).a) : new Left(((Right) this).b); + return isLeft() ? new Right<>(((Left) this).a) : new Left<>(((Right) this).b); } private static final class Left extends Either { @@ -265,7 +265,7 @@ public void foreachDoEffect(final Effect1 f) { * @return A new either value after mapping. */ public Either map(final F f) { - return isLeft() ? new Left(f.f(value())) : new Right(e.right().value()); + return isLeft() ? new Left<>(f.f(value())) : new Right<>(e.right().value()); } /** @@ -275,7 +275,7 @@ public Either map(final F f) { * @return A new either value after binding. */ public Either bind(final F> f) { - return isLeft() ? f.f(value()) : new Right(e.right().value()); + return isLeft() ? f.f(value()) : new Right<>(e.right().value()); } /** @@ -285,7 +285,7 @@ public Either bind(final F> f) { * @return An either after binding through this projection. */ public Either sequence(final Either e) { - return bind(Function.>constant(e)); + return bind(Function.constant(e)); } /** @@ -297,7 +297,7 @@ public Either sequence(final Either e) { public List> traverseList(final F> f) { return isLeft() ? f.f(value()).map(Either::left) : - list(Either.right(e.right().value())); + list(Either.right(e.right().value())); } /** @@ -309,7 +309,7 @@ public List> traverseList(final F> f) { public IO> traverseIO(final F> f) { return isRight() ? IOFunctions.map(f.f(value()), Either::left) : - IOFunctions.unit(Either.right(e.right().value())); + IOFunctions.unit(Either.right(e.right().value())); } /** @@ -323,9 +323,9 @@ public IO> traverseIO(final F> f) { public Option> filter(final F f) { return isLeft() ? f.f(value()) ? - Option.>some(new Left<>(value())) : - Option.>none() : - Option.>none(); + Option.some(new Left<>(value())) : + Option.none() : + Option.none(); } /** @@ -368,7 +368,7 @@ public boolean exists(final F f) { * @return A single element list if this projection has a value, otherwise an empty list. */ public List toList() { - return isLeft() ? single(value()) : List.nil(); + return isLeft() ? single(value()) : List.nil(); } /** @@ -379,7 +379,7 @@ public List toList() { * None. */ public Option toOption() { - return isLeft() ? some(value()) : Option.none(); + return isLeft() ? some(value()) : Option.none(); } /** @@ -402,7 +402,7 @@ public Array toArray() { * @return A single element stream if this projection has a value, otherwise an empty stream. */ public Stream toStream() { - return isLeft() ? Stream.single(value()) : Stream.nil(); + return isLeft() ? Stream.single(value()) : Stream.nil(); } /** @@ -417,13 +417,13 @@ public Collection toCollection() { public Option> traverseOption(F> f) { return isLeft() ? f.f(value()).map(Either::left) : - some(Either.right(e.right().value())); + some(Either.right(e.right().value())); } public Stream> traverseStream(F> f) { return isLeft() ? f.f(value()).map(Either::left) : - Stream.single(Either.right(e.right().value())); + Stream.single(Either.right(e.right().value())); } } @@ -551,7 +551,7 @@ public Either bind(final F> f) { * @return An either after binding through this projection. */ public Either sequence(final Either e) { - return bind(Function.>constant(e)); + return bind(Function.constant(e)); } /** * Traverse with function that produces List (non-determinism). @@ -562,7 +562,7 @@ public Either sequence(final Either e) { public List> traverseList(final F> f) { return isRight() ? f.f(value()).map(Either::right) : - list(Either.left(e.left().value())); + list(Either.left(e.left().value())); } /** @@ -574,19 +574,19 @@ public List> traverseList(final F> f) { public IO> traverseIO(final F> f) { return isRight() ? IOFunctions.map(f.f(value()), Either::right) : - IOFunctions.lazy(() -> Either.left(e.left().value())); + IOFunctions.lazy(() -> Either.left(e.left().value())); } public P1> traverseP1(final F> f) { return isRight() ? f.f(value()).map(Either::right) : - p(Either.left(e.left().value())); + p(Either.left(e.left().value())); } public Option> traverseOption(final F> f) { return isRight() ? f.f(value()).map(Either::right) : - some(Either.left(e.left().value())); + some(Either.left(e.left().value())); } /** @@ -600,9 +600,9 @@ public Option> traverseOption(final F> f) { public Option> filter(final F f) { return isRight() ? f.f(value()) ? - Option.>some(new Right(value())) : - Option.>none() : - Option.>none(); + Option.some(new Right(value())) : + Option.none() : + Option.none(); } /** @@ -645,7 +645,7 @@ public boolean exists(final F f) { * @return A single element list if this projection has a value, otherwise an empty list. */ public List toList() { - return isRight() ? single(value()) : List.nil(); + return isRight() ? single(value()) : List.nil(); } /** @@ -656,7 +656,7 @@ public List toList() { * None. */ public Option toOption() { - return isRight() ? some(value()) : Option.none(); + return isRight() ? some(value()) : Option.none(); } /** @@ -679,7 +679,7 @@ public Array toArray() { * @return A single element stream if this projection has a value, otherwise an empty stream. */ public Stream toStream() { - return isRight() ? Stream.single(value()) : Stream.nil(); + return isRight() ? Stream.single(value()) : Stream.nil(); } /** @@ -694,7 +694,7 @@ public Collection toCollection() { public Stream> traverseStream(F> f) { return isRight() ? f.f(value()).map(Either::right) : - Stream.>single(left(e.left().value())); + Stream.single(left(e.left().value())); } } @@ -706,7 +706,7 @@ public Stream> traverseStream(F> f) { * @return A left value of either. */ public static Either left(final A a) { - return new Left(a); + return new Left<>(a); } /** @@ -734,7 +734,7 @@ public static F> right_() { * @return A right value of either. */ public static Either right(final B b) { - return new Right(b); + return new Right<>(b); } /** @@ -781,7 +781,7 @@ public static Either joinRight(final Either> e) { */ public static Either, X> sequenceLeft(final List> a) { return a.isEmpty() ? - Either., X>left(List.nil()) : + Either.left(List.nil()) : a.head().left().bind(aa -> sequenceLeft(a.tail()).left().map(cons_(aa))); } @@ -793,7 +793,7 @@ public static Either, X> sequenceLeft(final List> a) */ public static Either> sequenceRight(final List> a) { return a.isEmpty() ? - Either.>right(List.nil()) : + Either.right(List.nil()) : a.head().right().bind(bb -> sequenceRight(a.tail()).right().map(cons_(bb))); } @@ -803,7 +803,7 @@ public static Either> sequenceRight(final List> a * @return traversed value */ public List> traverseListRight(final F> f) { - return right().traverseList(f); + return right().traverseList(f); } /** @@ -812,7 +812,7 @@ public List> traverseListRight(final F> f) { * @return traversed value */ public List> traverseListLeft(final F> f) { - return left().traverseList(f); + return left().traverseList(f); } /** @@ -821,7 +821,7 @@ public List> traverseListLeft(final F> f) { * @return traversed value */ public IO> traverseIORight(final F> f) { - return right().traverseIO(f); + return right().traverseIO(f); } /** @@ -830,7 +830,7 @@ public IO> traverseIORight(final F> f) { * @return traversed value */ public IO> traverseIOLeft(final F> f) { - return left().traverseIO(f); + return left().traverseIO(f); } /** @@ -839,7 +839,7 @@ public IO> traverseIOLeft(final F> f) { * @return traversed value */ public Option> traverseOptionRight(final F> f) { - return right().traverseOption(f); + return right().traverseOption(f); } /** @@ -848,7 +848,7 @@ public Option> traverseOptionRight(final F> f) { * @return traversed value */ public Option> traverseOptionLeft(final F> f) { - return left().traverseOption(f); + return left().traverseOption(f); } /** @@ -857,7 +857,7 @@ public Option> traverseOptionLeft(final F> f) { * @return traversed value */ public Stream> traverseStreamRight(final F> f) { - return right().traverseStream(f); + return right().traverseStream(f); } /** @@ -866,7 +866,7 @@ public Stream> traverseStreamRight(final F> f) { * @return traversed value */ public Stream> traverseStreamLeft(final F> f) { - return left().traverseStream(f); + return left().traverseStream(f); } @@ -890,7 +890,7 @@ public static A reduce(final Either e) { * @return A constructed either based on the given condition. */ public static Either iif(final boolean c, final F0 right, final F0 left) { - return c ? new Right(right.f()) : new Left(left.f()); + return c ? new Right<>(right.f()) : new Left<>(left.f()); } /** @@ -900,7 +900,7 @@ public static Either iif(final boolean c, final F0 right, final * @return All the left values in the given list. */ public static List lefts(final List> es) { - return es.foldRight(e -> as -> e.isLeft() ? as.cons(e.left().value()) : as, List.nil()); + return es.foldRight(e -> as -> e.isLeft() ? as.cons(e.left().value()) : as, List.nil()); } /** @@ -910,7 +910,7 @@ public static List lefts(final List> es) { * @return All the right values in the given list. */ public static List rights(final List> es) { - return es.foldRight(e -> bs -> e.isRight() ? bs.cons(e.right().value()) : bs, List.nil()); + return es.foldRight(e -> bs -> e.isRight() ? bs.cons(e.right().value()) : bs, List.nil()); } public String toString() { diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index b7533ffd..1666d7b2 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -220,7 +220,7 @@ public Enumerator setMax(final Option max) { public static Enumerator enumerator(final F> successor, final F> predecessor, final Option max, final Option min, final Ord order, final F>> plus) { - return new Enumerator(successor, predecessor, max, min, order, plus); + return new Enumerator<>(successor, predecessor, max, min, order, plus); } /** @@ -236,30 +236,30 @@ public static Enumerator enumerator(final F> successor, fina */ public static Enumerator enumerator(final F> successor, final F> predecessor, final Option max, final Option min, final Ord order) { - return new Enumerator(successor, predecessor, max, min, order, curry((a, l) -> { - if (l == 0L) - return some(a); - else if (l < 0L) { - A aa = a; - for (long x = l; x < 0; x++) { - final Option s = predecessor.f(aa); - if (s.isNone()) - return none(); - else - aa = s.some(); - } - return some(aa); - } else { - A aa = a; - for (long x = l; x > 0; x--) { - final Option s = successor.f(aa); - if (s.isNone()) - return none(); - else - aa = s.some(); - } - return some(aa); + return new Enumerator<>(successor, predecessor, max, min, order, curry((a, l) -> { + if (l == 0L) + return some(a); + else if (l < 0L) { + A aa = a; + for (long x = l; x < 0; x++) { + final Option s = predecessor.f(aa); + if (s.isNone()) + return none(); + else + aa = s.some(); } + return some(aa); + } else { + A aa = a; + for (long x = l; x > 0; x--) { + final Option s = successor.f(aa); + if (s.isNone()) + return none(); + else + aa = s.some(); + } + return some(aa); + } })); } @@ -267,8 +267,8 @@ else if (l < 0L) { * An enumerator for boolean. */ public static final Enumerator booleanEnumerator = enumerator( - b -> b ? Option.none() : some(true), - b -> b ? some(false) : Option.none(), + b -> b ? Option.none() : some(true), + b -> b ? some(false) : Option.none(), some(true), some(false), booleanOrd ); @@ -276,8 +276,8 @@ else if (l < 0L) { * An enumerator for byte. */ public static final Enumerator byteEnumerator = enumerator( - b -> b == Byte.MAX_VALUE ? Option.none() : some((byte) (b + 1)), - b -> b == Byte.MIN_VALUE ? Option.none() : some((byte) (b - 1)), + b -> b == Byte.MAX_VALUE ? Option.none() : some((byte) (b + 1)), + b -> b == Byte.MIN_VALUE ? Option.none() : some((byte) (b - 1)), some(Byte.MAX_VALUE), some(Byte.MIN_VALUE), byteOrd ); @@ -285,8 +285,8 @@ else if (l < 0L) { * An enumerator for char. */ public static final Enumerator charEnumerator = enumerator( - c -> c == Character.MAX_VALUE ? Option.none() : some((char) (c + 1)), - c -> c == Character.MIN_VALUE ? Option.none() : some((char) (c - 1)), + c -> c == Character.MAX_VALUE ? Option.none() : some((char) (c + 1)), + c -> c == Character.MIN_VALUE ? Option.none() : some((char) (c - 1)), some(Character.MAX_VALUE), some(Character.MIN_VALUE), charOrd ); @@ -294,8 +294,8 @@ else if (l < 0L) { * An enumerator for double. */ public static final Enumerator doubleEnumerator = enumerator( - d -> d == Double.MAX_VALUE ? Option.none() : some(d + 1D), - d -> d == Double.MIN_VALUE ? Option.none() : some(d - 1D), + d -> d == Double.MAX_VALUE ? Option.none() : some(d + 1D), + d -> d == Double.MIN_VALUE ? Option.none() : some(d - 1D), some(Double.MAX_VALUE), some(Double.MIN_VALUE), doubleOrd ); @@ -303,8 +303,8 @@ else if (l < 0L) { * An enumerator for float. */ public static final Enumerator floatEnumerator = enumerator( - f -> f == Float.MAX_VALUE ? Option.none() : some(f + 1F), - f -> f == Float.MIN_VALUE ? Option.none() : some(f - 1F), + f -> f == Float.MAX_VALUE ? Option.none() : some(f + 1F), + f -> f == Float.MIN_VALUE ? Option.none() : some(f - 1F), some(Float.MAX_VALUE), some(Float.MIN_VALUE), floatOrd ); @@ -312,8 +312,8 @@ else if (l < 0L) { * An enumerator for int. */ public static final Enumerator intEnumerator = enumerator( - i -> i == Integer.MAX_VALUE ? Option.none() : some(i + 1), - i -> i == Integer.MIN_VALUE ? Option.none() : some(i - 1), + i -> i == Integer.MAX_VALUE ? Option.none() : some(i + 1), + i -> i == Integer.MIN_VALUE ? Option.none() : some(i - 1), some(Integer.MAX_VALUE), some(Integer.MIN_VALUE), intOrd ); @@ -323,7 +323,7 @@ else if (l < 0L) { public static final Enumerator bigintEnumerator = enumerator( i -> some(i.add(BigInteger.ONE)), i -> some(i.subtract(BigInteger.ONE)), - Option.none(), Option.none(), bigintOrd, + Option.none(), Option.none(), bigintOrd, curry((i, l) -> some(i.add(BigInteger.valueOf(l)))) ); @@ -333,7 +333,7 @@ else if (l < 0L) { public static final Enumerator bigdecimalEnumerator = enumerator( i -> some(i.add(BigDecimal.ONE)), i -> some(i.subtract(BigDecimal.ONE)), - Option.none(), Option.none(), bigdecimalOrd, + Option.none(), Option.none(), bigdecimalOrd, curry((d, l) -> some(d.add(BigDecimal.valueOf(l)))) ); @@ -341,8 +341,8 @@ else if (l < 0L) { * An enumerator for long. */ public static final Enumerator longEnumerator = enumerator( - i -> i == Long.MAX_VALUE ? Option.none() : some(i + 1L), - i -> i == Long.MIN_VALUE ? Option.none() : some(i - 1L), + i -> i == Long.MAX_VALUE ? Option.none() : some(i + 1L), + i -> i == Long.MIN_VALUE ? Option.none() : some(i - 1L), some(Long.MAX_VALUE), some(Long.MIN_VALUE), longOrd ); @@ -350,8 +350,8 @@ else if (l < 0L) { * An enumerator for short. */ public static final Enumerator shortEnumerator = enumerator( - i -> i == Short.MAX_VALUE ? Option.none() : some((short) (i + 1)), - i -> i == Short.MIN_VALUE ? Option.none() : some((short) (i - 1)), + i -> i == Short.MAX_VALUE ? Option.none() : some((short) (i + 1)), + i -> i == Short.MIN_VALUE ? Option.none() : some((short) (i - 1)), some(Short.MAX_VALUE), some(Short.MIN_VALUE), shortOrd ); @@ -359,8 +359,8 @@ else if (l < 0L) { * An enumerator for Ordering. */ public static final Enumerator orderingEnumerator = enumerator( - o -> o == LT ? some(EQ) : o == EQ ? some(GT) : Option.none(), - o -> o == GT ? some(EQ) : o == EQ ? some(LT) : Option.none(), + o -> o == LT ? some(EQ) : o == EQ ? some(GT) : Option.none(), + o -> o == GT ? some(EQ) : o == EQ ? some(LT) : Option.none(), some(GT), some(LT), orderingOrd ); @@ -370,7 +370,7 @@ else if (l < 0L) { public static final Enumerator naturalEnumerator = enumerator( n -> some(n.succ()), Natural::pred, - Option.none(), some(Natural.ZERO), naturalOrd, + Option.none(), some(Natural.ZERO), naturalOrd, curry((n, l) -> some(n).apply( Natural.natural(l).map(curry((n1, n2) -> n1.add(n2))) diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index 6b03a96a..9a145b37 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -63,7 +63,7 @@ public Iterator iterator() { * @param h The hashing strategy. */ public HashMap(final Equal e, final Hash h) { - m = new java.util.HashMap, V>(); + m = new java.util.HashMap<>(); this.e = e; this.h = h; } @@ -83,13 +83,13 @@ public HashMap(java.util.Map map, final Equal e, final Hash h) { * @param initialCapacity The initial capacity. */ public HashMap(final Equal e, final Hash h, final int initialCapacity) { - m = new java.util.HashMap, V>(initialCapacity); + m = new java.util.HashMap<>(initialCapacity); this.e = e; this.h = h; } public HashMap(java.util.Map map) { - this(map, Equal.anyEqual(), Hash.anyHash()); + this(map, Equal.anyEqual(), Hash.anyHash()); } /** @@ -101,7 +101,7 @@ public HashMap(java.util.Map map) { * @param loadFactor The load factor. */ public HashMap(final Equal e, final Hash h, final int initialCapacity, final float loadFactor) { - m = new java.util.HashMap, V>(initialCapacity, loadFactor); + m = new java.util.HashMap<>(initialCapacity, loadFactor); this.e = e; this.h = h; } @@ -121,7 +121,7 @@ public static HashMap hashMap() { * @return A new hash map. */ public static HashMap hashMap(final Equal e, final Hash h) { - return new HashMap(e, h); + return new HashMap<>(e, h); } /** @@ -152,7 +152,7 @@ public int hash(final K k) { * @return A potential value for the given key. */ public Option get(final K k) { - return fromNull(m.get(new Key(k, e, h))); + return fromNull(m.get(new Key<>(k, e, h))); } /** @@ -178,7 +178,7 @@ public void clear() { * @return true if this hash map contains the given key, false otherwise. */ public boolean contains(final K k) { - return m.containsKey(new Key(k, e, h)); + return m.containsKey(new Key<>(k, e, h)); } /** @@ -187,7 +187,7 @@ public boolean contains(final K k) { * @return All key entries in this hash map. */ public List keys() { - final List.Buffer b = new List.Buffer(); + final List.Buffer b = new List.Buffer<>(); for (final Key k : m.keySet()) { b.snoc(k.k()); @@ -202,7 +202,7 @@ public List keys() { * @return All values in this hash map. */ public List values() { - return keys().map(k -> m.get(new Key(k, e, h))); + return keys().map(k -> m.get(new Key<>(k, e, h))); } /** @@ -231,7 +231,7 @@ public int size() { */ public void set(final K k, final V v) { if (v != null) { - m.put(new Key(k, e, h), v); + m.put(new Key<>(k, e, h), v); } } @@ -241,7 +241,7 @@ public void set(final K k, final V v) { * @param k The key to delete from this hash map. */ public void delete(final K k) { - m.remove(new Key(k, e, h)); + m.remove(new Key<>(k, e, h)); } /** @@ -251,13 +251,13 @@ public void delete(final K k) { * @return The value that was associated with the given key, if there was one. */ public Option getDelete(final K k) { - return fromNull(m.remove(new Key(k, e, h))); + return fromNull(m.remove(new Key<>(k, e, h))); } public HashMap map(F keyFunction, F valueFunction, Equal equal, Hash hash) { - final HashMap hashMap = new HashMap(equal, hash); + final HashMap hashMap = new HashMap<>(equal, hash); for (K key : keys()) { final A newKey = keyFunction.f(key); final B newValue = valueFunction.f(get(key).some()); @@ -268,7 +268,7 @@ public HashMap map(F keyFunction, public HashMap map(F keyFunction, F valueFunction) { - return map(keyFunction, valueFunction, Equal.anyEqual(), Hash.anyHash()); + return map(keyFunction, valueFunction, Equal.anyEqual(), Hash.anyHash()); } public HashMap map(F, P2> function, Equal equal, Hash hash) { @@ -280,15 +280,15 @@ public HashMap map(F, P2> function) { } public HashMap mapKeys(F keyFunction, Equal equal, Hash hash) { - return map(keyFunction, Function.identity(), equal, hash); + return map(keyFunction, Function.identity(), equal, hash); } public HashMap mapKeys(F function) { - return mapKeys(function, Equal.anyEqual(), Hash.anyHash()); + return mapKeys(function, Equal.anyEqual(), Hash.anyHash()); } public HashMap mapValues(F function) { - return map(Function.identity(), function, e, h); + return map(Function.identity(), function, e, h); } public void foreachDoEffect(Effect1> effect) { @@ -325,7 +325,7 @@ public Array> toArray() { } public java.util.Map toMap() { - final java.util.HashMap result = new java.util.HashMap(); + final java.util.HashMap result = new java.util.HashMap<>(); for (K key : keys()) { result.put(key, get(key).some()); } @@ -368,7 +368,7 @@ public static HashMap from(final Iterable> entries, final * Converts the Iterable to a HashMap */ public static HashMap iterableHashMap(final Equal equal, final Hash hash, final Iterable> entries) { - final HashMap map = new HashMap(equal, hash); + final HashMap map = new HashMap<>(equal, hash); for (P2 entry : entries) { map.set(entry._1(), entry._2()); } @@ -379,7 +379,7 @@ public static HashMap iterableHashMap(final Equal equal, final H * Converts the Iterable to a HashMap */ public static HashMap iterableHashMap(final Iterable> entries) { - return iterableHashMap(Equal.anyEqual(), Hash.anyHash(), entries); + return iterableHashMap(Equal.anyEqual(), Hash.anyHash(), entries); } /** diff --git a/core/src/main/java/fj/data/HashSet.java b/core/src/main/java/fj/data/HashSet.java index 1c6868e3..d7b2c832 100644 --- a/core/src/main/java/fj/data/HashSet.java +++ b/core/src/main/java/fj/data/HashSet.java @@ -36,7 +36,7 @@ public Iterator iterator() { * @param h The hashing strategy. */ public HashSet(final Equal e, final Hash h) { - m = new HashMap(e, h); + m = new HashMap<>(e, h); } /** @@ -47,7 +47,7 @@ public HashSet(final Equal e, final Hash h) { * @param initialCapacity The initial capacity. */ public HashSet(final Equal e, final Hash h, final int initialCapacity) { - m = new HashMap(e, h, initialCapacity); + m = new HashMap<>(e, h, initialCapacity); } /** @@ -59,7 +59,7 @@ public HashSet(final Equal e, final Hash h, final int initialCapacity) { * @param loadFactor The load factor. */ public HashSet(final Equal e, final Hash h, final int initialCapacity, final float loadFactor) { - m = new HashMap(e, h, initialCapacity, loadFactor); + m = new HashMap<>(e, h, initialCapacity, loadFactor); } /** @@ -87,7 +87,7 @@ public int hash(final A a) { * Creates a new HashSet using the given Equal and Hash */ public static HashSet empty(final Equal e, final Hash h) { - return new HashSet(e, h); + return new HashSet<>(e, h); } /** @@ -230,7 +230,7 @@ public java.util.List toJavaList() { } public java.util.Set toJavaSet() { - return new java.util.HashSet(toCollection()); + return new java.util.HashSet<>(toCollection()); } public static HashSet fromSet(java.util.Set s) { diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index c3d5fe01..cfe5eba2 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -94,8 +94,8 @@ public static IO closeReader(final Reader r) { */ public static IO> enumFileLines(final File f, final Option encoding, final IterV i) { return bracket(bufferedReader(f, encoding) - , Function.>vary(closeReader) - , partialApply2(IOFunctions.lineReader(), i)); + , Function.vary(closeReader) + , partialApply2(IOFunctions.lineReader(), i)); } /** @@ -107,8 +107,8 @@ public static IO> enumFileLines(final File f, final Option< */ public static IO> enumFileCharChunks(final File f, final Option encoding, final IterV i) { return bracket(fileReader(f, encoding) - , Function.>vary(closeReader) - , partialApply2(IOFunctions.charChunkReader(), i)); + , Function.vary(closeReader) + , partialApply2(IOFunctions.charChunkReader(), i)); } /** @@ -120,8 +120,8 @@ public static IO> enumFileCharChunks(final File f, final Op */ public static IO> enumFileChars(final File f, final Option encoding, final IterV i) { return bracket(fileReader(f, encoding) - , Function.>vary(closeReader) - , partialApply2(IOFunctions.charChunkReader2(), i)); + , Function.vary(closeReader) + , partialApply2(IOFunctions.charChunkReader2(), i)); } public static IO bufferedReader(final File f, final Option encoding) { @@ -194,8 +194,8 @@ public IO> f(final IterV it) { if (s == null) { return i; } - final Input input = Input.el(s); - final F, IterV>, P1>> cont = F1Functions.lazy(Function., IterV>apply(input)); + final Input input = Input.el(s); + final F, IterV>, P1>> cont = F1Functions.lazy(Function.apply(input)); i = i.fold(done, cont)._1(); } return i; @@ -238,9 +238,9 @@ public IO> f(final IterV it) { if (numRead < buffer.length) { buffer = Arrays.copyOfRange(buffer, 0, numRead); } - final Input input = Input.el(buffer); + final Input input = Input.el(buffer); final F, IterV>, P1>> cont = - F1Functions.lazy(Function., IterV>apply(input)); + F1Functions.lazy(Function.apply(input)); i = i.fold(done, cont)._1(); } return i; @@ -286,7 +286,7 @@ public IO> f(final IterV it) { for (int c = 0; c < buffer.length; c++) { final Input input = Input.el(buffer[c]); final F, IterV>, IterV> cont = - Function., IterV>apply(input); + Function.apply(input); i = i.fold(done, cont); } } @@ -326,14 +326,14 @@ public static IO unless(final Boolean b, final IO io) { public static IO> sequence(List> list) { F2, IO>, IO>> f2 = (io, ioList) -> bind(ioList, (xs) -> map(io, x -> List.cons(x, xs))); - return list.foldRight(f2, unit(List.nil())); + return list.foldRight(f2, unit(List.nil())); } public static IO> sequence(Stream> stream) { F2>, IO, IO>> f2 = (ioList, io) -> bind(ioList, (xs) -> map(io, x -> Stream.cons(x, () -> xs))); - return stream.foldLeft(f2, unit(Stream.nil())); + return stream.foldLeft(f2, unit(Stream.nil())); } @@ -380,7 +380,7 @@ public static IO> sequenceWhileEager(final Stream> stream, f return () -> { boolean loop = true; Stream> input = stream; - Stream result = Stream.nil(); + Stream result = Stream.nil(); while (loop) { if (input.isEmpty()) { loop = false; @@ -453,8 +453,8 @@ public static IO stdoutPrint(final String s) { } public static IO getContents() { - Stream> s = Stream.>repeat(() -> (int) stdinBufferedReader.read()); - return map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> (char) i.intValue()))); + Stream> s = Stream.repeat(() -> stdinBufferedReader.read()); + return map(sequenceWhile(s, i -> i != -1), s2 -> LazyString.fromStream(s2.map(i -> (char) i.intValue()))); } public static IO interact(F f) { diff --git a/core/src/main/java/fj/data/IterableW.java b/core/src/main/java/fj/data/IterableW.java index 0633ffd4..db75dbb5 100644 --- a/core/src/main/java/fj/data/IterableW.java +++ b/core/src/main/java/fj/data/IterableW.java @@ -33,7 +33,7 @@ private IterableW(final Iterable i) { * @return An iterable equipped with some useful functions. */ public static IterableW wrap(final Iterable a) { - return new IterableW(a); + return new IterableW<>(a); } /** @@ -128,9 +128,9 @@ public static F, F, IterableW>> liftM2(fina public static > IterableW> sequence(final Iterable as) { final Stream ts = iterableStream(as); return ts.isEmpty() ? - iterable(wrap(Option.none())) : + iterable(wrap(Option.none())) : wrap(ts.head()).bind(a -> - sequence(ts.tail().map(IterableW.>wrap())._1()).bind(as2 -> + sequence(ts.tail().map(IterableW.wrap())._1()).bind(as2 -> iterable(wrap(Stream.cons(a, () -> iterableStream(as2)))) ) ); diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index 391c4087..bcb03cc0 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -82,17 +82,17 @@ public Z fold(final F>, Z> done, final F, IterV, Option> runCont = new F, Option>() { - final F>, Option> done = F1Functions.andThen(P2.>__1(), Option.some_()); - final F, IterV>, Option> cont = Function.constant(Option.none()); + final F>, Option> done = F1Functions.andThen(P2.__1(), Option.some_()); + final F, IterV>, Option> cont = Function.constant(Option.none()); @Override public Option f(final IterV i) { return i.fold(done, cont); } }; - final F>, A> done = P2.>__1(); + final F>, A> done = P2.__1(); final F, IterV>, A> cont = - k -> runCont.f(k.f(Input.eof())).valueE("diverging iteratee"); + k -> runCont.f(k.f(Input.eof())).valueE("diverging iteratee"); return fold(done, cont); } @@ -154,7 +154,7 @@ public IterV f(final Input s) { } }; return n == 0 - ? done(Unit.unit(), Input.empty()) + ? done(Unit.unit(), Input.empty()) : cont(step); } @@ -166,7 +166,7 @@ public static IterV> head() { final F0>> empty = () -> cont(step); - final F0>>> el = () -> e -> done(Option.some(e), Input.empty()); + final F0>>> el = () -> e -> done(Option.some(e), Input.empty()); final F0>> eof = () -> done(Option.none(), Input.eof()); @@ -186,7 +186,7 @@ public static IterV> peek() { final F0>> empty = () -> cont(step); - final F0>>> el = () -> e -> done(Option.some(e), Input.el(e)); + final F0>>> el = () -> e -> done(Option.some(e), Input.el(e)); final F0>> eof = () -> done(Option.none(), Input.eof()); @@ -216,7 +216,7 @@ public F, IterV>> f(final List acc) { return s -> s.apply(empty, el, eof); } }; - return cont(step.f(List. nil())); + return cont(step.f(List.nil())); } } diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 0be648f2..b4b6173a 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -51,7 +51,7 @@ private Java() { * @return A function that converts lists to array lists. */ public static F, ArrayList> List_ArrayList() { - return as -> new ArrayList(as.toCollection()); + return as -> new ArrayList<>(as.toCollection()); } /** @@ -78,7 +78,7 @@ public static > F, EnumSet> List_EnumSet() { * @return A function that converts lists to hash sets. */ public static F, HashSet> List_HashSet() { - return as -> new HashSet(as.toCollection()); + return as -> new HashSet<>(as.toCollection()); } /** @@ -87,7 +87,7 @@ public static F, HashSet> List_HashSet() { * @return A function that converts lists to linked hash sets. */ public static F, LinkedHashSet> List_LinkedHashSet() { - return as -> new LinkedHashSet(as.toCollection()); + return as -> new LinkedHashSet<>(as.toCollection()); } /** @@ -96,7 +96,7 @@ public static F, LinkedHashSet> List_LinkedHashSet() { * @return A function that converts lists to linked lists. */ public static F, LinkedList> List_LinkedList() { - return as -> new LinkedList(as.toCollection()); + return as -> new LinkedList<>(as.toCollection()); } /** @@ -105,7 +105,7 @@ public static F, LinkedList> List_LinkedList() { * @return A function that converts lists to priority queues. */ public static F, PriorityQueue> List_PriorityQueue() { - return as -> new PriorityQueue(as.toCollection()); + return as -> new PriorityQueue<>(as.toCollection()); } /** @@ -115,7 +115,7 @@ public static F, PriorityQueue> List_PriorityQueue() { */ public static F, Stack> List_Stack() { return as -> { - final Stack s = new Stack(); + final Stack s = new Stack<>(); s.addAll(as.toCollection()); return s; }; @@ -127,7 +127,7 @@ public static F, Stack> List_Stack() { * @return A function that converts lists to stacks. */ public static F, TreeSet> List_TreeSet() { - return as -> new TreeSet(as.toCollection()); + return as -> new TreeSet<>(as.toCollection()); } /** @@ -136,7 +136,7 @@ public static F, TreeSet> List_TreeSet() { * @return A function that converts lists to vectors. */ public static F, Vector> List_Vector() { - return as -> new Vector(as.toCollection()); + return as -> new Vector<>(as.toCollection()); } /** @@ -146,7 +146,7 @@ public static F, Vector> List_Vector() { * @return A function that converts lists to array blocking queue. */ public static F, ArrayBlockingQueue> List_ArrayBlockingQueue(final boolean fair) { - return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection()); + return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection()); } /** @@ -155,7 +155,7 @@ public static F, ArrayBlockingQueue> List_ArrayBlockingQueue(fina * @return A function that converts lists to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> List_ConcurrentLinkedQueue() { - return as -> new ConcurrentLinkedQueue(as.toCollection()); + return as -> new ConcurrentLinkedQueue<>(as.toCollection()); } /** @@ -164,7 +164,7 @@ public static F, ConcurrentLinkedQueue> List_ConcurrentLinkedQueu * @return A function that converts lists to copy on write array lists. */ public static F, CopyOnWriteArrayList> List_CopyOnWriteArrayList() { - return as -> new CopyOnWriteArrayList(as.toCollection()); + return as -> new CopyOnWriteArrayList<>(as.toCollection()); } /** @@ -173,7 +173,7 @@ public static F, CopyOnWriteArrayList> List_CopyOnWriteArrayList( * @return A function that converts lists to copy on write array sets. */ public static F, CopyOnWriteArraySet> List_CopyOnWriteArraySet() { - return as -> new CopyOnWriteArraySet(as.toCollection()); + return as -> new CopyOnWriteArraySet<>(as.toCollection()); } /** @@ -182,7 +182,7 @@ public static F, CopyOnWriteArraySet> List_CopyOnWriteArraySet() * @return A function that converts lists to delay queues. */ public static F, DelayQueue> List_DelayQueue() { - return as -> new DelayQueue(as.toCollection()); + return as -> new DelayQueue<>(as.toCollection()); } /** @@ -191,7 +191,7 @@ public static F, DelayQueue> List_DelayQueue() { * @return A function that converts lists to linked blocking queues. */ public static F, LinkedBlockingQueue> List_LinkedBlockingQueue() { - return as -> new LinkedBlockingQueue(as.toCollection()); + return as -> new LinkedBlockingQueue<>(as.toCollection()); } /** @@ -200,7 +200,7 @@ public static F, LinkedBlockingQueue> List_LinkedBlockingQueue() * @return A function that converts lists to priority blocking queues. */ public static F, PriorityBlockingQueue> List_PriorityBlockingQueue() { - return as -> new PriorityBlockingQueue(as.toCollection()); + return as -> new PriorityBlockingQueue<>(as.toCollection()); } /** @@ -211,7 +211,7 @@ public static F, PriorityBlockingQueue> List_PriorityBlockingQueu */ public static F, SynchronousQueue> List_SynchronousQueue(final boolean fair) { return as -> { - final SynchronousQueue q = new SynchronousQueue(fair); + final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(as.toCollection()); return q; }; @@ -227,7 +227,7 @@ public static F, SynchronousQueue> List_SynchronousQueue(final bo * @return A function that converts arrays to array lists. */ public static F, ArrayList> Array_ArrayList() { - return as -> new ArrayList(as.toCollection()); + return as -> new ArrayList<>(as.toCollection()); } /** @@ -255,7 +255,7 @@ public static > F, EnumSet> Array_EnumSet() { * @return A function that converts arrays to hash sets. */ public static F, HashSet> Array_HashSet() { - return as -> new HashSet(as.toCollection()); + return as -> new HashSet<>(as.toCollection()); } /** @@ -264,7 +264,7 @@ public static F, HashSet> Array_HashSet() { * @return A function that converts arrays to linked hash sets. */ public static F, LinkedHashSet> Array_LinkedHashSet() { - return as -> new LinkedHashSet(as.toCollection()); + return as -> new LinkedHashSet<>(as.toCollection()); } /** @@ -273,7 +273,7 @@ public static F, LinkedHashSet> Array_LinkedHashSet() { * @return A function that converts arrays to linked lists. */ public static F, LinkedList> Array_LinkedList() { - return as -> new LinkedList(as.toCollection()); + return as -> new LinkedList<>(as.toCollection()); } /** @@ -282,7 +282,7 @@ public static F, LinkedList> Array_LinkedList() { * @return A function that converts arrays to priority queues. */ public static F, PriorityQueue> Array_PriorityQueue() { - return as -> new PriorityQueue(as.toCollection()); + return as -> new PriorityQueue<>(as.toCollection()); } /** @@ -292,7 +292,7 @@ public static F, PriorityQueue> Array_PriorityQueue() { */ public static F, Stack> Array_Stack() { return as -> { - final Stack s = new Stack(); + final Stack s = new Stack<>(); s.addAll(as.toCollection()); return s; }; @@ -304,7 +304,7 @@ public static F, Stack> Array_Stack() { * @return A function that converts arrays to tree sets. */ public static F, TreeSet> Array_TreeSet() { - return as -> new TreeSet(as.toCollection()); + return as -> new TreeSet<>(as.toCollection()); } /** @@ -313,7 +313,7 @@ public static F, TreeSet> Array_TreeSet() { * @return A function that converts arrays to vectors. */ public static F, Vector> Array_Vector() { - return as -> new Vector(as.toCollection()); + return as -> new Vector<>(as.toCollection()); } /** @@ -323,7 +323,7 @@ public static F, Vector> Array_Vector() { * @return A function that converts arrays to array blocking queues. */ public static F, ArrayBlockingQueue> Array_ArrayBlockingQueue(final boolean fair) { - return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection()); + return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection()); } /** @@ -332,7 +332,7 @@ public static F, ArrayBlockingQueue> Array_ArrayBlockingQueue(fi * @return A function that converts arrays to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Array_ConcurrentLinkedQueue() { - return as -> new ConcurrentLinkedQueue(as.toCollection()); + return as -> new ConcurrentLinkedQueue<>(as.toCollection()); } /** @@ -341,7 +341,7 @@ public static F, ConcurrentLinkedQueue> Array_ConcurrentLinkedQu * @return A function that converts arrays to copy on write array lists. */ public static F, CopyOnWriteArrayList> Array_CopyOnWriteArrayList() { - return as -> new CopyOnWriteArrayList(as.toCollection()); + return as -> new CopyOnWriteArrayList<>(as.toCollection()); } /** @@ -350,7 +350,7 @@ public static F, CopyOnWriteArrayList> Array_CopyOnWriteArrayLis * @return A function that converts arrays to copy on write array sets. */ public static F, CopyOnWriteArraySet> Array_CopyOnWriteArraySet() { - return as -> new CopyOnWriteArraySet(as.toCollection()); + return as -> new CopyOnWriteArraySet<>(as.toCollection()); } /** @@ -359,7 +359,7 @@ public static F, CopyOnWriteArraySet> Array_CopyOnWriteArraySet( * @return A function that converts arrays to delay queues. */ public static F, DelayQueue> Array_DelayQueue() { - return as -> new DelayQueue(as.toCollection()); + return as -> new DelayQueue<>(as.toCollection()); } /** @@ -368,7 +368,7 @@ public static F, DelayQueue> Array_DelayQueue() * @return A function that converts arrays to linked blocking queues. */ public static F, LinkedBlockingQueue> Array_LinkedBlockingQueue() { - return as -> new LinkedBlockingQueue(as.toCollection()); + return as -> new LinkedBlockingQueue<>(as.toCollection()); } /** @@ -377,7 +377,7 @@ public static F, LinkedBlockingQueue> Array_LinkedBlockingQueue( * @return A function that converts arrays to priority blocking queues. */ public static F, PriorityBlockingQueue> Array_PriorityBlockingQueue() { - return as -> new PriorityBlockingQueue(as.toCollection()); + return as -> new PriorityBlockingQueue<>(as.toCollection()); } /** @@ -388,7 +388,7 @@ public static F, PriorityBlockingQueue> Array_PriorityBlockingQu */ public static F, SynchronousQueue> Array_SynchronousQueue(final boolean fair) { return as -> { - final SynchronousQueue q = new SynchronousQueue(fair); + final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(as.toCollection()); return q; }; @@ -433,7 +433,7 @@ public void remove() { * @return A function that converts streams to array lists. */ public static F, ArrayList> Stream_ArrayList() { - return as -> new ArrayList(as.toCollection()); + return as -> new ArrayList<>(as.toCollection()); } /** @@ -460,7 +460,7 @@ public static > F, EnumSet> Stream_EnumSet() { * @return A function that converts streams to hash sets. */ public static F, HashSet> Stream_HashSet() { - return as -> new HashSet(as.toCollection()); + return as -> new HashSet<>(as.toCollection()); } /** @@ -469,7 +469,7 @@ public static F, HashSet> Stream_HashSet() { * @return A function that converts streams to linked hash sets. */ public static F, LinkedHashSet> Stream_LinkedHashSet() { - return as -> new LinkedHashSet(as.toCollection()); + return as -> new LinkedHashSet<>(as.toCollection()); } /** @@ -478,7 +478,7 @@ public static F, LinkedHashSet> Stream_LinkedHashSet() { * @return A function that converts streams to linked lists. */ public static F, LinkedList> Stream_LinkedList() { - return as -> new LinkedList(as.toCollection()); + return as -> new LinkedList<>(as.toCollection()); } /** @@ -487,7 +487,7 @@ public static F, LinkedList> Stream_LinkedList() { * @return A function that converts streams to priority queues. */ public static F, PriorityQueue> Stream_PriorityQueue() { - return as -> new PriorityQueue(as.toCollection()); + return as -> new PriorityQueue<>(as.toCollection()); } /** @@ -497,7 +497,7 @@ public static F, PriorityQueue> Stream_PriorityQueue() { */ public static F, Stack> Stream_Stack() { return as -> { - final Stack s = new Stack(); + final Stack s = new Stack<>(); s.addAll(as.toCollection()); return s; }; @@ -509,7 +509,7 @@ public static F, Stack> Stream_Stack() { * @return A function that converts streams to tree sets. */ public static F, TreeSet> Stream_TreeSet() { - return as -> new TreeSet(as.toCollection()); + return as -> new TreeSet<>(as.toCollection()); } /** @@ -518,7 +518,7 @@ public static F, TreeSet> Stream_TreeSet() { * @return A function that converts streams to vectors. */ public static F, Vector> Stream_Vector() { - return as -> new Vector(as.toCollection()); + return as -> new Vector<>(as.toCollection()); } /** @@ -528,7 +528,7 @@ public static F, Vector> Stream_Vector() { * @return A function that converts streams to array blocking queues. */ public static F, ArrayBlockingQueue> Stream_ArrayBlockingQueue(final boolean fair) { - return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection()); + return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection()); } /** @@ -537,7 +537,7 @@ public static F, ArrayBlockingQueue> Stream_ArrayBlockingQueue( * @return A function that converts streams to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Stream_ConcurrentLinkedQueue() { - return as -> new ConcurrentLinkedQueue(as.toCollection()); + return as -> new ConcurrentLinkedQueue<>(as.toCollection()); } /** @@ -546,7 +546,7 @@ public static F, ConcurrentLinkedQueue> Stream_ConcurrentLinked * @return A function that converts streams to copy on write array lists. */ public static F, CopyOnWriteArrayList> Stream_CopyOnWriteArrayList() { - return as -> new CopyOnWriteArrayList(as.toCollection()); + return as -> new CopyOnWriteArrayList<>(as.toCollection()); } /** @@ -555,7 +555,7 @@ public static F, CopyOnWriteArrayList> Stream_CopyOnWriteArrayL * @return A function that converts streams to copy on write array sets. */ public static F, CopyOnWriteArraySet> Stream_CopyOnWriteArraySet() { - return as -> new CopyOnWriteArraySet(as.toCollection()); + return as -> new CopyOnWriteArraySet<>(as.toCollection()); } /** @@ -564,7 +564,7 @@ public static F, CopyOnWriteArraySet> Stream_CopyOnWriteArraySe * @return A function that converts streams to delay queues. */ public static F, DelayQueue> Stream_DelayQueue() { - return as -> new DelayQueue(as.toCollection()); + return as -> new DelayQueue<>(as.toCollection()); } /** @@ -573,7 +573,7 @@ public static F, DelayQueue> Stream_DelayQueue( * @return A function that converts streams to linked blocking queues. */ public static F, LinkedBlockingQueue> Stream_LinkedBlockingQueue() { - return as -> new LinkedBlockingQueue(as.toCollection()); + return as -> new LinkedBlockingQueue<>(as.toCollection()); } /** @@ -582,7 +582,7 @@ public static F, LinkedBlockingQueue> Stream_LinkedBlockingQueu * @return A function that converts streams to priority blocking queues. */ public static F, PriorityBlockingQueue> Stream_PriorityBlockingQueue() { - return as -> new PriorityBlockingQueue(as.toCollection()); + return as -> new PriorityBlockingQueue<>(as.toCollection()); } /** @@ -593,7 +593,7 @@ public static F, PriorityBlockingQueue> Stream_PriorityBlocking */ public static F, SynchronousQueue> Stream_SynchronousQueue(final boolean fair) { return as -> { - final SynchronousQueue q = new SynchronousQueue(fair); + final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(as.toCollection()); return q; }; @@ -609,7 +609,7 @@ public static F, SynchronousQueue> Stream_SynchronousQueue(fina * @return A function that converts options to array lists. */ public static F, ArrayList> Option_ArrayList() { - return as -> new ArrayList(as.toCollection()); + return as -> new ArrayList<>(as.toCollection()); } /** @@ -640,7 +640,7 @@ public static > F, EnumSet> Option_EnumSet() { * @return A function that converts options to hash sets. */ public static F, HashSet> Option_HashSet() { - return as -> new HashSet(as.toCollection()); + return as -> new HashSet<>(as.toCollection()); } /** @@ -649,7 +649,7 @@ public static F, HashSet> Option_HashSet() { * @return A function that converts options to linked hash sets. */ public static F, LinkedHashSet> Option_LinkedHashSet() { - return as -> new LinkedHashSet(as.toCollection()); + return as -> new LinkedHashSet<>(as.toCollection()); } /** @@ -658,7 +658,7 @@ public static F, LinkedHashSet> Option_LinkedHashSet() { * @return A function that converts options to linked lists. */ public static F, LinkedList> Option_LinkedList() { - return as -> new LinkedList(as.toCollection()); + return as -> new LinkedList<>(as.toCollection()); } /** @@ -667,7 +667,7 @@ public static F, LinkedList> Option_LinkedList() { * @return A function that converts options to priority queues. */ public static F, PriorityQueue> Option_PriorityQueue() { - return as -> new PriorityQueue(as.toCollection()); + return as -> new PriorityQueue<>(as.toCollection()); } /** @@ -677,7 +677,7 @@ public static F, PriorityQueue> Option_PriorityQueue() { */ public static F, Stack> Option_Stack() { return as -> { - final Stack s = new Stack(); + final Stack s = new Stack<>(); s.addAll(as.toCollection()); return s; }; @@ -689,7 +689,7 @@ public static F, Stack> Option_Stack() { * @return A function that converts options to tree sets. */ public static F, TreeSet> Option_TreeSet() { - return as -> new TreeSet(as.toCollection()); + return as -> new TreeSet<>(as.toCollection()); } /** @@ -698,7 +698,7 @@ public static F, TreeSet> Option_TreeSet() { * @return A function that converts options to vectors. */ public static F, Vector> Option_Vector() { - return as -> new Vector(as.toCollection()); + return as -> new Vector<>(as.toCollection()); } /** @@ -708,7 +708,7 @@ public static F, Vector> Option_Vector() { * @return A function that converts options to array blocking queues. */ public static F, ArrayBlockingQueue> Option_ArrayBlockingQueue(final boolean fair) { - return as -> new ArrayBlockingQueue(as.length(), fair, as.toCollection()); + return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection()); } /** @@ -717,7 +717,7 @@ public static F, ArrayBlockingQueue> Option_ArrayBlockingQueue( * @return A function that converts options to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Option_ConcurrentLinkedQueue() { - return as -> new ConcurrentLinkedQueue(as.toCollection()); + return as -> new ConcurrentLinkedQueue<>(as.toCollection()); } /** @@ -726,7 +726,7 @@ public static F, ConcurrentLinkedQueue> Option_ConcurrentLinked * @return A function that converts options to copy on write array lists. */ public static F, CopyOnWriteArrayList> Option_CopyOnWriteArrayList() { - return as -> new CopyOnWriteArrayList(as.toCollection()); + return as -> new CopyOnWriteArrayList<>(as.toCollection()); } /** @@ -735,7 +735,7 @@ public static F, CopyOnWriteArrayList> Option_CopyOnWriteArrayL * @return A function that converts options to copy on write array sets. */ public static F, CopyOnWriteArraySet> Option_CopyOnWriteArraySet() { - return as -> new CopyOnWriteArraySet(as.toCollection()); + return as -> new CopyOnWriteArraySet<>(as.toCollection()); } /** @@ -744,7 +744,7 @@ public static F, CopyOnWriteArraySet> Option_CopyOnWriteArraySe * @return A function that converts options to delay queues. */ public static F, DelayQueue> Option_DelayQueue() { - return as -> new DelayQueue(as.toCollection()); + return as -> new DelayQueue<>(as.toCollection()); } /** @@ -753,7 +753,7 @@ public static F, DelayQueue> Option_DelayQueue( * @return A function that converts options to linked blocking queues. */ public static F, LinkedBlockingQueue> Option_LinkedBlockingQueue() { - return as -> new LinkedBlockingQueue(as.toCollection()); + return as -> new LinkedBlockingQueue<>(as.toCollection()); } /** @@ -762,7 +762,7 @@ public static F, LinkedBlockingQueue> Option_LinkedBlockingQueu * @return A function that converts options to priority blocking queues. */ public static F, PriorityBlockingQueue> Option_PriorityBlockingQueue() { - return as -> new PriorityBlockingQueue(as.toCollection()); + return as -> new PriorityBlockingQueue<>(as.toCollection()); } /** @@ -773,7 +773,7 @@ public static F, PriorityBlockingQueue> Option_PriorityBlocking */ public static F, SynchronousQueue> Option_SynchronousQueue(final boolean fair) { return as -> { - final SynchronousQueue q = new SynchronousQueue(fair); + final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(as.toCollection()); return q; }; @@ -789,7 +789,7 @@ public static F, SynchronousQueue> Option_SynchronousQueue(fina * @return A function that converts eithers to array lists. */ public static F, ArrayList> Either_ArrayListA() { - return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionA()); } /** @@ -798,7 +798,7 @@ public static F, ArrayList> Either_ArrayListA() { * @return A function that converts eithers to array lists. */ public static F, ArrayList> Either_ArrayListB() { - return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_ArrayList(), Conversions.Either_OptionB()); } /** @@ -807,7 +807,7 @@ public static F, ArrayList> Either_ArrayListB() { * @return A function that converts eithers to bit sets. */ public static F, BitSet> Either_BitSetA() { - return Function.compose(Option_BitSet, Conversions.Either_OptionA()); + return Function.compose(Option_BitSet, Conversions.Either_OptionA()); } /** @@ -816,7 +816,7 @@ public static F, BitSet> Either_BitSetA() { * @return A function that converts eithers to bit sets. */ public static F, BitSet> Either_BitSetB() { - return Function.compose(Option_BitSet, Conversions.Either_OptionB()); + return Function.compose(Option_BitSet, Conversions.Either_OptionB()); } /** @@ -843,7 +843,7 @@ public static > F, EnumSet> Either_EnumSetB * @return A function that converts eithers to hash sets. */ public static F, HashSet> Either_HashSetA() { - return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionA()); } /** @@ -852,7 +852,7 @@ public static F, HashSet> Either_HashSetA() { * @return A function that converts eithers to hash sets. */ public static F, HashSet> Either_HashSetB() { - return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_HashSet(), Conversions.Either_OptionB()); } /** @@ -861,7 +861,7 @@ public static F, HashSet> Either_HashSetB() { * @return A function that converts eithers to linked hash sets. */ public static F, LinkedHashSet> Either_LinkedHashSetA() { - return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionA()); } /** @@ -870,7 +870,7 @@ public static F, LinkedHashSet> Either_LinkedHashSetA() { * @return A function that converts eithers to linked hash sets. */ public static F, LinkedHashSet> Either_LinkedHashSetB() { - return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_LinkedHashSet(), Conversions.Either_OptionB()); } /** @@ -879,7 +879,7 @@ public static F, LinkedHashSet> Either_LinkedHashSetB() { * @return A function that converts eithers to linked lists. */ public static F, LinkedList> Either_LinkedListA() { - return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionA()); } /** @@ -888,7 +888,7 @@ public static F, LinkedList> Either_LinkedListA() { * @return A function that eithers options to priority queues. */ public static F, PriorityQueue> Option_PriorityQueueA() { - return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionA()); } /** @@ -897,7 +897,7 @@ public static F, PriorityQueue> Option_PriorityQueueA() { * @return A function that eithers options to priority queues. */ public static F, PriorityQueue> Option_PriorityQueueB() { - return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_PriorityQueue(), Conversions.Either_OptionB()); } /** @@ -906,7 +906,7 @@ public static F, PriorityQueue> Option_PriorityQueueB() { * @return A function that converts eithers to linked lists. */ public static F, LinkedList> Either_LinkedListB() { - return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_LinkedList(), Conversions.Either_OptionB()); } /** @@ -915,7 +915,7 @@ public static F, LinkedList> Either_LinkedListB() { * @return A function that converts eithers to stacks. */ public static F, Stack> Either_StackA() { - return Function.compose(Java.Option_Stack(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_Stack(), Conversions.Either_OptionA()); } /** @@ -924,7 +924,7 @@ public static F, Stack> Either_StackA() { * @return A function that converts eithers to stacks. */ public static F, Stack> Either_StackB() { - return Function.compose(Java.Option_Stack(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_Stack(), Conversions.Either_OptionB()); } /** @@ -933,7 +933,7 @@ public static F, Stack> Either_StackB() { * @return A function that converts eithers to tree sets. */ public static F, TreeSet> Either_TreeSetA() { - return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionA()); } /** @@ -942,7 +942,7 @@ public static F, TreeSet> Either_TreeSetA() { * @return A function that converts eithers to tree sets. */ public static F, TreeSet> Either_TreeSetB() { - return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_TreeSet(), Conversions.Either_OptionB()); } /** @@ -951,7 +951,7 @@ public static F, TreeSet> Either_TreeSetB() { * @return A function that converts eithers to vectors. */ public static F, Vector> Either_VectorA() { - return Function.compose(Java.Option_Vector(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_Vector(), Conversions.Either_OptionA()); } /** @@ -960,7 +960,7 @@ public static F, Vector> Either_VectorA() { * @return A function that converts eithers to vectors. */ public static F, Vector> Either_VectorB() { - return Function.compose(Java.Option_Vector(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_Vector(), Conversions.Either_OptionB()); } /** @@ -970,7 +970,7 @@ public static F, Vector> Either_VectorB() { * @return A function that converts eithers to array blocking queues. */ public static F, ArrayBlockingQueue> Either_ArrayBlockingQueueA(final boolean fair) { - return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionA()); + return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionA()); } /** @@ -980,7 +980,7 @@ public static F, ArrayBlockingQueue> Either_ArrayBlocking * @return A function that converts eithers to array blocking queues. */ public static F, ArrayBlockingQueue> Either_ArrayBlockingQueueB(final boolean fair) { - return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionB()); + return Function.compose(Java.Option_ArrayBlockingQueue(fair), Conversions.Either_OptionB()); } /** @@ -989,7 +989,7 @@ public static F, ArrayBlockingQueue> Either_ArrayBlocking * @return A function that converts eithers to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Either_ConcurrentLinkedQueueA() { - return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionA()); } /** @@ -998,7 +998,7 @@ public static F, ConcurrentLinkedQueue> Either_Concurrent * @return A function that converts eithers to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Either_ConcurrentLinkedQueueB() { - return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_ConcurrentLinkedQueue(), Conversions.Either_OptionB()); } /** @@ -1007,7 +1007,7 @@ public static F, ConcurrentLinkedQueue> Either_Concurrent * @return A function that converts eithers to copy on write array lists. */ public static F, CopyOnWriteArrayList> Either_CopyOnWriteArrayListA() { - return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionA()); } /** @@ -1016,7 +1016,7 @@ public static F, CopyOnWriteArrayList> Either_CopyOnWrite * @return A function that converts eithers to copy on write array lists. */ public static F, CopyOnWriteArrayList> Either_CopyOnWriteArrayListB() { - return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_CopyOnWriteArrayList(), Conversions.Either_OptionB()); } /** @@ -1025,7 +1025,7 @@ public static F, CopyOnWriteArrayList> Either_CopyOnWrite * @return A function that converts eithers to copy on write array sets. */ public static F, CopyOnWriteArraySet> Either_CopyOnWriteArraySetA() { - return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionA()); } /** @@ -1034,7 +1034,7 @@ public static F, CopyOnWriteArraySet> Either_CopyOnWriteA * @return A function that converts eithers to copy on write array sets. */ public static F, CopyOnWriteArraySet> Either_CopyOnWriteArraySetB() { - return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_CopyOnWriteArraySet(), Conversions.Either_OptionB()); } /** @@ -1043,7 +1043,7 @@ public static F, CopyOnWriteArraySet> Either_CopyOnWriteA * @return A function that converts eithers to delay queues. */ public static F, DelayQueue> Either_DelayQueueA() { - return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionA()); } /** @@ -1052,7 +1052,7 @@ public static F, DelayQueue> Either_Delay * @return A function that converts eithers to delay queues. */ public static F, DelayQueue> Either_DelayQueueB() { - return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_DelayQueue(), Conversions.Either_OptionB()); } /** @@ -1061,7 +1061,7 @@ public static F, DelayQueue> Either_Delay * @return A function that converts eithers to linked blocking queues. */ public static F, LinkedBlockingQueue> Either_LinkedBlockingQueueA() { - return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionA()); } /** @@ -1070,7 +1070,7 @@ public static F, LinkedBlockingQueue> Either_LinkedBlocki * @return A function that converts eithers to linked blocking queues. */ public static F, LinkedBlockingQueue> Either_LinkedBlockingQueueB() { - return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_LinkedBlockingQueue(), Conversions.Either_OptionB()); } /** @@ -1079,7 +1079,7 @@ public static F, LinkedBlockingQueue> Either_LinkedBlocki * @return A function that converts eithers to priority blocking queues. */ public static F, PriorityBlockingQueue> Either_PriorityBlockingQueueA() { - return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionA()); + return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionA()); } /** @@ -1088,7 +1088,7 @@ public static F, PriorityBlockingQueue> Either_PriorityBl * @return A function that converts eithers to priority blocking queues. */ public static F, PriorityBlockingQueue> Either_PriorityBlockingQueueB() { - return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionB()); + return Function.compose(Java.Option_PriorityBlockingQueue(), Conversions.Either_OptionB()); } /** @@ -1098,7 +1098,7 @@ public static F, PriorityBlockingQueue> Either_PriorityBl * @return A function that converts eithers to synchronous queues. */ public static F, SynchronousQueue> Either_SynchronousQueueA(final boolean fair) { - return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionA()); + return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionA()); } /** @@ -1108,7 +1108,7 @@ public static F, SynchronousQueue> Either_SynchronousQueu * @return A function that converts eithers to synchronous queues. */ public static F, SynchronousQueue> Either_SynchronousQueueB(final boolean fair) { - return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionB()); + return Function.compose(Java.Option_SynchronousQueue(fair), Conversions.Either_OptionB()); } // END Either -> @@ -1119,49 +1119,49 @@ public static F, SynchronousQueue> Either_SynchronousQueu * A function that converts strings to array lists. */ public static final F> String_ArrayList = - Function.compose(Java.List_ArrayList(), Conversions.String_List); + Function.compose(Java.List_ArrayList(), Conversions.String_List); /** * A function that converts strings to hash sets. */ public static final F> String_HashSet = - Function.compose(Java.List_HashSet(), Conversions.String_List); + Function.compose(Java.List_HashSet(), Conversions.String_List); /** * A function that converts strings to linked hash sets. */ public static final F> String_LinkedHashSet = - Function.compose(Java.List_LinkedHashSet(), Conversions.String_List); + Function.compose(Java.List_LinkedHashSet(), Conversions.String_List); /** * A function that converts strings to linked lists. */ public static final F> String_LinkedList = - Function.compose(Java.List_LinkedList(), Conversions.String_List); + Function.compose(Java.List_LinkedList(), Conversions.String_List); /** * A function that converts strings to priority queues. */ public static final F> String_PriorityQueue = - Function.compose(Java.List_PriorityQueue(), Conversions.String_List); + Function.compose(Java.List_PriorityQueue(), Conversions.String_List); /** * A function that converts strings to stacks. */ public static final F> String_Stack = - Function.compose(Java.List_Stack(), Conversions.String_List); + Function.compose(Java.List_Stack(), Conversions.String_List); /** * A function that converts strings to tree sets. */ public static final F> String_TreeSet = - Function.compose(Java.List_TreeSet(), Conversions.String_List); + Function.compose(Java.List_TreeSet(), Conversions.String_List); /** * A function that converts strings to vectors. */ public static final F> String_Vector = - Function.compose(Java.List_Vector(), Conversions.String_List); + Function.compose(Java.List_Vector(), Conversions.String_List); /** * A function that converts strings to array blocking queues. @@ -1170,38 +1170,38 @@ public static F, SynchronousQueue> Either_SynchronousQueu * @return A function that converts strings to array blocking queues. */ public static F> String_ArrayBlockingQueue(final boolean fair) { - return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.String_List); + return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.String_List); } /** * A function that converts strings to concurrent linked queues. */ public static final F> String_ConcurrentLinkedQueue = - Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.String_List); + Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.String_List); /** * A function that converts strings to copy on write array lists. */ public static final F> String_CopyOnWriteArrayList = - Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.String_List); + Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.String_List); /** * A function that converts strings to copy on write array sets. */ public static final F> String_CopyOnWriteArraySet = - Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.String_List); + Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.String_List); /** * A function that converts strings to linked blocking queues. */ public static final F> String_LinkedBlockingQueue = - Function.compose(Java.List_LinkedBlockingQueue(), Conversions.String_List); + Function.compose(Java.List_LinkedBlockingQueue(), Conversions.String_List); /** * A function that converts strings to priority blocking queues. */ public static final F> String_PriorityBlockingQueue = - Function.compose(Java.List_PriorityBlockingQueue(), Conversions.String_List); + Function.compose(Java.List_PriorityBlockingQueue(), Conversions.String_List); /** * A function that converts strings to synchronous queues. @@ -1210,7 +1210,7 @@ public static F> String_ArrayBlockingQueue * @return A function that converts strings to synchronous queues. */ public static F> String_SynchronousQueue(final boolean fair) { - return Function.compose(Java.List_SynchronousQueue(fair), Conversions.String_List); + return Function.compose(Java.List_SynchronousQueue(fair), Conversions.String_List); } // END String -> @@ -1221,49 +1221,49 @@ public static F> String_SynchronousQueue(fin * A function that converts string buffers to array lists. */ public static final F> StringBuffer_ArrayList = - Function.compose(Java.List_ArrayList(), Conversions.StringBuffer_List); + Function.compose(Java.List_ArrayList(), Conversions.StringBuffer_List); /** * A function that converts string buffers to hash sets. */ public static final F> StringBuffer_HashSet = - Function.compose(Java.List_HashSet(), Conversions.StringBuffer_List); + Function.compose(Java.List_HashSet(), Conversions.StringBuffer_List); /** * A function that converts string buffers to linked hash sets. */ public static final F> StringBuffer_LinkedHashSet = - Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuffer_List); + Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuffer_List); /** * A function that converts string buffers to linked lists. */ public static final F> StringBuffer_LinkedList = - Function.compose(Java.List_LinkedList(), Conversions.StringBuffer_List); + Function.compose(Java.List_LinkedList(), Conversions.StringBuffer_List); /** * A function that converts string buffers to priority queues. */ public static final F> StringBuffer_PriorityQueue = - Function.compose(Java.List_PriorityQueue(), Conversions.StringBuffer_List); + Function.compose(Java.List_PriorityQueue(), Conversions.StringBuffer_List); /** * A function that converts string buffers to stacks. */ public static final F> StringBuffer_Stack = - Function.compose(Java.List_Stack(), Conversions.StringBuffer_List); + Function.compose(Java.List_Stack(), Conversions.StringBuffer_List); /** * A function that converts string buffers to tree sets. */ public static final F> StringBuffer_TreeSet = - Function.compose(Java.List_TreeSet(), Conversions.StringBuffer_List); + Function.compose(Java.List_TreeSet(), Conversions.StringBuffer_List); /** * A function that converts string buffers to vectors. */ public static final F> StringBuffer_Vector = - Function.compose(Java.List_Vector(), Conversions.StringBuffer_List); + Function.compose(Java.List_Vector(), Conversions.StringBuffer_List); /** * A function that converts string buffers to array blocking queues. @@ -1272,38 +1272,38 @@ public static F> String_SynchronousQueue(fin * @return A function that converts string buffers to array blocking queues. */ public static F> StringBuffer_ArrayBlockingQueue(final boolean fair) { - return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuffer_List); + return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuffer_List); } /** * A function that converts string buffers to concurrent linked queues. */ public static final F> StringBuffer_ConcurrentLinkedQueue = - Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuffer_List); + Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuffer_List); /** * A function that converts string buffers to copy on write array lists. */ public static final F> StringBuffer_CopyOnWriteArrayList = - Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuffer_List); + Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuffer_List); /** * A function that converts string buffers to copy on write array sets. */ public static final F> StringBuffer_CopyOnWriteArraySet = - Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuffer_List); + Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuffer_List); /** * A function that converts string buffers to linked blocking queues. */ public static final F> StringBuffer_LinkedBlockingQueue = - Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuffer_List); + Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuffer_List); /** * A function that converts string buffers to priority blocking queues. */ public static final F> StringBuffer_PriorityBlockingQueue = - Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuffer_List); + Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuffer_List); /** * A function that converts string buffers to synchronous queues. @@ -1312,7 +1312,7 @@ public static F> StringBuffer_ArrayB * @return A function that converts string buffers to synchronous queues. */ public static F> StringBuffer_SynchronousQueue(final boolean fair) { - return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuffer_List); + return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuffer_List); } // END StringBuffer -> @@ -1323,49 +1323,49 @@ public static F> StringBuffer_Synchron * A function that converts string builders to array lists. */ public static final F> StringBuilder_ArrayList = - Function.compose(Java.List_ArrayList(), Conversions.StringBuilder_List); + Function.compose(Java.List_ArrayList(), Conversions.StringBuilder_List); /** * A function that converts string builders to hash sets. */ public static final F> StringBuilder_HashSet = - Function.compose(Java.List_HashSet(), Conversions.StringBuilder_List); + Function.compose(Java.List_HashSet(), Conversions.StringBuilder_List); /** * A function that converts string builders to linked hash sets. */ public static final F> StringBuilder_LinkedHashSet = - Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuilder_List); + Function.compose(Java.List_LinkedHashSet(), Conversions.StringBuilder_List); /** * A function that converts string builders to linked lists. */ public static final F> StringBuilder_LinkedList = - Function.compose(Java.List_LinkedList(), Conversions.StringBuilder_List); + Function.compose(Java.List_LinkedList(), Conversions.StringBuilder_List); /** * A function that converts string builders to priority queues. */ public static final F> StringBuilder_PriorityQueue = - Function.compose(Java.List_PriorityQueue(), Conversions.StringBuilder_List); + Function.compose(Java.List_PriorityQueue(), Conversions.StringBuilder_List); /** * A function that converts string builders to stacks. */ public static final F> StringBuilder_Stack = - Function.compose(Java.List_Stack(), Conversions.StringBuilder_List); + Function.compose(Java.List_Stack(), Conversions.StringBuilder_List); /** * A function that converts string builders to tree sets. */ public static final F> StringBuilder_TreeSet = - Function.compose(Java.List_TreeSet(), Conversions.StringBuilder_List); + Function.compose(Java.List_TreeSet(), Conversions.StringBuilder_List); /** * A function that converts string builders to vectors. */ public static final F> StringBuilder_Vector = - Function.compose(Java.List_Vector(), Conversions.StringBuilder_List); + Function.compose(Java.List_Vector(), Conversions.StringBuilder_List); /** * A function that converts string builders to array blocking queues. @@ -1374,38 +1374,38 @@ public static F> StringBuffer_Synchron * @return A function that converts string builders to array blocking queues. */ public static F> StringBuilder_ArrayBlockingQueue(final boolean fair) { - return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuilder_List); + return Function.compose(Java.List_ArrayBlockingQueue(fair), Conversions.StringBuilder_List); } /** * A function that converts string builders to concurrent linked queues. */ public static final F> StringBuilder_ConcurrentLinkedQueue = - Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuilder_List); + Function.compose(Java.List_ConcurrentLinkedQueue(), Conversions.StringBuilder_List); /** * A function that converts string builders to copy on write array lists. */ public static final F> StringBuilder_CopyOnWriteArrayList = - Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuilder_List); + Function.compose(Java.List_CopyOnWriteArrayList(), Conversions.StringBuilder_List); /** * A function that converts string builders to copy on write array sets. */ public static final F> StringBuilder_CopyOnWriteArraySet = - Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuilder_List); + Function.compose(Java.List_CopyOnWriteArraySet(), Conversions.StringBuilder_List); /** * A function that converts string builders to linked blocking queues. */ public static final F> StringBuilder_LinkedBlockingQueue = - Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuilder_List); + Function.compose(Java.List_LinkedBlockingQueue(), Conversions.StringBuilder_List); /** * A function that converts string builders to priority blocking queues. */ public static final F> StringBuilder_PriorityBlockingQueue = - Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuilder_List); + Function.compose(Java.List_PriorityBlockingQueue(), Conversions.StringBuilder_List); /** * A function that converts string builders to synchronous queues. @@ -1414,7 +1414,7 @@ public static F> StringBuilder_Arra * @return A function that converts string builders to synchronous queues. */ public static F> StringBuilder_SynchronousQueue(final boolean fair) { - return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuilder_List); + return Function.compose(Java.List_SynchronousQueue(fair), Conversions.StringBuilder_List); } // END StringBuffer -> @@ -1458,7 +1458,7 @@ public static List JavaList_List(java.util.List list) { * A function that converts bit sets to lists. */ public static final F> BitSet_List = s -> List.unfold(i -> i == s.length() ? - Option.>none() : + Option.none() : some(p(s.get(i), i + 1)), 0); // todo @@ -1481,7 +1481,7 @@ public static List Collection_List(Collection c) { } public static F, List> Collection_List() { - return c -> List.list(c.toArray(array(c.size()))); + return c -> List.list(c.toArray(array(c.size()))); } @SafeVarargs diff --git a/core/src/main/java/fj/data/LazyString.java b/core/src/main/java/fj/data/LazyString.java index 2583621f..3e393cf8 100644 --- a/core/src/main/java/fj/data/LazyString.java +++ b/core/src/main/java/fj/data/LazyString.java @@ -256,7 +256,7 @@ public boolean matches(final String regex) { public Stream split(final F p) { final Stream findIt = s.dropWhile(p); final P2, Stream> ws = findIt.split(p); - return findIt.isEmpty() ? Stream.nil() + return findIt.isEmpty() ? Stream.nil() : Stream.cons(fromStream(ws._1()), () -> fromStream(ws._2()).split(p)); } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 5a2e2504..399cc016 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -167,7 +167,7 @@ public final Option toOption() { * @return The optional head of the list. */ public Option headOption() { - return isEmpty() ? Option.none() : some(head()); + return isEmpty() ? Option.none() : some(head()); } /** @@ -178,7 +178,7 @@ public Option headOption() { * @return An either projection of this list. */ public final Either toEither(final F0 x) { - return isEmpty() ? Either.left(x.f()) : Either.right(head()); + return isEmpty() ? Either.left(x.f()) : Either.right(head()); } /** @@ -258,7 +258,7 @@ public final A[] array(final Class c) { * @return A new list with the given element at the head. */ public final List cons(final A a) { - return new Cons(a, this); + return new Cons<>(a, this); } /** @@ -269,7 +269,7 @@ public final List cons(final A a) { * @return A new list with the given element at the head. */ public final List conss(final A a) { - return new Cons(a, this); + return new Cons<>(a, this); } /** @@ -412,7 +412,7 @@ public final P2, List> span(final F p) { else return p(b.toList(), xs); } - return p(b.toList(), List.nil()); + return p(b.toList(), List.nil()); } /** @@ -614,7 +614,7 @@ public final List sequence(final List bs) { public Option> traverseOption(final F> f) { return foldRight( (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))), - some(List.nil()) + some(List.nil()) ); } @@ -627,67 +627,67 @@ public Option> traverseOption(final F> f) { public Either> traverseEither(final F> f) { return foldRight( (a, acc) -> f.f(a).right().bind(e -> acc.right().map(es -> es.cons(e))), - Either.>right(List.nil()) + Either.right(List.nil()) ); } public Stream> traverseStream(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(s -> acc.map(ss -> ss.cons(s))), - Stream.>nil() + Stream.nil() ); } public P1> traverseP1(final F> f){ return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - p(List.nil()) + p(List.nil()) ); } public IO> traverseIO(F> f) { return this.foldRight( (a, acc) -> IOFunctions.bind(f.f(a), b -> IOFunctions.map(acc, bs -> bs.cons(b))), - IOFunctions.unit(List.nil()) + IOFunctions.unit(List.nil()) ); } public F> traverseF(F> f) { return this.foldRight( (a, acc) -> Function.bind(acc, - (bs) -> Function.> compose(bs::cons, f.f(a))), - constant(List. nil()) + (bs) -> Function.compose(bs::cons, f.f(a))), + constant(List.nil()) ); } public Trampoline> traverseTrampoline(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - Trampoline.pure(List. nil())); + Trampoline.pure(List.nil())); } public Promise> traversePromise(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.fmap(bs -> bs.cons(b))), - Promise.promise(Strategy.idStrategy(), p(List. nil()))); + Promise.promise(Strategy.idStrategy(), p(List.nil()))); } public List> traverseList(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - single(List. nil())); + single(List.nil())); } public Validation> traverseValidation(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - Validation.success(List. nil())); + Validation.success(List.nil())); } public V2> traverseV2(final F> f) { return foldRight( (a, acc) -> acc.apply(f.f(a)., List>> map(e -> es -> es.cons(e))), - v(List. nil(), List. nil())); + v(List.nil(), List.nil())); } /** @@ -800,7 +800,7 @@ public final A foldLeft1(final F> f) { * @return A new list that is the reverse of this one. */ public final List reverse() { - return foldLeft(as -> a -> cons(a, as), List.nil()); + return foldLeft(as -> a -> cons(a, as), List.nil()); } /** @@ -865,7 +865,7 @@ public final List drop(final int i) { */ public final P2, List> splitAt(final int i) { int c = 0; - List first = List.nil(); + List first = List.nil(); List second = nil(); for (List xs = this; xs.isNotEmpty(); xs = xs.tail()) { final A h = xs.head(); @@ -891,7 +891,7 @@ public final List> partition(final int n) { throw error("Can't create list partitions shorter than 1 element long."); if (isEmpty()) throw error("Partition on empty list."); - return unfold(as -> as.isEmpty() ? Option., List>>none() : some(as.splitAt(n)), this); + return unfold(as -> as.isEmpty() ? Option.none() : some(as.splitAt(n)), this); } /** @@ -916,7 +916,7 @@ public P2, List> partition(F f) { * @return The list of initial segments of this list, shortest first. */ public final List> inits() { - List> s = single(List.nil()); + List> s = single(List.nil()); if (isNotEmpty()) s = s.append(tail().inits().map(List.cons().f(head()))); return s; @@ -928,7 +928,7 @@ public final List> inits() { * @return The list of final segments of this list, longest first. */ public final List> tails() { - return isEmpty() ? single(List.nil()) : cons(this, tail().tails()); + return isEmpty() ? single(List.nil()) : cons(this, tail().tails()); } /** @@ -1133,7 +1133,7 @@ public final List intercalate(final List> as) { * @return A list without duplicates according to object equality. */ public final List nub() { - return nub(Equal.anyEqual()); + return nub(Equal.anyEqual()); } /** @@ -1154,7 +1154,7 @@ public final List nub(final Equal eq) { */ @SuppressWarnings("unchecked") public final List nub(final Ord o) { - return sort(o).group(o.equal()).map(List.head_()); + return sort(o).group(o.equal()).map(List.head_()); } @@ -1227,7 +1227,7 @@ public final Option> mapMOption(final F> f) { * @return A list of values in the Trampoline monad. */ public final Trampoline> mapMTrampoline(final F> f) { - return foldRight((a, bs) -> f.f(a).bind(b -> bs.map(bbs -> bbs.cons(b))), Trampoline.>pure(List.nil())); + return foldRight((a, bs) -> f.f(a).bind(b -> bs.map(bbs -> bbs.cons(b))), Trampoline.pure(List.nil())); } /** @@ -1296,7 +1296,7 @@ public final List insertBy(final F> f, final A x) { * @return The most common element in this list. */ public final A mode(final Ord o) { - return sort(o).group(o.equal()).maximum(intOrd.contramap(List.length_())).head(); + return sort(o).group(o.equal()).maximum(intOrd.contramap(List.length_())).head(); } /** @@ -1350,7 +1350,7 @@ public final TreeMap> groupBy( final F keyFunction, final F valueFunction, final Ord keyOrd) { - return this.>groupBy(keyFunction, valueFunction, List.nil(), List::cons, keyOrd); + return this.groupBy(keyFunction, valueFunction, List.nil(), List::cons, keyOrd); } /** @@ -1398,7 +1398,7 @@ public final TreeMap groupBy( return map.set(key, map.get(key) .map(existing -> groupingAcc.f(value, existing)) .orSome(groupingAcc.f(value, groupingIdentity))); - }, TreeMap.empty(keyOrd) + }, TreeMap.empty(keyOrd) ); } @@ -1470,7 +1470,7 @@ public final A minimum(final Ord o) { } public final java.util.List toJavaList() { - return new java.util.LinkedList(toCollection()); + return new java.util.LinkedList<>(toCollection()); } /** @@ -1511,7 +1511,7 @@ public int size() { } private static final class Nil extends List { - public static final Nil INSTANCE = new Nil(); + public static final Nil INSTANCE = new Nil<>(); public A head() { throw error("head on empty list"); @@ -1638,7 +1638,7 @@ public static F, List> cons_(final A a) { * @return The list with the given element prepended. */ public static List cons(final A head, final List tail) { - return new Cons(head, tail); + return new Cons<>(head, tail); } /** @@ -1798,7 +1798,7 @@ public static F, String> asString() { * @return A list of one element containing the given value. */ public static List single(final A a) { - return cons(a, List.nil()); + return cons(a, List.nil()); } /** @@ -1826,7 +1826,7 @@ public static List iterateWhile(final F f, final F p, f * @return An associated value with the given key in the list of pairs. */ public static Option lookup(final Equal e, final List> x, final A a) { - return x.find(p -> e.eq(p._1(), a)).map(P2.__2()); + return x.find(p -> e.eq(p._1(), a)).map(P2.__2()); } /** @@ -1865,8 +1865,8 @@ public static F, F, List>> map_() { * and returns a list of the results. */ public static F> sequence_(final List> fs) { - return fs.foldRight(Function., List, B>lift(List.cons()), Function - .>constant(List.nil())); + return fs.foldRight(Function.lift(List.cons()), Function + .constant(List.nil())); } /** @@ -1936,7 +1936,7 @@ public Buffer snoc(final A a) { if (exported) copy(); - final Cons t = new Cons(a, List.nil()); + final Cons t = new Cons<>(a, List.nil()); if (tail == null) start = t; @@ -2009,7 +2009,7 @@ public Collection toCollection() { * @return An empty buffer. */ public static Buffer empty() { - return new Buffer(); + return new Buffer<>(); } /** @@ -2019,7 +2019,7 @@ public static Buffer empty() { * @return A buffer from the given list. */ public static Buffer fromList(final List as) { - final Buffer b = new Buffer(); + final Buffer b = new Buffer<>(); for (List xs = as; xs.isNotEmpty(); xs = xs.tail()) b.snoc(xs.head()); @@ -2067,7 +2067,7 @@ private void copy() { * @return true if this list is equal to the provided argument */ @Override public boolean equals( final Object obj ) { - return Equal.equals0(List.class, this, obj, () -> Equal.listEqual(Equal.anyEqual())); + return Equal.equals0(List.class, this, obj, () -> Equal.listEqual(Equal.anyEqual())); } /** diff --git a/core/src/main/java/fj/data/Natural.java b/core/src/main/java/fj/data/Natural.java index 1779d8c7..23080a49 100644 --- a/core/src/main/java/fj/data/Natural.java +++ b/core/src/main/java/fj/data/Natural.java @@ -32,7 +32,7 @@ private Natural(final BigInteger i) { */ public static Option natural(final BigInteger i) { return i.compareTo(BigInteger.ZERO) < 0 - ? Option.none() + ? Option.none() : Option.some(new Natural(i)); } diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index c8dd4cca..013b287c 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -79,7 +79,7 @@ public NonEmptyList snoc(final A a) { * @return A new list with the given list appended. */ public NonEmptyList append(final NonEmptyList as) { - final List.Buffer b = new List.Buffer(); + final List.Buffer b = new List.Buffer<>(); b.append(tail); b.snoc(as.head); b.append(as.tail); @@ -104,7 +104,7 @@ public NonEmptyList map(final F f) { * @return A new list after performing the map, then final join. */ public NonEmptyList bind(final F> f) { - final List.Buffer b = new List.Buffer(); + final List.Buffer b = new List.Buffer<>(); final NonEmptyList p = f.f(head); b.snoc(p.head); b.append(p.tail); @@ -125,7 +125,7 @@ public NonEmptyList bind(final F> f) { public NonEmptyList> sublists() { return fromList( somes(toList().toStream().substreams() - .map(F1Functions.o(NonEmptyList::fromList, Conversions.Stream_List())).toList())).some(); + .map(F1Functions.o(NonEmptyList::fromList, Conversions.Stream_List())).toList())).some(); } /** @@ -277,7 +277,7 @@ public static F, List> toList_() { * @return A non-empty list with the given head and tail. */ public static NonEmptyList nel(final A head, final List tail) { - return new NonEmptyList(head, tail); + return new NonEmptyList<>(head, tail); } /** @@ -308,7 +308,7 @@ public static F> nel() { */ public static Option> fromList(final List as) { return as.isEmpty() ? - Option.>none() : + Option.none() : some(nel(as.head(), as.tail())); } @@ -328,7 +328,7 @@ public static Option> fromList(final List as) { * @return true if this list is equal to the provided argument */ @Override public boolean equals( final Object obj ) { - return Equal.equals0(NonEmptyList.class, this, obj, () -> Equal.nonEmptyListEqual(Equal.anyEqual())); + return Equal.equals0(NonEmptyList.class, this, obj, () -> Equal.nonEmptyListEqual(Equal.anyEqual())); } @Override public int hashCode() { diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 5c8dca74..1ec77980 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -191,7 +191,7 @@ public final A valueE(final String message) { * @return A new optional value after the given function has been applied to its element. */ public final Option map(final F f) { - return isSome() ? some(f.f(some())) : Option.none(); + return isSome() ? some(f.f(some())) : Option.none(); } /** @@ -231,7 +231,7 @@ public final void foreachDoEffect(final Effect1 f) { * @return A new optional value whose value matches the given predicate if it has one. */ public final Option filter(final F f) { - return isSome() ? f.f(some()) ? this : Option.none() : Option.none(); + return isSome() ? f.f(some()) ? this : Option.none() : Option.none(); } /** @@ -241,7 +241,7 @@ public final Option filter(final F f) { * @return A new optional value after performing the map, then final join. */ public final Option bind(final F> f) { - return isSome() ? f.f(some()) : Option.none(); + return isSome() ? f.f(some()) : Option.none(); } /** @@ -366,38 +366,38 @@ public final Option bind(final Option ob, final Option oc, } public final Option> bindProduct(final Option ob) { - return bind(ob, P.p2()); + return bind(ob, P.p2()); } public final Option> bindProduct(final Option ob, final Option oc) { - return bind(ob, oc, P.p3()); + return bind(ob, oc, P.p3()); } public final Option> bindProduct(final Option ob, final Option oc, final Option od) { - return bind(ob, oc, od, P.p4()); + return bind(ob, oc, od, P.p4()); } public final Option> bindProduct(final Option ob, final Option oc, final Option od, final Option oe) { - return bind(ob, oc, od, oe, P.p5()); + return bind(ob, oc, od, oe, P.p5()); } public final Option> bindProduct(final Option ob, final Option oc, final Option od, final Option oe, final Option of) { - return bind(ob, oc, od, oe, of, P.p6()); + return bind(ob, oc, od, oe, of, P.p6()); } public final Option> bindProduct(final Option ob, final Option oc, final Option od, final Option oe, final Option of, final Option og) { - return bind(ob, oc, od, oe, of, og, P.p7()); + return bind(ob, oc, od, oe, of, og, P.p7()); } public final Option> bindProduct(final Option ob, final Option oc, final Option od, final Option oe, final Option of, final Option og, final Option oh) { - return bind(ob, oc, od, oe, of, og, oh, P.p8()); + return bind(ob, oc, od, oe, of, og, oh, P.p8()); } /** @@ -491,7 +491,7 @@ public final Option orElse(final Option o) { * @return An either projection of this optional value. */ public final Either toEither(final F0 x) { - return isSome() ? Either.right(some()) : Either.left(x.f()); + return isSome() ? Either.right(some()) : Either.left(x.f()); } /** @@ -502,7 +502,7 @@ public final Either toEither(final F0 x) { * @return An either projection of this optional value. */ public final Either toEither(final X x) { - return isSome() ? Either.right(some()) : Either.left(x); + return isSome() ? Either.right(some()) : Either.left(x); } public final Validation toValidation(final X x) { @@ -525,7 +525,7 @@ public static F, F>> toEither() { * @return A list projection of this optional value. */ public final List toList() { - return isSome() ? cons(some(), List.nil()) : List.nil(); + return isSome() ? cons(some(), List.nil()) : List.nil(); } /** @@ -534,7 +534,7 @@ public final List toList() { * @return A stream projection of this optional value. */ public final Stream toStream() { - return isSome() ? Stream.nil().cons(some()) : Stream.nil(); + return isSome() ? Stream.nil().cons(some()) : Stream.nil(); } /** @@ -544,7 +544,7 @@ public final Stream toStream() { */ @SuppressWarnings("unchecked") public final Array toArray() { - return isSome() ? Array.array(some()) : Array.empty(); + return isSome() ? Array.array(some()) : Array.empty(); } /** @@ -609,7 +609,7 @@ public final boolean exists(final F f) { @Override public boolean equals(Object other) { - return Equal.equals0(Option.class, this, other, () -> Equal.optionEqual(Equal.anyEqual())); + return Equal.equals0(Option.class, this, other, () -> Equal.optionEqual(Equal.anyEqual())); } /** @@ -651,7 +651,7 @@ public static F> some_() { * @return An optional value that has a value of the given argument. */ public static Option some(final T t) { - return new Some(t); + return new Some<>(t); } public static F> none_() { @@ -664,7 +664,7 @@ public static F> none_() { * @return An optional value that has no value. */ public static Option none() { - return new None(); + return new None<>(); } /** @@ -675,7 +675,7 @@ public static Option none() { * @return If t == null then return none, otherwise, return it in some. */ public static Option fromNull(final T t) { - return t == null ? Option.none() : some(t); + return t == null ? Option.none() : some(t); } /** @@ -707,7 +707,7 @@ public static Option join(final Option> o) { */ public static Option> sequence(final List> a) { return a.isEmpty() ? - some(List.nil()) : + some(List.nil()) : a.head().bind(aa -> sequence(a.tail()).map(cons_(aa))); } @@ -722,7 +722,7 @@ public static Option> sequence(final List> a) { * on that argument, otherwise, returns no value. */ public static Option iif(final F f, final A a) { - return f.f(a) ? some(a) : Option.none(); + return f.f(a) ? some(a) : Option.none(); } /** @@ -735,7 +735,7 @@ public static Option iif(final F f, final A a) { * no value. */ public static Option iif(final boolean p, final F0 a) { - return p ? some(a.f()) : Option.none(); + return p ? some(a.f()) : Option.none(); } /** @@ -768,7 +768,7 @@ public static F2, A, Option> iif() { * @return All the values in the given list. */ public static List somes(final List> as) { - return as.filter(Option.isSome_()).map(o -> o.some()); + return as.filter(Option.isSome_()).map(o -> o.some()); } @@ -779,7 +779,7 @@ public static List somes(final List> as) { * @return All the values in the given stream. */ public static Stream somes(final Stream> as) { - return as.filter(Option.isSome_()).map(o -> o.some()); + return as.filter(Option.isSome_()).map(o -> o.some()); } /** diff --git a/core/src/main/java/fj/data/Reader.java b/core/src/main/java/fj/data/Reader.java index 749f4c9b..042db624 100644 --- a/core/src/main/java/fj/data/Reader.java +++ b/core/src/main/java/fj/data/Reader.java @@ -20,7 +20,7 @@ public F getFunction() { } public static Reader unit(F f) { - return new Reader(f); + return new Reader<>(f); } public static Reader constant(B b) { diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index 84b26d6e..c6eb98be 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -22,7 +22,7 @@ public final class Seq implements Iterable { private static final Measured ELEM_MEASURED = measured(intAdditionMonoid, Function.constant(1)); private static final MakeTree MK_TREE = FingerTree.mkTree(ELEM_MEASURED); - private static final Seq EMPTY = new Seq(MK_TREE.empty()); + private static final Seq EMPTY = new Seq<>(MK_TREE.empty()); @SuppressWarnings("unchecked") private static MakeTree mkTree() { @@ -52,7 +52,7 @@ public static Seq empty() { @Override public boolean equals(Object other) { - return Equal.equals0(Seq.class, this, other, () -> Equal.seqEqual(Equal.anyEqual())); + return Equal.equals0(Seq.class, this, other, () -> Equal.seqEqual(Equal.anyEqual())); } /** @@ -62,7 +62,7 @@ public boolean equals(Object other) { * @return A new sequence with the given element in it. */ public static Seq single(final A a) { - return new Seq(Seq.mkTree().single(a)); + return new Seq<>(Seq.mkTree().single(a)); } /** @@ -146,7 +146,7 @@ public static Seq fromJavaList(final java.util.List list) { * @return A new sequence with the given element at the front. */ public Seq cons(final A a) { - return new Seq(ftree.cons(a)); + return new Seq<>(ftree.cons(a)); } /** @@ -156,7 +156,7 @@ public Seq cons(final A a) { * @return A new sequence with the given element at the end. */ public Seq snoc(final A a) { - return new Seq(ftree.snoc(a)); + return new Seq<>(ftree.snoc(a)); } /** @@ -263,7 +263,7 @@ public String toString() { * @return A new sequence with the given sequence appended to this one. */ public Seq append(final Seq as) { - return new Seq(ftree.append(as.ftree)); + return new Seq<>(ftree.append(as.ftree)); } /** @@ -312,7 +312,7 @@ public P2, Seq> split(final int i) { */ public A index(final int i) { checkBounds(i); - return ftree.lookup(Function.identity(), i)._2(); + return ftree.lookup(Function.identity(), i)._2(); } /** @@ -376,7 +376,7 @@ public int hashCode() { } public Seq map(F f) { - return new Seq(ftree.map(f, Seq.elemMeasured())); + return new Seq<>(ftree.map(f, Seq.elemMeasured())); } } diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 4dcd10de..5bb902d6 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -115,20 +115,20 @@ public Set r() { public final P2> update(final A a, final F f) { return isEmpty() ? P.p(false, this) - : tryUpdate(a, f).either(a2 -> P.p(true, delete(a).insert(a2)), Function.>>identity()); + : tryUpdate(a, f).either(a2 -> P.p(true, delete(a).insert(a2)), Function.identity()); } private Either>> tryUpdate(final A a, final F f) { if (isEmpty()) return right(P.p(false, this)); else if (ord.isLessThan(a, head())) - return l().tryUpdate(a, f).right().map(set -> set._1() ? P.p(true, (Set) new Tree(ord, color(), set._2(), head(), r())) : set); + return l().tryUpdate(a, f).right().map(set -> set._1() ? P.p(true, (Set) new Tree<>(ord, color(), set._2(), head(), r())) : set); else if (ord.eq(a, head())) { final A h = f.f(head()); return ord.eq(head(), h) ? Either - .>>right(P.p(true, (Set) new Tree(ord, color(), l(), h, r()))) - : Either.>>left(h); - } else return r().tryUpdate(a, f).right().map(set -> set._1() ? P.p(true, (Set) new Tree(ord, color(), l(), head(), set._2())) : set); + .right(P.p(true, (Set) new Tree<>(ord, color(), l(), h, r()))) + : Either.left(h); + } else return r().tryUpdate(a, f).right().map(set -> set._1() ? P.p(true, (Set) new Tree<>(ord, color(), l(), head(), set._2())) : set); } /** @@ -138,12 +138,12 @@ else if (ord.eq(a, head())) { * @return the empty set. */ public static Set empty(final Ord ord) { - return new Empty(ord); + return new Empty<>(ord); } @Override public boolean equals(Object other) { - return Equal.equals0(Set.class, this, other, () -> Equal.setEqual(Equal.anyEqual())); + return Equal.equals0(Set.class, this, other, () -> Equal.setEqual(Equal.anyEqual())); } @Override @@ -197,16 +197,16 @@ public static F, Set>> insert() { private Set ins(final A x) { return isEmpty() - ? new Tree(ord, Color.R, empty(ord), x, empty(ord)) + ? new Tree<>(ord, Color.R, empty(ord), x, empty(ord)) : ord.isLessThan(x, head()) ? balance(ord, color(), l().ins(x), head(), r()) : ord.eq(x, head()) - ? new Tree(ord, color(), l(), x, r()) + ? new Tree<>(ord, color(), l(), x, r()) : balance(ord, color(), l(), head(), r().ins(x)); } private Set makeBlack() { - return new Tree(ord, Color.B, l(), head(), r()); + return new Tree<>(ord, Color.B, l(), head(), r()); } @SuppressWarnings("SuspiciousNameCombination") @@ -214,11 +214,11 @@ private static Tree tr(final Ord o, final Set a, final A x, final Set b, final A y, final Set c, final A z, final Set d) { - return new Tree(o, Color.R, new Tree(o, Color.B, a, x, b), y, new Tree(o, Color.B, c, z, d)); + return new Tree<>(o, Color.R, new Tree<>(o, Color.B, a, x, b), y, new Tree<>(o, Color.B, c, z, d)); } private static Set balance(final Ord ord, final Color c, final Set l, final A h, final Set r) { - return c == Color.B && l.isTR() && l.l().isTR() ? tr(ord, l.l().l(), l.l().head(), l.l().r(), l.head(), l.r(), h, r) : c == Color.B && l.isTR() && l.r().isTR() ? tr(ord, l.l(), l.head(), l.r().l(), l.r().head(), l.r().r(), h, r) : c == Color.B && r.isTR() && r.l().isTR() ? tr(ord, l, h, r.l().l(), r.l().head(), r.l().r(), r.head(), r.r()) : c == Color.B && r.isTR() && r.r().isTR() ? tr(ord, l, h, r.l(), r.head(), r.r().l(), r.r().head(), r.r().r()) : new Tree(ord, c, l, h, r); + return c == Color.B && l.isTR() && l.l().isTR() ? tr(ord, l.l().l(), l.l().head(), l.l().r(), l.head(), l.r(), h, r) : c == Color.B && l.isTR() && l.r().isTR() ? tr(ord, l.l(), l.head(), l.r().l(), l.r().head(), l.r().r(), h, r) : c == Color.B && r.isTR() && r.l().isTR() ? tr(ord, l, h, r.l().l(), r.l().head(), r.l().r(), r.head(), r.r()) : c == Color.B && r.isTR() && r.r().isTR() ? tr(ord, l, h, r.l(), r.head(), r.r().l(), r.r().head(), r.r().r()) : new Tree<>(ord, c, l, h, r); } private boolean isTR() { @@ -288,7 +288,7 @@ public final B foldMapRight(final F f, final Monoid m) { * @return a list representation of this set. */ public final List toList() { - return foldMap(List.cons(List.nil()), Monoid.listMonoid()); + return foldMap(List.cons(List.nil()), Monoid.listMonoid()); } /** @@ -306,7 +306,7 @@ public final java.util.Set toJavaSet() { * @return a java.util.HashSet representation of this set. */ public final java.util.HashSet toJavaHashSet() { - return new java.util.HashSet(toStream().toCollection()); + return new java.util.HashSet<>(toStream().toCollection()); } /** @@ -315,7 +315,7 @@ public final java.util.HashSet toJavaHashSet() { * @return a java.util.TreeSet representation of this set. */ public final java.util.TreeSet toJavaTreeSet() { - return new java.util.TreeSet(toStream().toCollection()); + return new java.util.TreeSet<>(toStream().toCollection()); } /** @@ -324,7 +324,7 @@ public final java.util.TreeSet toJavaTreeSet() { * @return a java.util.List representation of this set. */ public final java.util.List toJavaList() { - return new java.util.ArrayList(toStream().toCollection()); + return new java.util.ArrayList<>(toStream().toCollection()); } /** @@ -333,7 +333,7 @@ public final java.util.List toJavaList() { * @return a list representation of this set in reverse order. */ public final List toListReverse() { - return foldMapRight(List.cons(List.nil()), Monoid.listMonoid()); + return foldMapRight(List.cons(List.nil()), Monoid.listMonoid()); } /** @@ -500,7 +500,7 @@ public final int size() { */ public final P3, Option, Set> split(final A a) { if (isEmpty()) - return P.p(empty(ord), Option.none(), empty(ord)); + return P.p(empty(ord), Option.none(), empty(ord)); else { final A h = head(); final Ordering i = ord.compare(a, h); @@ -539,7 +539,7 @@ public final boolean subsetOf(final Set s) { */ public static Set join(final Ord o, final Set> s) { final F, Set> id = identity(); - return s.foldMap(id, Monoid.setMonoid(o)); + return s.foldMap(id, Monoid.setMonoid(o)); } /** diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 47703e7b..e0724373 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -20,7 +20,7 @@ public P2 run(S s) { } public static State unit(F> f) { - return new State(f); + return new State<>(f); } public static State units(F f) { @@ -102,7 +102,7 @@ public static State gets(F f) { public static State> sequence(List> list) { return list.foldLeft((State> acc, State ma) -> acc.flatMap((List xs) -> ma.map(xs::snoc) - ), constant(List.nil())); + ), constant(List.nil())); } /** @@ -112,7 +112,7 @@ public static State> sequence(List> list) { public static State> traverse(List list, F> f) { return list.foldLeft((State> acc, A a) -> acc.flatMap(bs -> f.f(a).map(bs::snoc) - ), constant(List.nil())); + ), constant(List.nil())); } } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 8e04e499..4abde573 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -145,7 +145,7 @@ public final B foldRight(final F2, B> f, final B b) { * @return The final result after the right-fold reduction. */ public final B foldRight1(final F> f, final B b) { - return foldRight(compose(Function., B, B>andThen().f(P1.__1()), f), b); + return foldRight(compose(Function., B, B>andThen().f(P1.__1()), f), b); } /** @@ -255,7 +255,7 @@ public Stream prefix(final A x, final Stream xs) { * @return A new stream after the given function has been applied to each element. */ public final Stream map(final F f) { - return isEmpty() ? Stream.nil() : cons(f.f(head()), () -> tail()._1().map(f)); + return isEmpty() ? Stream.nil() : cons(f.f(head()), () -> tail()._1().map(f)); } /** @@ -353,7 +353,7 @@ public final Stream removeAll(final F f) { */ public static F> sequence_(final Stream> fs) { return fs.foldRight((baf, p1) -> Function.bind(baf, p1._1(), curry((a, stream) -> cons(a, p(stream)))), Function - .>constant(Stream.nil())); + .constant(Stream.nil())); } /** @@ -580,7 +580,7 @@ public static Stream enumerationStream(Enumeration e) { * @return A new stream with the elements of this stream sorted according to the given ordering. */ public final Stream sort(final Ord o) { - return mergesort(o, map(flip(Stream.cons()).f(p(Stream.nil())))); + return mergesort(o, map(flip(Stream.cons()).f(p(Stream.nil())))); } // Merges a stream of individually sorted streams into a single sorted stream. @@ -700,7 +700,7 @@ public int size() { * to value (exclusive). */ public static Stream range(final int from, final long to) { - return from >= to ? Stream.nil() : cons(from, () -> range(from + 1, to)); + return from >= to ? Stream.nil() : cons(from, () -> range(from + 1, to)); } /** @@ -768,7 +768,7 @@ public static Stream forever(final Enumerator e, final A from) { * given value and stepping at the given increment. */ public static Stream forever(final Enumerator e, final A from, final long step) { - return cons(from, () -> e.plus(from, step).map(a -> forever(e, a, step)).orSome(Stream.nil())); + return cons(from, () -> e.plus(from, step).map(a -> forever(e, a, step)).orSome(Stream.nil())); } /** @@ -830,7 +830,7 @@ public static F, F, Stream>> filter() { * @return A new stream with a length the same as the shortest of this stream and the given stream. */ public final Stream zapp(final Stream> fs) { - return fs.isEmpty() || isEmpty() ? Stream.nil() : + return fs.isEmpty() || isEmpty() ? Stream.nil() : cons(fs.head().f(head()), () -> tail()._1().zapp(fs.tail()._1())); } @@ -904,7 +904,7 @@ public final Stream> zipIndex() { * @return An either projection of this stream. */ public final Either toEither(final F0 x) { - return isEmpty() ? Either.left(x.f()) : Either.right(head()); + return isEmpty() ? Either.left(x.f()) : Either.right(head()); } /** @@ -914,7 +914,7 @@ public final Either toEither(final F0 x) { * @return An option projection of this stream. */ public final Option toOption() { - return isEmpty() ? Option.none() : some(head()); + return isEmpty() ? Option.none() : some(head()); } /** @@ -950,7 +950,7 @@ public final List toList() { * Returns a java.util.List projection of this stream. */ public final java.util.List toJavaList() { - return new java.util.LinkedList(toCollection()); + return new java.util.LinkedList<>(toCollection()); } /** @@ -1007,7 +1007,7 @@ public final A[] array(final Class c) { * @return A new stream with the given element at the head. */ public final Stream cons(final A a) { - return new Cons(a, () -> Stream.this); + return new Cons<>(a, () -> Stream.this); } /** @@ -1062,8 +1062,8 @@ public final Stream snoc(final F0 a) { */ public final Stream take(final int n) { return n <= 0 || isEmpty() ? - Stream.nil() : - cons(head(), () -> n <= 1 ? Stream.nil() : tail()._1().take(n - 1)); + Stream.nil() : + cons(head(), () -> n <= 1 ? Stream.nil() : tail()._1().take(n - 1)); } /** @@ -1093,7 +1093,7 @@ public final Stream takeWhile(final F f) { this : f.f(head()) ? cons(head(), () -> tail()._1().takeWhile(f)) : - Stream.nil(); + Stream.nil(); } /** @@ -1104,7 +1104,7 @@ public final Stream takeWhile(final F f) { public final IO> traverseIO(F> f) { return this.foldRight1((a, acc) -> IOFunctions.bind(acc, (Stream bs) -> - IOFunctions.map(f.f(a), bs::cons)), IOFunctions.unit(Stream.nil())); + IOFunctions.map(f.f(a), bs::cons)), IOFunctions.unit(Stream.nil())); } @@ -1114,7 +1114,7 @@ public final IO> traverseIO(F> f) { * @return traversed value */ public final Option> traverseOption(F> f) { - return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil())); + return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil())); } /** @@ -1146,11 +1146,11 @@ public final P2, Stream> span(final F p) { else if (p.f(head())) { final P1, Stream>> yszs = P.lazy(() -> tail()._1().span(p)); return P.lazy( - () -> cons(head(), yszs.map(P2., Stream>__1())), + () -> cons(head(), yszs.map(P2.__1())), () -> yszs._1()._2() ); } else - return p(Stream.nil(), this); + return p(Stream.nil(), this); } /** @@ -1187,7 +1187,7 @@ public final P2, Stream> split(final F p) { * @return A new stream that is the reverse of this one. */ public final Stream reverse() { - return foldLeft(as -> a -> cons(a, () -> as), Stream.nil()); + return foldLeft(as -> a -> cons(a, () -> as), Stream.nil()); } /** @@ -1259,7 +1259,7 @@ public final boolean forall(final F f) { @Override public boolean equals(Object other) { - return Equal.equals0(Stream.class, this, other, () -> Equal.streamEqual(Equal.anyEqual())); + return Equal.equals0(Stream.class, this, other, () -> Equal.streamEqual(Equal.anyEqual())); } @Override @@ -1325,7 +1325,7 @@ public final Stream cobind(final F, B> k) { * @return a stream of the suffixes of this stream, starting with the stream itself. */ public final Stream> tails() { - return isEmpty() ? Stream.>nil() : cons(this, () -> tail()._1().tails()); + return isEmpty() ? Stream.nil() : cons(this, () -> tail()._1().tails()); } /** @@ -1334,7 +1334,7 @@ public final Stream> tails() { * @return a stream of the prefixes of this stream, starting with the stream itself. */ public final Stream> inits() { - final Stream> nil = cons(Stream.nil(), Stream::nil); + final Stream> nil = cons(Stream.nil(), Stream::nil); return isEmpty() ? nil : nil.append(() -> tail()._1().inits().map(Stream.cons_().f(head()))); } @@ -1354,7 +1354,7 @@ public final Stream> substreams() { * @return the position of the first element matching the given predicate, if any. */ public final Option indexOf(final F p) { - return zipIndex().find(p2 -> p.f(p2._1())).map(P2.__2()); + return zipIndex().find(p2 -> p.f(p2._1())).map(P2.__2()); } /** @@ -1365,7 +1365,7 @@ public final Option indexOf(final F p) { */ public final Stream sequenceW(final Stream, B>> fs) { return fs.isEmpty() - ? Stream.nil() + ? Stream.nil() : cons(fs.head().f(this), () -> sequenceW(fs.tail()._1())); } @@ -1403,7 +1403,7 @@ public static Stream fromFunction(final Enumerator e, final F final Option s = e.successor(i); return s.isSome() ? fromFunction(e, f, s.some()) - : Stream.nil(); + : Stream.nil(); }); } @@ -1417,7 +1417,7 @@ public static P2, Stream> unzip(final Stream> xs) { return xs.foldRight((p, ps) -> { final P2, Stream> pp = ps._1(); return p(cons(p._1(), p(pp._1())), cons(p._2(), p(pp._2()))); - }, p(Stream.nil(), Stream.nil())); + }, p(Stream.nil(), Stream.nil())); } /** @@ -1482,7 +1482,7 @@ public static F, Stream>> cons_() { * @return An empty stream. */ public static Stream nil() { - return new Nil(); + return new Nil<>(); } /** @@ -1539,7 +1539,7 @@ public static F> single() { * @return The stream with the given element prepended. */ public static Stream cons(final A head, final F0> tail) { - return new Cons(head, tail); + return new Cons<>(head, tail); } /** @@ -1605,8 +1605,8 @@ public static Stream iterableStream(final Iterable i) { @SafeVarargs public static Stream arrayStream(final A...as) { - return as.length == 0 ? Stream.nil() - : unfold(P2.tuple((as1, i) -> i >= as.length ? Option.>>none() + return as.length == 0 ? Stream.nil() + : unfold(P2.tuple((as1, i) -> i >= as.length ? Option.none() : some(p(as[i], p(as, i + 1)))), p(as, 0)); } diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index 82e682bc..4b0ce7eb 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -38,7 +38,7 @@ private Tree(final A root, final P1>> subForest) { * @return A nullary tree with the root element in it. */ public static Tree leaf(final A root) { - return node(root, Stream.>nil()); + return node(root, Stream.nil()); } /** @@ -49,7 +49,7 @@ public static Tree leaf(final A root) { * @return A newly sprouted tree. */ public static Tree node(final A root, final P1>> forest) { - return new Tree(root, forest); + return new Tree<>(root, forest); } /** @@ -60,7 +60,7 @@ public static Tree node(final A root, final P1>> forest) { * @return A newly sprouted tree. */ public static Tree node(final A root, final Stream> forest) { - return new Tree(root, P.p(forest)); + return new Tree<>(root, P.p(forest)); } /** @@ -130,7 +130,7 @@ public Stream f(final Tree t, final P1> xs) { return cons(t.root(), t.subForest().map(Stream., Stream>foldRight().f(F2Functions.curry(this)).f(xs._1()))); } }; - return squish.f(this, P.p(Stream.nil())); + return squish.f(this, P.p(Stream.nil())); } /** @@ -152,9 +152,9 @@ public static F, Stream> flatten_() { */ public Stream> levels() { final F>, Stream>> flatSubForests = - Stream., Tree>bind_().f(compose(P1.>>__1(), Tree.subForest_())); - final F>, Stream> roots = Stream., A>map_().f(Tree.root_()); - return iterateWhile(flatSubForests, Stream.>isNotEmpty_(), single(this)).map(roots); + Stream., Tree>bind_().f(compose(P1.__1(), Tree.subForest_())); + final F>, Stream> roots = Stream., A>map_().f(Tree.root_()); + return iterateWhile(flatSubForests, Stream.isNotEmpty_(), single(this)).map(roots); } /** @@ -245,7 +245,7 @@ public Tree> cojoin() { } private static Stream drawSubTrees(final Show s, final Stream> ts) { - return ts.isEmpty() ? Stream.nil() + return ts.isEmpty() ? Stream.nil() : ts.tail()._1().isEmpty() ? shift("`- ", " ", ts.head().drawTree(s)).cons("|") : shift("+- ", "| ", ts.head().drawTree(s)) .append(drawSubTrees(s, ts.tail()._1())); @@ -261,7 +261,7 @@ private Stream drawTree(final Show s) { @Override public boolean equals(Object other) { - return Equal.equals0(Tree.class, this, other, () -> Equal.treeEqual(Equal.anyEqual())); + return Equal.equals0(Tree.class, this, other, () -> Equal.treeEqual(Equal.anyEqual())); } @Override @@ -328,7 +328,7 @@ public Tree zipWith(final Tree bs, final F> f) { public static Tree bottomUp(Tree t, final F>, B> f) { final F, Tree> recursiveCall = a -> bottomUp(a, f); final Stream> tbs = t.subForest()._1().map(recursiveCall); - return node(f.f(P.p(t.root(), tbs.map(Tree. getRoot()))), tbs); + return node(f.f(P.p(t.root(), tbs.map(Tree.getRoot()))), tbs); } /** diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index de4876ec..f663ab09 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -31,7 +31,7 @@ private TreeMap(final Set>> tree) { } private static Ord> ord(final Ord keyOrd) { - return keyOrd.contramap(P2.__1()); + return keyOrd.contramap(P2.__1()); } /** @@ -41,12 +41,12 @@ private static Ord> ord(final Ord keyOrd) { * @return an empty TreeMap with the given key order. */ public static TreeMap empty(final Ord keyOrd) { - return new TreeMap(Set.empty(TreeMap.>ord(keyOrd))); + return new TreeMap<>(Set.empty(TreeMap.ord(keyOrd))); } @Override public boolean equals(Object other) { - return Equal.equals0(TreeMap.class, this, other, () -> Equal.treeMapEqual(Equal.anyEqual(), Equal.anyEqual())); + return Equal.equals0(TreeMap.class, this, other, () -> Equal.treeMapEqual(Equal.anyEqual(), Equal.anyEqual())); } @Override @@ -129,8 +129,8 @@ public static TreeMap arrayTreeMap(final Ord keyOrd, final P2 get(final K k) { - final Option>> x = tree.split(p(k, Option.none()))._2(); - return x.bind(P2.>__2()); + final Option>> x = tree.split(p(k, Option.none()))._2(); + return x.bind(P2.__2()); } /** @@ -142,7 +142,7 @@ public Option get(final K k) { * @return A new tree map with the given value mapped to the given key. */ public TreeMap set(final K k, final V v) { - return new TreeMap(tree.insert(p(k, Option.some(v)))); + return new TreeMap<>(tree.insert(p(k, Option.some(v)))); } /** @@ -152,7 +152,7 @@ public TreeMap set(final K k, final V v) { * @return A new tree map with the entry corresponding to the given key removed. */ public TreeMap delete(final K k) { - return new TreeMap(tree.delete(p(k, Option.none()))); + return new TreeMap<>(tree.delete(p(k, Option.none()))); } /** @@ -179,7 +179,7 @@ public boolean isEmpty() { * @return All values in this tree map. */ public List values() { - return iterableList(join(tree.toList().map(compose(IterableW.>wrap(), P2.>__2())))); + return iterableList(join(tree.toList().map(compose(IterableW.wrap(), P2.__2())))); } /** @@ -188,7 +188,7 @@ public List values() { * @return All keys in this tree map. */ public List keys() { - return tree.toList().map(P2.>__1()); + return tree.toList().map(P2.__1()); } /** @@ -198,7 +198,7 @@ public List keys() { * @return true if this tree map contains the given key, false otherwise. */ public boolean contains(final K k) { - return tree.member(p(k, Option.none())); + return tree.member(p(k, Option.none())); } /** @@ -208,8 +208,8 @@ public boolean contains(final K k) { * @return A iterator for this map's key-value pairs. */ public Iterator> iterator() { - return join(tree.toStream().map(P2., IterableW>map2_(IterableW.>wrap()) - ).map(P2.tuple(compose(IterableW.>map(), P.p2())))).iterator(); + return join(tree.toStream().map(P2.map2_(IterableW.wrap()) + ).map(P2.tuple(compose(IterableW.map(), P.p2())))).iterator(); } /** @@ -220,7 +220,7 @@ public Iterator> iterator() { public Map toMutableMap() { final F>> fakePair = k -> p(k, Option.none()); final Comparator comparator = tree.ord().contramap(fakePair).toComparator(); - final Map m = new java.util.TreeMap(comparator); + final Map m = new java.util.TreeMap<>(comparator); for (final P2 e : this) { m.put(e._1(), e._2()); } @@ -277,8 +277,8 @@ public F> get() { */ public P2> update(final K k, final F f) { final P2>>> up = - tree.update(p(k, Option.none()), compose(P2.tuple(P.p2()), P2., Option>map2_(Option.map().f(f)))); - return p(up._1(), new TreeMap(up._2())); + tree.update(p(k, Option.none()), compose(P2.tuple(P.p2()), P2.map2_(Option.map().f(f)))); + return p(up._1(), new TreeMap<>(up._2())); } /** @@ -309,9 +309,9 @@ public TreeMap update(final K k, final F f, final V v) { * and the optional value is the value associated with the given key if present, otherwise None. */ public P3, Option, Set> split(Ord ord, final K k) { - final F>>, Set> getSome = F1Functions.mapSet(F1Functions.o(Option.fromSome(), P2.>__2()), ord); - return tree.split(p(k, Option.none())).map1(getSome).map3(getSome) - .map2(F1Functions.o(Option.join(), F1Functions.mapOption(P2.>__2()))); + final F>>, Set> getSome = F1Functions.mapSet(F1Functions.o(Option.fromSome(), P2.__2()), ord); + return tree.split(p(k, Option.none())).map1(getSome).map3(getSome) + .map2(F1Functions.o(Option.join(), F1Functions.mapOption(P2.__2()))); } /** @@ -321,7 +321,7 @@ public P3, Option, Set> split(Ord ord, final K k) { * @return a TreeMap with the given elements. */ private static TreeMap treeMap(Ord ord, Set>> s) { - TreeMap empty = TreeMap.empty(ord); + TreeMap empty = TreeMap.empty(ord); TreeMap tree = s.toList().foldLeft((tm, p2) -> { Option opt = p2._2(); if (opt.isSome()) { @@ -348,7 +348,7 @@ private static TreeMap treeMap(Ord ord, Set>> s) */ public P3, Option, TreeMap> splitLookup(final K k) { P3>>, Option>>, Set>>> p3 = tree.split(p(k, get(k))); - Ord o = tree.ord().contramap(k2 -> p(k2, Option.none())); + Ord o = tree.ord().contramap(k2 -> p(k2, Option.none())); return p(treeMap(o, p3._1()), get(k), treeMap(o, p3._3())); } @@ -361,9 +361,9 @@ public P3, Option, TreeMap> splitLookup(final K k) { @SuppressWarnings("unchecked") public TreeMap map(final F f) { final F>, P2>> g = P2.map2_(F1Functions.mapOption(f)); - final F>> coord = flip(P.>p2()).f(Option.none()); + final F>> coord = flip(P.>p2()).f(Option.none()); final Ord o = tree.ord().contramap(coord); - return new TreeMap(tree.map(TreeMap.>ord(o), g)); + return new TreeMap<>(tree.map(TreeMap.ord(o), g)); } /** diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index a9d92b5a..c94287cf 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -68,7 +68,7 @@ public static TreeZipper treeZipper(final Tree tree, final Stream> lefts, final Stream> rights, final Stream>, A, Stream>>> parents) { - return new TreeZipper(tree, lefts, rights, parents); + return new TreeZipper<>(tree, lefts, rights, parents); } /** @@ -114,7 +114,7 @@ public static Equal> eq(final Equal e) { treeEqual(e), streamEqual(treeEqual(e)), streamEqual(treeEqual(e)), - streamEqual(p3Equal(streamEqual(treeEqual(e)), e, streamEqual(treeEqual(e))))).contramap(TreeZipper.p_()); + streamEqual(p3Equal(streamEqual(treeEqual(e)), e, streamEqual(treeEqual(e))))).contramap(TreeZipper.p_()); } /** @@ -128,13 +128,13 @@ public static Show> show(final Show s) { treeShow(s), streamShow(treeShow(s)), streamShow(treeShow(s)), - streamShow(p3Show(streamShow(treeShow(s)), s, streamShow(treeShow(s))))).contramap(TreeZipper.p_()); + streamShow(p3Show(streamShow(treeShow(s)), s, streamShow(treeShow(s))))).contramap(TreeZipper.p_()); } private static Stream> combChildren(final Stream> ls, final Tree t, final Stream> rs) { - return ls.foldLeft(compose(flip(Stream.>cons()), P.>>p1()), Stream.cons(t, P.p(rs))); + return ls.foldLeft(compose(flip(Stream.cons()), P.p1()), Stream.cons(t, P.p(rs))); } /** @@ -158,7 +158,7 @@ public Option> parent() { * @return A new tree zipper focused on the top-most parent of the current node. */ public TreeZipper root() { - return parent().option(this, TreeZipper.root_()); + return parent().option(this, TreeZipper.root_()); } /** @@ -177,7 +177,7 @@ public static F, TreeZipper> root_() { * or none if there are no siblings on the left. */ public Option> left() { - return lefts.isEmpty() ? Option.>none() + return lefts.isEmpty() ? Option.none() : some(treeZipper(lefts.head(), lefts.tail()._1(), rights.cons(tree), parents)); } @@ -188,7 +188,7 @@ public Option> left() { * or none if there are no siblings on the right. */ public Option> right() { - return rights.isEmpty() ? Option.>none() + return rights.isEmpty() ? Option.none() : some(treeZipper(rights.head(), lefts.cons(tree), rights.tail()._1(), parents)); } @@ -199,8 +199,8 @@ public Option> right() { */ public Option> firstChild() { final Stream> ts = tree.subForest()._1(); - return ts.isEmpty() ? Option.>none() - : some(treeZipper(ts.head(), Stream.>nil(), ts.tail()._1(), downParents())); + return ts.isEmpty() ? Option.none() + : some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), downParents())); } /** @@ -210,8 +210,8 @@ public Option> firstChild() { */ public Option> lastChild() { final Stream> ts = tree.subForest()._1().reverse(); - return ts.isEmpty() ? Option.>none() - : some(treeZipper(ts.head(), ts.tail()._1(), Stream.>nil(), downParents())); + return ts.isEmpty() ? Option.none() + : some(treeZipper(ts.head(), ts.tail()._1(), Stream.nil(), downParents())); } /** @@ -223,7 +223,7 @@ public Option> lastChild() { public Option> getChild(final int n) { Option> r = none(); for (final P2>, Stream>> lr - : splitChildren(Stream.>nil(), tree.subForest()._1(), n)) { + : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { r = some(treeZipper(lr._1().head(), lr._1().tail()._1(), lr._2(), downParents())); } return r; @@ -246,14 +246,14 @@ public Option>, Tree, Stream>>> f(final Stream>, Tree, Stream>>>none(); + : Option.none(); } }; Stream> subforest = tree.subForest()._1(); if (subforest.isNotEmpty()) { for (final P3>, Tree, Stream>> ltr - : split.f(Stream.>nil(), subforest)) { + : split.f(Stream.nil(), subforest)) { r = some(treeZipper(ltr._2(), ltr._1(), ltr._3(), downParents())); } } @@ -269,7 +269,7 @@ private static Option, Stream>> splitChildren(final Stream, Stream>>none(); + : Option.none(); } private static Stream>, A, Stream>>> lp3nil() { @@ -283,7 +283,7 @@ private static Stream>, A, Stream>>> lp3nil() { * @return a new tree zipper focused on the root of the given tree. */ public static TreeZipper fromTree(final Tree t) { - return treeZipper(t, Stream.>nil(), Stream.>nil(), TreeZipper.lp3nil()); + return treeZipper(t, Stream.nil(), Stream.nil(), TreeZipper.lp3nil()); } /** @@ -294,8 +294,8 @@ public static TreeZipper fromTree(final Tree t) { */ public static Option> fromForest(final Stream> ts) { return ts.isNotEmpty() - ? some(treeZipper(ts.head(), Stream.>nil(), ts.tail()._1(), TreeZipper.lp3nil())) - : Option.>none(); + ? some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), TreeZipper.lp3nil())) + : Option.none(); } /** @@ -474,7 +474,7 @@ public TreeZipper insertRight(final Tree t) { * @return A new tree zipper with the given tree in focus, as the first child of the current node. */ public TreeZipper insertDownFirst(final Tree t) { - return treeZipper(t, Stream.>nil(), tree.subForest()._1(), downParents()); + return treeZipper(t, Stream.nil(), tree.subForest()._1(), downParents()); } /** @@ -484,7 +484,7 @@ public TreeZipper insertDownFirst(final Tree t) { * @return A new tree zipper with the given tree in focus, as the last child of the current node. */ public TreeZipper insertDownLast(final Tree t) { - return treeZipper(t, tree.subForest()._1().reverse(), Stream.>nil(), downParents()); + return treeZipper(t, tree.subForest()._1().reverse(), Stream.nil(), downParents()); } /** @@ -499,7 +499,7 @@ public TreeZipper insertDownLast(final Tree t) { public Option> insertDownAt(final int n, final Tree t) { Option> r = none(); for (final P2>, Stream>> lr - : splitChildren(Stream.>nil(), tree.subForest()._1(), n)) { + : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { r = some(treeZipper(t, lr._1(), lr._2(), downParents())); } return r; @@ -518,7 +518,7 @@ public Option> delete() { else if (lefts.isNotEmpty()) r = some(treeZipper(lefts.head(), lefts.tail()._1(), rights, parents)); else for (final TreeZipper loc : parent()) - r = some(loc.modifyTree(t -> node(t.root(), Stream.>nil()))); + r = some(loc.modifyTree(t -> node(t.root(), Stream.nil()))); return r; } @@ -531,7 +531,7 @@ else for (final TreeZipper loc : parent()) */ public TreeZipper> zipWithFocus() { final F> f = flip(P.p2()).f(false); - return map(f).modifyLabel(P2.map2_(Booleans.not)); + return map(f).modifyLabel(P2.map2_(Booleans.not)); } /** @@ -582,15 +582,15 @@ public static F, Option>> right_() { */ public TreeZipper> positions() { final Tree> t = unfoldTree(TreeZipper.dwn()).f(this); - final Stream>> l = uf(TreeZipper.left_()); - final Stream>> r = uf(TreeZipper.right_()); + final Stream>> l = uf(TreeZipper.left_()); + final Stream>> r = uf(TreeZipper.right_()); final Stream>>, TreeZipper, Stream>>>> p = unfold( o -> { Option>>, TreeZipper, Stream>>>, Option>>> r1 = none(); for (final TreeZipper z : o) { - r1 = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); + r1 = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); } return r1; }, parent()); @@ -609,7 +609,7 @@ private Stream>> uf(final F, Option F, P2, P1>>>> dwn() { - return tz -> P., P1>>>p(tz, new P1>>() { + return tz -> P.p(tz, new P1>>() { private F>, Option, Option>>>> fwd() { return o -> { Option, Option>>> r = none(); diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 8328590f..9d82596b 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -175,8 +175,8 @@ public void foreachDoEffect(final Effect1 f) { @SuppressWarnings("unchecked") public Validation map(final F f) { return isFail() ? - Validation.fail(fail()) : - Validation.success(f.f(success())); + Validation.fail(fail()) : + Validation.success(f.f(success())); } /** @@ -187,7 +187,7 @@ public Validation map(final F f) { */ @SuppressWarnings("unchecked") public Validation bind(final F> f) { - return isSuccess() ? f.f(success()) : Validation.fail(fail()); + return isSuccess() ? f.f(success()) : Validation.fail(fail()); } /** @@ -197,7 +197,7 @@ public Validation bind(final F> f) { * @return A validation after binding. */ public Validation sequence(final Validation v) { - return bind(Function.>constant(v)); + return bind(Function.constant(v)); } /** @@ -206,7 +206,7 @@ public Validation sequence(final Validation v) { */ public static Validation> sequence(final Semigroup s, final List> list) { if (list.exists(Validation::isFail)) { - return Validation.>fail(list.filter(Validation::isFail).map(v -> v.fail()).foldLeft1((F2) s::sum)); + return Validation.fail(list.filter(Validation::isFail).map(v -> v.fail()).foldLeft1((F2) s::sum)); } else { return success(list.foldLeft((List acc, Validation v) -> acc.cons(v.success()), List.nil()).reverse()); } @@ -221,7 +221,7 @@ public static Validation> sequence(final Semigroup s, final * success value, otherwise, returns a success in Some. */ public Option> filter(final F f) { - return e.right().filter(f).map(Validation.validation()); + return e.right().filter(f).map(Validation.validation()); } /** @@ -260,7 +260,7 @@ public boolean exists(final F f) { @Override public boolean equals(Object other) { - return Equal.equals0(Validation.class, this, other, () -> Equal.validationEqual(Equal.anyEqual(), Equal.anyEqual())); + return Equal.equals0(Validation.class, this, other, () -> Equal.validationEqual(Equal.anyEqual(), Equal.anyEqual())); } @Override @@ -316,12 +316,12 @@ public Stream toStream() { @SuppressWarnings("unchecked") public Validation accumapply(final Semigroup s, final Validation> v) { return isFail() ? - Validation.fail(v.isFail() ? + Validation.fail(v.isFail() ? s.sum(v.fail(), fail()) : fail()) : v.isFail() ? - Validation.fail(v.fail()) : - Validation.success(v.success().f(success())); + Validation.fail(v.fail()) : + Validation.success(v.success().f(success())); } /** @@ -722,7 +722,7 @@ public Iterator iterator() { public Validation, T> accumulate() { if (isFail()) { - return fail(List.single(fail())); + return fail(List.single(fail())); } else { return success(success()); } @@ -730,7 +730,7 @@ public Validation, T> accumulate() { public Validation, B> accumulate(F f) { if (isFail()) { - return fail(List.single(fail())); + return fail(List.single(fail())); } else { return success(f.f(success())); } @@ -969,7 +969,7 @@ public Validation map(final F f) { * @return A new validation value after binding. */ public Validation bind(final F> f) { - return v.isFail() ? f.f(v.fail()) : Validation.success(v.success()); + return v.isFail() ? f.f(v.fail()) : Validation.success(v.success()); } /** @@ -992,7 +992,7 @@ public Validation sequence(final Validation v) { * failing value, otherwise, returns a fail in Some. */ public Option> filter(final F f) { - return v.toEither().left().filter(f).map(Validation.validation()); + return v.toEither().left().filter(f).map(Validation.validation()); } /** @@ -1083,8 +1083,8 @@ public Iterator iterator() { @SuppressWarnings("unchecked") public Validation, T> nel() { return isSuccess() ? - Validation., T>success(success()) : - Validation., T>fail(NonEmptyList.nel(fail())); + Validation.success(success()) : + Validation.fail(NonEmptyList.nel(fail())); } /** @@ -1122,7 +1122,7 @@ public static F, Either> either() { * @return A succeeding validation containing the given value. */ public static Validation success(final T t) { - return validation(Either.right(t)); + return validation(Either.right(t)); } /** @@ -1132,7 +1132,7 @@ public static Validation success(final T t) { * @return A failing validation containing the given value. */ public static Validation fail(final E e) { - return validation(Either.left(e)); + return validation(Either.left(e)); } /** @@ -1155,7 +1155,7 @@ public static Validation, T> failNEL(final E e) { * @return A validation based on a boolean condition. */ public static Validation condition(final boolean c, final E e, final T t) { - return c ? Validation.success(t) : Validation.fail(e); + return c ? Validation.success(t) : Validation.fail(e); } /** diff --git a/core/src/main/java/fj/data/Writer.java b/core/src/main/java/fj/data/Writer.java index b384e259..b6b4579b 100644 --- a/core/src/main/java/fj/data/Writer.java +++ b/core/src/main/java/fj/data/Writer.java @@ -34,11 +34,11 @@ public Monoid monoid() { } public static Writer unit(A a, W w, Monoid m) { - return new Writer(a, w, m); + return new Writer<>(a, w, m); } public static Writer unit(A a, Monoid m) { - return new Writer(a, m.zero(), m); + return new Writer<>(a, m.zero(), m); } public Writer tell(W w) { diff --git a/core/src/main/java/fj/data/Zipper.java b/core/src/main/java/fj/data/Zipper.java index f24ecf01..24414ed2 100644 --- a/core/src/main/java/fj/data/Zipper.java +++ b/core/src/main/java/fj/data/Zipper.java @@ -54,7 +54,7 @@ private Zipper(final Stream left, final A focus, final Stream right) { * @return a new Zipper with the given streams before and after the focus, and the given focused item. */ public static Zipper zipper(final Stream left, final A focus, final Stream right) { - return new Zipper(left, focus, right); + return new Zipper<>(left, focus, right); } /** @@ -65,7 +65,7 @@ public static Zipper zipper(final Stream left, final A focus, final St * @return a new Zipper created from the given triple. */ public static Zipper zipper(final P3, A, Stream> p) { - return new Zipper(p._1(), p._2(), p._3()); + return new Zipper<>(p._1(), p._2(), p._3()); } /** @@ -103,7 +103,7 @@ public static F, P3, A, Stream>> p_() { */ public static Ord> ord(final Ord o) { final Ord> so = Ord.streamOrd(o); - return Ord.p3Ord(so, o, so).contramap(Zipper.p_()); + return Ord.p3Ord(so, o, so).contramap(Zipper.p_()); } /** @@ -114,7 +114,7 @@ public static Ord> ord(final Ord o) { */ public static Equal> eq(final Equal e) { final Equal> se = Equal.streamEqual(e); - return Equal.p3Equal(se, e, se).contramap(Zipper.p_()); + return Equal.p3Equal(se, e, se).contramap(Zipper.p_()); } /** @@ -125,7 +125,7 @@ public static Equal> eq(final Equal e) { */ public static Show> show(final Show s) { final Show> ss = Show.streamShow(s); - return Show.p3Show(ss, s, ss).contramap(Zipper.p_()); + return Show.p3Show(ss, s, ss).contramap(Zipper.p_()); } /** @@ -148,7 +148,7 @@ public Zipper map(final F f) { public B foldRight(final F> f, final B z) { return left.foldLeft(flip(f), right.cons(focus).foldRight(compose( - Function., B, B>andThen().f(P1.__1()), f), z)); + Function., B, B>andThen().f(P1.__1()), f), z)); } /** @@ -158,7 +158,7 @@ public B foldRight(final F> f, final B z) { * @return a new zipper with a single element which is in focus. */ public static Zipper single(final A a) { - return zipper(Stream.nil(), a, Stream.nil()); + return zipper(Stream.nil(), a, Stream.nil()); } /** @@ -174,7 +174,7 @@ public static Option> fromStream(final Stream a) { if (a.isEmpty()) return none(); else - return some(zipper(Stream.nil(), a.head(), a.tail()._1())); + return some(zipper(Stream.nil(), a.head(), a.tail()._1())); } /** @@ -190,7 +190,7 @@ public static Option> fromStreamEnd(final Stream a) { return none(); else { final Stream xs = a.reverse(); - return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); + return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); } } @@ -210,7 +210,7 @@ public A focus() { * focus, otherwise None. */ public Option> next() { - return right.isEmpty() ? Option.>none() : some(tryNext()); + return right.isEmpty() ? Option.none() : some(tryNext()); } /** @@ -233,7 +233,7 @@ public Zipper tryNext() { * focus, otherwise None. */ public Option> previous() { - return left.isEmpty() ? Option.>none() : some(tryPrevious()); + return left.isEmpty() ? Option.none() : some(tryPrevious()); } /** @@ -297,7 +297,7 @@ public Zipper insertRight(final A a) { */ public Option> deleteLeft() { return left.isEmpty() && right.isEmpty() - ? Option.>none() + ? Option.none() : some(zipper(left.isEmpty() ? left : left.tail()._1(), left.isEmpty() ? right.head() : left.head(), left.isEmpty() ? right.tail()._1() : right)); @@ -313,7 +313,7 @@ public Option> deleteLeft() { */ public Option> deleteRight() { return left.isEmpty() && right.isEmpty() - ? Option.>none() + ? Option.none() : some(zipper(right.isEmpty() ? left.tail()._1() : left, right.isEmpty() ? left.head() : right.head(), right.isEmpty() ? right : right.tail()._1())); @@ -335,7 +335,7 @@ public Zipper deleteOthers() { * @return the length of this zipper. */ public int length() { - return foldRight(Function.>constant(Integers.add.f(1)), 0); + return foldRight(Function.constant(Integers.add.f(1)), 0); } /** @@ -365,9 +365,9 @@ public boolean atEnd() { */ public Zipper> positions() { final Stream> left = Stream.unfold( - p -> p.previous().map(join(P., Zipper>p2())), this); + p -> p.previous().map(join(P.p2())), this); final Stream> right = Stream.unfold( - p -> p.next().map(join(P., Zipper>p2())), this); + p -> p.next().map(join(P.p2())), this); return zipper(left, this, right); } @@ -407,10 +407,10 @@ public Option> move(final int n) { return none(); else if (ll >= n) for (int i = ll - n; i > 0; i--) - p = p.bind(Zipper.previous_()); + p = p.bind(Zipper.previous_()); else if (rl >= n) for (int i = rl - n; i > 0; i--) - p = p.bind(Zipper.next_()); + p = p.bind(Zipper.next_()); return p; } @@ -458,7 +458,7 @@ public Zipper cycleNext() { return this; else if (right.isEmpty()) { final Stream xs = left.reverse(); - return zipper(Stream.nil(), xs.head(), xs.tail()._1().snoc(P.p(focus))); + return zipper(Stream.nil(), xs.head(), xs.tail()._1().snoc(P.p(focus))); } else return tryNext(); } @@ -474,7 +474,7 @@ public Zipper cyclePrevious() { return this; else if (left.isEmpty()) { final Stream xs = right.reverse(); - return zipper(xs.tail()._1().snoc(P.p(focus)), xs.head(), Stream.nil()); + return zipper(xs.tail()._1().snoc(P.p(focus)), xs.head(), Stream.nil()); } else return tryPrevious(); } @@ -493,7 +493,7 @@ else if (left.isNotEmpty()) return some(zipper(left.tail()._1(), left.head(), right)); else { final Stream xs = right.reverse(); - return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); + return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); } } @@ -511,7 +511,7 @@ else if (right.isNotEmpty()) return some(zipper(left, right.head(), right.tail()._1())); else { final Stream xs = left.reverse(); - return some(zipper(Stream.nil(), xs.head(), xs.tail()._1())); + return some(zipper(Stream.nil(), xs.head(), xs.tail()._1())); } } diff --git a/core/src/main/java/fj/data/fingertrees/Deep.java b/core/src/main/java/fj/data/fingertrees/Deep.java index 17e775e6..ea906507 100644 --- a/core/src/main/java/fj/data/fingertrees/Deep.java +++ b/core/src/main/java/fj/data/fingertrees/Deep.java @@ -57,24 +57,24 @@ public Digit suffix() { } @Override public B foldRight(final F> aff, final B z) { - return prefix.foldRight(aff, middle.foldRight(flip(Node.foldRight_(aff)), suffix.foldRight(aff, z))); + return prefix.foldRight(aff, middle.foldRight(flip(Node.foldRight_(aff)), suffix.foldRight(aff, z))); } @Override public A reduceRight(final F> aff) { - return prefix.foldRight(aff, middle.foldRight(flip(Node.foldRight_(aff)), suffix.reduceRight(aff))); + return prefix.foldRight(aff, middle.foldRight(flip(Node.foldRight_(aff)), suffix.reduceRight(aff))); } @Override public B foldLeft(final F> bff, final B z) { - return suffix.foldLeft(bff, middle.foldLeft(Node.foldLeft_(bff), prefix.foldLeft(bff, z))); + return suffix.foldLeft(bff, middle.foldLeft(Node.foldLeft_(bff), prefix.foldLeft(bff, z))); } @Override public A reduceLeft(final F> aff) { - return suffix.foldLeft(aff, middle.foldLeft(Node.foldLeft_(aff), prefix.reduceLeft(aff))); + return suffix.foldLeft(aff, middle.foldLeft(Node.foldLeft_(aff), prefix.reduceLeft(aff))); } @Override public FingerTree map(final F abf, final Measured m) { - return new Deep(m, v, prefix.map(abf, m), middle.map(Node.liftM(abf, m), m.nodeMeasured()), - suffix.map(abf, m)); + return new Deep<>(m, v, prefix.map(abf, m), middle.map(Node.liftM(abf, m), m.nodeMeasured()), + suffix.map(abf, m)); } /** @@ -281,9 +281,9 @@ private static FingerTree> append1(final Measured m, final Node a, final FingerTree> ys) { return xs.match(empty -> ys.cons(a), single -> ys.cons(a).cons(single.value()), deep1 -> ys.match(empty -> xs.snoc(a), single -> xs.snoc(a).snoc(single.value()), deep2 -> { final Measured> nm = m.nodeMeasured(); - return new Deep>(nm, m.sum(m.sum(deep1.v, nm.measure(a)), deep2.v), deep1.prefix, - addDigits1(nm, deep1.middle, deep1.suffix, a, deep2.prefix, deep2.middle), - deep2.suffix); + return new Deep<>(nm, m.sum(m.sum(deep1.v, nm.measure(a)), deep2.v), deep1.prefix, + addDigits1(nm, deep1.middle, deep1.suffix, a, deep2.prefix, deep2.middle), + deep2.suffix); })); } @@ -336,11 +336,11 @@ private static FingerTree>> addDigits1(final Measur private static FingerTree> append2(final Measured m, final FingerTree> t1, final Node n1, final Node n2, final FingerTree> t2) { - return t1.match(empty -> t2.cons(n2).cons(n1), single -> t2.cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2), single -> deep.snoc(n1).snoc(n2).snoc(single.value()), deep2 -> new Deep>(m.nodeMeasured(), - m.sum(m.sum(m.sum(deep.measure(), n1.measure()), n2.measure()), - deep2.measure()), deep.prefix, - addDigits2(m.nodeMeasured(), deep.middle, deep.suffix, n1, n2, deep2.prefix, - deep2.middle), deep2.suffix))); + return t1.match(empty -> t2.cons(n2).cons(n1), single -> t2.cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2), single -> deep.snoc(n1).snoc(n2).snoc(single.value()), deep2 -> new Deep<>(m.nodeMeasured(), + m.sum(m.sum(m.sum(deep.measure(), n1.measure()), n2.measure()), + deep2.measure()), deep.prefix, + addDigits2(m.nodeMeasured(), deep.middle, deep.suffix, n1, n2, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits2(final Measured> m, @@ -395,10 +395,10 @@ private static FingerTree> append3(final Measured m, final Node n1, final Node n2, final Node n3, final FingerTree> t2) { final Measured> nm = m.nodeMeasured(); - return t1.match(empty -> t2.cons(n3).cons(n2).cons(n1), single -> t2.cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2).snoc(n3), single -> deep.snoc(n1).snoc(n2).snoc(n3).snoc(single.value()), deep2 -> new Deep>(nm, nm.monoid().sumLeft( + return t1.match(empty -> t2.cons(n3).cons(n2).cons(n1), single -> t2.cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> deep.snoc(n1).snoc(n2).snoc(n3), single -> deep.snoc(n1).snoc(n2).snoc(n3).snoc(single.value()), deep2 -> new Deep<>(nm, nm.monoid().sumLeft( list(deep.v, n1.measure(), n2.measure(), n3.measure(), deep2.v)), deep.prefix, - addDigits3(nm, deep.middle, deep.suffix, n1, n2, n3, deep2.prefix, - deep2.middle), deep2.suffix))); + addDigits3(nm, deep.middle, deep.suffix, n1, n2, n3, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits3(final Measured> m, @@ -462,10 +462,10 @@ private static FingerTree> append4(final Measured m, final Node n4, final FingerTree> t2) { final Measured> nm = m.nodeMeasured(); - return t1.match(empty -> t2.cons(n4).cons(n3).cons(n2).cons(n1), single -> t2.cons(n4).cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4), single -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4).snoc(single.value()), deep2 -> new Deep>(nm, m.monoid().sumLeft( + return t1.match(empty -> t2.cons(n4).cons(n3).cons(n2).cons(n1), single -> t2.cons(n4).cons(n3).cons(n2).cons(n1).cons(single.value()), deep -> t2.match(empty -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4), single -> t1.snoc(n1).snoc(n2).snoc(n3).snoc(n4).snoc(single.value()), deep2 -> new Deep<>(nm, m.monoid().sumLeft( list(deep.v, n1.measure(), n2.measure(), n3.measure(), n4.measure(), deep2.v)), deep.prefix, - addDigits4(nm, deep.middle, deep.suffix, n1, n2, n3, n4, deep2.prefix, - deep2.middle), deep2.suffix))); + addDigits4(nm, deep.middle, deep.suffix, n1, n2, n3, n4, deep2.prefix, + deep2.middle), deep2.suffix))); } private static FingerTree>> addDigits4(final Measured> m, diff --git a/core/src/main/java/fj/data/fingertrees/Digit.java b/core/src/main/java/fj/data/fingertrees/Digit.java index 2b51f7a7..415f08c2 100644 --- a/core/src/main/java/fj/data/fingertrees/Digit.java +++ b/core/src/main/java/fj/data/fingertrees/Digit.java @@ -88,10 +88,10 @@ public final A reduceLeft(final F> f) { */ public final Digit map(final F f, final Measured m) { return match( - one -> new One(m, f.f(one.value())), - two -> new Two(m, two.values().map(f)), - three -> new Three(m, three.values().map(f)), - four -> new Four(m, four.values().map(f)) + one -> new One<>(m, f.f(one.value())), + two -> new Two<>(m, two.values().map(f)), + three -> new Three<>(m, three.values().map(f)), + four -> new Four<>(m, four.values().map(f)) ); } @@ -132,27 +132,27 @@ public final FingerTree toTree() { final MakeTree mk = mkTree(m); return match( one -> mk.single(one.value()), - two -> mk.deep(mk.one(two.values()._1()), new Empty>(m.nodeMeasured()), mk.one(two.values()._2())), - three -> mk.deep(mk.two(three.values()._1(), three.values()._2()), new Empty>(m.nodeMeasured()), mk.one(three.values()._3())), - four -> mk.deep(mk.two(four.values()._1(), four.values()._2()), new Empty>(m.nodeMeasured()), mk.two(four.values()._3(), four.values()._4())) + two -> mk.deep(mk.one(two.values()._1()), new Empty<>(m.nodeMeasured()), mk.one(two.values()._2())), + three -> mk.deep(mk.two(three.values()._1(), three.values()._2()), new Empty<>(m.nodeMeasured()), mk.one(three.values()._3())), + four -> mk.deep(mk.two(four.values()._1(), four.values()._2()), new Empty<>(m.nodeMeasured()), mk.two(four.values()._3(), four.values()._4())) ); } Option> tail() { return match( - one -> Option.> none(), - two -> Option.> some(mkTree(m).one(two.values()._2())), - three -> Option.> some(mkTree(m).two(three.values()._2(), three.values()._3())), - four -> Option.> some(mkTree(m).three(four.values()._2(), four.values()._3(), four.values()._4())) + one -> Option.none(), + two -> Option.some(mkTree(m).one(two.values()._2())), + three -> Option.some(mkTree(m).two(three.values()._2(), three.values()._3())), + four -> Option.some(mkTree(m).three(four.values()._2(), four.values()._3(), four.values()._4())) ); } Option> init() { return match( - one -> Option.> none(), - two -> Option.> some(mkTree(m).one(two.values()._1())), - three -> Option.> some(mkTree(m).two(three.values()._1(), three.values()._2())), - four -> Option.> some(mkTree(m).three(four.values()._1(), four.values()._2(), four.values()._3())) + one -> Option.none(), + two -> Option.some(mkTree(m).one(two.values()._1())), + three -> Option.some(mkTree(m).two(three.values()._1(), three.values()._2())), + four -> Option.some(mkTree(m).three(four.values()._1(), four.values()._2(), four.values()._3())) ); } diff --git a/core/src/main/java/fj/data/fingertrees/Empty.java b/core/src/main/java/fj/data/fingertrees/Empty.java index 9f2b9bd2..95065aef 100644 --- a/core/src/main/java/fj/data/fingertrees/Empty.java +++ b/core/src/main/java/fj/data/fingertrees/Empty.java @@ -15,7 +15,7 @@ public final class Empty extends FingerTree { } @Override public FingerTree cons(final A a) { - return new Single(measured(), a); + return new Single<>(measured(), a); } @Override public FingerTree snoc(final A a) { @@ -58,7 +58,7 @@ public A reduceRight(final F> aff) { } @Override public FingerTree map(final F abf, final Measured m) { - return new Empty(m); + return new Empty<>(m); } /** diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index 1078374b..060e976f 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -77,7 +77,7 @@ public B foldLeft(final F2 f, final B z) { public abstract FingerTree map(final F f, final Measured m); public FingerTree filter(final F f) { - FingerTree tree = new Empty(m); + FingerTree tree = new Empty<>(m); return foldLeft((acc, a) -> f.f(a) ? acc.snoc(a) : acc, tree); } @@ -134,7 +134,7 @@ public static Measured measured(final Monoid monoid, final F MakeTree mkTree(final Measured m) { - return new MakeTree(m); + return new MakeTree<>(m); } /** @@ -161,7 +161,7 @@ public static MakeTree mkTree(final Measured m) { public abstract A head(); public Option headOption() { - return isEmpty() ? Option.none() : Option.some(head()); + return isEmpty() ? Option.none() : Option.some(head()); } /** diff --git a/core/src/main/java/fj/data/fingertrees/MakeTree.java b/core/src/main/java/fj/data/fingertrees/MakeTree.java index b435d955..b2a3da84 100644 --- a/core/src/main/java/fj/data/fingertrees/MakeTree.java +++ b/core/src/main/java/fj/data/fingertrees/MakeTree.java @@ -14,7 +14,7 @@ public final class MakeTree { MakeTree(final Measured m) { this.m = m; - this.empty = new Empty(m); + this.empty = new Empty<>(m); } // Tree constructors @@ -35,7 +35,7 @@ public FingerTree empty() { * @return A tree with the given value as the single element. */ public FingerTree single(final A a) { - return new Single(m, a); + return new Single<>(m, a); } /** @@ -63,7 +63,7 @@ public FingerTree deep(final Digit prefix, final FingerTree deep(final V v, final Digit prefix, final FingerTree> middle, final Digit suffix) { - return new Deep(m, v, prefix, middle, suffix); + return new Deep<>(m, v, prefix, middle, suffix); } // Digit constructors @@ -75,7 +75,7 @@ public FingerTree deep(final V v, final Digit prefix, final FingerTr * @return A digit of the given element. */ public One one(final A a) { - return new One(m, a); + return new One<>(m, a); } /** @@ -86,7 +86,7 @@ public One one(final A a) { * @return A digit of the given elements. */ public Two two(final A a, final A b) { - return new Two(m, v(a, b)); + return new Two<>(m, v(a, b)); } /** @@ -98,7 +98,7 @@ public Two two(final A a, final A b) { * @return A digit of the given elements. */ public Three three(final A a, final A b, final A c) { - return new Three(m, v(a, b, c)); + return new Three<>(m, v(a, b, c)); } /** @@ -111,7 +111,7 @@ public Three three(final A a, final A b, final A c) { * @return A digit of the given elements. */ public Four four(final A a, final A b, final A c, final A d) { - return new Four(m, v(a, b, c, d)); + return new Four<>(m, v(a, b, c, d)); } // Node constructors @@ -124,7 +124,7 @@ public Four four(final A a, final A b, final A c, final A d) { * @return A new binary tree node. */ public Node2 node2(final A a, final A b) { - return new Node2(m, v(a, b)); + return new Node2<>(m, v(a, b)); } /** @@ -136,7 +136,7 @@ public Node2 node2(final A a, final A b) { * @return A new trinary tree node. */ public Node3 node3(final A a, final A b, final A c) { - return new Node3(m, v(a, b, c)); + return new Node3<>(m, v(a, b, c)); } /** @@ -146,7 +146,7 @@ public Node3 node3(final A a, final A b, final A c) { * @return A new binary tree node. */ public Node2 node2(final V2 v) { - return new Node2(m, v); + return new Node2<>(m, v); } /** @@ -156,7 +156,7 @@ public Node2 node2(final V2 v) { * @return A new trinary tree node. */ public Node3 node3(final V3 v) { - return new Node3(m, v); + return new Node3<>(m, v); } } diff --git a/core/src/main/java/fj/data/fingertrees/Measured.java b/core/src/main/java/fj/data/fingertrees/Measured.java index d33b5726..28c94abe 100644 --- a/core/src/main/java/fj/data/fingertrees/Measured.java +++ b/core/src/main/java/fj/data/fingertrees/Measured.java @@ -17,7 +17,7 @@ private Measured(final Monoid m, final F measure) { } public static Measured measured(final Monoid m, final F measure) { - return new Measured(m, measure); + return new Measured<>(m, measure); } /** @@ -74,7 +74,7 @@ public V zero() { * @return A measured instance for nodes. */ public Measured> nodeMeasured() { - return new Measured>(m, Node::measure); + return new Measured<>(m, Node::measure); } /** @@ -83,7 +83,7 @@ public Measured> nodeMeasured() { * @return A measured instance for digits. */ public Measured> digitMeasured() { - return new Measured>(m, Digit::measure); + return new Measured<>(m, Digit::measure); } } diff --git a/core/src/main/java/fj/data/fingertrees/Node.java b/core/src/main/java/fj/data/fingertrees/Node.java index d107c8d4..674195d7 100644 --- a/core/src/main/java/fj/data/fingertrees/Node.java +++ b/core/src/main/java/fj/data/fingertrees/Node.java @@ -28,8 +28,8 @@ public static F, B>> foldRight_(final F> af public final Node map(final F f, final Measured m) { return match( - node2 -> new Node2(m, node2.toVector().map(f)), - node3 -> new Node3(m, node3.toVector().map(f)) + node2 -> new Node2<>(m, node2.toVector().map(f)), + node3 -> new Node3<>(m, node3.toVector().map(f)) ); } diff --git a/core/src/main/java/fj/data/fingertrees/Node2.java b/core/src/main/java/fj/data/fingertrees/Node2.java index 5fc979be..5af121c2 100644 --- a/core/src/main/java/fj/data/fingertrees/Node2.java +++ b/core/src/main/java/fj/data/fingertrees/Node2.java @@ -31,7 +31,7 @@ public final class Node2 extends Node { } public Digit toDigit() { - return new Two(measured(), as); + return new Two<>(measured(), as); } P3>, A, Option>> split1(final F predicate, final V acc) { diff --git a/core/src/main/java/fj/data/fingertrees/Node3.java b/core/src/main/java/fj/data/fingertrees/Node3.java index 233fcda7..5eb9bf58 100644 --- a/core/src/main/java/fj/data/fingertrees/Node3.java +++ b/core/src/main/java/fj/data/fingertrees/Node3.java @@ -40,7 +40,7 @@ public int length() { } public Digit toDigit() { - return new Three(measured(), as); + return new Three<>(measured(), as); } P3>, A, Option>> split1(final F predicate, final V acc) { diff --git a/core/src/main/java/fj/data/fingertrees/Single.java b/core/src/main/java/fj/data/fingertrees/Single.java index 1bbe7884..d322dcaa 100644 --- a/core/src/main/java/fj/data/fingertrees/Single.java +++ b/core/src/main/java/fj/data/fingertrees/Single.java @@ -37,7 +37,7 @@ public final class Single extends FingerTree { } @Override public FingerTree map(final F abf, final Measured m) { - return new Single(m, abf.f(a)); + return new Single<>(m, abf.f(a)); } /** @@ -59,12 +59,12 @@ public V measure() { @Override public FingerTree cons(final A b) { final MakeTree mk = mkTree(measured()); - return mk.deep(mk.one(b), new Empty>(measured().nodeMeasured()), mk.one(a)); + return mk.deep(mk.one(b), new Empty<>(measured().nodeMeasured()), mk.one(a)); } @Override public FingerTree snoc(final A b) { final MakeTree mk = mkTree(measured()); - return mk.deep(mk.one(a), new Empty>(measured().nodeMeasured()), mk.one(b)); + return mk.deep(mk.one(a), new Empty<>(measured().nodeMeasured()), mk.one(b)); } @Override public A head() { return a; } diff --git a/core/src/main/java/fj/data/hlist/HList.java b/core/src/main/java/fj/data/hlist/HList.java index b02d9504..639c9e64 100644 --- a/core/src/main/java/fj/data/hlist/HList.java +++ b/core/src/main/java/fj/data/hlist/HList.java @@ -47,7 +47,7 @@ public static HNil nil() { * @return a heterogeneous list consisting of an element and another list. */ public static > HCons cons(final E e, final L l) { - return new HCons(e, l); + return new HCons<>(e, l); } /** @@ -91,7 +91,7 @@ public C append(final A a, final B b) { * @return a method for concatenating lists to the empty list. */ public static > HAppend append() { - return new HAppend((hNil, l) -> l); + return new HAppend<>((hNil, l) -> l); } /** @@ -102,7 +102,7 @@ public static > HAppend append() { */ public static , B, C extends HList, H extends HAppend> HAppend, B, HCons> append(final H h) { - return new HAppend, B, HCons>((c, l) -> cons(c.head(), h.append(c.tail(), l))); + return new HAppend<>((c, l) -> cons(c.head(), h.append(c.tail(), l))); } } @@ -212,7 +212,7 @@ private HFoldr(final F3 foldRight) { * @return a fold instance for the empty list. */ public static HFoldr hFoldr() { - return new HFoldr((f, v, hNil) -> v); + return new HFoldr<>((f, v, hNil) -> v); } /** @@ -234,7 +234,7 @@ public static HFoldr hFoldr() { H extends HFoldr, PP extends Apply, RR>> HFoldr, RR> hFoldr(final PP p, final H h) { - return new HFoldr, RR>((f, v, c) -> p.apply(f, P.p(c.head(), h.foldRight(f, v, c.tail())))); + return new HFoldr<>((f, v, c) -> p.apply(f, P.p(c.head(), h.foldRight(f, v, c.tail())))); } /** diff --git a/core/src/main/java/fj/data/optic/Fold.java b/core/src/main/java/fj/data/optic/Fold.java index 21aca09f..af6b5739 100644 --- a/core/src/main/java/fj/data/optic/Fold.java +++ b/core/src/main/java/fj/data/optic/Fold.java @@ -76,7 +76,7 @@ public final Fold composeFold(final Fold other) { return new Fold() { @Override public F foldMap(final Monoid m, final F f) { - return Fold.this. foldMap(m, other. foldMap(m, f)); + return Fold.this.foldMap(m, other. foldMap(m, f)); } }; } diff --git a/core/src/main/java/fj/data/optic/Optional.java b/core/src/main/java/fj/data/optic/Optional.java index 200a952d..b2106cae 100644 --- a/core/src/main/java/fj/data/optic/Optional.java +++ b/core/src/main/java/fj/data/optic/Optional.java @@ -180,7 +180,7 @@ public static final Optional optional(final F> getOpti @Override public Either getOrModify(final S s) { - return getOption.f(s).option(Either.left(s), Either. right_()); + return getOption.f(s).option(Either.left(s), Either.right_()); } @Override @@ -213,7 +213,7 @@ public F> modifyEitherF(final F> f) { public F> modifyIOF(final F> f) { return s -> getOption.f(s).option( IOFunctions.unit(s), - a -> IOFunctions. map(f.f(a), b -> set.f(b).f(s)) + a -> IOFunctions.map(f.f(a), b -> set.f(b).f(s)) ); } diff --git a/core/src/main/java/fj/data/optic/POptional.java b/core/src/main/java/fj/data/optic/POptional.java index 5c0bdd8c..73cc6fe9 100644 --- a/core/src/main/java/fj/data/optic/POptional.java +++ b/core/src/main/java/fj/data/optic/POptional.java @@ -403,7 +403,7 @@ public F> modifyEitherF(final F> f) { public F> modifyIOF(final F> f) { return s -> getOrModify.f(s).either( IOFunctions::unit, - t -> IOFunctions. map(f.f(t), b -> set.f(b).f(s)) + t -> IOFunctions.map(f.f(t), b -> set.f(b).f(s)) ); } diff --git a/core/src/main/java/fj/data/optic/Prism.java b/core/src/main/java/fj/data/optic/Prism.java index 42decaaf..c2160b1f 100644 --- a/core/src/main/java/fj/data/optic/Prism.java +++ b/core/src/main/java/fj/data/optic/Prism.java @@ -95,7 +95,7 @@ public static Prism prism(final F> getOption, final F< @Override public Either getOrModify(final S s) { - return getOption.f(s).option(Either.left(s), Either. right_()); + return getOption.f(s).option(Either.left(s), Either.right_()); } @Override diff --git a/core/src/main/java/fj/data/vector/V2.java b/core/src/main/java/fj/data/vector/V2.java index 700a8409..fdab115c 100644 --- a/core/src/main/java/fj/data/vector/V2.java +++ b/core/src/main/java/fj/data/vector/V2.java @@ -30,7 +30,7 @@ private V2(final P2 inner) { * @return A new vector-2. */ public static V2 p(final P2 p) { - return new V2(p); + return new V2<>(p); } /** diff --git a/core/src/main/java/fj/data/vector/V3.java b/core/src/main/java/fj/data/vector/V3.java index ceb492bc..9b25258f 100644 --- a/core/src/main/java/fj/data/vector/V3.java +++ b/core/src/main/java/fj/data/vector/V3.java @@ -30,7 +30,7 @@ private V3(final P1 head, final V2 tail) { * @return A new vector-3. */ public static V3 p(final P3 p) { - return new V3( + return new V3<>( P.lazy(p::_1), V2.p(P.lazy(p::_2, p::_3)) ); @@ -44,7 +44,7 @@ public static V3 p(final P3 p) { * @return The new vector. */ public static V3 cons(final P1 head, final V2 tail) { - return new V3(head, tail); + return new V3<>(head, tail); } /** @@ -131,7 +131,7 @@ public Array toArray() { * @return A new vector after zipping the given vector of functions over this vector. */ public V3 apply(final V3> vf) { - return new V3(head.apply(vf.head()), tail.apply(vf.tail())); + return new V3<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** @@ -202,7 +202,7 @@ public Stream toStream() { * @return A new vector after the given function has been applied to each element. */ public V3 map(final F f) { - return new V3(head().map(f), tail().map(f)); + return new V3<>(head().map(f), tail().map(f)); } /** diff --git a/core/src/main/java/fj/data/vector/V4.java b/core/src/main/java/fj/data/vector/V4.java index 8e142023..1f39346b 100644 --- a/core/src/main/java/fj/data/vector/V4.java +++ b/core/src/main/java/fj/data/vector/V4.java @@ -30,20 +30,20 @@ private V4(final P1 head, final V3 tail) { * @return A new vector-4. */ public static V4 p(final P4 p) { - return new V4(P.lazy(p::_1), - V3.p(new P3() { - public A _1() { - return p._2(); - } - - public A _2() { - return p._3(); - } - - public A _3() { - return p._4(); - } - })); + return new V4<>(P.lazy(p::_1), + V3.p(new P3() { + public A _1() { + return p._2(); + } + + public A _2() { + return p._3(); + } + + public A _3() { + return p._4(); + } + })); } /** @@ -54,7 +54,7 @@ public A _3() { * @return The new vector. */ public static V4 cons(final P1 head, final V3 tail) { - return new V4(head, tail); + return new V4<>(head, tail); } /** @@ -180,7 +180,7 @@ public Array toArray() { * @return A new vector after the given function has been applied to each element. */ public V4 map(final F f) { - return new V4(head.map(f), tail.map(f)); + return new V4<>(head.map(f), tail.map(f)); } /** @@ -190,7 +190,7 @@ public V4 map(final F f) { * @return A new vector after zipping the given vector of functions over this vector. */ public V4 apply(final V4> vf) { - return new V4(head.apply(vf.head()), tail.apply(vf.tail())); + return new V4<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** diff --git a/core/src/main/java/fj/data/vector/V5.java b/core/src/main/java/fj/data/vector/V5.java index d386cb32..0119dcf9 100644 --- a/core/src/main/java/fj/data/vector/V5.java +++ b/core/src/main/java/fj/data/vector/V5.java @@ -30,24 +30,24 @@ private V5(final P1 head, final V4 tail) { * @return A new vector-5. */ public static V5 p(final P5 p) { - return new V5(P.lazy(p::_1), - V4.p(new P4() { - public A _1() { - return p._2(); - } - - public A _2() { - return p._3(); - } - - public A _3() { - return p._4(); - } - - public A _4() { - return p._5(); - } - })); + return new V5<>(P.lazy(p::_1), + V4.p(new P4() { + public A _1() { + return p._2(); + } + + public A _2() { + return p._3(); + } + + public A _3() { + return p._4(); + } + + public A _4() { + return p._5(); + } + })); } /** @@ -58,7 +58,7 @@ public A _4() { * @return The new vector. */ public static V5 cons(final P1 head, final V4 tail) { - return new V5(head, tail); + return new V5<>(head, tail); } /** @@ -197,7 +197,7 @@ public Array toArray() { * @return A new vector after the given function has been applied to each element. */ public V5 map(final F f) { - return new V5(head.map(f), tail.map(f)); + return new V5<>(head.map(f), tail.map(f)); } /** @@ -207,7 +207,7 @@ public V5 map(final F f) { * @return A new vector after zipping the given vector of functions over this vector. */ public V5 apply(final V5> vf) { - return new V5(head.apply(vf.head()), tail.apply(vf.tail())); + return new V5<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** diff --git a/core/src/main/java/fj/data/vector/V6.java b/core/src/main/java/fj/data/vector/V6.java index 107c01a5..47a0c4e7 100644 --- a/core/src/main/java/fj/data/vector/V6.java +++ b/core/src/main/java/fj/data/vector/V6.java @@ -30,28 +30,28 @@ private V6(final P1 head, final V5 tail) { * @return A new vector-6. */ public static V6 p(final P6 p) { - return new V6(P.lazy(p::_1), - V5.p(new P5() { - public A _1() { - return p._2(); - } - - public A _2() { - return p._3(); - } - - public A _3() { - return p._4(); - } - - public A _4() { - return p._5(); - } - - public A _5() { - return p._6(); - } - })); + return new V6<>(P.lazy(p::_1), + V5.p(new P5() { + public A _1() { + return p._2(); + } + + public A _2() { + return p._3(); + } + + public A _3() { + return p._4(); + } + + public A _4() { + return p._5(); + } + + public A _5() { + return p._6(); + } + })); } /** @@ -62,7 +62,7 @@ public A _5() { * @return The new vector. */ public static V6 cons(final P1 head, final V5 tail) { - return new V6(head, tail); + return new V6<>(head, tail); } /** @@ -214,7 +214,7 @@ public Array toArray() { * @return A new vector after the given function has been applied to each element. */ public V6 map(final F f) { - return new V6(head.map(f), tail.map(f)); + return new V6<>(head.map(f), tail.map(f)); } /** @@ -224,7 +224,7 @@ public V6 map(final F f) { * @return A new vector after zipping the given vector of functions over this vector. */ public V6 apply(final V6> vf) { - return new V6(head.apply(vf.head()), tail.apply(vf.tail())); + return new V6<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** diff --git a/core/src/main/java/fj/data/vector/V7.java b/core/src/main/java/fj/data/vector/V7.java index 52699481..c0dfa4b6 100644 --- a/core/src/main/java/fj/data/vector/V7.java +++ b/core/src/main/java/fj/data/vector/V7.java @@ -30,32 +30,32 @@ private V7(final P1 head, final V6 tail) { * @return A new vector-7. */ public static V7 p(final P7 p) { - return new V7(P.lazy(p::_1), - V6.p(new P6() { - public A _1() { - return p._2(); - } - - public A _2() { - return p._3(); - } - - public A _3() { - return p._4(); - } - - public A _4() { - return p._5(); - } - - public A _5() { - return p._6(); - } - - public A _6() { - return p._7(); - } - })); + return new V7<>(P.lazy(p::_1), + V6.p(new P6() { + public A _1() { + return p._2(); + } + + public A _2() { + return p._3(); + } + + public A _3() { + return p._4(); + } + + public A _4() { + return p._5(); + } + + public A _5() { + return p._6(); + } + + public A _6() { + return p._7(); + } + })); } /** @@ -66,7 +66,7 @@ public A _6() { * @return The new vector. */ public static V7 cons(final P1 head, final V6 tail) { - return new V7(head, tail); + return new V7<>(head, tail); } /** @@ -231,7 +231,7 @@ public Array toArray() { * @return A new vector after the given function has been applied to each element. */ public V7 map(final F f) { - return new V7(head.map(f), tail.map(f)); + return new V7<>(head.map(f), tail.map(f)); } /** @@ -241,7 +241,7 @@ public V7 map(final F f) { * @return A new vector after zipping the given vector of functions over this vector. */ public V7 apply(final V7> vf) { - return new V7(head.apply(vf.head()), tail.apply(vf.tail())); + return new V7<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** diff --git a/core/src/main/java/fj/data/vector/V8.java b/core/src/main/java/fj/data/vector/V8.java index 8ad96cdd..f01dc2fe 100644 --- a/core/src/main/java/fj/data/vector/V8.java +++ b/core/src/main/java/fj/data/vector/V8.java @@ -30,36 +30,36 @@ private V8(final P1 head, final V7 tail) { * @return A new vector-8. */ public static V8 p(final P8 p) { - return new V8(P.lazy(p::_1), - V7.p(new P7() { - public A _1() { - return p._2(); - } + return new V8<>(P.lazy(p::_1), + V7.p(new P7() { + public A _1() { + return p._2(); + } - public A _2() { - return p._3(); - } + public A _2() { + return p._3(); + } - public A _3() { - return p._4(); - } + public A _3() { + return p._4(); + } - public A _4() { - return p._5(); - } + public A _4() { + return p._5(); + } - public A _5() { - return p._6(); - } + public A _5() { + return p._6(); + } - public A _6() { - return p._7(); - } + public A _6() { + return p._7(); + } - public A _7() { - return p._8(); - } - })); + public A _7() { + return p._8(); + } + })); } /** @@ -70,7 +70,7 @@ public A _7() { * @return The new vector. */ public static V8 cons(final P1 head, final V7 tail) { - return new V8(head, tail); + return new V8<>(head, tail); } /** @@ -248,7 +248,7 @@ public Array toArray() { * @return A new vector after the given function has been applied to each element. */ public V8 map(final F f) { - return new V8(head.map(f), tail.map(f)); + return new V8<>(head.map(f), tail.map(f)); } /** @@ -258,7 +258,7 @@ public V8 map(final F f) { * @return A new vector after zipping the given vector of functions over this vector. */ public V8 apply(final V8> vf) { - return new V8(head.apply(vf.head()), tail.apply(vf.tail())); + return new V8<>(head.apply(vf.head()), tail.apply(vf.tail())); } /** diff --git a/core/src/main/java/fj/function/Visitor.java b/core/src/main/java/fj/function/Visitor.java index 0f8c3846..bdca3b5e 100644 --- a/core/src/main/java/fj/function/Visitor.java +++ b/core/src/main/java/fj/function/Visitor.java @@ -42,7 +42,7 @@ public static X findFirst(final List> values, final F0 def) { * @return The first non-null value in the given list of optional values. If none is found return the given default value. */ public static X nullablefindFirst(final List values, final F0 def) { - return findFirst(values.map(Option.fromNull()), def); + return findFirst(values.map(Option.fromNull()), def); } /** @@ -56,7 +56,7 @@ public static X nullablefindFirst(final List values, final F0 def) { * given default. */ public static B visitor(final List>> visitors, final F0 def, final A value) { - return findFirst(visitors.map(Function.>apply(value)), def); + return findFirst(visitors.map(Function.apply(value)), def); } /** @@ -70,7 +70,7 @@ public static B visitor(final List>> visitors, final F0 * given default. */ public static B nullableVisitor(final List> visitors, final F0 def, final A value) { - return visitor(visitors.map(k -> compose(Option.fromNull(), k)), def, value); + return visitor(visitors.map(k -> compose(Option.fromNull(), k)), def, value); } /** diff --git a/core/src/main/java/fj/parser/Parser.java b/core/src/main/java/fj/parser/Parser.java index 605125f0..3ea6dd15 100644 --- a/core/src/main/java/fj/parser/Parser.java +++ b/core/src/main/java/fj/parser/Parser.java @@ -210,7 +210,7 @@ public Parser sequence(final Parser p) { * @return A new parser after function application. */ public Parser apply(final Parser, E> p) { - return p.bind((F, Parser>) this::map); + return p.bind(this::map); } /** @@ -265,8 +265,8 @@ public Parser or(final Parser alt, final Semigroup s) { */ public Parser not(final F0 e) { return parser(i -> parse(i).isFail() ? - Validation.>success(result(i, unit())) : - Validation.>fail(e.f())); + Validation.success(result(i, unit())) : + Validation.fail(e.f())); } /** @@ -285,7 +285,7 @@ public Parser not(final E e) { * @return A parser that repeats application of this parser zero or many times. */ public Parser, E> repeat() { - return repeat1().or(() -> value(Stream.nil())); + return repeat1().or(() -> value(Stream.nil())); } /** @@ -345,7 +345,7 @@ public static Parser fail(final E e) { */ public static Parser, E> sequence(final List> ps) { return ps.isEmpty() ? - Parser., E>value(List.nil()) : + Parser.value(List.nil()) : ps.head().bind(a -> sequence(ps.tail()).map(cons_(a))); } @@ -365,8 +365,8 @@ private StreamParser() { */ public static Parser, I, E> element(final F0 e) { return parser(is -> is.isEmpty() ? - Validation., I>>fail(e.f()) : - Validation., I>>success(result(is.tail()._1(), is.head()))); + Validation.fail(e.f()) : + Validation.success(result(is.tail()._1(), is.head()))); } /** @@ -390,8 +390,8 @@ public static Parser, I, E> element(final E e) { public static Parser, I, E> satisfy(final F0 missing, final F sat, final F f) { return StreamParser.element(missing).bind(x -> f.f(x) ? - Parser., I, E>value(x) : - Parser., I, E>fail(sat.f(x))); + Parser.value(x) : + Parser.fail(sat.f(x))); } /** @@ -470,8 +470,8 @@ public static Parser, Character, E> character(final E miss */ public static Parser, Stream, E> characters(final F0 missing, final int n) { return n <= 0 ? - Parser., Stream, E>value(Stream.nil()) : - character(missing).bind(characters(missing, n - 1), Stream.cons_()); + Parser.value(Stream.nil()) : + character(missing).bind(characters(missing, n - 1), Stream.cons_()); } /** @@ -497,8 +497,8 @@ public static Parser, Stream, E> characters(fin final F sat, final Stream cs) { return cs.isEmpty() ? - Parser., Stream, E>value(Stream.nil()) : - character(missing, sat, cs.head()).bind(characters(missing, sat, cs.tail()._1()), Stream.cons_()); + Parser.value(Stream.nil()) : + character(missing, sat, cs.head()).bind(characters(missing, sat, cs.tail()._1()), Stream.cons_()); } /** diff --git a/core/src/main/java/fj/parser/Result.java b/core/src/main/java/fj/parser/Result.java index 8f5a4b78..51e115f6 100644 --- a/core/src/main/java/fj/parser/Result.java +++ b/core/src/main/java/fj/parser/Result.java @@ -133,7 +133,7 @@ public void remove() { * @return A result with the given remainder of the parse input and parse value. */ public static Result result(final I i, final A a) { - return new Result(i, a); + return new Result<>(i, a); } /** diff --git a/demo/src/main/java/fj/demo/ChequeWrite.java b/demo/src/main/java/fj/demo/ChequeWrite.java index ee958fc9..6e28153c 100644 --- a/demo/src/main/java/fj/demo/ChequeWrite.java +++ b/demo/src/main/java/fj/demo/ChequeWrite.java @@ -24,7 +24,7 @@ public final class ChequeWrite { private ChequeWrite() {} static List toZero(final int from) { - return unfold(i -> i < 0 ? Option.>none() : some(p(i, i - 1)), from); + return unfold(i -> i < 0 ? Option.none() : some(p(i, i - 1)), from); } static int signum(final int i) { @@ -60,9 +60,9 @@ static List show(final List cs) { : stringShow.showl( list("twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety").index( d1 - '0' - 2)) - .append(d2 == '0' ? List.nil() : show(d2).cons('-')) + .append(d2 == '0' ? List.nil() : show(d2).cons('-')) : d1 == '0' && d2 == '0' && d2r.head() == '0' - ? List.nil() + ? List.nil() : d1 == '0' ? show(list(d2, d2r.head())) : d2 == '0' && d2r.head() == '0' @@ -76,7 +76,7 @@ static List, Integer>> split(final List as) { final int len = as.length(); final List> ds = as.zip(toZero(len - 1)).foldRight((ki, z) -> - ki._2() % 3 == 0 ? z.conss(single(ki._1())) : z.tail().conss(z.head().cons(ki._1())), List.>nil() + ki._2() % 3 == 0 ? z.conss(single(ki._1())) : z.tail().conss(z.head().cons(ki._1())), List.nil() ); return ds.zip(toZero(len / 3 + signum(len % 3) - 1)); } @@ -106,7 +106,7 @@ static boolean eq(final List a, final List b) { if (cs.isEmpty()) return fromString("zero dollars"); else { - final List.Buffer> x = new List.Buffer>(); + final List.Buffer> x = new List.Buffer<>(); final List, Integer>> k = split(cs); final int c = k.head()._2(); diff --git a/demo/src/main/java/fj/demo/Comonad_example.java b/demo/src/main/java/fj/demo/Comonad_example.java index 9a64c34e..8d5bc683 100644 --- a/demo/src/main/java/fj/demo/Comonad_example.java +++ b/demo/src/main/java/fj/demo/Comonad_example.java @@ -22,11 +22,11 @@ public static void main(final String[] args) { } public static Stream> perms(final Stream s) { - Stream> r = single(Stream.nil()); + Stream> r = single(Stream.nil()); for (final Zipper z : fromStream(s)) r = join(z.cobind(zp -> perms(zp.lefts().reverse().append(zp.rights())).map( - F1Functions.o(Stream.cons().f(zp.focus()), P.>p1()) + F1Functions.o(Stream.cons().f(zp.focus()), P.p1()) ) ).toStream()); return r; diff --git a/demo/src/main/java/fj/demo/Option_bind.java b/demo/src/main/java/fj/demo/Option_bind.java index d02a1493..edf3dd83 100644 --- a/demo/src/main/java/fj/demo/Option_bind.java +++ b/demo/src/main/java/fj/demo/Option_bind.java @@ -18,9 +18,9 @@ public static void main(final String[] args) { final Option o5 = o2.bind(f); final Option o6 = o3.bind(f); - final Option p1 = o1.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); - final Option p2 = o2.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); - final Option p3 = o3.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); + final Option p1 = o1.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); + final Option p2 = o2.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); + final Option p3 = o3.bind(i -> i % 2 == 0 ? some(i * 3) : Option.none()); optionShow(intShow).println(o4); // None optionShow(intShow).println(o5); // Some(24) diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index 167a08f5..56763ce5 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -75,7 +75,7 @@ VendingMachine next(Input i) { } static State simulate(List list) { - return list.foldLeft((s, i) -> s.map(m -> m.next(i)), State.init()); + return list.foldLeft((s, i) -> s.map(m -> m.next(i)), State.init()); } static void test() { diff --git a/demo/src/main/java/fj/demo/concurrent/Fibs.java b/demo/src/main/java/fj/demo/concurrent/Fibs.java index 5e95e597..e2e94fc8 100644 --- a/demo/src/main/java/fj/demo/concurrent/Fibs.java +++ b/demo/src/main/java/fj/demo/concurrent/Fibs.java @@ -52,7 +52,7 @@ public static void main(final String[] args) {return n < CUTOFF ? promise(su, P.p(seqFib(n))) : f(n - 1).bind(f(n - 2), add);}}; System.out.println("Calculating Fibonacci sequence in parallel..."); - join(su, spi.parMap(fib, range(0, 46)).map(Promise.sequence(su))).to(out);} + join(su, spi.parMap(fib, range(0, 46)).map(Promise.sequence(su))).to(out);} // The sequential version of the recursive Fibonacci function public static int seqFib(final int n) diff --git a/demo/src/main/java/fj/demo/concurrent/MapReduce.java b/demo/src/main/java/fj/demo/concurrent/MapReduce.java index 57a59d9e..3cb2d761 100644 --- a/demo/src/main/java/fj/demo/concurrent/MapReduce.java +++ b/demo/src/main/java/fj/demo/concurrent/MapReduce.java @@ -64,7 +64,7 @@ public Stream f(final BufferedReader reader) { })); final ExecutorService pool = newFixedThreadPool(16); - final ParModule m = parModule(Strategy.executorStrategy(pool)); + final ParModule m = parModule(Strategy.executorStrategy(pool)); System.out.println("Word Count: " + countWords(documents, m).claim()); diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index dbbd035c..203b8feb 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -56,7 +56,7 @@ private static Map update(Map map, K key, F valueFuncti private static final F> fileNameToWordsAndCountsWithCharChunkIteratee = fileName -> { try { - return IOFunctions.enumFileCharChunks(new File(fileName), Option.none(), wordCountsFromCharChunks()).run().run(); + return IOFunctions.enumFileCharChunks(new File(fileName), Option.none(), wordCountsFromCharChunks()).run().run(); } catch (final IOException e) { throw new RuntimeException(e); } @@ -64,7 +64,7 @@ private static Map update(Map map, K key, F valueFuncti private static final F> fileNameToWordsAndCountsWithCharChunk2Iteratee = fileName -> { try { - return IOFunctions.enumFileChars(new File(fileName), Option. none(), wordCountsFromChars()).run().run(); + return IOFunctions.enumFileChars(new File(fileName), Option.none(), wordCountsFromChars()).run().run(); } catch (final IOException e) { throw new RuntimeException(e); } @@ -72,7 +72,7 @@ private static Map update(Map map, K key, F valueFuncti private static final F> fileNameToWordsAndCountsWithCharIteratee = fileName -> { try { - return IOFunctions.enumFileChars(new File(fileName), Option. none(), wordCountsFromChars()).run().run(); + return IOFunctions.enumFileChars(new File(fileName), Option.none(), wordCountsFromChars()).run().run(); } catch (final IOException e) { throw new RuntimeException(e); } @@ -115,9 +115,9 @@ public F>> _1() { final StringBuilder sb = acc._1(); if(sb.length() > 0) { final Map map = update(acc._2(), sb.toString(), addOne, Integer.valueOf(0)); - return IterV.done(map, Input.eof()); + return IterV.done(map, Input.eof()); } - return IterV.done(acc._2(), Input.eof()); + return IterV.done(acc._2(), Input.eof()); }); return s -> s.apply(empty, el, eof); @@ -157,9 +157,9 @@ public F, IterV>> f(final P2 0) { final Map map = update(acc._2(), sb.toString(), addOne, Integer.valueOf(0)); - return IterV.done(map, Input.eof()); + return IterV.done(map, Input.eof()); } - return IterV.done(acc._2(), Input.eof()); + return IterV.done(acc._2(), Input.eof()); } ); return s -> s.apply(empty, el, eof); @@ -268,7 +268,7 @@ private static void print(Map wordsAndCountsFromFiles) { private static P2, Map> writeSampleFiles( int numFiles, int numSharedWords) throws IOException { - final Map expectedWordsAndCounts = new HashMap(); + final Map expectedWordsAndCounts = new HashMap<>(); List fileNames = nil(); for(int i = 0; i < numFiles; i++) { final File file = File.createTempFile("wordcount-"+ i + "-", ".txt"); @@ -294,7 +294,7 @@ public static Map getWordsAndCountsFromFilesWithIteratee(final public static Map getWordsAndCountsFromFilesInParallel( final List fileNames, final F> fileNameToWordsAndCounts, int numThreads) { final ExecutorService pool = newFixedThreadPool(numThreads); - final ParModule m = parModule(Strategy. executorStrategy(pool)); + final ParModule m = parModule(Strategy.executorStrategy(pool)); // Long wordCount = countWords(fileNames.map(readFile), m).claim(); final Map result = getWordsAndCountsFromFiles(fileNames, fileNameToWordsAndCounts, m).claim(); @@ -315,7 +315,7 @@ public static Promise> getWordsAndCountsFromFiles( } private static Map plus(Map a, Map b) { - final Map result = new HashMap(a); + final Map result = new HashMap<>(a); for(Map.Entry entry : b.entrySet()) { final Integer num = result.get(entry.getKey()); result.put(entry.getKey(), num != null ? num.intValue() + entry.getValue() : entry.getValue()); diff --git a/demo/src/main/java/fj/demo/test/JavaLinkedList.java b/demo/src/main/java/fj/demo/test/JavaLinkedList.java index 5ce11fba..ba8ec1f1 100644 --- a/demo/src/main/java/fj/demo/test/JavaLinkedList.java +++ b/demo/src/main/java/fj/demo/test/JavaLinkedList.java @@ -17,7 +17,7 @@ public final class JavaLinkedList { public static void main(final String[] args) { final Property p = property(arbLinkedList(arbInteger), arbLinkedList(arbInteger), (x, y) -> { - final LinkedList xy = new LinkedList(x); + final LinkedList xy = new LinkedList<>(x); xy.addAll(y); return prop(xy.size() == x.size() + y.size()); }); diff --git a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java index 8ed7a306..6f17f827 100644 --- a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java +++ b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java @@ -40,7 +40,7 @@ For any list, mapping the identity function (\x -> x) produces the same list. @SuppressWarnings("PackageVisibleField") @CheckParams(minSuccessful = 1000) public final class ListFunctorLaws { - final Property identity = property(arbList(arbString), x -> prop(listEqual(stringEqual).eq(x, x.map(Function.identity())))); + final Property identity = property(arbList(arbString), x -> prop(listEqual(stringEqual).eq(x, x.map(Function.identity())))); final Property composition = property(arbF(coarbInteger, arbString), arbF(coarbLong, arbInteger), arbList(arbLong), (f, g, x) -> { final List s1 = x.map(compose(f, g)); diff --git a/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java b/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java index 18d1b5d7..5e5550a3 100644 --- a/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java +++ b/demo/src/main/java/fj/demo/test/OptionMonadFunctorLaw.java @@ -19,7 +19,7 @@ For any Option (o) and any function (f), then calling flatMap on o with a */ public final class OptionMonadFunctorLaw { public static void main(final String[] args) { - final Property unitMap = property(arbOption(arbInteger), Arbitrary.arbFInvariant(arbString), (o, f) -> prop(optionEqual(stringEqual).eq(o.bind(andThen(f, Option.some_())), o.map(f)))); + final Property unitMap = property(arbOption(arbInteger), Arbitrary.arbFInvariant(arbString), (o, f) -> prop(optionEqual(stringEqual).eq(o.bind(andThen(f, Option.some_())), o.map(f)))); summary.println(unitMap.minSuccessful(500)); // OK, passed 500 tests. } } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index a9f05549..848585aa 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -97,7 +97,7 @@ private Arbitrary(final Gen gen) { * @return A new arbitrary that uses the given generator. */ public static Arbitrary arbitrary(final Gen g) { - return new Arbitrary(g); + return new Arbitrary<>(g); } /** @@ -140,7 +140,7 @@ public static Arbitrary arbLcgRng() { * @return An arbitrary for functions. */ public static Arbitrary> arbFInvariant(final Arbitrary a) { - return arbitrary(a.gen.map(Function.constant())); + return arbitrary(a.gen.map(Function.constant())); } /** @@ -153,7 +153,7 @@ public static Arbitrary> arbFInvariant(final Arbitrary a) { */ public static Arbitrary> arbF2(final Coarbitrary ca, final Coarbitrary cb, final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, a)).gen.map(Function.uncurryF2())); + return arbitrary(arbF(ca, arbF(cb, a)).gen.map(Function.uncurryF2())); } /** @@ -164,7 +164,7 @@ public static Arbitrary> arbF2(final Coarbitrary ca, fi */ public static Arbitrary> arbF2Invariant(final Arbitrary a) { return arbitrary(a.gen.map( - compose(Function.uncurryF2(), compose(Function.>constant(), Function.constant())))); + compose(Function.uncurryF2(), compose(Function.constant(), Function.constant())))); } /** @@ -178,7 +178,7 @@ public static Arbitrary> arbF2Invariant(final Arbitrary */ public static Arbitrary> arbF3(final Coarbitrary ca, final Coarbitrary cb, final Coarbitrary cc, final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, a))).gen.map(Function.uncurryF3())); + return arbitrary(arbF(ca, arbF(cb, arbF(cc, a))).gen.map(Function.uncurryF3())); } /** @@ -188,10 +188,10 @@ public static Arbitrary> arbF3(final Coarbitrary * @return An arbitrary for function-3. */ public static Arbitrary> arbF3Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF3(), compose(Function.>>constant(), + return arbitrary(a.gen.map(compose(Function.uncurryF3(), compose(Function.constant(), compose( - Function.>constant(), - Function.constant()))))); + Function.constant(), + Function.constant()))))); } /** @@ -207,7 +207,7 @@ public static Arbitrary> arbF3Invariant(final Arbitr public static Arbitrary> arbF4(final Coarbitrary ca, final Coarbitrary cb, final Coarbitrary cc, final Coarbitrary cd, final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, a)))).gen.map(Function.uncurryF4())); + return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, a)))).gen.map(Function.uncurryF4())); } /** @@ -217,11 +217,11 @@ public static Arbitrary> arbF4(final Coarbitra * @return An arbitrary for function-4. */ public static Arbitrary> arbF4Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF4(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant())))))); + return arbitrary(a.gen.map(compose(Function.uncurryF4(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + Function.constant())))))); } /** @@ -242,7 +242,7 @@ public static Arbitrary> arbF4Invariant(final final Coarbitrary ce, final Arbitrary a) { return arbitrary( - arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, a))))).gen.map(Function.uncurryF5())); + arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, a))))).gen.map(Function.uncurryF5())); } /** @@ -252,12 +252,12 @@ public static Arbitrary> arbF4Invariant(final * @return An arbitrary for function-5. */ public static Arbitrary> arbF5Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF5(), - compose(Function.>>>>constant(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant()))))))); + return arbitrary(a.gen.map(compose(Function.uncurryF5(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + Function.constant()))))))); } /** @@ -280,7 +280,7 @@ public static Arbitrary> arbF4Invariant(final final Coarbitrary cf, final Arbitrary a) { return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, a)))))).gen.map( - Function.uncurryF6())); + Function.uncurryF6())); } /** @@ -291,12 +291,12 @@ public static Arbitrary> arbF4Invariant(final */ public static Arbitrary> arbF6Invariant(final Arbitrary a) { return arbitrary(a.gen.map(compose(Function.uncurryF6(), - compose(Function.>>>>>constant(), - compose(Function.>>>>constant(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant())))))))); + compose(Function.>>>>>constant(), + compose(Function.>>>>constant(), + compose(Function.>>>constant(), + compose(Function.>>constant(), + compose(Function.>constant(), + Function.constant())))))))); } /** @@ -321,7 +321,7 @@ public static Arbitrary> arbF4Invariant(final final Coarbitrary cg, final Arbitrary a) { return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, a))))))).gen.map( - Function.uncurryF7())); + Function.uncurryF7())); } /** @@ -332,13 +332,13 @@ public static Arbitrary> arbF4Invariant(final */ public static Arbitrary> arbF7Invariant(final Arbitrary a) { return arbitrary(a.gen.map(compose(Function.uncurryF7(), - compose(Function.>>>>>>constant(), - compose(Function.>>>>>constant(), - compose(Function.>>>>constant(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant()))))))))); + compose(Function.>>>>>>constant(), + compose(Function.>>>>>constant(), + compose(Function.>>>>constant(), + compose(Function.>>>constant(), + compose(Function.>>constant(), + compose(Function.>constant(), + Function.constant()))))))))); } /** @@ -365,7 +365,7 @@ public static Arbitrary> arbF4Invariant(final final Coarbitrary ch, final Arbitrary a) { return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, arbF(ch, a)))))))).gen.map( - Function.uncurryF8())); + Function.uncurryF8())); } /** @@ -377,16 +377,16 @@ public static Arbitrary> arbF4Invariant(final public static Arbitrary> arbF8Invariant( final Arbitrary a) { return arbitrary(a.gen.map(compose(Function.uncurryF8(), - compose(Function.>>>>>>>constant(), - compose(Function.>>>>>>constant(), - compose(Function.>>>>>constant(), - compose( - Function.>>>>constant(), - compose(Function.>>>constant(), - compose( - Function.>>constant(), - compose(Function.>constant(), - Function.constant())))))))))); + compose(Function.>>>>>>>constant(), + compose(Function.>>>>>>constant(), + compose(Function.>>>>>constant(), + compose( + Function.>>>>constant(), + compose(Function.>>>constant(), + compose( + Function.>>constant(), + compose(Function.>constant(), + Function.constant())))))))))); } /** @@ -619,7 +619,7 @@ public static Arbitrary> arbGen(final Arbitrary aa) { */ public static Arbitrary> arbOption(final Arbitrary aa) { return arbitrary(sized(i -> i == 0 ? - value(Option.none()) : + value(Option.none()) : aa.gen.map(Option::some).resize(i - 1))); } @@ -695,7 +695,7 @@ public static Arbitrary> arbValidation(final Arbitrary Arbitrary> arbStream(final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(List::toStream)); + return arbitrary(arbList(aa).gen.map(List::toStream)); } /** @@ -753,7 +753,7 @@ public static Arbitrary arbThrowable(final Arbitrary as) { * @return An arbitrary implementation for array lists. */ public static Arbitrary> arbArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new ArrayList(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new ArrayList<>(a.toCollection()))); } /** @@ -842,7 +842,7 @@ public static Arbitrary> arbHashMap(final Arbitrary ak, * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new HashSet(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new HashSet<>(a.toCollection()))); } /** @@ -856,7 +856,7 @@ public static Arbitrary> arbHashSet(final Arbitrary aa) { */ public static Arbitrary> arbHashtable(final Arbitrary ak, final Arbitrary av) { return arbitrary(arbList(ak).gen.bind(arbList(av).gen, ks -> vs -> { - final Hashtable t = new Hashtable(); + final Hashtable t = new Hashtable<>(); ks.zip(vs).foreachDoEffect(kv -> t.put(kv._1(), kv._2())); @@ -898,7 +898,7 @@ public static Arbitrary> arbLinkedHashMap(final Arbit * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbLinkedHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet<>(a.toCollection()))); } /** @@ -908,7 +908,7 @@ public static Arbitrary> arbLinkedHashSet(final Arbitrary Arbitrary> arbLinkedList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedList(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedList<>(a.toCollection()))); } /** @@ -918,7 +918,7 @@ public static Arbitrary> arbLinkedList(final Arbitrary aa) * @return An arbitrary implementation for priority queues. */ public static Arbitrary> arbPriorityQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue<>(a.toCollection()))); } /** @@ -943,7 +943,7 @@ public static Arbitrary> arbPriorityQueue(final Arbitrary Arbitrary> arbStack(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.map(a -> { - final Stack s = new Stack(); + final Stack s = new Stack<>(); s.addAll(a.toCollection()); return s; })); @@ -1005,7 +1005,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb * @return An arbitrary implementation for tree sets. */ public static Arbitrary> arbTreeSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new TreeSet(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new TreeSet<>(a.toCollection()))); } /** @@ -1016,7 +1016,7 @@ public static Arbitrary> arbTreeSet(final Arbitrary aa) { */ @SuppressWarnings("UseOfObsoleteCollectionType") public static Arbitrary> arbVector(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new Vector(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new Vector<>(a.toCollection()))); } /** @@ -1071,7 +1071,7 @@ public static Arbitrary> arbConcurrentHashMap(fin * @return An arbitrary implementation for concurrent linked queues. */ public static Arbitrary> arbConcurrentLinkedQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue<>(a.toCollection()))); } /** @@ -1082,7 +1082,7 @@ public static Arbitrary> arbConcurrentLinkedQueue(f * @return An arbitrary implementation for copy-on-write array lists. */ public static Arbitrary> arbCopyOnWriteArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList<>(a.toCollection()))); } /** @@ -1093,7 +1093,7 @@ public static Arbitrary> arbCopyOnWriteArrayList(fin * @return An arbitrary implementation for copy-on-write array sets. */ public static Arbitrary> arbCopyOnWriteArraySet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet<>(a.toCollection()))); } /** @@ -1103,7 +1103,7 @@ public static Arbitrary> arbCopyOnWriteArraySet(final * @return An arbitrary implementation for delay queues. */ public static Arbitrary> arbDelayQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue<>(a.toCollection()))); } /** @@ -1114,7 +1114,7 @@ public static Arbitrary> arbDelayQueue(final A * @return An arbitrary implementation for linked blocking queues. */ public static Arbitrary> arbLinkedBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue<>(a.toCollection()))); } /** @@ -1125,7 +1125,7 @@ public static Arbitrary> arbLinkedBlockingQueue(final * @return An arbitrary implementation for priority blocking queues. */ public static Arbitrary> arbPriorityBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue<>(a.toCollection()))); } /** @@ -1137,7 +1137,7 @@ public static Arbitrary> arbPriorityBlockingQueue(f */ public static Arbitrary> arbSynchronousQueue(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.bind(arbBoolean.gen, a -> fair -> { - final SynchronousQueue q = new SynchronousQueue(fair); + final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(a.toCollection()); return q; })); diff --git a/quickcheck/src/main/java/fj/test/Arg.java b/quickcheck/src/main/java/fj/test/Arg.java index 337f8027..4187c15d 100644 --- a/quickcheck/src/main/java/fj/test/Arg.java +++ b/quickcheck/src/main/java/fj/test/Arg.java @@ -28,7 +28,7 @@ private Arg(final T value, final int shrinks) { * @return A new argument. */ public static Arg arg(final T value, final int shrinks) { - return new Arg(value, shrinks); + return new Arg<>(value, shrinks); } /** diff --git a/quickcheck/src/main/java/fj/test/CheckResult.java b/quickcheck/src/main/java/fj/test/CheckResult.java index dc0195d7..718daf03 100644 --- a/quickcheck/src/main/java/fj/test/CheckResult.java +++ b/quickcheck/src/main/java/fj/test/CheckResult.java @@ -55,7 +55,7 @@ private CheckResult(final R r, final Option>> args, final Option>>none(), Option.none(), succeeded, discarded); + return new CheckResult(R.Passed, Option.none(), Option.none(), succeeded, discarded); } /** @@ -67,7 +67,7 @@ public static CheckResult passed(final int succeeded, final int discarded) { * @return A result that the property has been proven. */ public static CheckResult proven(final List> args, final int succeeded, final int discarded) { - return new CheckResult(R.Proven, some(args), Option.none(), succeeded, discarded); + return new CheckResult(R.Proven, some(args), Option.none(), succeeded, discarded); } /** @@ -79,7 +79,7 @@ public static CheckResult proven(final List> args, final int succeeded, f * @return A result that the property has been falsified. */ public static CheckResult falsified(final List> args, final int succeeded, final int discarded) { - return new CheckResult(R.Falsified, some(args), Option.none(), succeeded, discarded); + return new CheckResult(R.Falsified, some(args), Option.none(), succeeded, discarded); } /** @@ -90,7 +90,7 @@ public static CheckResult falsified(final List> args, final int succeeded * @return A result that the property has been exhausted in checking. */ public static CheckResult exhausted(final int succeeded, final int discarded) { - return new CheckResult(R.Exhausted, Option.>>none(), Option.none(), succeeded, discarded); + return new CheckResult(R.Exhausted, Option.none(), Option.none(), succeeded, discarded); } /** @@ -117,7 +117,7 @@ public static CheckResult propException(final List> args, final Throwable * @return A result that generating values to check the property threw an exception. */ public static CheckResult genException(final Throwable ex, final int succeeded, final int discarded) { - return new CheckResult(R.GenException, Option.>>none(), some(ex), succeeded, discarded); + return new CheckResult(R.GenException, Option.none(), some(ex), succeeded, discarded); } /** diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index 9655aec2..cd519513 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -574,7 +574,7 @@ public static , V> Coarbitrary> coarbEnumMap(fin return new Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final EnumMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -589,7 +589,7 @@ public static > Coarbitrary> coarbEnumSet(final Coa return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final EnumSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet(as), g); + return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); } }; } @@ -614,7 +614,7 @@ public static Coarbitrary> coarbHashMap(final Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final HashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -668,7 +668,7 @@ public static Coarbitrary> coarbIdentityHashMap(fin return new Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final IdentityHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -685,7 +685,7 @@ public static Coarbitrary> coarbLinkedHashMap(final C return new Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final LinkedHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -700,7 +700,7 @@ public static Coarbitrary> coarbLinkedHashSet(final Coarbit return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedHashSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet(as), g); + return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); } }; } @@ -741,7 +741,7 @@ public Gen coarbitrary(final PriorityQueue as, final Gen g) { public static final Coarbitrary coarbProperties = new Coarbitrary() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final Properties p, final Gen g) { - final Hashtable t = new Hashtable(); + final Hashtable t = new Hashtable<>(); for (final Object s : p.keySet()) { t.put((String) s, p.getProperty((String) s)); @@ -777,7 +777,7 @@ public static Coarbitrary> coarbTreeMap(final Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final TreeMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -792,7 +792,7 @@ public static Coarbitrary> coarbTreeSet(final Coarbitrary c) { return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final TreeSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet(as), g); + return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); } }; } @@ -824,7 +824,7 @@ public static Coarbitrary> coarbWeakHashMap(final Coarb return new Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final WeakHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } @@ -860,7 +860,7 @@ public static Coarbitrary> coarbConcurrentHashMap return new Coarbitrary>() { @SuppressWarnings("UseOfObsoleteCollectionType") public Gen coarbitrary(final ConcurrentHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable(m), g); + return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); } }; } diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 45a4429a..0ffed76a 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -110,7 +110,7 @@ public A gen(final int i, final Rand r) { * @return A new generator after applying the mapping function. */ public Gen map(final F f) { - return new Gen(i -> r -> f.f(gen(i, r))); + return new Gen<>(i -> r -> f.f(gen(i, r))); } /** @@ -161,7 +161,7 @@ public void foreachDoEffect(final Integer i, final Rand r, final Effect1 f) { * @return A new generator after binding the given function. */ public Gen bind(final F> f) { - return new Gen(i -> r -> f.f(gen(i, r)).f.f(i).f(r)); + return new Gen<>(i -> r -> f.f(gen(i, r)).f.f(i).f(r)); } /** @@ -286,7 +286,7 @@ public Gen apply(final Gen> gf) { * @return A new generator that uses the given size. */ public Gen resize(final int s) { - return new Gen(i -> r -> f.f(s).f(r)); + return new Gen<>(i -> r -> f.f(s).f(r)); } /** @@ -296,7 +296,7 @@ public Gen resize(final int s) { * @return A new generator that uses the given function. */ public static Gen gen(final F> f) { - return new Gen(f); + return new Gen<>(f); } /** @@ -328,7 +328,7 @@ public static Gen> sequenceN(final int n, final Gen g) { * @return A new generator. */ public static Gen parameterised(final F>> f) { - return new Gen(curry((i, r) -> f.f(i).f(r).gen(i, r))); + return new Gen<>(curry((i, r) -> f.f(i).f(r).gen(i, r))); } /** @@ -338,7 +338,7 @@ public static Gen parameterised(final F>> f) { * @return A new generator. */ public static Gen sized(final F> f) { - return parameterised(flip(Function.>>constant(f))); + return parameterised(flip(Function.constant(f))); } /** @@ -348,7 +348,7 @@ public static Gen sized(final F> f) { * @return A generator that always produces the given value. */ public static Gen value(final A a) { - return new Gen(i -> r -> a); + return new Gen<>(i -> r -> a); } /** @@ -383,7 +383,7 @@ public static Gen choose(final double from, final double to) { * @return A generator that never returns a value. */ public static Gen fail() { - return new Gen(i -> r -> { + return new Gen<>(i -> r -> { throw error("Failing generator"); }); } @@ -395,7 +395,7 @@ public static Gen fail() { * @return A new generator after joining the given generator. */ public static Gen join(final Gen> g) { - return g.bind(Function.>identity()); + return g.bind(Function.identity()); } /** @@ -443,7 +443,7 @@ public static Gen elemFrequency(final List> as) { */ @SafeVarargs public static Gen elements(final A... as) { - return array(as).isEmpty() ? Gen.fail() : choose(0, as.length - 1).map(i -> as[i]); + return array(as).isEmpty() ? Gen.fail() : choose(0, as.length - 1).map(i -> as[i]); } /** @@ -455,7 +455,7 @@ public static Gen elements(final A... as) { * requests. */ public static Gen oneOf(final List> gs) { - return gs.isEmpty() ? Gen.fail() : choose(0, gs.length() - 1).bind(gs::index); + return gs.isEmpty() ? Gen.fail() : choose(0, gs.length() - 1).bind(gs::index); } /** @@ -723,6 +723,6 @@ public static Gen> someWordOf(int maxLength, List as) { * @return A generator for functions. */ public static Gen> promote(final F> f) { - return new Gen>(i -> r -> a -> f.f(a).f.f(i).f(r)); + return new Gen<>(i -> r -> a -> f.f(a).f.f(i).f(r)); } } diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index d69d0c65..274a7453 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -368,7 +368,7 @@ public static Property prop(final Result r) { * otherwise. */ public static Property prop(final boolean b) { - return b ? prop(Result.proven(List.>nil())) : prop(Result.falsified(List.>nil())); + return b ? prop(Result.proven(List.nil())) : prop(Result.falsified(List.nil())); } /** @@ -471,7 +471,7 @@ public static Property property(final Arbitrary aa, final Shrink sa, f * application of its arguments. */ public static Property propertyP(final Arbitrary aa, final F> f) { - return propertyP(aa, Shrink.empty(), f); + return propertyP(aa, Shrink.empty(), f); } /** @@ -521,7 +521,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F> f) { - return propertyP(aa, ab, sa, sb, compose2(P.p1(), f)); + return propertyP(aa, ab, sa, sb, compose2(P.p1(), f)); } /** @@ -549,7 +549,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final F> f) { - return propertyP(aa, ab, compose2(P.p1(), f)); + return propertyP(aa, ab, compose2(P.p1(), f)); } /** @@ -581,7 +581,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F2 f) { - return propertyP(aa, ab, sa, sb, compose2(P.p1(), curry(f))); + return propertyP(aa, ab, sa, sb, compose2(P.p1(), curry(f))); } /** @@ -609,7 +609,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final F2 f) { - return propertyP(aa, ab, compose2(P.p1(), curry(f))); + return propertyP(aa, ab, compose2(P.p1(), curry(f))); } /** @@ -1320,7 +1320,7 @@ public static Property exception(final F0 p) { try { return p.f(); } catch (final Throwable t) { - return new Property(i -> r -> Result.exception(List.>nil(), t)); + return new Property(i -> r -> Result.exception(List.nil(), t)); } } diff --git a/quickcheck/src/main/java/fj/test/Rand.java b/quickcheck/src/main/java/fj/test/Rand.java index 567dba77..97f94596 100644 --- a/quickcheck/src/main/java/fj/test/Rand.java +++ b/quickcheck/src/main/java/fj/test/Rand.java @@ -52,7 +52,7 @@ public int choose(final long seed, final int from, final int to) { * @return A random value in the given range. */ public int choose(final int from, final int to) { - return f.f(Option.none()).f(from).f(to); + return f.f(Option.none()).f(from).f(to); } /** @@ -75,7 +75,7 @@ public double choose(final long seed, final double from, final double to) { * @return A random value in the given range. */ public double choose(final double from, final double to) { - return g.f(Option.none()).f(from).f(to); + return g.f(Option.none()).f(from).f(to); } /** diff --git a/quickcheck/src/main/java/fj/test/Result.java b/quickcheck/src/main/java/fj/test/Result.java index 467e2ae2..8ad743bb 100644 --- a/quickcheck/src/main/java/fj/test/Result.java +++ b/quickcheck/src/main/java/fj/test/Result.java @@ -165,7 +165,7 @@ public static Result noResult(final Option r) { * @return A result representing no result. */ public static Result noResult() { - return new Result(Option.>>none(), R.NoResult, Option.none()); + return new Result(Option.none(), R.NoResult, Option.none()); } /** @@ -175,7 +175,7 @@ public static Result noResult() { * @return An unfalsified result. */ public static Result unfalsified(final List> args) { - return new Result(some(args), R.Unfalsified, Option.none()); + return new Result(some(args), R.Unfalsified, Option.none()); } /** @@ -185,7 +185,7 @@ public static Result unfalsified(final List> args) { * @return A falsified result. */ public static Result falsified(final List> args) { - return new Result(some(args), R.Falsified, Option.none()); + return new Result(some(args), R.Falsified, Option.none()); } /** @@ -195,7 +195,7 @@ public static Result falsified(final List> args) { * @return A proven result. */ public static Result proven(final List> args) { - return new Result(some(args), R.Proven, Option.none()); + return new Result(some(args), R.Proven, Option.none()); } /** diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 751a1307..46ca3380 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -119,7 +119,7 @@ public Shrink map(final F f, final F g) { * value. */ public static Shrink shrink(final F> f) { - return new Shrink(f); + return new Shrink<>(f); } /** @@ -148,7 +148,7 @@ public static Shrink empty() { * A shrink strategy for booleans using false as the bottom of the shrink. */ public static final Shrink shrinkBoolean = - shrink(Function.>constant(Stream.single(false))); + shrink(Function.constant(Stream.single(false))); /** * A shrink strategy for integers using 0 as the bottom of the shrink. @@ -189,8 +189,8 @@ public static Shrink empty() { */ public static Shrink> shrinkOption(final Shrink sa) { return shrink(o -> o.isNone() ? - Stream.>nil() : - cons(Option.none(), () -> sa.shrink(o.some()).map(Option.some_()))); + Stream.nil() : + cons(Option.none(), () -> sa.shrink(o.some()).map(Option.some_()))); } /** @@ -202,8 +202,8 @@ public static Shrink> shrinkOption(final Shrink sa) { */ public static Shrink> shrinkEither(final Shrink sa, final Shrink sb) { return shrink(e -> e.isLeft() ? - sa.shrink(e.left().value()).map(Either.left_()) : - sb.shrink(e.right().value()).map(Either.right_())); + sa.shrink(e.left().value()).map(Either.left_()) : + sb.shrink(e.right().value()).map(Either.right_())); } /** @@ -218,7 +218,7 @@ Stream> removeChunks(final int n, final List as) { if (as.isEmpty()) return nil(); else if (as.tail().isEmpty()) - return cons(List.nil(), Stream.>nil_()); + return cons(List.nil(), Stream.nil_()); else { final int n1 = n / 2; final int n2 = n - n1; @@ -263,7 +263,7 @@ Stream> shrinkOne(final List as) { * @return A shrink strategy for arrays. */ public static Shrink> shrinkArray(final Shrink sa) { - return shrinkList(sa).map(Conversions.List_Array(), Conversions.Array_List()); + return shrinkList(sa).map(Conversions.List_Array(), Conversions.Array_List()); } /** @@ -273,7 +273,7 @@ public static Shrink> shrinkArray(final Shrink sa) { * @return A shrink strategy for streams. */ public static Shrink> shrinkStream(final Shrink sa) { - return shrinkList(sa).map(Conversions.List_Stream(), Conversions.Stream_List()); + return shrinkList(sa).map(Conversions.List_Stream(), Conversions.Stream_List()); } /** @@ -318,7 +318,7 @@ public static Shrink shrinkThrowable(final Shrink ss) { * @return A shrink strategy for array lists. */ public static Shrink> shrinkArrayList(final Shrink sa) { - return shrinkList(sa).map(Java.List_ArrayList(), Java.ArrayList_List()); + return shrinkList(sa).map(Java.List_ArrayList(), Java.ArrayList_List()); } /** @@ -361,7 +361,7 @@ public static , V> Shrink> shrinkEnumMap(final S * @return A shrink strategy for enum sets. */ public static > Shrink> shrinkEnumSet(final Shrink sa) { - return shrinkList(sa).map(Java.List_EnumSet(), Java.EnumSet_List()); + return shrinkList(sa).map(Java.List_EnumSet(), Java.EnumSet_List()); } /** @@ -392,7 +392,7 @@ public static Shrink> shrinkHashMap(final Shrink sk, fin * @return A shrink strategy for hash sets. */ public static Shrink> shrinkHashSet(final Shrink sa) { - return shrinkList(sa).map(Java.List_HashSet(), Java.HashSet_List()); + return shrinkList(sa).map(Java.List_HashSet(), Java.HashSet_List()); } /** @@ -405,7 +405,7 @@ public static Shrink> shrinkHashSet(final Shrink sa) { @SuppressWarnings("UseOfObsoleteCollectionType") public static Shrink> shrinkHashtable(final Shrink sk, final Shrink sv) { return shrinkList(shrinkP2(sk, sv)).map(kvs -> { - final Hashtable h = new Hashtable(); + final Hashtable h = new Hashtable<>(); kvs.foreachDoEffect(kv -> h.put(kv._1(), kv._2())); return h; }, h -> { @@ -448,7 +448,7 @@ public static Shrink> shrinkLinkedHashMap(final Shrin * @return A shrink strategy for linked hash sets. */ public static Shrink> shrinkLinkedHashSet(final Shrink sa) { - return shrinkList(sa).map(Java.List_LinkedHashSet(), Java.LinkedHashSet_List()); + return shrinkList(sa).map(Java.List_LinkedHashSet(), Java.LinkedHashSet_List()); } /** @@ -458,7 +458,7 @@ public static Shrink> shrinkLinkedHashSet(final Shrink s * @return A shrink strategy for linked lists. */ public static Shrink> shrinkLinkedList(final Shrink sa) { - return shrinkList(sa).map(Java.List_LinkedList(), Java.LinkedList_List()); + return shrinkList(sa).map(Java.List_LinkedList(), Java.LinkedList_List()); } /** @@ -468,7 +468,7 @@ public static Shrink> shrinkLinkedList(final Shrink sa) { * @return A shrink strategy for priority queues. */ public static Shrink> shrinkPriorityQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_PriorityQueue(), Java.PriorityQueue_List()); + return shrinkList(sa).map(Java.List_PriorityQueue(), Java.PriorityQueue_List()); } /** @@ -484,7 +484,7 @@ public static Shrink> shrinkPriorityQueue(final Shrink s return p; }, p -> { - final Hashtable t = new Hashtable(); + final Hashtable t = new Hashtable<>(); for (final Object s : p.keySet()) { t.put((String) s, p.getProperty((String) s)); @@ -500,7 +500,7 @@ public static Shrink> shrinkPriorityQueue(final Shrink s * @return A shrink strategy for stacks. */ public static Shrink> shrinkStack(final Shrink sa) { - return shrinkList(sa).map(Java.List_Stack(), Java.Stack_List()); + return shrinkList(sa).map(Java.List_Stack(), Java.Stack_List()); } /** @@ -521,7 +521,7 @@ public static Shrink> shrinkTreeMap(final Shrink sk, fin * @return A shrink strategy for tree sets. */ public static Shrink> shrinkTreeSet(final Shrink sa) { - return shrinkList(sa).map(Java.List_TreeSet(), Java.TreeSet_List()); + return shrinkList(sa).map(Java.List_TreeSet(), Java.TreeSet_List()); } /** @@ -531,7 +531,7 @@ public static Shrink> shrinkTreeSet(final Shrink sa) { * @return A shrink strategy for vectors. */ public static Shrink> shrinkVector(final Shrink sa) { - return shrinkList(sa).map(Java.List_Vector(), Java.Vector_List()); + return shrinkList(sa).map(Java.List_Vector(), Java.Vector_List()); } /** @@ -556,7 +556,7 @@ public static Shrink> shrinkWeakHashMap(final Shrink * @return A shrink strategy for array blocking queues. */ public static Shrink> shrinkArrayBlockingQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_ArrayBlockingQueue(false), Java.ArrayBlockingQueue_List()); + return shrinkList(sa).map(Java.List_ArrayBlockingQueue(false), Java.ArrayBlockingQueue_List()); } /** @@ -577,7 +577,7 @@ public static Shrink> shrinkConcurrentHashMap(fin * @return A shrink strategy for concurrent linked queues. */ public static Shrink> shrinkConcurrentLinkedQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_ConcurrentLinkedQueue(), Java.ConcurrentLinkedQueue_List()); + return shrinkList(sa).map(Java.List_ConcurrentLinkedQueue(), Java.ConcurrentLinkedQueue_List()); } /** @@ -587,7 +587,7 @@ public static Shrink> shrinkConcurrentLinkedQueue(f * @return A shrink strategy for copy on write array lists. */ public static Shrink> shrinkCopyOnWriteArrayList(final Shrink sa) { - return shrinkList(sa).map(Java.List_CopyOnWriteArrayList(), Java.CopyOnWriteArrayList_List()); + return shrinkList(sa).map(Java.List_CopyOnWriteArrayList(), Java.CopyOnWriteArrayList_List()); } /** @@ -597,7 +597,7 @@ public static Shrink> shrinkCopyOnWriteArrayList(fin * @return A shrink strategy for copy on write array sets. */ public static Shrink> shrinkCopyOnWriteArraySet(final Shrink sa) { - return shrinkList(sa).map(Java.List_CopyOnWriteArraySet(), Java.CopyOnWriteArraySet_List()); + return shrinkList(sa).map(Java.List_CopyOnWriteArraySet(), Java.CopyOnWriteArraySet_List()); } /** @@ -607,7 +607,7 @@ public static Shrink> shrinkCopyOnWriteArraySet(final * @return A shrink strategy for delay queues. */ public static Shrink> shrinkDelayQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_DelayQueue(), Java.DelayQueue_List()); + return shrinkList(sa).map(Java.List_DelayQueue(), Java.DelayQueue_List()); } /** @@ -617,7 +617,7 @@ public static Shrink> shrinkDelayQueue(final S * @return A shrink strategy for linked blocking queues. */ public static Shrink> shrinkLinkedBlockingQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_LinkedBlockingQueue(), Java.LinkedBlockingQueue_List()); + return shrinkList(sa).map(Java.List_LinkedBlockingQueue(), Java.LinkedBlockingQueue_List()); } /** @@ -627,7 +627,7 @@ public static Shrink> shrinkLinkedBlockingQueue(final * @return A shrink strategy for priority blocking queues. */ public static Shrink> shrinkPriorityBlockingQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_PriorityBlockingQueue(), Java.PriorityBlockingQueue_List()); + return shrinkList(sa).map(Java.List_PriorityBlockingQueue(), Java.PriorityBlockingQueue_List()); } /** @@ -637,7 +637,7 @@ public static Shrink> shrinkPriorityBlockingQueue(f * @return A shrink strategy for synchronous queues. */ public static Shrink> shrinkSynchronousQueue(final Shrink sa) { - return shrinkList(sa).map(Java.List_SynchronousQueue(false), Java.SynchronousQueue_List()); + return shrinkList(sa).map(Java.List_SynchronousQueue(false), Java.SynchronousQueue_List()); } // END java.util.concurrent diff --git a/quickcheck/src/main/java/fj/test/Variant.java b/quickcheck/src/main/java/fj/test/Variant.java index f50bf923..a0ef3276 100644 --- a/quickcheck/src/main/java/fj/test/Variant.java +++ b/quickcheck/src/main/java/fj/test/Variant.java @@ -11,7 +11,7 @@ * @version %build.number% */ public final class Variant { - private static final HashMap> variantMemo = new HashMap>(); + private static final HashMap> variantMemo = new HashMap<>(); private static final class LongGen { private final long n; diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index f4da2459..eb865e04 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -264,7 +264,7 @@ private static Array>> properties(f @SuppressWarnings("unchecked") final List bss = somes(list(fromNull(e.getAnnotation(Category.class)).map(p1), fromNull(declaringClass.getAnnotation(Category.class)).map(p1))); - return bss.exists(Function.identity()); + return bss.exists(Function.identity()); }; final F nameS = Name::value; @@ -281,7 +281,7 @@ private static Array>> properties(f try { final Option params = fromNull(m.element().getAnnotation(CheckParams.class)).orElse(fromNull(declaringClass.getAnnotation(CheckParams.class))); final String name = fromNull(m.element().getAnnotation(Name.class)).map(nameS).orSome(m.name()); - return p(m.invoke(t.orSome(P.p(null))), name, params); + return p(m.invoke(t.orSome(P.p(null))), name, params); } catch(Exception e) { throw new Error(e.getMessage(), e); } From 1830edcf4a29bf4f5a55397c7ae9f660ed33ec48 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 08:16:39 +0100 Subject: [PATCH 046/336] Use simpler foreach instead of for loop --- core/src/main/java/fj/data/IOFunctions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index cfe5eba2..1440b692 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -283,10 +283,10 @@ public IO> f(final IterV it) { if (numRead < buffer.length) { buffer = Arrays.copyOfRange(buffer, 0, numRead); } - for (int c = 0; c < buffer.length; c++) { - final Input input = Input.el(buffer[c]); + for (char c : buffer) { + final Input input = Input.el(c); final F, IterV>, IterV> cont = - Function.apply(input); + Function.apply(input); i = i.fold(done, cont); } } From 06d0257b3fda740c28284f41fe8985ca2e2fc437 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 08:29:26 +0100 Subject: [PATCH 047/336] Add missing type parameter --- core/src/main/java/fj/data/DList.java | 2 +- core/src/main/java/fj/data/Set.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index cf2f0af5..af9d68b0 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -75,7 +75,7 @@ public List run() { /** * Converts the DList to a standard java.util.List. */ - public java.util.List toJavaList() { + public java.util.List toJavaList() { return run().toJavaList(); } diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 5bb902d6..42ce0bac 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -323,7 +323,7 @@ public final java.util.TreeSet toJavaTreeSet() { * * @return a java.util.List representation of this set. */ - public final java.util.List toJavaList() { + public final java.util.List toJavaList() { return new java.util.ArrayList<>(toStream().toCollection()); } From bf1d634f012f7014ee8813d1522b3373821f3b91 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 08:49:51 +0100 Subject: [PATCH 048/336] Improve HashMap.Key and HashMap#values --- core/src/main/java/fj/data/HashMap.java | 35 ++++++++++--------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index 9a145b37..cf112b94 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -8,6 +8,7 @@ import java.util.Map; import static fj.P.p; +import static fj.data.List.iterableList; import static fj.data.Option.fromNull; /** @@ -17,24 +18,16 @@ * @see java.util.HashMap */ public final class HashMap implements Iterable { - private final class Key { - private final K k; - private final Equal e; - private final Hash h; + private final class Key { + final K k; - Key(final K k, final Equal e, final Hash h) { + Key(final K k) { this.k = k; - this.e = e; - this.h = h; - } - - K k() { - return k; } @SuppressWarnings("unchecked") public boolean equals(final Object o) { - return o instanceof Key && e.eq(k, (K) ((Key) o).k()); + return o instanceof HashMap.Key && e.eq(k, ((Key) o).k); } public int hashCode() { @@ -51,7 +44,7 @@ public Iterator iterator() { return keys().iterator(); } - private final java.util.HashMap, V> m; + private final java.util.HashMap m; private final Equal e; private final Hash h; @@ -152,7 +145,7 @@ public int hash(final K k) { * @return A potential value for the given key. */ public Option get(final K k) { - return fromNull(m.get(new Key<>(k, e, h))); + return fromNull(m.get(new Key(k))); } /** @@ -178,7 +171,7 @@ public void clear() { * @return true if this hash map contains the given key, false otherwise. */ public boolean contains(final K k) { - return m.containsKey(new Key<>(k, e, h)); + return m.containsKey(new Key(k)); } /** @@ -189,8 +182,8 @@ public boolean contains(final K k) { public List keys() { final List.Buffer b = new List.Buffer<>(); - for (final Key k : m.keySet()) { - b.snoc(k.k()); + for (final Key k : m.keySet()) { + b.snoc(k.k); } return b.toList(); @@ -202,7 +195,7 @@ public List keys() { * @return All values in this hash map. */ public List values() { - return keys().map(k -> m.get(new Key<>(k, e, h))); + return iterableList(m.values()); } /** @@ -231,7 +224,7 @@ public int size() { */ public void set(final K k, final V v) { if (v != null) { - m.put(new Key<>(k, e, h), v); + m.put(new Key(k), v); } } @@ -241,7 +234,7 @@ public void set(final K k, final V v) { * @param k The key to delete from this hash map. */ public void delete(final K k) { - m.remove(new Key<>(k, e, h)); + m.remove(new Key(k)); } /** @@ -251,7 +244,7 @@ public void delete(final K k) { * @return The value that was associated with the given key, if there was one. */ public Option getDelete(final K k) { - return fromNull(m.remove(new Key<>(k, e, h))); + return fromNull(m.remove(new Key(k))); } public HashMap map(F keyFunction, From e76812f402df2feece7ca9bc10890ed1e2783abe Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 14:20:05 +0100 Subject: [PATCH 049/336] Precompile regex --- core/src/main/java/fj/function/Strings.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/function/Strings.java b/core/src/main/java/fj/function/Strings.java index c64db043..dadbfd22 100644 --- a/core/src/main/java/fj/function/Strings.java +++ b/core/src/main/java/fj/function/Strings.java @@ -3,6 +3,9 @@ import fj.F; import fj.data.List; import fj.data.Stream; + +import java.util.regex.Pattern; + import static fj.Function.curry; import static fj.function.Booleans.not; import static fj.function.Characters.isWhitespace; @@ -17,6 +20,8 @@ private Strings() { throw new UnsupportedOperationException(); } + private static final Pattern lineSeparatorPattern = Pattern.compile("\\r?\\n"); + public static final String lineSeparator = System.getProperty("line.separator"); /** @@ -76,7 +81,7 @@ private Strings() { public static final F> matches = curry((s1, s2) -> s2.matches(s1)); public static List lines(String s) { - return List.list(s.split("\\r?\\n")); + return List.list(lineSeparatorPattern.split(s)); } public static F> lines() { From 7790a18a976cdb659ca972ebc6892986a981d19b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 14:23:59 +0100 Subject: [PATCH 050/336] Iterate over entrySet of j.u.Map instead of keySet + get --- core/src/main/java/fj/data/HashMap.java | 4 ++-- quickcheck/src/main/java/fj/test/Arbitrary.java | 4 ++-- quickcheck/src/main/java/fj/test/Coarbitrary.java | 5 +++-- quickcheck/src/main/java/fj/test/Shrink.java | 9 +++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index cf112b94..400cf415 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -63,8 +63,8 @@ public HashMap(final Equal e, final Hash h) { public HashMap(java.util.Map map, final Equal e, final Hash h) { this(e, h); - for (K key : map.keySet()) { - set(key, map.get(key)); + for (Map.Entry entry : map.entrySet()) { + set(entry.getKey(), entry.getValue()); } } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 848585aa..c675120c 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -928,8 +928,8 @@ public static Arbitrary> arbPriorityQueue(final Arbitrary { final Properties p = new Properties(); - for (final String k : ht.keySet()) { - p.setProperty(k, ht.get(k)); + for (final Map.Entry entry : ht.entrySet()) { + p.setProperty(entry.getKey(), entry.getValue()); } return p; diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index cd519513..b0f6be6d 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -33,6 +33,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; +import java.util.Map; import java.util.PriorityQueue; import java.util.Properties; import java.util.Stack; @@ -647,8 +648,8 @@ public static Coarbitrary> coarbHashtable(final Coarbitra public Gen coarbitrary(final Hashtable h, final Gen g) { List> x = nil(); - for (final K k : h.keySet()) { - x = x.snoc(p(k, h.get(k))); + for (final Map.Entry entry : h.entrySet()) { + x = x.snoc(p(entry.getKey(), entry.getValue())); } return coarbList(coarbP2(ck, cv)).coarbitrary(x, g); diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 46ca3380..2a2f0061 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -56,6 +56,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; +import java.util.Map; import java.util.PriorityQueue; import java.util.Properties; import java.util.Stack; @@ -411,8 +412,8 @@ public static Shrink> shrinkHashtable(final Shrink sk, }, h -> { List> x = List.nil(); - for (final K k : h.keySet()) { - x = x.snoc(p(k, h.get(k))); + for (final Map.Entry entry : h.entrySet()) { + x = x.snoc(p(entry.getKey(), entry.getValue())); } return x; @@ -478,8 +479,8 @@ public static Shrink> shrinkPriorityQueue(final Shrink s .map(h -> { final Properties p = new Properties(); - for (final String k : h.keySet()) { - p.setProperty(k, h.get(k)); + for (final Map.Entry entry : h.entrySet()) { + p.setProperty(entry.getKey(), entry.getValue()); } return p; From 4d800f8a2cf45443bace99355839824cd245c6af Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 14:25:52 +0100 Subject: [PATCH 051/336] IOW#getContents and IOW#interact should be static --- core/src/main/java/fj/data/IOW.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java index adb0c7af..859c9cdb 100644 --- a/core/src/main/java/fj/data/IOW.java +++ b/core/src/main/java/fj/data/IOW.java @@ -35,11 +35,11 @@ public SafeIO> safe() { public IOW append(IO iob) { return lift(IOFunctions.append(io, iob)); } - public IOW getContents() { + public static IOW getContents() { return lift(() -> IOFunctions.getContents().run()); } - public IOW interact(F f) { + public static IOW interact(F f) { return lift(() -> IOFunctions.interact(f).run()); } } From 344c9de7c888145bf6a932839bce9df8691ee3e4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 14:28:30 +0100 Subject: [PATCH 052/336] Presize StringBuilder when possible --- core/src/main/java/fj/data/Conversions.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/Conversions.java b/core/src/main/java/fj/data/Conversions.java index 35cf68be..403ca6d1 100644 --- a/core/src/main/java/fj/data/Conversions.java +++ b/core/src/main/java/fj/data/Conversions.java @@ -125,7 +125,7 @@ public static F, F, Either>> Array_Either() { * A function that converts arrays to strings. */ public static final F, String> Array_String = cs -> { - final StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(cs.length()); cs.foreachDoEffect(sb::append); return sb.toString(); }; @@ -134,7 +134,7 @@ public static F, F, Either>> Array_Either() { * A function that converts arrays to string buffers. */ public static final F, StringBuffer> Array_StringBuffer = cs -> { - final StringBuffer sb = new StringBuffer(); + final StringBuffer sb = new StringBuffer(cs.length()); cs.foreachDoEffect(sb::append); return sb; }; @@ -143,7 +143,7 @@ public static F, F, Either>> Array_Either() { * A function that converts arrays to string builders. */ public static final F, StringBuilder> Array_StringBuilder = cs -> { - final StringBuilder sb = new StringBuilder(); + final StringBuilder sb = new StringBuilder(cs.length()); cs.foreachDoEffect(sb::append); return sb; }; From 93a003e9cdcb08cadfaed4e04fd5b7aef5e963a6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 14:36:10 +0100 Subject: [PATCH 053/336] Avoid unnecessary null check in Optional_Option --- java8/src/main/java/fj/data/Java8.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/java8/src/main/java/fj/data/Java8.java b/java8/src/main/java/fj/data/Java8.java index d893a370..be776822 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/java8/src/main/java/fj/data/Java8.java @@ -108,7 +108,7 @@ public static Option Optional_Option(final Optional o) { } public static F, Option> Optional_Option() { - return o -> o.isPresent() ? Option.fromNull(o.get()) : Option.none(); + return o -> o.isPresent() ? Option.some(o.get()) : Option.none(); } public static Optional Option_Optional(final Option o) { From 1e40671d37573a2ebb2aebdc0b5e717a2b6f5357 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:00:30 +0100 Subject: [PATCH 054/336] Array: simpler conversion to jdk collections --- core/src/main/java/fj/data/Array.java | 47 ++++++------------- core/src/main/java/fj/data/Java.java | 34 +++++++------- .../src/main/java/fj/test/Arbitrary.java | 34 +++++++------- 3 files changed, 49 insertions(+), 66 deletions(-) diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index 09b56f9a..75dd3c3a 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -13,7 +13,9 @@ import java.util.AbstractCollection; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.Iterator; import java.util.NoSuchElementException; @@ -775,44 +777,25 @@ public Array> zipIndex() { * * @return An immutable collection of this array. */ - @SuppressWarnings("unchecked") public Collection toCollection() { - return new AbstractCollection() { - public Iterator iterator() { - return new Iterator() { - private int i; - - public boolean hasNext() { - return i < a.length; - } - - public A next() { - if (i >= a.length) - throw new NoSuchElementException(); - else { - final A aa = (A) a[i]; - i++; - return aa; - } - } - - public void remove() { - throw new UnsupportedOperationException(); - } - }; - } + return asJavaList(); + } - public int size() { - return a.length; - } - }; + /** + * Projects an unmodifiable list view of this array. + * + * @return An unmodifiable list view of this array. + */ + @SuppressWarnings("unchecked") + public java.util.List asJavaList() { + return Collections.unmodifiableList(Arrays.asList((A[]) a)); } /** - * Returns a standard java.util.List projection of this array. + * Returns a java.util.ArrayList projection of this array. */ - java.util.List toJavaList() { - return new ArrayList<>(toCollection()); + public ArrayList toJavaList() { + return new ArrayList<>(asJavaList()); } /** diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index b4b6173a..487e9703 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -227,7 +227,7 @@ public static F, SynchronousQueue> List_SynchronousQueue(final bo * @return A function that converts arrays to array lists. */ public static F, ArrayList> Array_ArrayList() { - return as -> new ArrayList<>(as.toCollection()); + return Array::toJavaList; } /** @@ -246,7 +246,7 @@ public static F, ArrayList> Array_ArrayList() { * @return A function that converts arrays to enum sets. */ public static > F, EnumSet> Array_EnumSet() { - return as -> copyOf(as.toCollection()); + return as -> copyOf(as.asJavaList()); } /** @@ -255,7 +255,7 @@ public static > F, EnumSet> Array_EnumSet() { * @return A function that converts arrays to hash sets. */ public static F, HashSet> Array_HashSet() { - return as -> new HashSet<>(as.toCollection()); + return as -> new HashSet<>(as.asJavaList()); } /** @@ -264,7 +264,7 @@ public static F, HashSet> Array_HashSet() { * @return A function that converts arrays to linked hash sets. */ public static F, LinkedHashSet> Array_LinkedHashSet() { - return as -> new LinkedHashSet<>(as.toCollection()); + return as -> new LinkedHashSet<>(as.asJavaList()); } /** @@ -273,7 +273,7 @@ public static F, LinkedHashSet> Array_LinkedHashSet() { * @return A function that converts arrays to linked lists. */ public static F, LinkedList> Array_LinkedList() { - return as -> new LinkedList<>(as.toCollection()); + return as -> new LinkedList<>(as.asJavaList()); } /** @@ -282,7 +282,7 @@ public static F, LinkedList> Array_LinkedList() { * @return A function that converts arrays to priority queues. */ public static F, PriorityQueue> Array_PriorityQueue() { - return as -> new PriorityQueue<>(as.toCollection()); + return as -> new PriorityQueue<>(as.asJavaList()); } /** @@ -293,7 +293,7 @@ public static F, PriorityQueue> Array_PriorityQueue() { public static F, Stack> Array_Stack() { return as -> { final Stack s = new Stack<>(); - s.addAll(as.toCollection()); + s.addAll(as.asJavaList()); return s; }; } @@ -304,7 +304,7 @@ public static F, Stack> Array_Stack() { * @return A function that converts arrays to tree sets. */ public static F, TreeSet> Array_TreeSet() { - return as -> new TreeSet<>(as.toCollection()); + return as -> new TreeSet<>(as.asJavaList()); } /** @@ -313,7 +313,7 @@ public static F, TreeSet> Array_TreeSet() { * @return A function that converts arrays to vectors. */ public static F, Vector> Array_Vector() { - return as -> new Vector<>(as.toCollection()); + return as -> new Vector<>(as.asJavaList()); } /** @@ -323,7 +323,7 @@ public static F, Vector> Array_Vector() { * @return A function that converts arrays to array blocking queues. */ public static F, ArrayBlockingQueue> Array_ArrayBlockingQueue(final boolean fair) { - return as -> new ArrayBlockingQueue<>(as.length(), fair, as.toCollection()); + return as -> new ArrayBlockingQueue<>(as.length(), fair, as.asJavaList()); } /** @@ -332,7 +332,7 @@ public static F, ArrayBlockingQueue> Array_ArrayBlockingQueue(fi * @return A function that converts arrays to concurrent linked queues. */ public static F, ConcurrentLinkedQueue> Array_ConcurrentLinkedQueue() { - return as -> new ConcurrentLinkedQueue<>(as.toCollection()); + return as -> new ConcurrentLinkedQueue<>(as.asJavaList()); } /** @@ -341,7 +341,7 @@ public static F, ConcurrentLinkedQueue> Array_ConcurrentLinkedQu * @return A function that converts arrays to copy on write array lists. */ public static F, CopyOnWriteArrayList> Array_CopyOnWriteArrayList() { - return as -> new CopyOnWriteArrayList<>(as.toCollection()); + return as -> new CopyOnWriteArrayList<>(as.asJavaList()); } /** @@ -350,7 +350,7 @@ public static F, CopyOnWriteArrayList> Array_CopyOnWriteArrayLis * @return A function that converts arrays to copy on write array sets. */ public static F, CopyOnWriteArraySet> Array_CopyOnWriteArraySet() { - return as -> new CopyOnWriteArraySet<>(as.toCollection()); + return as -> new CopyOnWriteArraySet<>(as.asJavaList()); } /** @@ -359,7 +359,7 @@ public static F, CopyOnWriteArraySet> Array_CopyOnWriteArraySet( * @return A function that converts arrays to delay queues. */ public static F, DelayQueue> Array_DelayQueue() { - return as -> new DelayQueue<>(as.toCollection()); + return as -> new DelayQueue<>(as.asJavaList()); } /** @@ -368,7 +368,7 @@ public static F, DelayQueue> Array_DelayQueue() * @return A function that converts arrays to linked blocking queues. */ public static F, LinkedBlockingQueue> Array_LinkedBlockingQueue() { - return as -> new LinkedBlockingQueue<>(as.toCollection()); + return as -> new LinkedBlockingQueue<>(as.asJavaList()); } /** @@ -377,7 +377,7 @@ public static F, LinkedBlockingQueue> Array_LinkedBlockingQueue( * @return A function that converts arrays to priority blocking queues. */ public static F, PriorityBlockingQueue> Array_PriorityBlockingQueue() { - return as -> new PriorityBlockingQueue<>(as.toCollection()); + return as -> new PriorityBlockingQueue<>(as.asJavaList()); } /** @@ -389,7 +389,7 @@ public static F, PriorityBlockingQueue> Array_PriorityBlockingQu public static F, SynchronousQueue> Array_SynchronousQueue(final boolean fair) { return as -> { final SynchronousQueue q = new SynchronousQueue<>(fair); - q.addAll(as.toCollection()); + q.addAll(as.asJavaList()); return q; }; } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index c675120c..20e6e2f0 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -753,7 +753,7 @@ public static Arbitrary arbThrowable(final Arbitrary as) { * @return An arbitrary implementation for array lists. */ public static Arbitrary> arbArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new ArrayList<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(Array::toJavaList)); } /** @@ -810,7 +810,7 @@ public static , V> Arbitrary> arbEnumMap(final A * @return An arbitrary implementation for enum sets. */ public static > Arbitrary> arbEnumSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> copyOf(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> copyOf(a.asJavaList()))); } /** @@ -842,7 +842,7 @@ public static Arbitrary> arbHashMap(final Arbitrary ak, * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new HashSet<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new HashSet<>(a.asJavaList()))); } /** @@ -898,7 +898,7 @@ public static Arbitrary> arbLinkedHashMap(final Arbit * @return An arbitrary implementation for hash sets. */ public static Arbitrary> arbLinkedHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet<>(a.asJavaList()))); } /** @@ -908,7 +908,7 @@ public static Arbitrary> arbLinkedHashSet(final Arbitrary Arbitrary> arbLinkedList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedList<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedList<>(a.asJavaList()))); } /** @@ -918,7 +918,7 @@ public static Arbitrary> arbLinkedList(final Arbitrary aa) * @return An arbitrary implementation for priority queues. */ public static Arbitrary> arbPriorityQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue<>(a.asJavaList()))); } /** @@ -944,7 +944,7 @@ public static Arbitrary> arbPriorityQueue(final Arbitrary Arbitrary> arbStack(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.map(a -> { final Stack s = new Stack<>(); - s.addAll(a.toCollection()); + s.addAll(a.asJavaList()); return s; })); } @@ -1005,7 +1005,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb * @return An arbitrary implementation for tree sets. */ public static Arbitrary> arbTreeSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new TreeSet<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new TreeSet<>(a.asJavaList()))); } /** @@ -1016,7 +1016,7 @@ public static Arbitrary> arbTreeSet(final Arbitrary aa) { */ @SuppressWarnings("UseOfObsoleteCollectionType") public static Arbitrary> arbVector(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new Vector<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new Vector<>(a.asJavaList()))); } /** @@ -1046,7 +1046,7 @@ public static Arbitrary> arbWeakHashMap(final Arbitrary public static Arbitrary> arbArrayBlockingQueue(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.bind(arbInteger.gen, arbBoolean.gen, a -> capacity -> fair -> new ArrayBlockingQueue(a.length() + abs(capacity), - fair, a.toCollection()))); + fair, a.asJavaList()))); } /** @@ -1071,7 +1071,7 @@ public static Arbitrary> arbConcurrentHashMap(fin * @return An arbitrary implementation for concurrent linked queues. */ public static Arbitrary> arbConcurrentLinkedQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue<>(a.asJavaList()))); } /** @@ -1082,7 +1082,7 @@ public static Arbitrary> arbConcurrentLinkedQueue(f * @return An arbitrary implementation for copy-on-write array lists. */ public static Arbitrary> arbCopyOnWriteArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList<>(a.asJavaList()))); } /** @@ -1093,7 +1093,7 @@ public static Arbitrary> arbCopyOnWriteArrayList(fin * @return An arbitrary implementation for copy-on-write array sets. */ public static Arbitrary> arbCopyOnWriteArraySet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet<>(a.asJavaList()))); } /** @@ -1103,7 +1103,7 @@ public static Arbitrary> arbCopyOnWriteArraySet(final * @return An arbitrary implementation for delay queues. */ public static Arbitrary> arbDelayQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue<>(a.asJavaList()))); } /** @@ -1114,7 +1114,7 @@ public static Arbitrary> arbDelayQueue(final A * @return An arbitrary implementation for linked blocking queues. */ public static Arbitrary> arbLinkedBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue<>(a.asJavaList()))); } /** @@ -1125,7 +1125,7 @@ public static Arbitrary> arbLinkedBlockingQueue(final * @return An arbitrary implementation for priority blocking queues. */ public static Arbitrary> arbPriorityBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue<>(a.toCollection()))); + return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue<>(a.asJavaList()))); } /** @@ -1138,7 +1138,7 @@ public static Arbitrary> arbPriorityBlockingQueue(f public static Arbitrary> arbSynchronousQueue(final Arbitrary aa) { return arbitrary(arbArray(aa).gen.bind(arbBoolean.gen, a -> fair -> { final SynchronousQueue q = new SynchronousQueue<>(fair); - q.addAll(a.toCollection()); + q.addAll(a.asJavaList()); return q; })); } From cdd8fbe647a06d54cd6b708ef2d4bd90b3daffce Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:05:11 +0100 Subject: [PATCH 055/336] Avoid unecessary array type cast. --- .../src/main/java/fj/test/Arbitrary.java | 2 +- .../src/main/java/fj/test/Coarbitrary.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 20e6e2f0..a776e15b 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -716,7 +716,7 @@ public static Arbitrary> arbArray(final Arbitrary aa) { */ @SuppressWarnings("unchecked") public static Arbitrary> arbSeq(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(array -> Seq.seq((A[]) array.array()))); + return arbitrary(arbArray(aa).gen.map(Seq::iterableSeq)); } public static Arbitrary> arbSet(Ord ord, final Arbitrary aa) { diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index b0f6be6d..d158a90f 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -8,6 +8,7 @@ import fj.data.*; import static fj.data.Array.array; +import static fj.data.Array.iterableArray; import static fj.data.List.fromString; import static fj.data.List.nil; @@ -525,7 +526,7 @@ public static Coarbitrary> coarbArrayList(final Coarbitrary return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final ArrayList as, final Gen g) { - return coarbArray(ca).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(ca).coarbitrary(iterableArray(as), g); } }; } @@ -630,7 +631,7 @@ public static Coarbitrary> coarbHashSet(final Coarbitrary c) { return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final HashSet as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -716,7 +717,7 @@ public static Coarbitrary> coarbLinkedList(final Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedList as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -731,7 +732,7 @@ public static Coarbitrary> coarbPriorityQueue(final Coarbit return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final PriorityQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -762,7 +763,7 @@ public static Coarbitrary> coarbStack(final Coarbitrary c) { return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final Stack as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -808,7 +809,7 @@ public static Coarbitrary> coarbVector(final Coarbitrary c) { return new Coarbitrary>() { @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"}) public Gen coarbitrary(final Vector as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -844,7 +845,7 @@ public static Coarbitrary> coarbArrayBlockingQueue(fin return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final ArrayBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -876,7 +877,7 @@ public static Coarbitrary> coarbConcurrentLinkedQue return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final ConcurrentLinkedQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -891,7 +892,7 @@ public static Coarbitrary> coarbCopyOnWriteArrayList return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final CopyOnWriteArrayList as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -906,7 +907,7 @@ public static Coarbitrary> coarbCopyOnWriteArraySet(f return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final CopyOnWriteArraySet as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -921,7 +922,7 @@ public static Coarbitrary> coarbDelayQueue(fin return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final DelayQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -936,7 +937,7 @@ public static Coarbitrary> coarbLinkedBlockingQueue(f return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final LinkedBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -951,7 +952,7 @@ public static Coarbitrary> coarbPriorityBlockingQue return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final PriorityBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } @@ -966,7 +967,7 @@ public static Coarbitrary> coarbSynchronousQueue(final C return new Coarbitrary>() { @SuppressWarnings("unchecked") public Gen coarbitrary(final SynchronousQueue as, final Gen g) { - return coarbArray(c).coarbitrary(array(as.toArray((A[]) new Object[as.size()])), g); + return coarbArray(c).coarbitrary(iterableArray(as), g); } }; } From dd14dd4f9f0b1de69913d6e86736ffe47625fa27 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:06:27 +0100 Subject: [PATCH 056/336] make implicit throw explicit for readability --- quickcheck/src/main/java/fj/test/Arbitrary.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index a776e15b..e2a00b29 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -981,7 +981,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb public static Arbitrary> arbTreeMap(Ord ord, Arbitrary ak, Arbitrary av, Arbitrary ai) { Gen>> gl2 = ai.gen.bind(i -> { if (i < 0) { - Bottom.error("Undefined: arbitrary natural is negative (" + i + ")"); + throw Bottom.error("Undefined: arbitrary natural is negative (" + i + ")"); } return Gen.sequenceN(Math.max(i, 0), arbP2(ak, av).gen); }); @@ -993,7 +993,7 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb */ public static Arbitrary> arbTreeMap(Ord ord, Arbitrary ak, Arbitrary av, int maxSize) { if (maxSize < 0) { - Bottom.error("Undefined: arbitrary natural is negative (" + maxSize + ")"); + throw Bottom.error("Undefined: arbitrary natural is negative (" + maxSize + ")"); } return arbTreeMap(ord, ak, av, arbitrary(choose(0, maxSize))); } From d33454285e734a8c4654e06d7c8e4771e440bbf2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:09:29 +0100 Subject: [PATCH 057/336] use Strings#lineSeparator instead of System.getProperty("line.separator") --- quickcheck/src/main/java/fj/test/CheckResult.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/CheckResult.java b/quickcheck/src/main/java/fj/test/CheckResult.java index 718daf03..c9c0a2fe 100644 --- a/quickcheck/src/main/java/fj/test/CheckResult.java +++ b/quickcheck/src/main/java/fj/test/CheckResult.java @@ -5,6 +5,8 @@ import fj.Show; import fj.data.List; import fj.data.Option; +import fj.function.Strings; + import static fj.data.Option.some; import static fj.Show.listShow; import static fj.Show.showS; @@ -252,12 +254,12 @@ else if (r.isPropException()) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); r.exception().some().printStackTrace(pw); - return "Exception on property evaluation with " + arguments(r) + System.getProperty("line.separator") + sw; + return "Exception on property evaluation with " + arguments(r) + Strings.lineSeparator + sw; } else if (r.isGenException()) { final StringWriter sw = new StringWriter(); final PrintWriter pw = new PrintWriter(sw); r.exception().some().printStackTrace(pw); - return "Exception on argument generation " + System.getProperty("line.separator") + sw; + return "Exception on argument generation " + Strings.lineSeparator + sw; } else throw decons(r.getClass()); } From 99fe9fdb93fa0bab9c1adc1930b5284a4570e423 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:38:10 +0100 Subject: [PATCH 058/336] Make methods that are not meant to be overriden final. --- core/src/main/java/fj/F1W.java | 138 +++++------ core/src/main/java/fj/F2W.java | 54 ++--- core/src/main/java/fj/LcgRng.java | 6 +- core/src/main/java/fj/Ord.java | 2 +- core/src/main/java/fj/P1.java | 48 ++-- core/src/main/java/fj/P2.java | 6 +- core/src/main/java/fj/P3.java | 6 +- core/src/main/java/fj/P4.java | 6 +- core/src/main/java/fj/P5.java | 6 +- core/src/main/java/fj/P6.java | 6 +- core/src/main/java/fj/P7.java | 6 +- core/src/main/java/fj/P8.java | 6 +- core/src/main/java/fj/Rng.java | 4 +- core/src/main/java/fj/control/Trampoline.java | 6 +- core/src/main/java/fj/data/Either.java | 22 +- core/src/main/java/fj/data/List.java | 38 +-- core/src/main/java/fj/data/Option.java | 28 +-- core/src/main/java/fj/data/Reader.java | 12 +- core/src/main/java/fj/data/Set.java | 10 +- core/src/main/java/fj/data/Stream.java | 10 +- core/src/main/java/fj/data/Validation.java | 218 +++++++++--------- .../main/java/fj/data/fingertrees/Digit.java | 4 +- .../java/fj/data/fingertrees/FingerTree.java | 10 +- .../main/java/fj/data/fingertrees/Node.java | 2 +- core/src/main/java/fj/data/optic/PIso.java | 2 +- demo/src/main/java/fj/demo/IODemo.java | 8 +- .../fj/demo/StateDemo_VendingMachine.java | 8 +- .../main/java/fj/demo/concurrent/Ping.java | 4 +- .../java/fj/demo/concurrent/PingPong.java | 2 +- .../main/java/fj/demo/concurrent/Pong.java | 2 +- .../main/java/fj/demo/optic/LensPerson.java | 8 +- .../fj/test/runner/PropertyTestRunner.java | 6 +- 32 files changed, 348 insertions(+), 346 deletions(-) diff --git a/core/src/main/java/fj/F1W.java b/core/src/main/java/fj/F1W.java index 19a978dc..611c9e01 100644 --- a/core/src/main/java/fj/F1W.java +++ b/core/src/main/java/fj/F1W.java @@ -22,7 +22,7 @@ public abstract class F1W implements F { * @param g A function to compose with this one. * @return The composed function such that this function is applied last. */ - public F1W o(final F g) { + public final F1W o(final F g) { return lift(F1Functions.o(this, g)); } @@ -31,7 +31,7 @@ public F1W o(final F g) { * * @return A function that composes this function with another. */ - public F1W, F> o() { + public final F1W, F> o() { return lift(F1Functions.o(this)); } @@ -42,7 +42,7 @@ public F1W, F> o() { * @return The composed function such that this function is applied first. */ @SuppressWarnings("unchecked") - public F1W andThen(final F g) { + public final F1W andThen(final F g) { return lift(F1Functions.andThen(this, g)); } @@ -51,7 +51,7 @@ public F1W andThen(final F g) { * * @return A function that invokes this function and then a given function on the result. */ - public F1W, F> andThen() { + public final F1W, F> andThen() { return lift( F1Functions.andThen(this)); } @@ -61,7 +61,7 @@ public F1W, F> andThen() { * @param g A function that takes the return value of this function as an argument, yielding a new function. * @return A function that invokes this function on its argument and then the given function on the result. */ - public F1W bind(final F> g) { + public final F1W bind(final F> g) { return lift(F1Functions.bind(this, g)); } @@ -71,7 +71,7 @@ public F1W bind(final F> g) { * * @return A function that binds another function across this function. */ - public F1W>, F> bind() { + public final F1W>, F> bind() { return lift(F1Functions.bind(this)); } @@ -83,7 +83,7 @@ public F1W>, F> bind() { * @return A new function that invokes the given function on its argument, yielding a new function that is then * applied to the result of applying this function to the argument. */ - public F1W apply(final F> g) { + public final F1W apply(final F> g) { return lift(F1Functions.apply(this, g)); } @@ -93,7 +93,7 @@ public F1W apply(final F> g) { * * @return A function that applies a given function within the environment of this function. */ - public F1W>, F> apply() { + public final F1W>, F> apply() { return lift(F1Functions.apply(this)); } @@ -103,7 +103,7 @@ public F1W>, F> apply() { * @param g The function over whose arguments to apply this function. * @return A new function that invokes this function on its arguments before invoking the given function. */ - public F1W> on(final F> g) { + public final F1W> on(final F> g) { return lift(F1Functions.on(this, g)); } @@ -113,7 +113,7 @@ public F1W> on(final F> g) { * * @return A function that applies this function over the arguments of another function. */ - public F1W>, F>> on() { + public final F1W>, F>> on() { return lift(F1Functions.on(this)); } @@ -122,7 +122,7 @@ public F1W>, F>> on() { * * @return This function promoted to return its result in a product-1. */ - public F1W> lazy() { + public final F1W> lazy() { return lift(F1Functions.lazy(this)); } @@ -133,7 +133,7 @@ public F1W> lazy() { * @param a The A to which to apply this function. * @return The function partially applied to the given argument to return a lazy value. */ - public P1 lazy(final A a) { + public final P1 lazy(final A a) { return F1Functions.f(this, a); } @@ -142,7 +142,7 @@ public P1 lazy(final A a) { * * @return This function promoted to map over a product-1. */ - public F1W, P1> mapP1() { + public final F1W, P1> mapP1() { return lift(F1Functions.mapP1(this)); } @@ -151,7 +151,7 @@ public F1W, P1> mapP1() { * * @return This function promoted to return its result in an Option. */ - public F1W> optionK() { + public final F1W> optionK() { return lift(F1Functions.optionK(this)); } @@ -161,7 +161,7 @@ public F1W> optionK() { * * @return This function promoted to map over an optional value. */ - public F1W, Option> mapOption() { + public final F1W, Option> mapOption() { return lift(F1Functions.mapOption(this)); } @@ -170,7 +170,7 @@ public F1W, Option> mapOption() { * * @return This function promoted to return its result in a List. */ - public F1W> listK() { + public final F1W> listK() { return lift( F1Functions.listK(this)); } @@ -179,7 +179,7 @@ public F1W> listK() { * * @return This function promoted to map over a List. */ - public F1W, List> mapList() { + public final F1W, List> mapList() { return lift(F1Functions.mapList(this)); } @@ -188,7 +188,7 @@ public F1W, List> mapList() { * * @return This function promoted to return its result in a Stream. */ - public F1W> streamK() { + public final F1W> streamK() { return lift(F1Functions.streamK(this)); } @@ -197,7 +197,7 @@ public F1W> streamK() { * * @return This function promoted to map over a Stream. */ - public F1W, Stream> mapStream() { + public final F1W, Stream> mapStream() { return lift(F1Functions.mapStream(this)); } @@ -206,7 +206,7 @@ public F1W, Stream> mapStream() { * * @return This function promoted to return its result in a Array. */ - public F1W> arrayK() { + public final F1W> arrayK() { return lift(F1Functions.arrayK(this)); } @@ -216,7 +216,7 @@ public F1W> arrayK() { * * @return This function promoted to map over a Array. */ - public F1W, Array> mapArray() { + public final F1W, Array> mapArray() { return lift(F1Functions.mapArray(this)); } @@ -225,7 +225,7 @@ public F1W, Array> mapArray() { * * @return A function that contramaps over a given actor. */ - public F1W, Actor> contramapActor() { + public final F1W, Actor> contramapActor() { return lift(F1Functions.contramapActor(this)); } @@ -235,7 +235,7 @@ public F1W, Actor> contramapActor() { * @param s A parallel strategy for concurrent execution. * @return A concurrent function that returns a Promise of a value. */ - public F1W> promiseK(final Strategy s) { + public final F1W> promiseK(final Strategy s) { return lift(F1Functions.promiseK(this, s)); } @@ -244,7 +244,7 @@ public F1W> promiseK(final Strategy s) { * * @return This function promoted to map over Promises. */ - public F1W, Promise> mapPromise() { + public final F1W, Promise> mapPromise() { return lift(F1Functions.mapPromise(this)); } @@ -255,7 +255,7 @@ public F1W, Promise> mapPromise() { * @return This function promoted to return its result on the left side of an Either. */ @SuppressWarnings("unchecked") - public F1W> eitherLeftK() { + public final F1W> eitherLeftK() { return lift(F1Functions.eitherLeftK(this)); } @@ -266,7 +266,7 @@ public F1W> eitherLeftK() { * @return This function promoted to return its result on the right side of an Either. */ @SuppressWarnings("unchecked") - public F1W> eitherRightK() { + public final F1W> eitherRightK() { return lift(F1Functions.eitherRightK(this)); } @@ -276,7 +276,7 @@ public F1W> eitherRightK() { * @return This function promoted to map over the left side of an Either. */ @SuppressWarnings("unchecked") - public F1W, Either> mapLeft() { + public final F1W, Either> mapLeft() { return lift(F1Functions.mapLeft(this)); } @@ -286,7 +286,7 @@ public F1W, Either> mapLeft() { * @return This function promoted to map over the right side of an Either. */ @SuppressWarnings("unchecked") - public F1W, Either> mapRight() { + public final F1W, Either> mapRight() { return lift(F1Functions.mapRight(this)); } @@ -295,7 +295,7 @@ public F1W, Either> mapRight() { * * @return a function that returns the left side of a given Either, or this function applied to the right side. */ - public F1W, B> onLeft() { + public final F1W, B> onLeft() { return lift(F1Functions.onLeft(this)); } @@ -304,7 +304,7 @@ public F1W, B> onLeft() { * * @return a function that returns the right side of a given Either, or this function applied to the left side. */ - public F1W, B> onRight() { + public final F1W, B> onRight() { return lift(F1Functions.onRight(this)); } @@ -314,7 +314,7 @@ public F1W, B> onRight() { * @return This function promoted to return its value in an Iterable. */ @SuppressWarnings("unchecked") - public F1W> iterableK() { + public final F1W> iterableK() { return lift( F1Functions.iterableK(this)); } @@ -324,7 +324,7 @@ public F1W> iterableK() { * @return This function promoted to map over Iterables. */ @SuppressWarnings("unchecked") - public F1W, IterableW> mapIterable() { + public final F1W, IterableW> mapIterable() { return lift( F1Functions.mapIterable(this)); } @@ -334,7 +334,7 @@ public F1W, IterableW> mapIterable() { * @return This function promoted to return its value in a NonEmptyList. */ @SuppressWarnings("unchecked") - public F1W> nelK() { + public final F1W> nelK() { return lift(F1Functions.nelK(this)); } @@ -343,7 +343,7 @@ public F1W> nelK() { * * @return This function promoted to map over a NonEmptyList. */ - public F1W, NonEmptyList> mapNel() { + public final F1W, NonEmptyList> mapNel() { return lift(F1Functions.mapNel(this)); } @@ -353,7 +353,7 @@ public F1W, NonEmptyList> mapNel() { * @param o An order for the set. * @return This function promoted to return its value in a Set. */ - public F1W> setK(final Ord o) { + public final F1W> setK(final Ord o) { return lift(F1Functions.setK(this, o)); } @@ -363,7 +363,7 @@ public F1W> setK(final Ord o) { * @param o An order for the resulting set. * @return This function promoted to map over a Set. */ - public F1W, Set> mapSet(final Ord o) { + public final F1W, Set> mapSet(final Ord o) { return lift(F1Functions.mapSet(this, o)); } @@ -372,7 +372,7 @@ public F1W, Set> mapSet(final Ord o) { * * @return This function promoted to return its value in a Tree. */ - public F1W> treeK() { + public final F1W> treeK() { return lift(F1Functions.treeK(this)); } @@ -382,7 +382,7 @@ public F1W> treeK() { * @return This function promoted to map over a Tree. */ @SuppressWarnings("unchecked") - public F1W, Tree> mapTree() { + public final F1W, Tree> mapTree() { return lift(F1Functions.mapTree(this)); } @@ -392,7 +392,7 @@ public F1W, Tree> mapTree() { * @param m The monoid with which to fold the mapped tree. * @return a function that maps this function over a tree and folds it with the given monoid. */ - public F1W, B> foldMapTree(final Monoid m) { + public final F1W, B> foldMapTree(final Monoid m) { return lift(F1Functions.foldMapTree(this, m)); } @@ -401,7 +401,7 @@ public F1W, B> foldMapTree(final Monoid m) { * * @return This function promoted to return its value in a TreeZipper. */ - public F1W> treeZipperK() { + public final F1W> treeZipperK() { return lift(F1Functions.treeZipperK(this)); } @@ -410,7 +410,7 @@ public F1W> treeZipperK() { * * @return This function promoted to map over a TreeZipper. */ - public F1W, TreeZipper> mapTreeZipper() { + public final F1W, TreeZipper> mapTreeZipper() { return lift(F1Functions.mapTreeZipper(this)); } @@ -420,7 +420,7 @@ public F1W, TreeZipper> mapTreeZipper() { * * @return This function promoted to return its result on the failure side of a Validation. */ - public F1W> failK() { + public final F1W> failK() { return lift(F1Functions.failK(this)); } @@ -430,7 +430,7 @@ public F1W> failK() { * * @return This function promoted to return its result on the success side of an Validation. */ - public F1W> successK() { + public final F1W> successK() { return lift( F1Functions.successK(this)); } @@ -439,7 +439,7 @@ public F1W> successK() { * * @return This function promoted to map over the failure side of a Validation. */ - public F1W, Validation> mapFail() { + public final F1W, Validation> mapFail() { return lift(F1Functions.mapFail(this)); } @@ -448,7 +448,7 @@ public F1W, Validation> mapFail() { * * @return This function promoted to map over the success side of a Validation. */ - public F1W, Validation> mapSuccess() { + public final F1W, Validation> mapSuccess() { return lift(F1Functions.mapSuccess(this)); } @@ -459,7 +459,7 @@ public F1W, Validation> mapSuccess() { * @return a function that returns the failure side of a given Validation, * or this function applied to the success side. */ - public F1W, B> onFail() { + public final F1W, B> onFail() { return lift(F1Functions.onFail(this)); } @@ -470,7 +470,7 @@ public F1W, B> onFail() { * @return a function that returns the success side of a given Validation, * or this function applied to the failure side. */ - public F1W, B> onSuccess() { + public final F1W, B> onSuccess() { return lift(F1Functions.onSuccess(this)); } @@ -479,7 +479,7 @@ public F1W, B> onSuccess() { * * @return This function promoted to return its value in a Zipper. */ - public F1W> zipperK() { + public final F1W> zipperK() { return lift(F1Functions.zipperK(this)); } @@ -488,7 +488,7 @@ public F1W> zipperK() { * * @return This function promoted to map over a Zipper. */ - public F1W, Zipper> mapZipper() { + public final F1W, Zipper> mapZipper() { return lift(F1Functions.mapZipper(this)); } @@ -497,7 +497,7 @@ public F1W, Zipper> mapZipper() { * * @return This function promoted to map over an Equal as a contravariant functor. */ - public F1W, Equal> contramapEqual() { + public final F1W, Equal> contramapEqual() { return lift(F1Functions.contramapEqual(this)); } @@ -506,7 +506,7 @@ public F1W, Equal> contramapEqual() { * * @return This function promoted to map over a Hash as a contravariant functor. */ - public F1W, Hash> contramapHash() { + public final F1W, Hash> contramapHash() { return lift(F1Functions.contramapHash(this)); } @@ -515,7 +515,7 @@ public F1W, Hash> contramapHash() { * * @return This function promoted to map over a Show as a contravariant functor. */ - public F1W, Show> contramapShow() { + public final F1W, Show> contramapShow() { return lift(F1Functions.contramapShow(this)); } @@ -524,7 +524,7 @@ public F1W, Show> contramapShow() { * * @return This function promoted to map over the first element of a pair. */ - public F1W, P2> mapFst() { + public final F1W, P2> mapFst() { return lift(F1Functions.mapFst(this)); } @@ -533,7 +533,7 @@ public F1W, P2> mapFst() { * * @return This function promoted to map over the second element of a pair. */ - public F1W, P2> mapSnd() { + public final F1W, P2> mapSnd() { return lift(F1Functions.mapSnd(this)); } @@ -542,7 +542,7 @@ public F1W, P2> mapSnd() { * * @return This function promoted to map over both elements of a pair. */ - public F1W, P2> mapBoth() { + public final F1W, P2> mapBoth() { return lift(F1Functions.mapBoth(this)); } @@ -552,7 +552,7 @@ public F1W, P2> mapBoth() { * @param as A SynchronousQueue to map this function over. * @return A new SynchronousQueue with this function applied to each element. */ - public SynchronousQueue mapJ(final SynchronousQueue as) { + public final SynchronousQueue mapJ(final SynchronousQueue as) { return F1Functions.mapJ(this, as); } @@ -563,7 +563,7 @@ public SynchronousQueue mapJ(final SynchronousQueue as) { * @param as A PriorityBlockingQueue to map this function over. * @return A new PriorityBlockingQueue with this function applied to each element. */ - public PriorityBlockingQueue mapJ(final PriorityBlockingQueue as) { + public final PriorityBlockingQueue mapJ(final PriorityBlockingQueue as) { return F1Functions.mapJ(this, as); } @@ -573,7 +573,7 @@ public PriorityBlockingQueue mapJ(final PriorityBlockingQueue as) { * @param as A LinkedBlockingQueue to map this function over. * @return A new LinkedBlockingQueue with this function applied to each element. */ - public LinkedBlockingQueue mapJ(final LinkedBlockingQueue as) { + public final LinkedBlockingQueue mapJ(final LinkedBlockingQueue as) { return F1Functions.mapJ(this, as); } @@ -583,7 +583,7 @@ public LinkedBlockingQueue mapJ(final LinkedBlockingQueue as) { * @param as A CopyOnWriteArraySet to map this function over. * @return A new CopyOnWriteArraySet with this function applied to each element. */ - public CopyOnWriteArraySet mapJ(final CopyOnWriteArraySet as) { + public final CopyOnWriteArraySet mapJ(final CopyOnWriteArraySet as) { return F1Functions.mapJ(this, as); } @@ -593,7 +593,7 @@ public CopyOnWriteArraySet mapJ(final CopyOnWriteArraySet as) { * @param as A CopyOnWriteArrayList to map this function over. * @return A new CopyOnWriteArrayList with this function applied to each element. */ - public CopyOnWriteArrayList mapJ(final CopyOnWriteArrayList as) { + public final CopyOnWriteArrayList mapJ(final CopyOnWriteArrayList as) { return F1Functions.mapJ(this, as); } @@ -603,7 +603,7 @@ public CopyOnWriteArrayList mapJ(final CopyOnWriteArrayList as) { * @param as A ConcurrentLinkedQueue to map this function over. * @return A new ConcurrentLinkedQueue with this function applied to each element. */ - public ConcurrentLinkedQueue mapJ(final ConcurrentLinkedQueue as) { + public final ConcurrentLinkedQueue mapJ(final ConcurrentLinkedQueue as) { return F1Functions.mapJ(this, as); } @@ -613,7 +613,7 @@ public ConcurrentLinkedQueue mapJ(final ConcurrentLinkedQueue as) { * @param as An ArrayBlockingQueue to map this function over. * @return A new ArrayBlockingQueue with this function applied to each element. */ - public ArrayBlockingQueue mapJ(final ArrayBlockingQueue as) { + public final ArrayBlockingQueue mapJ(final ArrayBlockingQueue as) { return F1Functions.mapJ(this, as); } @@ -624,7 +624,7 @@ public ArrayBlockingQueue mapJ(final ArrayBlockingQueue as) { * @param as A TreeSet to map this function over. * @return A new TreeSet with this function applied to each element. */ - public TreeSet mapJ(final TreeSet as) { + public final TreeSet mapJ(final TreeSet as) { return F1Functions.mapJ(this, as); } @@ -634,7 +634,7 @@ public TreeSet mapJ(final TreeSet as) { * @param as A PriorityQueue to map this function over. * @return A new PriorityQueue with this function applied to each element. */ - public PriorityQueue mapJ(final PriorityQueue as) { + public final PriorityQueue mapJ(final PriorityQueue as) { return F1Functions.mapJ(this, as); } @@ -644,7 +644,7 @@ public PriorityQueue mapJ(final PriorityQueue as) { * @param as A LinkedList to map this function over. * @return A new LinkedList with this function applied to each element. */ - public LinkedList mapJ(final LinkedList as) { + public final LinkedList mapJ(final LinkedList as) { return F1Functions.mapJ(this, as); } @@ -654,15 +654,15 @@ public LinkedList mapJ(final LinkedList as) { * @param as An ArrayList to map this function over. * @return A new ArrayList with this function applied to each element. */ - public ArrayList mapJ(final ArrayList as) { + public final ArrayList mapJ(final ArrayList as) { return F1Functions.mapJ(this, as); } - public F1W map(F f) { + public final F1W map(F f) { return lift(F1Functions.map(this, f)); } - public F1W contramap(F f) { + public final F1W contramap(F f) { return lift(F1Functions.contramap(this, f)); } @@ -673,7 +673,7 @@ public F1WFunc(F f) { } @Override - public B f(A a) { + public final B f(A a) { return func.f(a); } } diff --git a/core/src/main/java/fj/F2W.java b/core/src/main/java/fj/F2W.java index eb2fb590..1f35855a 100644 --- a/core/src/main/java/fj/F2W.java +++ b/core/src/main/java/fj/F2W.java @@ -14,7 +14,7 @@ public abstract class F2W implements F2 { * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ - public F1W f(final A a) { + public final F1W f(final A a) { return F1W.lift(F2Functions.f(this, a)); } @@ -23,7 +23,7 @@ public F1W f(final A a) { * * @return a wrapped function of arity-1 that returns another wrapped function. */ - public F1W> curry() { + public final F1W> curry() { return F1W.lift(F2Functions.curry(this)); } @@ -32,7 +32,7 @@ public F1W> curry() { * * @return A new function with the arguments of this function flipped. */ - public F2W flip() { + public final F2W flip() { return lift(F2Functions.flip(this)); } @@ -41,7 +41,7 @@ public F2W flip() { * * @return A new function that calls this function with the elements of a given tuple. */ - public F1W, C> tuple() { + public final F1W, C> tuple() { return F1W.lift(F2Functions.tuple(this)); } @@ -50,7 +50,7 @@ public F1W, C> tuple() { * * @return This function promoted to transform Arrays. */ - public F2W, Array, Array> arrayM() { + public final F2W, Array, Array> arrayM() { return lift(F2Functions.arrayM(this)); } @@ -59,7 +59,7 @@ public F2W, Array, Array> arrayM() { * * @return This function promoted to transform Promises. */ - public F2W, Promise, Promise> promiseM() { + public final F2W, Promise, Promise> promiseM() { return lift(F2Functions.promiseM(this)); } @@ -68,7 +68,7 @@ public F2W, Promise, Promise> promiseM() { * * @return This function promoted to transform Iterables. */ - public F2W, Iterable, IterableW> iterableM() { + public final F2W, Iterable, IterableW> iterableM() { return lift(F2Functions.iterableM(this)); } @@ -77,7 +77,7 @@ public F2W, Iterable, IterableW> iterableM() { * * @return This function promoted to transform Lists. */ - public F2W, List, List> listM() { + public final F2W, List, List> listM() { return lift(F2Functions.listM(this)); } @@ -86,7 +86,7 @@ public F2W, List, List> listM() { * * @return This function promoted to transform non-empty lists. */ - public F2W, NonEmptyList, NonEmptyList> nelM() { + public final F2W, NonEmptyList, NonEmptyList> nelM() { return lift(F2Functions.nelM(this)); } @@ -95,7 +95,7 @@ public F2W, NonEmptyList, NonEmptyList> nelM() { * * @return This function promoted to transform Options. */ - public F2W, Option, Option> optionM() { + public final F2W, Option, Option> optionM() { return lift(F2Functions.optionM(this)); } @@ -105,7 +105,7 @@ public F2W, Option, Option> optionM() { * @param o An ordering for the result of the promoted function. * @return This function promoted to transform Sets. */ - public F2W, Set, Set> setM(final Ord o) { + public final F2W, Set, Set> setM(final Ord o) { return lift(F2Functions.setM(this, o)); } @@ -114,7 +114,7 @@ public F2W, Set, Set> setM(final Ord o) { * * @return This function promoted to transform Streams. */ - public F2W, Stream, Stream> streamM() { + public final F2W, Stream, Stream> streamM() { return lift(F2Functions.streamM(this)); } @@ -123,7 +123,7 @@ public F2W, Stream, Stream> streamM() { * * @return This function promoted to transform Trees. */ - public F2W, Tree, Tree> treeM() { + public final F2W, Tree, Tree> treeM() { return lift(F2Functions.treeM(this)); } @@ -132,7 +132,7 @@ public F2W, Tree, Tree> treeM() { * * @return A function that zips two arrays with this function. */ - public F2W, Array, Array> zipArrayM() { + public final F2W, Array, Array> zipArrayM() { return lift(F2Functions.zipArrayM(this)); } @@ -141,7 +141,7 @@ public F2W, Array, Array> zipArrayM() { * * @return A function that zips two iterables with this function. */ - public F2W, Iterable, Iterable> zipIterableM() { + public final F2W, Iterable, Iterable> zipIterableM() { return lift(F2Functions.zipIterableM(this)); } @@ -150,7 +150,7 @@ public F2W, Iterable, Iterable> zipIterableM() { * * @return A function that zips two lists with this function. */ - public F2W, List, List> zipListM() { + public final F2W, List, List> zipListM() { return lift(F2Functions.zipListM(this)); } @@ -160,7 +160,7 @@ public F2W, List, List> zipListM() { * * @return A function that zips two streams with this function. */ - public F2W, Stream, Stream> zipStreamM() { + public final F2W, Stream, Stream> zipStreamM() { return lift(F2Functions.zipStreamM(this)); } @@ -169,7 +169,7 @@ public F2W, Stream, Stream> zipStreamM() { * * @return A function that zips two non-empty lists with this function. */ - public F2W, NonEmptyList, NonEmptyList> zipNelM() { + public final F2W, NonEmptyList, NonEmptyList> zipNelM() { return lift(F2Functions.zipNelM(this)); } @@ -179,7 +179,7 @@ public F2W, NonEmptyList, NonEmptyList> zipNelM() { * @param o An ordering for the resulting set. * @return A function that zips two sets with this function. */ - public F2W, Set, Set> zipSetM(final Ord o) { + public final F2W, Set, Set> zipSetM(final Ord o) { return lift(F2Functions.zipSetM(this, o)); } @@ -189,7 +189,7 @@ public F2W, Set, Set> zipSetM(final Ord o) { * * @return A function that zips two trees with this function. */ - public F2W, Tree, Tree> zipTreeM() { + public final F2W, Tree, Tree> zipTreeM() { return lift(F2Functions.zipTreeM(this)); } @@ -199,7 +199,7 @@ public F2W, Tree, Tree> zipTreeM() { * * @return A function that zips two zippers with this function. */ - public F2W, Zipper, Zipper> zipZipperM() { + public final F2W, Zipper, Zipper> zipZipperM() { return lift(F2Functions.zipZipperM(this)); } @@ -209,23 +209,23 @@ public F2W, Zipper, Zipper> zipZipperM() { * * @return A function that zips two TreeZippers with this function. */ - public F2W, TreeZipper, TreeZipper> zipTreeZipperM() { + public final F2W, TreeZipper, TreeZipper> zipTreeZipperM() { return lift(F2Functions.zipTreeZipperM(this)); } - public F2W contramapFirst(F f) { + public final F2W contramapFirst(F f) { return lift(F2Functions.contramapFirst(this, f)); } - public F2W contramapSecond(F f) { + public final F2W contramapSecond(F f) { return lift(F2Functions.contramapSecond(this, f)); } - public F2W contramap(F f, F g) { + public final F2W contramap(F f, F g) { return lift(F2Functions.contramap(this, f, g)); } - public F2W map(F f) { + public final F2W map(F f) { return lift(F2Functions.map(this, f)); } @@ -237,7 +237,7 @@ public F2WFunc(F2 f) { } @Override - public C f(A a, B b) { + public final C f(A a, B b) { return func.f(a, b); } } diff --git a/core/src/main/java/fj/LcgRng.java b/core/src/main/java/fj/LcgRng.java index 50ee9e03..215b3572 100644 --- a/core/src/main/java/fj/LcgRng.java +++ b/core/src/main/java/fj/LcgRng.java @@ -17,18 +17,18 @@ public LcgRng(long s) { seed = s; } - public long getSeed() { + public final long getSeed() { return seed; } - public P2 nextInt() { + public final P2 nextInt() { P2 p = nextLong(); int i = (int) p._2().longValue(); return P.p(p._1(), i); } - public P2 nextLong() { + public final P2 nextLong() { P2 p = nextLong(seed); return P.p(new LcgRng(p._1()), p._2()); } diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 471c110f..bb682ad8 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -527,7 +527,7 @@ public static Ord hashEqualsOrd() { class OrdComparator implements Comparator { @Override - public int compare(A o1, A o2) { + public final int compare(A o1, A o2) { return Ord.this.compare(o1, o2).toInt(); } } diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 5a1d9b8a..d6809da9 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -63,7 +63,7 @@ public static F, P1> map_(final F f) { * @param f A function to apply to the value in a product-1. * @return The result of applying the given function to the value of given product-1. */ - public P1 bind(final F> f) { + public final P1 bind(final F> f) { P1 self = this; return P.lazy(() -> f.f(self._1())._1()); } @@ -84,7 +84,7 @@ public static F> curry(final F f) { * @param cf The P1 function to apply. * @return A new P1 after applying the given P1 function to the first argument. */ - public P1 apply(final P1> cf) { + public final P1 apply(final P1> cf) { P1 self = this; return cf.bind(f -> map_(f).f(self)); } @@ -96,14 +96,14 @@ public P1 apply(final P1> cf) { * @param f The function to apply to the values in the given P1s. * @return A new P1 after performing the map, then final join. */ - public P1 bind(final P1 cb, final F> f) { + public final P1 bind(final P1 cb, final F> f) { return cb.apply(map_(f).f(this)); } /** * Binds the given function to the values in the given P1s with a final join. */ - public P1 bind(final P1 cb, final F2 f) { + public final P1 bind(final P1 cb, final F2 f) { return bind(cb, F2W.lift(f).curry()); } @@ -127,7 +127,7 @@ public static F, F, P1>> liftM2(final F> f) return Function.curry((pa, pb) -> pa.bind(pb, f)); } - public P1 liftM2(P1 pb, F2 f) { + public final P1 liftM2(P1 pb, F2 f) { return P.lazy(() -> f.f(_1(), pb._1())); } @@ -183,7 +183,7 @@ public static P1> sequence(final Array> as) { * @param f The function that takes A and produces a List (non-deterministic result) * @return A List of P1 */ - public List> traverseList(final F> f){ + public final List> traverseList(final F> f){ return f.f(_1()).map(P::p); } @@ -193,7 +193,7 @@ public List> traverseList(final F> f){ * @param f The function produces Either * @return An Either of P1 */ - public Either> traverseEither(final F> f){ + public final Either> traverseEither(final F> f){ return f.f(_1()).right().map(P::p); } @@ -203,7 +203,7 @@ public Either> traverseEither(final F> f){ * @param f The function that produces Option * @return An Option of P1 */ - public Option> traverseOption(final F> f){ + public final Option> traverseOption(final F> f){ return f.f(_1()).map(P::p); } @@ -213,7 +213,7 @@ public Option> traverseOption(final F> f){ * @param f The function might produces Validation * @return An Validation of P1 */ - public Validation> traverseValidation(final F> f){ + public final Validation> traverseValidation(final F> f){ return f.f(_1()).map(P::p); } @@ -223,7 +223,7 @@ public Validation> traverseValidation(final F */ - public Stream> traverseStream(final F> f){ + public final Stream> traverseStream(final F> f){ return f.f(_1()).map(P::p); } @@ -233,7 +233,7 @@ public Stream> traverseStream(final F> f){ * @param f The function to map with. * @return A product with the given function applied. */ - public P1 map(final F f) { + public final P1 map(final F f) { final P1 self = this; return P.lazy(() -> f.f(self._1())); } @@ -247,7 +247,7 @@ public P1 memo() { * * @return A P1 that calls this P1 once and remembers the value for subsequent calls. */ - public P1 hardMemo() { return new Memo<>(this); } + public final P1 hardMemo() { return new Memo<>(this); } /** * Like memo, but the memoized value is wrapped into a WeakReference @@ -274,7 +274,7 @@ static class Memo extends P1 { Memo(P1 self) { this.self = self; } - @Override public A _1() { + @Override public final A _1() { if (!initialized) { synchronized (this) { if (!initialized) { @@ -288,7 +288,7 @@ static class Memo extends P1 { return value; } - @Override public P1 memo() { return this; } + @Override public final P1 memo() { return this; } } abstract static class ReferenceMemo extends P1 { @@ -298,7 +298,7 @@ abstract static class ReferenceMemo extends P1 { ReferenceMemo(final P1 self) { this.self = self; } - @Override public A _1() { + @Override public final A _1() { Option o = v != null ? v.get() : null; if (o == null) { synchronized (latch) { @@ -317,14 +317,16 @@ abstract static class ReferenceMemo extends P1 { static class WeakReferenceMemo extends ReferenceMemo { WeakReferenceMemo(P1 self) { super(self); } - @Override Reference> newReference(final Option o) { return new WeakReference<>(o); } - @Override public P1 weakMemo() { return this; } + @Override + final Reference> newReference(final Option o) { return new WeakReference<>(o); } + @Override public final P1 weakMemo() { return this; } } static class SoftReferenceMemo extends ReferenceMemo { SoftReferenceMemo(P1 self) { super(self); } - @Override Reference> newReference(final Option o) { return new SoftReference<>(o); } - @Override public P1 softMemo() { return this; } + @Override + final Reference> newReference(final Option o) { return new SoftReference<>(o); } + @Override public final P1 softMemo() { return this; } } /** @@ -332,20 +334,20 @@ static class SoftReferenceMemo extends ReferenceMemo { * * @return A constant function that always uses this value. */ - public F constant() { return Function.constant(_1()); } + public final F constant() { return Function.constant(_1()); } @Override - public String toString() { + public final String toString() { return Show.p1Show(Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P1.class, this, other, () -> Equal.p1Equal(Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p1Hash(Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index be3be69b..521fc14d 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -27,12 +27,12 @@ public abstract class P2 { public abstract B _2(); @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P2.class, this, other, () -> Equal.p2Equal(Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p2Hash(Hash.anyHash(), Hash.anyHash()).hash(this); } @@ -311,7 +311,7 @@ public static F2 untuple(final F, C> f) { @Override - public String toString() { + public final String toString() { return Show.p2Show(Show.anyShow(), Show.anyShow()).showS(this); } diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index c6bc38a9..26c51b05 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -174,18 +174,18 @@ public static F, C> __3() { } @Override - public String toString() { + public final String toString() { return Show.p3Show(Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P3.class, this, other, () -> Equal.p3Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p3Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index 6181b75e..c2f94f8f 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -243,18 +243,18 @@ public static F, D> __4() { } @Override - public String toString() { + public final String toString() { return Show.p4Show(Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P4.class, this, other, () -> Equal.p4Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p4Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 2fd74ebe..902da93c 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -318,18 +318,18 @@ public static F, E> __5() { } @Override - public String toString() { + public final String toString() { return Show.p5Show(Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P5.class, this, other, () -> Equal.p5Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p5Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index 5c679a2c..37f5fe6c 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -404,19 +404,19 @@ public F _6() { } @Override - public String toString() { + public final String toString() { return Show.p6Show(Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P6.class, this, other, () -> Equal.p6Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p6Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index eb0cb913..e2673183 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -495,18 +495,18 @@ public G _7() { } @Override - public String toString() { + public final String toString() { return Show.p7Show(Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P7.class, this, other, () -> Equal.p7Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p7Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index de13749b..cfa916eb 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -597,18 +597,18 @@ public H _8() { } @Override - public String toString() { + public final String toString() { return Show.p8Show(Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow(), Show.anyShow()).showS(this); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(P8.class, this, other, () -> Equal.p8Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.p8Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); } diff --git a/core/src/main/java/fj/Rng.java b/core/src/main/java/fj/Rng.java index 45f03c06..20b3358f 100644 --- a/core/src/main/java/fj/Rng.java +++ b/core/src/main/java/fj/Rng.java @@ -10,12 +10,12 @@ public abstract class Rng { public abstract P2 nextLong(); // [low, high] inclusive - public P2 range(int low, int high) { + public final P2 range(int low, int high) { return nextNatural().map2(x -> (x % (high - low + 1)) + low); } - public P2 nextNatural() { + public final P2 nextNatural() { return nextInt().map2(x -> x < 0 ? -(x + 1) : x); } diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index fa07df3c..bd69ae7a 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -18,7 +18,7 @@ public abstract class Trampoline { private abstract static class Normal extends Trampoline { public abstract R foldNormal(final F pure, final F>, R> k); - public Trampoline bind(final F> f) { + public final Trampoline bind(final F> f) { return codense(this, f); } } @@ -199,7 +199,7 @@ public static F, Either>, A>> resume_() { * @return The end result of this computation. */ @SuppressWarnings("LoopStatementThatDoesntLoop") - public A run() { + public final A run() { Trampoline current = this; while (true) { final Either>, A> x = current.resume(); @@ -252,7 +252,7 @@ public static F, F, Trampoline>> liftM2 * @return A new trampoline that runs this trampoline and the given trampoline simultaneously. */ @SuppressWarnings("LoopStatementThatDoesntLoop") - public Trampoline zipWith(final Trampoline b, final F2 f) { + public final Trampoline zipWith(final Trampoline b, final F2 f) { final Either>, A> ea = resume(); final Either>, B> eb = b.resume(); for (final P1> x : ea.left()) { diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 0d944415..77dea3c3 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -92,12 +92,12 @@ public final Either bimap(final F left, final F right) } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(Either.class, this, other, () -> Equal.eitherEqual(Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.eitherHash(Hash.anyHash(), Hash.anyHash()).hash(this); } @@ -802,7 +802,7 @@ public static Either> sequenceRight(final List> a * * @return traversed value */ - public List> traverseListRight(final F> f) { + public final List> traverseListRight(final F> f) { return right().traverseList(f); } @@ -811,7 +811,7 @@ public List> traverseListRight(final F> f) { * * @return traversed value */ - public List> traverseListLeft(final F> f) { + public final List> traverseListLeft(final F> f) { return left().traverseList(f); } @@ -820,7 +820,7 @@ public List> traverseListLeft(final F> f) { * * @return traversed value */ - public IO> traverseIORight(final F> f) { + public final IO> traverseIORight(final F> f) { return right().traverseIO(f); } @@ -829,7 +829,7 @@ public IO> traverseIORight(final F> f) { * * @return traversed value */ - public IO> traverseIOLeft(final F> f) { + public final IO> traverseIOLeft(final F> f) { return left().traverseIO(f); } @@ -838,7 +838,7 @@ public IO> traverseIOLeft(final F> f) { * * @return traversed value */ - public Option> traverseOptionRight(final F> f) { + public final Option> traverseOptionRight(final F> f) { return right().traverseOption(f); } @@ -847,7 +847,7 @@ public Option> traverseOptionRight(final F> f) { * * @return traversed value */ - public Option> traverseOptionLeft(final F> f) { + public final Option> traverseOptionLeft(final F> f) { return left().traverseOption(f); } @@ -856,7 +856,7 @@ public Option> traverseOptionLeft(final F> f) { * * @return traversed value */ - public Stream> traverseStreamRight(final F> f) { + public final Stream> traverseStreamRight(final F> f) { return right().traverseStream(f); } @@ -865,7 +865,7 @@ public Stream> traverseStreamRight(final F> f) { * * @return traversed value */ - public Stream> traverseStreamLeft(final F> f) { + public final Stream> traverseStreamLeft(final F> f) { return left().traverseStream(f); } @@ -913,7 +913,7 @@ public static List rights(final List> es) { return es.foldRight(e -> bs -> e.isRight() ? bs.cons(e.right().value()) : bs, List.nil()); } - public String toString() { + public final String toString() { return Show.eitherShow(Show.anyShow(), Show.anyShow()).showS(this); } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 399cc016..15171e43 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -166,7 +166,7 @@ public final Option toOption() { * * @return The optional head of the list. */ - public Option headOption() { + public final Option headOption() { return isEmpty() ? Option.none() : some(head()); } @@ -611,7 +611,7 @@ public final List sequence(final List bs) { * @param f The function that produces Option value * @return none if applying f returns none to any element of the list or f mapped list in some . */ - public Option> traverseOption(final F> f) { + public final Option> traverseOption(final F> f) { return foldRight( (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))), some(List.nil()) @@ -624,35 +624,35 @@ public Option> traverseOption(final F> f) { * @param f The function that produces Either value. * @return error in left or f mapped list in right. */ - public Either> traverseEither(final F> f) { + public final Either> traverseEither(final F> f) { return foldRight( (a, acc) -> f.f(a).right().bind(e -> acc.right().map(es -> es.cons(e))), Either.right(List.nil()) ); } - public Stream> traverseStream(final F> f) { + public final Stream> traverseStream(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(s -> acc.map(ss -> ss.cons(s))), Stream.nil() ); } - public P1> traverseP1(final F> f){ + public final P1> traverseP1(final F> f){ return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), p(List.nil()) ); } - public IO> traverseIO(F> f) { + public final IO> traverseIO(F> f) { return this.foldRight( (a, acc) -> IOFunctions.bind(f.f(a), b -> IOFunctions.map(acc, bs -> bs.cons(b))), IOFunctions.unit(List.nil()) ); } - public F> traverseF(F> f) { + public final F> traverseF(F> f) { return this.foldRight( (a, acc) -> Function.bind(acc, (bs) -> Function.compose(bs::cons, f.f(a))), @@ -660,31 +660,31 @@ public F> traverseF(F> f) { ); } - public Trampoline> traverseTrampoline(final F> f) { + public final Trampoline> traverseTrampoline(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), Trampoline.pure(List.nil())); } - public Promise> traversePromise(final F> f) { + public final Promise> traversePromise(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.fmap(bs -> bs.cons(b))), Promise.promise(Strategy.idStrategy(), p(List.nil()))); } - public List> traverseList(final F> f) { + public final List> traverseList(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), single(List.nil())); } - public Validation> traverseValidation(final F> f) { + public final Validation> traverseValidation(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), Validation.success(List.nil())); } - public V2> traverseV2(final F> f) { + public final V2> traverseV2(final F> f) { return foldRight( (a, acc) -> acc.apply(f.f(a)., List>> map(e -> es -> es.cons(e))), v(List.nil(), List.nil())); @@ -902,7 +902,7 @@ public final List> partition(final int n) { * * @param f Predicate function. */ - public P2, List> partition(F f) { + public final P2, List> partition(F f) { P2, List> p2 = foldLeft(acc -> a -> f.f(a) ? p(acc._1().cons(a), acc._2()) : p(acc._1(), acc._2().cons(a)), p(nil(), nil()) @@ -1172,7 +1172,7 @@ public static F, A> head_() { * Reutrns the tail of the list, if any. * @return The optional tail of the list. */ - public Option> tailOption() { + public final Option> tailOption() { return isEmpty() ? none() : some(tail()); } @@ -1410,7 +1410,7 @@ public final TreeMap groupBy( * @param eq The equality test. * @return Whether or not all elements in the list are equal according to the given equality test. */ - public boolean allEqual(final Equal eq) { + public final boolean allEqual(final Equal eq) { return isEmpty() || tail().isEmpty() || eq.eq(head(), tail().head()) && tail().allEqual(eq); } @@ -2066,7 +2066,7 @@ private void copy() { * @param obj the other object to check for equality against. * @return true if this list is equal to the provided argument */ - @Override public boolean equals( final Object obj ) { + @Override public final boolean equals(final Object obj) { return Equal.equals0(List.class, this, obj, () -> Equal.listEqual(Equal.anyEqual())); } @@ -2077,7 +2077,7 @@ private void copy() { * @return the hash code for this list. */ @Override - public int hashCode() { + public final int hashCode() { return Hash.listHash(Hash.anyHash()).hash(this); } @@ -2087,14 +2087,14 @@ public int hashCode() { * * @return a String representation of the list */ - @Override public String toString() { + @Override public final String toString() { return Show.listShow(Show.anyShow()).showS(this); } /** * True if and only if the list has one element. Runs in constant time. */ - public boolean isSingle() { + public final boolean isSingle() { return isNotEmpty() && tail().isEmpty(); } diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 1ec77980..a74d2495 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -51,7 +51,7 @@ private Option() { } @Override - public String toString() { + public final String toString() { return optionShow(Show.anyShow()).showS(this); } @@ -411,44 +411,44 @@ public final Option sequence(final Option o) { return bind(c); } - public Either> traverseEither(F> f) { + public final Either> traverseEither(F> f) { return map(a -> f.f(a).right().map(Option::some)).orSome(Either.right(none())); } - public IO> traverseIO(F> f) { + public final IO> traverseIO(F> f) { return map(a -> IOFunctions.map(f.f(a), Option::some)).orSome(IOFunctions.lazy(Option::none)); } - public List> traverseList(F> f) { + public final List> traverseList(F> f) { return map(a -> f.f(a).map(Option::some)).orSome(List.list()); } - public Option> traverseOption(F> f) { + public final Option> traverseOption(F> f) { return map(f); } - public Stream> traverseStream(F> f) { + public final Stream> traverseStream(F> f) { return map(a -> f.f(a).map(Option::some)).orSome(Stream.nil()); } - public P1> traverseP1(F> f) { + public final P1> traverseP1(F> f) { return map(a -> f.f(a).map(Option::some)).orSome(p(none())); } - public Seq> traverseSeq(F> f) { + public final Seq> traverseSeq(F> f) { return map(a -> f.f(a).map(Option::some)).orSome(Seq.empty()); } - public Set> traverseSet(Ord ord, F> f) { + public final Set> traverseSet(Ord ord, F> f) { Ord> optOrd = Ord.optionOrd(ord); return map(a -> f.f(a).map(optOrd, Option::some)).orSome(Set.empty(optOrd)); } - public F2, F>, Set>> traverseSet() { + public final F2, F>, Set>> traverseSet() { return this::traverseSet; } - public Validation> traverseValidation(F> f) { + public final Validation> traverseValidation(F> f) { return map(a -> f.f(a).map(Option::some)).orSome(Validation.success(none())); } @@ -608,7 +608,7 @@ public final boolean exists(final F f) { } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(Option.class, this, other, () -> Equal.optionEqual(Equal.anyEqual())); } @@ -796,7 +796,7 @@ public static Option fromString(final String s) { } @Override - public int hashCode() { + public final int hashCode() { return Hash.optionHash(Hash.anyHash()).hash(this); } @@ -836,7 +836,7 @@ public static F, F, Option>> liftM2(final F Option liftM2(final Option ob, final F2 f) { + public final Option liftM2(final Option ob, final F2 f) { return bind(a -> ob.map(b -> f.f(a, b))); } diff --git a/core/src/main/java/fj/data/Reader.java b/core/src/main/java/fj/data/Reader.java index 042db624..af66c87e 100644 --- a/core/src/main/java/fj/data/Reader.java +++ b/core/src/main/java/fj/data/Reader.java @@ -15,7 +15,7 @@ public Reader(F f) { function = f; } - public F getFunction() { + public final F getFunction() { return function; } @@ -27,23 +27,23 @@ public static Reader constant(B b) { return unit(a -> b); } - public B f(A a) { + public final B f(A a) { return function.f(a); } - public Reader map(F f) { + public final Reader map(F f) { return unit(F1Functions.andThen(function, f)); } - public Reader andThen(F f) { + public final Reader andThen(F f) { return map(f); } - public Reader flatMap(F> f) { + public final Reader flatMap(F> f) { return unit(a -> f.f(function.f(a)).f(a)); } - public Reader bind(F> f) { + public final Reader bind(F> f) { return flatMap(f); } diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 42ce0bac..35b3c683 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -142,17 +142,17 @@ public static Set empty(final Ord ord) { } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(Set.class, this, other, () -> Equal.setEqual(Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.setHash(Hash.anyHash()).hash(this); } @Override - public String toString() { + public final String toString() { return Show.setShow(Show.anyShow()).showS(this); } @@ -467,11 +467,11 @@ public static F, F, Set>> minus() { return curry(Set::minus); } - public Option min() { + public final Option min() { return isEmpty() ? none() : l().min().orElse(some(head())); } - public Option max() { + public final Option max() { return isEmpty() ? none() : r().max().orElse(some(head())); } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 4abde573..01e1756b 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -1258,25 +1258,25 @@ public final boolean forall(final F f) { } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(Stream.class, this, other, () -> Equal.streamEqual(Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.streamHash(Hash.anyHash()).hash(this); } @Override - public String toString() { + public final String toString() { return toStringLazy(); } - public String toStringLazy() { + public final String toStringLazy() { return isEmpty() ? "Nil()" : "Cons(" + Show.anyShow().showS(head()) + ", ?)"; } - public String toStringEager() { + public final String toStringEager() { return Show.streamShow(Show.anyShow()).showS(this); } diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 9d82596b..58aa5e9c 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -31,7 +31,7 @@ protected Validation(final Either e) { * * @return true if this is a failure, false otherwise. */ - public boolean isFail() { + public final boolean isFail() { return e.isLeft(); } @@ -40,7 +40,7 @@ public boolean isFail() { * * @return true if this is a success, false otherwise. */ - public boolean isSuccess() { + public final boolean isSuccess() { return e.isRight(); } @@ -49,7 +49,7 @@ public boolean isSuccess() { * * @return the failing value, or throws an error if there is no failing value. */ - public E fail() { + public final E fail() { if (isFail()) return e.left().value(); else @@ -61,7 +61,7 @@ public E fail() { * * @return the success value, or throws an error if there is no success value. */ - public T success() { + public final T success() { if (isSuccess()) return e.right().value(); else @@ -75,7 +75,7 @@ public T success() { * @param success The function to call if this succeeded. * @return The reduced value. */ - public X validation(final F fail, final F success) { + public final X validation(final F fail, final F success) { return e.either(fail, success); } @@ -84,7 +84,7 @@ public X validation(final F fail, final F success) { * * @return a failing projection of this validation. */ - public FailProjection f() { + public final FailProjection f() { return new FailProjection<>(this); } @@ -93,7 +93,7 @@ public FailProjection f() { * * @return An either projection of this validation. */ - public Either toEither() { + public final Either toEither() { return e; } @@ -103,7 +103,7 @@ public Either toEither() { * @param err The error message to fail with. * @return The success value. */ - public T successE(final F0 err) { + public final T successE(final F0 err) { return e.right().valueE(err); } @@ -113,7 +113,7 @@ public T successE(final F0 err) { * @param err The error message to fail with. * @return The success value. */ - public T successE(final String err) { + public final T successE(final String err) { return e.right().valueE(p(err)); } @@ -123,7 +123,7 @@ public T successE(final String err) { * @param t The value to return if this is failure. * @return The success value or the given value. */ - public T orSuccess(final F0 t) { + public final T orSuccess(final F0 t) { return e.right().orValue(t); } @@ -133,7 +133,7 @@ public T orSuccess(final F0 t) { * @param t The value to return if this is failure. * @return The success value or the given value. */ - public T orSuccess(final T t) { + public final T orSuccess(final T t) { return e.right().orValue(p(t)); } @@ -143,7 +143,7 @@ public T orSuccess(final T t) { * @param f The function to execute on the failing value. * @return The success value or the application of the given function to the failing value. */ - public T on(final F f) { + public final T on(final F f) { return e.right().on(f); } @@ -153,7 +153,7 @@ public T on(final F f) { * @param f The side-effect to execute. * @return The unit value. */ - public Unit foreach(final F f) { + public final Unit foreach(final F f) { return e.right().foreach(f); } @@ -162,7 +162,7 @@ public Unit foreach(final F f) { * * @param f The side-effect to execute. */ - public void foreachDoEffect(final Effect1 f) { + public final void foreachDoEffect(final Effect1 f) { e.right().foreachDoEffect(f); } @@ -173,7 +173,7 @@ public void foreachDoEffect(final Effect1 f) { * @return A new validation with the function mapped. */ @SuppressWarnings("unchecked") - public Validation map(final F f) { + public final Validation map(final F f) { return isFail() ? Validation.fail(fail()) : Validation.success(f.f(success())); @@ -186,7 +186,7 @@ public Validation map(final F f) { * @return A new validation value after binding. */ @SuppressWarnings("unchecked") - public Validation bind(final F> f) { + public final Validation bind(final F> f) { return isSuccess() ? f.f(success()) : Validation.fail(fail()); } @@ -196,7 +196,7 @@ public Validation bind(final F> f) { * @param v The value to bind with. * @return A validation after binding. */ - public Validation sequence(final Validation v) { + public final Validation sequence(final Validation v) { return bind(Function.constant(v)); } @@ -220,7 +220,7 @@ public static Validation> sequence(final Semigroup s, final * @return None if this is a failure or if the given predicate p does not hold for the * success value, otherwise, returns a success in Some. */ - public Option> filter(final F f) { + public final Option> filter(final F f) { return e.right().filter(f).map(Validation.validation()); } @@ -230,7 +230,7 @@ public Option> filter(final F f) { * @param v The validation of the function to apply on the success value. * @return The result of function application in validation. */ - public Validation apply(final Validation> v) { + public final Validation apply(final Validation> v) { return v.bind(this::map); } @@ -242,7 +242,7 @@ public Validation apply(final Validation> v) { * @return true if this is a failure or returns the result of the application of the given * function to the success value. */ - public boolean forall(final F f) { + public final boolean forall(final F f) { return e.right().forall(f); } @@ -254,17 +254,17 @@ public boolean forall(final F f) { * @return false if this is a failure or returns the result of the application of the given * function to the success value. */ - public boolean exists(final F f) { + public final boolean exists(final F f) { return e.right().exists(f); } @Override - public boolean equals(Object other) { + public final boolean equals(Object other) { return Equal.equals0(Validation.class, this, other, () -> Equal.validationEqual(Equal.anyEqual(), Equal.anyEqual())); } @Override - public int hashCode() { + public final int hashCode() { return Hash.validationHash(Hash.anyHash(), Hash.anyHash()).hash(this); } @@ -273,7 +273,7 @@ public int hashCode() { * * @return A single element list if this is a success value, otherwise an empty list. */ - public List toList() { + public final List toList() { return e.right().toList(); } @@ -282,7 +282,7 @@ public List toList() { * * @return The success value in Some if there is one, otherwise None. */ - public Option toOption() { + public final Option toOption() { return e.right().toOption(); } @@ -291,7 +291,7 @@ public Option toOption() { * * @return A single element array if this is a success value, otherwise an empty list. */ - public Array toArray() { + public final Array toArray() { return e.right().toArray(); } @@ -300,7 +300,7 @@ public Array toArray() { * * @return A single element stream if this is a success value, otherwise an empty list. */ - public Stream toStream() { + public final Stream toStream() { return e.right().toStream(); } @@ -314,7 +314,7 @@ public Stream toStream() { * succeeding validation if both succeeded. */ @SuppressWarnings("unchecked") - public Validation accumapply(final Semigroup s, final Validation> v) { + public final Validation accumapply(final Semigroup s, final Validation> v) { return isFail() ? Validation.fail(v.isFail() ? s.sum(v.fail(), fail()) : @@ -334,7 +334,7 @@ public Validation accumapply(final Semigroup s, final Validation Validation accumulate(final Semigroup s, final Validation va, final F> f) { + public final Validation accumulate(final Semigroup s, final Validation va, final F> f) { return va.accumapply(s, map(f)); } @@ -348,7 +348,7 @@ public Validation accumulate(final Semigroup s, final Validation * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, final F2 f) { + public final Validation accumulate(final Semigroup s, final Validation va, final F2 f) { return va.accumapply(s, map(curry(f))); } @@ -360,7 +360,7 @@ public Validation accumulate(final Semigroup s, final Validation * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va) { + public final Option accumulate(final Semigroup s, final Validation va) { return accumulate(s, va, (t, a) -> unit()).f().toOption(); } @@ -375,8 +375,8 @@ public Option accumulate(final Semigroup s, final Validation va) * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final F>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final F>> f) { return vb.accumapply(s, accumulate(s, va, f)); } @@ -391,8 +391,8 @@ public Validation accumulate(final Semigroup s, final Validat * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final F3 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final F3 f) { return vb.accumapply(s, accumulate(s, va, curry(f))); } @@ -405,7 +405,7 @@ public Validation accumulate(final Semigroup s, final Validat * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, final Validation vb) { + public final Option accumulate(final Semigroup s, final Validation va, final Validation vb) { return accumulate(s, va, vb, (t, a, b) -> unit()).f().toOption(); } @@ -421,9 +421,9 @@ public Option accumulate(final Semigroup s, final Validation * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final F>>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final F>>> f) { return vc.accumapply(s, accumulate(s, va, vb, f)); } @@ -439,9 +439,9 @@ public Validation accumulate(final Semigroup s, final Vali * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final F4 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final F4 f) { return vc.accumapply(s, accumulate(s, va, vb, curry(f))); } @@ -455,8 +455,8 @@ public Validation accumulate(final Semigroup s, final Vali * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, final Validation vb, - final Validation vc) { + public final Option accumulate(final Semigroup s, final Validation va, final Validation vb, + final Validation vc) { return accumulate(s, va, vb, vc, (t, a, b, c) -> unit()).f().toOption(); } @@ -473,10 +473,10 @@ public Option accumulate(final Semigroup s, final Validation Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, - final F>>>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, + final F>>>> f) { return vd.accumapply(s, accumulate(s, va, vb, vc, f)); } @@ -493,9 +493,9 @@ public Option accumulate(final Semigroup s, final Validation Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final F5 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final F5 f) { return vd.accumapply(s, accumulate(s, va, vb, vc, curry(f))); } @@ -510,8 +510,8 @@ public Option accumulate(final Semigroup s, final ValidationSome if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, final Validation vb, - final Validation vc, final Validation vd) { + public final Option accumulate(final Semigroup s, final Validation va, final Validation vb, + final Validation vc, final Validation vd) { return accumulate(s, va, vb, vc, vd, (t, a, b, c, d) -> unit()).f().toOption(); } @@ -529,10 +529,10 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final F>>>>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final F>>>>> f) { return ve.accumapply(s, accumulate(s, va, vb, vc, vd, f)); } @@ -550,10 +550,10 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final F6 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final F6 f) { return ve.accumapply(s, accumulate(s, va, vb, vc, vd, curry(f))); } @@ -569,9 +569,9 @@ public Option accumulate(final Semigroup s, final Validation< * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve) { + public final Option accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve) { return accumulate(s, va, vb, vc, vd, ve, (t, a, b, c, d, e1) -> unit()).f().toOption(); } @@ -590,11 +590,11 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf, - final F>>>>>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf, + final F>>>>>> f) { return vf.accumapply(s, accumulate(s, va, vb, vc, vd, ve, f)); } @@ -613,11 +613,11 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf, - final F7 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf, + final F7 f) { return vf.accumapply(s, accumulate(s, va, vb, vc, vd, ve, curry(f))); } @@ -634,10 +634,10 @@ public Option accumulate(final Semigroup s, final Validation< * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf) { + public final Option accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf) { return accumulate(s, va, vb, vc, vd, ve, vf, (t, a, b, c, d, e1, f) -> unit()).f().toOption(); } @@ -657,11 +657,11 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf, final Validation vg, - final F>>>>>>> f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf, final Validation vg, + final F>>>>>>> f) { return vg.accumapply(s, accumulate(s, va, vb, vc, vd, ve, vf, f)); } @@ -681,11 +681,11 @@ public Option accumulate(final Semigroup s, final Validation< * @return A succeeding validation if all validations succeeded, or a failing validation with errors accumulated if * one or more failed. */ - public Validation accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf, final Validation vg, - final F8 f) { + public final Validation accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf, final Validation vg, + final F8 f) { return vg.accumapply(s, accumulate(s, va, vb, vc, vd, ve, vf, curry(f))); } @@ -703,10 +703,10 @@ public Option accumulate(final Semigroup s, final Validation< * @return A Some if one or more validations failed (accumulated with the semigroup), otherwise, * None. */ - public Option accumulate(final Semigroup s, final Validation va, - final Validation vb, final Validation vc, - final Validation vd, final Validation ve, - final Validation vf, final Validation vg) { + public final Option accumulate(final Semigroup s, final Validation va, + final Validation vb, final Validation vc, + final Validation vd, final Validation ve, + final Validation vf, final Validation vg) { return accumulate(s, va, vb, vc, vd, ve, vf, vg, (t, a, b, c, d, e1, f, g) -> unit()).f().toOption(); } @@ -715,12 +715,12 @@ public Option accumulate(final Semigroup s, final Validation< * * @return A iterator for this validation. */ - public Iterator iterator() { + public final Iterator iterator() { return toEither().right().iterator(); } - public Validation, T> accumulate() { + public final Validation, T> accumulate() { if (isFail()) { return fail(List.single(fail())); } else { @@ -728,7 +728,7 @@ public Validation, T> accumulate() { } } - public Validation, B> accumulate(F f) { + public final Validation, B> accumulate(F f) { if (isFail()) { return fail(List.single(fail())); } else { @@ -737,7 +737,7 @@ public Validation, B> accumulate(F f) { } - public Validation, C> accumulate(Validation v2, F2 f) { + public final Validation, C> accumulate(Validation v2, F2 f) { List list = List.nil(); if (isFail()) { list = list.cons(fail()); @@ -754,7 +754,7 @@ public Validation, C> accumulate(Validation v2, F2 - public Validation, D> accumulate(Validation v2, Validation v3, F3 f) { + public final Validation, D> accumulate(Validation v2, Validation v3, F3 f) { List list = fails(list(this, v2, v3)); if (!list.isEmpty()) { return fail(list); @@ -763,7 +763,7 @@ public Validation, D> accumulate(Validation v2, Validati } } - public Validation, $E> accumulate(Validation v2, Validation v3, Validation v4, F4 f) { + public final Validation, $E> accumulate(Validation v2, Validation v3, Validation v4, F4 f) { List list = fails(list(this, v2, v3, v4)); if (!list.isEmpty()) { return fail(list); @@ -772,7 +772,7 @@ public Validation, D> accumulate(Validation v2, Validati } } - public Validation, $F> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, F5 f) { + public final Validation, $F> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, F5 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { return fail(list); @@ -782,7 +782,7 @@ public Validation, D> accumulate(Validation v2, Validati } - public Validation, G> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, F6 f) { + public final Validation, G> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, F6 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { return fail(list); @@ -791,7 +791,7 @@ public Validation, D> accumulate(Validation v2, Validati } } - public Validation, H> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, F7 f) { + public final Validation, H> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, F7 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { return fail(list); @@ -800,7 +800,7 @@ public Validation, D> accumulate(Validation v2, Validati } } - public Validation, I> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, Validation v8, F8 f) { + public final Validation, I> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, Validation v8, F8 f) { List list = fails(list(this, v2, v3, v4, v5)); if (!list.isEmpty()) { return fail(list); @@ -825,31 +825,31 @@ public static Validation, List> sequenceNonCumulative(List List> traverseList(F> f){ + public final List> traverseList(F> f){ return isSuccess() ? f.f(success()).map(Validation::success) : List.iterableList(fail(e.left().value())); } - public Stream> traverseStream(F> f){ + public final Stream> traverseStream(F> f){ return isSuccess() ? f.f(success()).map(Validation::success) : Stream.iterableStream(fail(e.left().value())); } - public Option> traverseOption(F> f){ + public final Option> traverseOption(F> f){ return isSuccess() ? f.f(success()).map(Validation::success) : Option.some(fail(e.left().value())); } - public IO> traverseIO(F> f){ + public final IO> traverseIO(F> f){ return isSuccess() ? IOFunctions.map(f.f(success()), Validation::success) : IOFunctions.unit(fail(e.left().value())); } - public P1> traverseP1(F> f){ + public final P1> traverseP1(F> f){ return isSuccess() ? f.f(success()).map(Validation::success) : p(fail(e.left().value())); @@ -1081,7 +1081,7 @@ public Iterator iterator() { * @return A validation with its failing value in a non-empty list if there is one. */ @SuppressWarnings("unchecked") - public Validation, T> nel() { + public final Validation, T> nel() { return isSuccess() ? Validation.success(success()) : Validation.fail(NonEmptyList.nel(fail())); @@ -1283,7 +1283,7 @@ public static P2, List> partition(List> list) } @Override - public String toString() { + public final String toString() { return Show.validationShow(Show.anyShow(), Show.anyShow()).showS(this); } diff --git a/core/src/main/java/fj/data/fingertrees/Digit.java b/core/src/main/java/fj/data/fingertrees/Digit.java index 415f08c2..fb552ce9 100644 --- a/core/src/main/java/fj/data/fingertrees/Digit.java +++ b/core/src/main/java/fj/data/fingertrees/Digit.java @@ -138,7 +138,7 @@ public final FingerTree toTree() { ); } - Option> tail() { + final Option> tail() { return match( one -> Option.none(), two -> Option.some(mkTree(m).one(two.values()._2())), @@ -147,7 +147,7 @@ Option> tail() { ); } - Option> init() { + final Option> init() { return match( one -> Option.none(), two -> Option.some(mkTree(m).one(two.values()._1())), diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index 060e976f..f361a76a 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -33,7 +33,7 @@ public abstract class FingerTree { */ public abstract B foldRight(final F> f, final B z); - public B foldRight(final F2 f, final B z) { + public final B foldRight(final F2 f, final B z) { return foldRight(F2Functions.curry(f), z); } @@ -54,7 +54,7 @@ public B foldRight(final F2 f, final B z) { */ public abstract B foldLeft(final F> f, final B z); - public B foldLeft(final F2 f, final B z) { + public final B foldLeft(final F2 f, final B z) { return foldLeft(F2Functions.curry(f), z); } @@ -76,7 +76,7 @@ public B foldLeft(final F2 f, final B z) { */ public abstract FingerTree map(final F f, final Measured m); - public FingerTree filter(final F f) { + public final FingerTree filter(final F f) { FingerTree tree = new Empty<>(m); return foldLeft((acc, a) -> f.f(a) ? acc.snoc(a) : acc, tree); } @@ -97,7 +97,7 @@ public final boolean isEmpty() { return this instanceof Empty; } - Measured measured() { + final Measured measured() { return m; } @@ -160,7 +160,7 @@ public static MakeTree mkTree(final Measured m) { */ public abstract A head(); - public Option headOption() { + public final Option headOption() { return isEmpty() ? Option.none() : Option.some(head()); } diff --git a/core/src/main/java/fj/data/fingertrees/Node.java b/core/src/main/java/fj/data/fingertrees/Node.java index 674195d7..c7e3e7a2 100644 --- a/core/src/main/java/fj/data/fingertrees/Node.java +++ b/core/src/main/java/fj/data/fingertrees/Node.java @@ -48,7 +48,7 @@ public final V measure() { return measure; } - Measured measured() { + final Measured measured() { return m; } diff --git a/core/src/main/java/fj/data/optic/PIso.java b/core/src/main/java/fj/data/optic/PIso.java index 4ed45ca0..7dcd0888 100644 --- a/core/src/main/java/fj/data/optic/PIso.java +++ b/core/src/main/java/fj/data/optic/PIso.java @@ -130,7 +130,7 @@ public final F set(final B b) { } /** pair two disjoint {@link PIso} */ - public PIso, P2, P2, P2> product(final PIso other) { + public final PIso, P2, P2, P2> product(final PIso other) { return pIso( ss1 -> P.p(get(ss1._1()), other.get(ss1._2())), bb1 -> P.p(reverseGet(bb1._1()), other.reverseGet(bb1._2()))); diff --git a/demo/src/main/java/fj/demo/IODemo.java b/demo/src/main/java/fj/demo/IODemo.java index 0bc7db12..6451a46b 100644 --- a/demo/src/main/java/fj/demo/IODemo.java +++ b/demo/src/main/java/fj/demo/IODemo.java @@ -28,7 +28,7 @@ public static void main(String[] args) { * Reads from standard input until the line length is less than three * and prints that last line. */ - public void readFirstShortLine() { + public final void readFirstShortLine() { F f = lift(lines_()).andThen(l -> l.filter(s -> s.length() < 3)).andThen(unlines_()); runSafe(interact(f)); } @@ -36,7 +36,7 @@ public void readFirstShortLine() { /** * Read a stream of input lazily using interact, in effect reading the first line */ - public void readFirstLine() { + public final void readFirstLine() { F f = lift(LazyString::lines).andThen(unlines_()); runSafe(interact(f)); } @@ -45,14 +45,14 @@ public void readFirstLine() { * Demonstrate use of interact, just echoing the lazy string. Reading lines is done * lazily, so just the first line is read. */ - public void simpleInteract() { + public final void simpleInteract() { runSafe(interact(s -> s)); } /** * Demonstrate that getContents returns a lazy string. */ - public void getContents() { + public final void getContents() { out.println(runSafe(IOFunctions.getContents())); } diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index 56763ce5..ef1a09cd 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -29,7 +29,7 @@ public VendingMachine(boolean lock, int things, int numCoins) { * Equals generated by Intellij */ @Override - public boolean equals(Object o) { + public final boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; @@ -46,18 +46,18 @@ public boolean equals(Object o) { * HashCode generated by Intellij */ @Override - public int hashCode() { + public final int hashCode() { int result = locked ? 1 : 0; result = 31 * result + items; result = 31 * result + coins; return result; } - public String toString() { + public final String toString() { return String.format("VendingMachine(locked=%b,items=%d,coins=%d)", locked, items, coins); } - VendingMachine next(Input i) { + final VendingMachine next(Input i) { if (items == 0) { return this; } else if (i == COIN && !locked) { diff --git a/demo/src/main/java/fj/demo/concurrent/Ping.java b/demo/src/main/java/fj/demo/concurrent/Ping.java index 3ba934fb..da2efd52 100644 --- a/demo/src/main/java/fj/demo/concurrent/Ping.java +++ b/demo/src/main/java/fj/demo/concurrent/Ping.java @@ -33,12 +33,12 @@ public void f(final Pong pong) { } // Commence pinging - public P1 start() { + public final P1 start() { return pong.act(this); } // Receive a pong - public P1 act(final Pong p) { + public final P1 act(final Pong p) { return ping.act(p); } } diff --git a/demo/src/main/java/fj/demo/concurrent/PingPong.java b/demo/src/main/java/fj/demo/concurrent/PingPong.java index a9109585..d845ab32 100644 --- a/demo/src/main/java/fj/demo/concurrent/PingPong.java +++ b/demo/src/main/java/fj/demo/concurrent/PingPong.java @@ -51,7 +51,7 @@ public static void main(final String[] args) { new PingPong(Executors.newFixedThreadPool(threads), actors, pings).start(); } - public void start() { + public final void start() { // We will use one Pong actor... final Pong pong = new Pong(s); diff --git a/demo/src/main/java/fj/demo/concurrent/Pong.java b/demo/src/main/java/fj/demo/concurrent/Pong.java index b0f0ad57..bc06a22d 100644 --- a/demo/src/main/java/fj/demo/concurrent/Pong.java +++ b/demo/src/main/java/fj/demo/concurrent/Pong.java @@ -23,7 +23,7 @@ public void f(final Ping m) { } // Receive a ping - public P1 act(final Ping ping) { + public final P1 act(final Ping ping) { return p.act(ping); } } \ No newline at end of file diff --git a/demo/src/main/java/fj/demo/optic/LensPerson.java b/demo/src/main/java/fj/demo/optic/LensPerson.java index 107ef659..51f5e103 100644 --- a/demo/src/main/java/fj/demo/optic/LensPerson.java +++ b/demo/src/main/java/fj/demo/optic/LensPerson.java @@ -48,14 +48,14 @@ public Address(int number, String street) { static final Person oldPerson = new Person(oldName, oldAddress); @Test - public void get() { + public final void get() { assertTrue(personNameLens.get(oldPerson).equals(oldName)); assertTrue(personNumberLens.get(oldPerson) == oldNumber); assertTrue(personStreetLens.get(oldPerson) == oldStreet); } @Test - public void setName() { + public final void setName() { String newName = "Bill"; Person p = personNameLens.set(newName).f(oldPerson); assertTrue(p.name.equals(newName)); @@ -63,7 +63,7 @@ public void setName() { } @Test - public void setNumber() { + public final void setNumber() { int newNumber = 20; Person p = personNumberLens.set(newNumber).f(oldPerson); assertTrue(p.name.equals(oldName)); @@ -72,7 +72,7 @@ public void setNumber() { } @Test - public void setStreet() { + public final void setStreet() { String newStreet = "First St"; Person p = personStreetLens.set(newStreet).f(oldPerson); assertTrue(p.name.equals(oldName)); diff --git a/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java b/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java index 7f2b04ce..876dbff1 100644 --- a/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java +++ b/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java @@ -29,14 +29,14 @@ public PropertyTestRunner(Class clas) { } @Override - public Description getDescription() { + public final Description getDescription() { Description suite = Description.createSuiteDescription(clas); filteredTests.foreachDoEffect(p -> suite.addChild(p._3())); return suite; } @Override - public void run(RunNotifier notifier) { + public final void run(RunNotifier notifier) { filteredTests.foreachDoEffect(p -> { Description desc = p._3(); notifier.fireTestStarted(desc); @@ -66,7 +66,7 @@ private static CheckResult checkProperty(Property prop, Option para } @Override - public void filter(Filter filter) throws NoTestsRemainException { + public final void filter(Filter filter) throws NoTestsRemainException { filteredTests = allTests.filter(p -> filter.shouldRun(p._3())); if (filteredTests.isEmpty()) { throw new NoTestsRemainException(); } } From e47222746840562302f28d9e7eea788d8d6e23e9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:42:59 +0100 Subject: [PATCH 059/336] Avoid potential static initialization deadlock with HNil singleton --- core/src/main/java/fj/data/hlist/HList.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/data/hlist/HList.java b/core/src/main/java/fj/data/hlist/HList.java index 639c9e64..8e9b5389 100644 --- a/core/src/main/java/fj/data/hlist/HList.java +++ b/core/src/main/java/fj/data/hlist/HList.java @@ -28,15 +28,13 @@ public abstract class HList> { public abstract Apply, HCons> extender(); - private static final HNil nil = new HNil(); - /** * Returns the empty list. * * @return the empty list. */ public static HNil nil() { - return nil; + return HNil.nil; } /** @@ -285,7 +283,10 @@ public HCons> extend(final X e) { * The empty list */ public static final class HNil extends HList { - HNil() { + + private static final HNil nil = new HNil(); + + private HNil() { } public HCons extend(final E e) { From c0caae8e7fa5652c21a14a68bb1dc0b3efee3a59 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:46:58 +0100 Subject: [PATCH 060/336] Trampoline#codense should be private --- core/src/main/java/fj/control/Trampoline.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index bd69ae7a..b47a5ea7 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -107,7 +107,7 @@ public Either>, A> resume() { } @SuppressWarnings("unchecked") - protected static Codense codense(final Normal a, final F> k) { + private static Codense codense(final Normal a, final F> k) { return new Codense<>((Normal) a, (F>) k); } From 5345f6ffea3054f97ac9690bce57952d9da3fb27 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:53:33 +0100 Subject: [PATCH 061/336] Male Either projections _static_ inner classes. --- core/src/main/java/fj/data/Either.java | 90 +++++++++++++------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 77dea3c3..a4f0fc02 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -145,7 +145,7 @@ public boolean isRight() { /** * A left projection of an either value. */ - public final class LeftProjection implements Iterable { + public static final class LeftProjection implements Iterable { private final Either e; private LeftProjection(final Either e) { @@ -210,7 +210,7 @@ public A value() { * @return The value of this projection or the given argument. */ public A orValue(final F0 a) { - return isLeft() ? value() : a.f(); + return e.isLeft() ? value() : a.f(); } /** @@ -220,7 +220,7 @@ public A orValue(final F0 a) { * @return The value of this projection or the given argument. */ public A orValue(final A a) { - return isLeft() ? value() : a; + return e.isLeft() ? value() : a; } /** @@ -232,7 +232,7 @@ public A orValue(final A a) { * value. */ public A on(final F f) { - return isLeft() ? value() : f.f(e.right().value()); + return e.isLeft() ? value() : f.f(e.right().value()); } /** @@ -242,7 +242,7 @@ public A on(final F f) { * @return The unit value. */ public Unit foreach(final F f) { - if (isLeft()) + if (e.isLeft()) f.f(value()); return unit(); @@ -254,7 +254,7 @@ public Unit foreach(final F f) { * @param f The side-effect to execute. */ public void foreachDoEffect(final Effect1 f) { - if (isLeft()) + if (e.isLeft()) f.f(value()); } @@ -265,7 +265,7 @@ public void foreachDoEffect(final Effect1 f) { * @return A new either value after mapping. */ public Either map(final F f) { - return isLeft() ? new Left<>(f.f(value())) : new Right<>(e.right().value()); + return e.isLeft() ? new Left<>(f.f(value())) : new Right<>(e.right().value()); } /** @@ -275,7 +275,7 @@ public Either map(final F f) { * @return A new either value after binding. */ public Either bind(final F> f) { - return isLeft() ? f.f(value()) : new Right<>(e.right().value()); + return e.isLeft() ? f.f(value()) : new Right<>(e.right().value()); } /** @@ -295,9 +295,9 @@ public Either sequence(final Either e) { * @return An either after traversing through this projection. */ public List> traverseList(final F> f) { - return isLeft() ? + return e.isLeft() ? f.f(value()).map(Either::left) : - list(Either.right(e.right().value())); + list(right(e.right().value())); } /** @@ -307,7 +307,7 @@ public List> traverseList(final F> f) { * @return An either after traversing through this projection. */ public IO> traverseIO(final F> f) { - return isRight() ? + return e.isRight() ? IOFunctions.map(f.f(value()), Either::left) : IOFunctions.unit(Either.right(e.right().value())); } @@ -321,9 +321,9 @@ public IO> traverseIO(final F> f) { * p does not hold for the value, otherwise, returns a right in Some. */ public Option> filter(final F f) { - return isLeft() ? + return e.isLeft() ? f.f(value()) ? - Option.some(new Left<>(value())) : + some(new Left<>(value())) : Option.none() : Option.none(); } @@ -347,7 +347,7 @@ public Either apply(final Either, B> e) { * function to the value. */ public boolean forall(final F f) { - return isRight() || f.f(value()); + return e.isRight() || f.f(value()); } /** @@ -359,7 +359,7 @@ public boolean forall(final F f) { * function to the value. */ public boolean exists(final F f) { - return isLeft() && f.f(value()); + return e.isLeft() && f.f(value()); } /** @@ -368,7 +368,7 @@ public boolean exists(final F f) { * @return A single element list if this projection has a value, otherwise an empty list. */ public List toList() { - return isLeft() ? single(value()) : List.nil(); + return e.isLeft() ? single(value()) : List.nil(); } /** @@ -379,7 +379,7 @@ public List toList() { * None. */ public Option toOption() { - return isLeft() ? some(value()) : Option.none(); + return e.isLeft() ? some(value()) : Option.none(); } /** @@ -388,7 +388,7 @@ public Option toOption() { * @return A single element array if this projection has a value, otherwise an empty array. */ public Array toArray() { - if (isLeft()) { + if (e.isLeft()) { final Object[] a = new Object[1]; a[0] = value(); return mkArray(a); @@ -402,7 +402,7 @@ public Array toArray() { * @return A single element stream if this projection has a value, otherwise an empty stream. */ public Stream toStream() { - return isLeft() ? Stream.single(value()) : Stream.nil(); + return e.isLeft() ? Stream.single(value()) : Stream.nil(); } /** @@ -415,13 +415,13 @@ public Collection toCollection() { } public Option> traverseOption(F> f) { - return isLeft() ? + return e.isLeft() ? f.f(value()).map(Either::left) : some(Either.right(e.right().value())); } public Stream> traverseStream(F> f) { - return isLeft() ? + return e.isLeft() ? f.f(value()).map(Either::left) : Stream.single(Either.right(e.right().value())); } @@ -430,7 +430,7 @@ public Stream> traverseStream(F> f) { /** * A right projection of an either value. */ - public final class RightProjection implements Iterable { + public static final class RightProjection implements Iterable { private final Either e; private RightProjection(final Either e) { @@ -485,7 +485,7 @@ public B value() { * @return The value of this projection or the given argument. */ public B orValue(final F0 b) { - return isRight() ? value() : b.f(); + return e.isRight() ? value() : b.f(); } /** @@ -497,7 +497,7 @@ public B orValue(final F0 b) { * value. */ public B on(final F f) { - return isRight() ? value() : f.f(e.left().value()); + return e.isRight() ? value() : f.f(e.left().value()); } /** @@ -507,7 +507,7 @@ public B on(final F f) { * @return The unit value. */ public Unit foreach(final F f) { - if (isRight()) + if (e.isRight()) f.f(value()); return unit(); @@ -519,7 +519,7 @@ public Unit foreach(final F f) { * @param f The side-effect to execute. */ public void foreachDoEffect(final Effect1 f) { - if (isRight()) + if (e.isRight()) f.f(value()); } @@ -530,7 +530,7 @@ public void foreachDoEffect(final Effect1 f) { * @return A new either value after mapping. */ public Either map(final F f) { - return isRight() ? new Right<>(f.f(value())) : new Left<>(e.left().value()); + return e.isRight() ? new Right<>(f.f(value())) : new Left<>(e.left().value()); } /** @@ -540,7 +540,7 @@ public Either map(final F f) { * @return A new either value after binding. */ public Either bind(final F> f) { - return isRight() ? f.f(value()) : new Left<>(e.left().value()); + return e.isRight() ? f.f(value()) : new Left<>(e.left().value()); } @@ -560,9 +560,9 @@ public Either sequence(final Either e) { * @return An either after traversing through this projection. */ public List> traverseList(final F> f) { - return isRight() ? + return e.isRight() ? f.f(value()).map(Either::right) : - list(Either.left(e.left().value())); + list(left(e.left().value())); } /** @@ -572,21 +572,21 @@ public List> traverseList(final F> f) { * @return An either after traversing through this projection. */ public IO> traverseIO(final F> f) { - return isRight() ? + return e.isRight() ? IOFunctions.map(f.f(value()), Either::right) : - IOFunctions.lazy(() -> Either.left(e.left().value())); + IOFunctions.lazy(() -> left(e.left().value())); } public P1> traverseP1(final F> f) { - return isRight() ? + return e.isRight() ? f.f(value()).map(Either::right) : - p(Either.left(e.left().value())); + p(left(e.left().value())); } public Option> traverseOption(final F> f) { - return isRight() ? + return e.isRight() ? f.f(value()).map(Either::right) : - some(Either.left(e.left().value())); + some(left(e.left().value())); } /** @@ -598,9 +598,9 @@ public Option> traverseOption(final F> f) { * p does not hold for the value, otherwise, returns a left in Some. */ public Option> filter(final F f) { - return isRight() ? + return e.isRight() ? f.f(value()) ? - Option.some(new Right(value())) : + some(new Right(value())) : Option.none() : Option.none(); } @@ -624,7 +624,7 @@ public Either apply(final Either> e) { * function to the value. */ public boolean forall(final F f) { - return isLeft() || f.f(value()); + return e.isLeft() || f.f(value()); } /** @@ -636,7 +636,7 @@ public boolean forall(final F f) { * function to the value. */ public boolean exists(final F f) { - return isRight() && f.f(value()); + return e.isRight() && f.f(value()); } /** @@ -645,7 +645,7 @@ public boolean exists(final F f) { * @return A single element list if this projection has a value, otherwise an empty list. */ public List toList() { - return isRight() ? single(value()) : List.nil(); + return e.isRight() ? single(value()) : List.nil(); } /** @@ -656,7 +656,7 @@ public List toList() { * None. */ public Option toOption() { - return isRight() ? some(value()) : Option.none(); + return e.isRight() ? some(value()) : Option.none(); } /** @@ -665,7 +665,7 @@ public Option toOption() { * @return A single element array if this projection has a value, otherwise an empty array. */ public Array toArray() { - if (isRight()) { + if (e.isRight()) { final Object[] a = new Object[1]; a[0] = value(); return mkArray(a); @@ -679,7 +679,7 @@ public Array toArray() { * @return A single element stream if this projection has a value, otherwise an empty stream. */ public Stream toStream() { - return isRight() ? Stream.single(value()) : Stream.nil(); + return e.isRight() ? Stream.single(value()) : Stream.nil(); } /** @@ -692,7 +692,7 @@ public Collection toCollection() { } public Stream> traverseStream(F> f) { - return isRight() ? + return e.isRight() ? f.f(value()).map(Either::right) : Stream.single(left(e.left().value())); From 345fb6c8e1be735c288c7c1bef9127b2f35aae1f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 15:59:52 +0100 Subject: [PATCH 062/336] Remove confusing hiding of type parameter --- core/src/main/java/fj/data/List.java | 4 ++-- quickcheck/src/main/java/fj/test/Gen.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 15171e43..cfd95898 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -943,7 +943,7 @@ public final List sort(final Ord o) { else if (tail().isEmpty()) return this; else { - final class Merge { + final class Merge { List merge(List xs, List ys, final Ord o) { final Buffer buf = empty(); @@ -975,7 +975,7 @@ List merge(List xs, List ys, final Ord o) { } final P2, List> s = splitAt(length() / 2); - return new Merge().merge(s._1().sort(o), s._2().sort(o), o); + return new Merge().merge(s._1().sort(o), s._2().sort(o), o); } } diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 0ffed76a..24e855a8 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -409,7 +409,7 @@ public static Gen join(final Gen> g) { */ public static Gen frequency(final List>> gs) { final class Pick { - Gen pick(final int n, final List>> gs) { + Gen pick(final int n, final List>> gs) { if(gs.isEmpty()) return fail(); else { @@ -421,7 +421,7 @@ Gen pick(final int n, final List>> gs) { final F>, Integer> f = __1(); - return choose(1, intAdditionMonoid.sumLeft(gs.map(f))).bind(i -> new Pick().pick(i, gs)); + return choose(1, intAdditionMonoid.sumLeft(gs.map(f))).bind(i -> new Pick().pick(i, gs)); } /** From d784b7f7ee1e5068d934a36a7b211e9974d53e9a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Mar 2016 16:09:45 +0100 Subject: [PATCH 063/336] unwrap redondant function application --- core/src/main/java/fj/control/Trampoline.java | 2 +- core/src/main/java/fj/data/Array.java | 2 +- core/src/main/java/fj/data/IOFunctions.java | 2 +- core/src/main/java/fj/data/Option.java | 2 +- core/src/main/java/fj/data/State.java | 2 +- core/src/main/java/fj/data/vector/V.java | 2 +- quickcheck/src/main/java/fj/test/Gen.java | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index b47a5ea7..cd477dd0 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -56,7 +56,7 @@ public Either>, A> resume() { // WARNING: In JDK 8, update 25 (current version) the following code is a // workaround for an internal JDK compiler error, likely due to // https:bugs.openjdk.java.net/browse/JDK-8062253. - F, Trampoline> f = o -> o.foldNormal(cont::f, t -> t._1().bind(cont)); + F, Trampoline> f = o -> o.foldNormal(cont, t -> t._1().bind(cont)); F, Trampoline> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont)); return ot.fold(f, g); }), o -> P.lazy(() -> cont.f(o)))); diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index 75dd3c3a..b6538ba5 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -529,7 +529,7 @@ public Array bind(final Array sb, final F2 f) { * @return A new array after applying the given array of functions through this array. */ public Array apply(final Array> lf) { - return lf.bind(f -> map(f::f)); + return lf.bind(f -> map(f)); } /** diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 1440b692..92263d09 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -417,7 +417,7 @@ public static IO> sequenceWhile(final Stream> stream, final } public static IO apply(IO io, IO> iof) { - return bind(iof, f -> map(io, f::f)); + return bind(iof, f -> map(io, f)); } public static IO liftM2(IO ioa, IO iob, F2 f) { diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index a74d2495..4cdb411f 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -460,7 +460,7 @@ public final Validation> traverseValidation(F Option apply(final Option> of) { - return of.bind(f -> map(f::f)); + return of.bind(f -> map(f)); } /** diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index e0724373..3128ae6c 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -93,7 +93,7 @@ public State withs(F f) { } public static State gets(F f) { - return State.init().map(f::f); + return State.init().map(f); } /** diff --git a/core/src/main/java/fj/data/vector/V.java b/core/src/main/java/fj/data/vector/V.java index 57249ac8..70d60f58 100644 --- a/core/src/main/java/fj/data/vector/V.java +++ b/core/src/main/java/fj/data/vector/V.java @@ -35,7 +35,7 @@ public static V2 v(final A a1, final A a2) { * @return The vector-2. */ public static V2 v(final F0 a1, final F0 a2) { - return V2.p(P.lazy(a1::f, a2::f)); + return V2.p(P.lazy(a1, a2)); } /** diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 24e855a8..6db7b304 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -276,7 +276,7 @@ public Gen bind(final Gen gb, final Gen gc, final Gen g * @return A new generator after function application. */ public Gen apply(final Gen> gf) { - return gf.bind(f1 -> map(f1::f)); + return gf.bind(f1 -> map(f1)); } /** From 3107a2f11f59f5b0dbf8226604e513908c210fd1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 9 May 2016 23:19:30 +0200 Subject: [PATCH 064/336] add unit tests for IOFunctions#bracket --- .../test/java/fj/data/IOFunctionsTest.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 core/src/test/java/fj/data/IOFunctionsTest.java diff --git a/core/src/test/java/fj/data/IOFunctionsTest.java b/core/src/test/java/fj/data/IOFunctionsTest.java new file mode 100644 index 00000000..dcafc221 --- /dev/null +++ b/core/src/test/java/fj/data/IOFunctionsTest.java @@ -0,0 +1,64 @@ +package fj.data; + +import fj.Unit; +import org.hamcrest.core.Is; +import org.junit.Assert; +import org.junit.Test; + +import java.io.*; +import java.io.Reader; +import java.util.concurrent.atomic.AtomicBoolean; + +import static org.junit.Assert.*; + +public class IOFunctionsTest { + + @Test + public void bracket_happy_path() throws Exception { + AtomicBoolean closed = new AtomicBoolean(); + Reader reader = new StringReader("Read OK") { + @Override + public void close() { + super.close(); + closed.set(true); + } + }; + + IO bracketed = IOFunctions.bracket( + () -> reader, + IOFunctions.closeReader, + r -> () -> new BufferedReader(r).readLine() + ); + + Assert.assertThat(bracketed.run(), Is.is("Read OK")); + Assert.assertThat(closed.get(), Is.is(true)); + } + + @Test + public void bracket_exception_path() throws Exception { + AtomicBoolean closed = new AtomicBoolean(); + Reader reader = new StringReader("Read OK") { + @Override + public void close() { + super.close(); + closed.set(true); + throw new IllegalStateException("Should be suppressed"); + } + }; + + IO bracketed = IOFunctions.bracket( + () -> reader, + IOFunctions.closeReader, + r -> () -> {throw new IllegalArgumentException("OoO");} + ); + + try { + bracketed.run(); + fail("Exception expected"); + } catch (IllegalArgumentException e) { + Assert.assertThat(e.getMessage(), Is.is("OoO")); + } + Assert.assertThat(closed.get(), Is.is(true)); + } + +} \ No newline at end of file From 30da36c20aabfc09b2335f227683bc74d725bab4 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Fri, 13 May 2016 23:08:44 +1000 Subject: [PATCH 065/336] Add "dual" methods on Semigroup and Monoid --- core/src/main/java/fj/Monoid.java | 8 ++++++++ core/src/main/java/fj/Semigroup.java | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index af6d95f9..a7f3106f 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -11,6 +11,7 @@ import fj.data.Set; import fj.data.Stream; +import static fj.Function.flip; import static fj.Semigroup.multiply1p; import static fj.data.Stream.iterableStream; @@ -191,6 +192,13 @@ public A join(final Iterable as, final A a) { s.foldLeft1(Function.compose(sum, flip(sum).f(a))); } + /** + * Swaps the arguments when summing. + */ + public Monoid dual() { + return monoid(flip(sum), zero); + } + /** * Constructs a monoid from the given sum function and zero value, which must follow the monoidal * laws. diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 057596f5..0aa4e810 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -14,6 +14,7 @@ import java.math.BigInteger; import static fj.Function.curry; +import static fj.Function.flip; /** * Implementations must satisfy the law of associativity: @@ -97,6 +98,13 @@ static A multiply1p(F> sum, int n, A a) { } /** + /** + * Swaps the arguments when summing. + */ + public Semigroup dual() { + return semigroup(flip(sum)); + } + * Constructs a semigroup from the given function. * * @param sum The function to construct this semigroup with. From e3bf1253bfc7dc10bbd86b0dad9bcf24d5f7912f Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 16 May 2016 18:46:59 +1000 Subject: [PATCH 066/336] Add min and max Semigroup instances for Ords --- core/src/main/java/fj/Ord.java | 11 ++++++++++- core/src/main/java/fj/Semigroup.java | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index bb682ad8..41b87f94 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -15,6 +15,7 @@ import java.util.Comparator; import static fj.Function.curry; +import static fj.Semigroup.semigroup; /** * Tests for ordering between two objects. @@ -157,7 +158,15 @@ public A min(final A a1, final A a2) { */ public final F> min = curry(this::min); - public Ord reverse() { return ord(Function.flip(f)); } + public final Semigroup minSemigroup() { + return semigroup(this::min); + } + + public final Semigroup maxSemigroup() { + return semigroup(this::max); + } + + public final Ord reverse() { return ord(Function.flip(f)); } /** * Returns an order instance that uses the given equality test and ordering function. diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 0aa4e810..8557c02b 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -147,12 +147,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that yields the maximum of integers. */ - public static final Semigroup intMaximumSemigroup = semigroup(Ord.intOrd.max); + public static final Semigroup intMaximumSemigroup = Ord.intOrd.maxSemigroup(); /** * A semigroup that yields the minimum of integers. */ - public static final Semigroup intMinimumSemigroup = semigroup(Ord.intOrd.min); + public static final Semigroup intMinimumSemigroup = Ord.intOrd.minSemigroup(); /** * A semigroup that adds big integers. @@ -169,12 +169,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that yields the maximum of big integers. */ - public static final Semigroup bigintMaximumSemigroup = semigroup(Ord.bigintOrd.max); + public static final Semigroup bigintMaximumSemigroup = Ord.bigintOrd.maxSemigroup(); /** * A semigroup that yields the minimum of big integers. */ - public static final Semigroup bigintMinimumSemigroup = semigroup(Ord.bigintOrd.min); + public static final Semigroup bigintMinimumSemigroup = Ord.bigintOrd.minSemigroup(); /** * A semigroup that adds big decimals. @@ -191,12 +191,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that yields the maximum of big decimals. */ - public static final Semigroup bigDecimalMaximumSemigroup = semigroup(Ord.bigdecimalOrd.max); + public static final Semigroup bigDecimalMaximumSemigroup = Ord.bigdecimalOrd.maxSemigroup(); /** * A semigroup that yields the minimum of big decimals. */ - public static final Semigroup bigDecimalMinimumSemigroup = semigroup(Ord.bigdecimalOrd.min); + public static final Semigroup bigDecimalMinimumSemigroup = Ord.bigdecimalOrd.minSemigroup(); /** * A semigroup that multiplies natural numbers. @@ -213,12 +213,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that yields the maximum of natural numbers. */ - public static final Semigroup naturalMaximumSemigroup = semigroup(Ord.naturalOrd.max); + public static final Semigroup naturalMaximumSemigroup = Ord.naturalOrd.maxSemigroup(); /** * A semigroup that yields the minimum of natural numbers. */ - public static final Semigroup naturalMinimumSemigroup = semigroup(Ord.naturalOrd.min); + public static final Semigroup naturalMinimumSemigroup = Ord.naturalOrd.minSemigroup(); /** * A semigroup that adds longs. @@ -233,12 +233,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that yields the maximum of longs. */ - public static final Semigroup longMaximumSemigroup = semigroup(Ord.longOrd.max); + public static final Semigroup longMaximumSemigroup = Ord.longOrd.maxSemigroup(); /** * A semigroup that yields the minimum of longs. */ - public static final Semigroup longMinimumSemigroup = semigroup(Ord.longOrd.min); + public static final Semigroup longMinimumSemigroup = Ord.longOrd.minSemigroup(); /** * A semigroup that ORs booleans. From 158aabf0d73fab255cb3420f25edc513102a13cd Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 16 May 2016 20:11:41 +1000 Subject: [PATCH 067/336] Add "lift" from Semigroup into an Option Monoid --- core/src/main/java/fj/Semigroup.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 8557c02b..6377ceae 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -105,6 +105,14 @@ public Semigroup dual() { return semigroup(flip(sum)); } + /** + * Lifts the semigroup to obtain a trivial monoid. + */ + public Monoid> lift() { + return Monoid.monoid(a -> b -> Option.liftM2(sum).f(a).f(b).orElse(a).orElse(b), Option.none()); + } + + /** * Constructs a semigroup from the given function. * * @param sum The function to construct this semigroup with. From 0386eb7abd644e8017aa30b1a36a1bcb5f503a68 Mon Sep 17 00:00:00 2001 From: Brian McKenna Date: Mon, 16 May 2016 20:13:06 +1000 Subject: [PATCH 068/336] Add sumNel for Semigroup using a NonEmptyList --- core/src/main/java/fj/Semigroup.java | 6 ++++++ core/src/main/java/fj/data/NonEmptyList.java | 21 ++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 6377ceae..1427f0e5 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -98,6 +98,12 @@ static A multiply1p(F> sum, int n, A a) { } /** + * Sums the given values with left-fold. + */ + public A sumNel(final NonEmptyList as) { + return as.foldLeft1(sum); + } + /** * Swaps the arguments when summing. */ diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index 013b287c..db994dc0 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -6,6 +6,7 @@ import java.util.Collection; import java.util.Iterator; +import static fj.Function.flip; import static fj.Function.identity; import static fj.data.Option.some; import static fj.data.Option.somes; @@ -87,6 +88,26 @@ public NonEmptyList append(final NonEmptyList as) { return nel(head, bb); } + /** + * Performs a right-fold reduction across this list. This function uses O(length) stack space. + */ + public final A foldRight1(final F> f) { + return reverse().foldLeft1(flip(f)); + } + + /** + * Performs a left-fold reduction across this list. This function runs in constant space. + */ + public final A foldLeft1(final F> f) { + A x = head; + + for (List xs = tail; !xs.isEmpty(); xs = xs.tail()) { + x = f.f(x).f(xs.head()); + } + + return x; + } + /** * Maps the given function across this list. * From 97b767e89e6db089c5f763971c3224b302eeb5db Mon Sep 17 00:00:00 2001 From: Clinton Selke Date: Thu, 26 May 2016 23:29:11 +1000 Subject: [PATCH 069/336] Hard memo memory reduction (#258) * hard memo memory reduction. Dereferences the computation allowing it to become garbage collected once the value has been memorised. * removed initialized --- core/src/main/java/fj/P1.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index d6809da9..1b36e0a7 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -268,19 +268,18 @@ public static P1 memo(F0 f) { } static class Memo extends P1 { - private final P1 self; - private volatile boolean initialized; + private volatile P1 self; private A value; Memo(P1 self) { this.self = self; } @Override public final A _1() { - if (!initialized) { + if (self != null) { synchronized (this) { - if (!initialized) { + if (self != null) { A a = self._1(); value = a; - initialized = true; + self = null; return a; } } From b947a4fbd033c3d8b826d666396bf88520e4cf94 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 2 Jun 2016 22:44:40 +1000 Subject: [PATCH 070/336] Added int min, int max and ord monoid. Added FingerTree empty and int max for pqueue's --- core/src/main/java/fj/Monoid.java | 8 ++++++++ .../main/java/fj/data/fingertrees/FingerTree.java | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index a7f3106f..d9bf40b5 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -401,6 +401,10 @@ public static Monoid> ioMonoid(final Monoid ma) { return monoid(Semigroup.ioSemigroup(ma.semigroup()), IOFunctions.unit(ma.zero())); } + public static final Monoid intMaxMonoid = monoid(Semigroup.intMaximumSemigroup, Integer.MIN_VALUE); + + public static final Monoid intMinMonoid = monoid(Semigroup.intMinimumSemigroup, Integer.MAX_VALUE); + /** * A monoid for the Unit value. */ @@ -416,4 +420,8 @@ public static Monoid> setMonoid(final Ord o) { return monoid(Semigroup.setSemigroup(), Set.empty(o)); } + public static Monoid ordMonoid(Ord o, A zero) { + return monoid(o.max, zero); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index f361a76a..c3dfbed9 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -5,6 +5,7 @@ import fj.data.Seq; import static fj.Monoid.intAdditionMonoid; +import static fj.Monoid.intMaxMonoid; /** * Provides 2-3 finger trees, a functional representation of persistent sequences supporting access to the ends in @@ -96,8 +97,8 @@ public final FingerTree filter(final F f) { public final boolean isEmpty() { return this instanceof Empty; } - - final Measured measured() { + + public final Measured measured() { return m; } @@ -225,7 +226,15 @@ public final P3, A, FingerTree> split1(final F FingerTree emptyIntAddition() { - return mkTree(FingerTree.measured(intAdditionMonoid, Function.constant(1))).empty(); + return empty(intAdditionMonoid, Function.constant(1)); } + public static FingerTree empty(Monoid m, F f) { + return FingerTree.mkTree(measured(m, f)).empty(); + } + + public static FingerTree> emptyIntMax() { + return empty(intMaxMonoid, (P2 p) -> p._1()); + } + } From 6e5c822d64879ba2277d3808ecf4a7b6cb90b951 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 2 Jun 2016 22:47:03 +1000 Subject: [PATCH 071/336] Added show instances and toString implementations for finger trees --- core/src/main/java/fj/Show.java | 40 +++++++++++++++++++ .../main/java/fj/data/fingertrees/Deep.java | 5 +++ .../main/java/fj/data/fingertrees/Digit.java | 3 ++ .../main/java/fj/data/fingertrees/Empty.java | 6 +++ .../main/java/fj/data/fingertrees/Four.java | 6 +++ .../main/java/fj/data/fingertrees/Node2.java | 6 +++ .../main/java/fj/data/fingertrees/Node3.java | 6 +++ .../main/java/fj/data/fingertrees/One.java | 5 +++ .../main/java/fj/data/fingertrees/Single.java | 7 ++++ .../main/java/fj/data/fingertrees/Three.java | 6 +++ .../main/java/fj/data/fingertrees/Two.java | 5 +++ .../src/main/java/fj/test/Arbitrary.java | 1 + 12 files changed, 96 insertions(+) diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 4d599693..b8bed494 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -1,6 +1,8 @@ package fj; import fj.data.*; +import fj.data.fingertrees.FingerTree; +import fj.data.fingertrees.Node; import fj.data.hlist.HList; import fj.data.vector.V2; import fj.data.vector.V3; @@ -301,6 +303,44 @@ public static Show> treeShow(final Show sa) { }); } + public static Show> digitShow(final Show sv, final Show sa) { + return show(d -> { + String s = d.match( + o -> "One(" + o.measure() + " -> " + o.value() + ")", + two -> "Two(" + two.measure() + " -> " + v2Show(sa).showS(two.values()) + ")", + three -> "Three(" + three.measure() + " -> " + v3Show(sa).showS(three.values()) + ")", + four -> "Four(" + four.measure() + " -> " + v4Show(sa).showS(four.values()) + ")" + ); + return Stream.fromString(s); + }); + } + + public static Show> nodeShow(final Show sv, final Show sa) { + return show(n -> { + final String s = n.match( + n2 -> "Node2(" + n2.measure() + " -> " + v2Show(sa).showS(n2.toVector()) + ")", + n3 -> "Node3(" + n3.measure() + " -> " + v3Show(sa).showS(n3.toVector()) + ")"); + return Stream.fromString(s); + }); + } + + public static Show> fingerTreeShow(final Show sv, final Show sa) { + + return show(ft -> { + String sep = ", "; + String str = ft.match(e -> "Empty()", + s -> "Single(" + sv.showS(ft.measure()) + " -> " + sa.showS(s.value()) + ")", + d -> "Deep(" + d.measure() + " -> " + + digitShow(sv, sa).showS(d.prefix()) + sep + + fingerTreeShow(sv, nodeShow(sv, sa)).showS(d.middle()) + sep + + digitShow(sv, sa).showS(d.suffix()) + + ")" + ); + return Stream.fromString(str); + }); + } + + public static Show> seqShow(final Show sa) { return show(s -> streamShow(sa, "Seq(", ",", ")").show(s.toStream())); } diff --git a/core/src/main/java/fj/data/fingertrees/Deep.java b/core/src/main/java/fj/data/fingertrees/Deep.java index ea906507..3a08c670 100644 --- a/core/src/main/java/fj/data/fingertrees/Deep.java +++ b/core/src/main/java/fj/data/fingertrees/Deep.java @@ -520,4 +520,9 @@ private static FingerTree>> addDigits4(final Measur }); }); } + + public String toString() { + return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Digit.java b/core/src/main/java/fj/data/fingertrees/Digit.java index fb552ce9..31e7aa04 100644 --- a/core/src/main/java/fj/data/fingertrees/Digit.java +++ b/core/src/main/java/fj/data/fingertrees/Digit.java @@ -162,4 +162,7 @@ final Option> init() { public abstract int length(); + public String toString() { + return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); + } } diff --git a/core/src/main/java/fj/data/fingertrees/Empty.java b/core/src/main/java/fj/data/fingertrees/Empty.java index 95065aef..f4f79271 100644 --- a/core/src/main/java/fj/data/fingertrees/Empty.java +++ b/core/src/main/java/fj/data/fingertrees/Empty.java @@ -3,6 +3,7 @@ import fj.F; import fj.P2; import fj.P3; +import fj.Show; import static fj.Bottom.error; @@ -81,4 +82,9 @@ public V measure() { @Override P3, A, FingerTree> split1(final F predicate, final V acc) { throw error("Splitting an empty tree"); } + + public String toString() { + return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Four.java b/core/src/main/java/fj/data/fingertrees/Four.java index c66ddeca..635cb45f 100644 --- a/core/src/main/java/fj/data/fingertrees/Four.java +++ b/core/src/main/java/fj/data/fingertrees/Four.java @@ -3,6 +3,7 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import fj.data.Option; import fj.data.vector.V4; import fj.F; @@ -88,4 +89,9 @@ public V4 values() { public int length() { return 4; } + + public String toString() { + return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Node2.java b/core/src/main/java/fj/data/fingertrees/Node2.java index 5af121c2..4f47c7c5 100644 --- a/core/src/main/java/fj/data/fingertrees/Node2.java +++ b/core/src/main/java/fj/data/fingertrees/Node2.java @@ -2,6 +2,7 @@ import fj.P; import fj.P3; +import fj.Show; import fj.data.Option; import fj.data.vector.V2; import fj.F; @@ -66,4 +67,9 @@ public int length() { public V2 toVector() { return as; } + + public String toString() { + return Show.nodeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Node3.java b/core/src/main/java/fj/data/fingertrees/Node3.java index 5eb9bf58..74a026c3 100644 --- a/core/src/main/java/fj/data/fingertrees/Node3.java +++ b/core/src/main/java/fj/data/fingertrees/Node3.java @@ -2,6 +2,7 @@ import fj.P; import fj.P3; +import fj.Show; import fj.data.Option; import fj.data.vector.V3; import fj.F; @@ -74,4 +75,9 @@ P3>, A, Option>> split1(final F predi public V3 toVector() { return as; } + + public String toString() { + return Show.nodeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/One.java b/core/src/main/java/fj/data/fingertrees/One.java index d07cab60..098003d2 100644 --- a/core/src/main/java/fj/data/fingertrees/One.java +++ b/core/src/main/java/fj/data/fingertrees/One.java @@ -4,6 +4,7 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import fj.data.Option; import static fj.data.Option.none; @@ -54,4 +55,8 @@ public A value() { public int length() { return 1; } + + public String toString() { + return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); + } } diff --git a/core/src/main/java/fj/data/fingertrees/Single.java b/core/src/main/java/fj/data/fingertrees/Single.java index d322dcaa..951d9976 100644 --- a/core/src/main/java/fj/data/fingertrees/Single.java +++ b/core/src/main/java/fj/data/fingertrees/Single.java @@ -4,8 +4,10 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import static fj.P.p; +import static fj.Show.anyShow; /** * A tree with a single element. @@ -99,4 +101,9 @@ public int length() { public A value() { return a; } + + public String toString() { + return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Three.java b/core/src/main/java/fj/data/fingertrees/Three.java index da9f6a9e..21a2fd2c 100644 --- a/core/src/main/java/fj/data/fingertrees/Three.java +++ b/core/src/main/java/fj/data/fingertrees/Three.java @@ -3,6 +3,7 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import fj.data.Option; import fj.data.vector.V3; import fj.F; @@ -78,4 +79,9 @@ public V3 values() { public int length() { return 3; } + + public String toString() { + return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Two.java b/core/src/main/java/fj/data/fingertrees/Two.java index 3029fd9d..c88ff639 100644 --- a/core/src/main/java/fj/data/fingertrees/Two.java +++ b/core/src/main/java/fj/data/fingertrees/Two.java @@ -3,6 +3,7 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import fj.data.Option; import fj.data.vector.V2; import fj.F; @@ -70,4 +71,8 @@ public int length() { return 2; } + public String toString() { + return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index e2a00b29..19cae500 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -62,6 +62,7 @@ import java.util.HashMap; import java.util.HashSet; +import java.util.PriorityQueue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; From 45abb41b3788c0f054ecc32cd12eb1880bea9301 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 2 Jun 2016 23:15:41 +1000 Subject: [PATCH 072/336] Test show on finger trees to expose what is going on inside the finger tree --- .../fj/data/fingertrees/FingerTreeTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 3d95d182..6ce46640 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -1,10 +1,19 @@ package fj.data.fingertrees; +import fj.Function; +import fj.P; +import fj.P2; import fj.data.List; +import fj.data.Seq; import org.junit.Test; +import static fj.Monoid.intAdditionMonoid; +import static fj.Monoid.intMaxMonoid; +import static fj.P.p; +import static fj.data.fingertrees.FingerTree.measured; import static fj.test.Property.prop; import static fj.test.Property.property; +import static java.lang.System.out; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -27,4 +36,33 @@ void validateSize(List list) { assertThat(ft.length(), equalTo(list.length())); } + @Test + public void testSeqString() { + FingerTree ft = FingerTree.emptyIntAddition(); +// out.println(ft.toString()); + String actual = List.range(1, 10).foldLeft(ft2 -> i -> { + FingerTree ft3 = ft2.snoc(i); +// out.println(ft3.toString()); + return ft3; + }, ft).toString(); + String expected = "Deep(9 -> One(1 -> 1), Deep(6 -> One(3 -> Node3(3 -> V3(2,3,4))), Empty(), One(3 -> Node3(3 -> V3(5,6,7)))), Two(2 -> V2(8,9)))"; + assertThat(actual, equalTo(expected)); + } + + @Test + public void testQueueString() { + FingerTree> ft = FingerTree.emptyIntMax(); +// out.println(ft.toString()); + String actual = List.range(1, 10).foldLeft(ft2 -> i -> { + int j = i % 2 == 0 ? 2 * i : i; + FingerTree> ft3 = ft2.snoc(P.p(j, j)); +// out.println(ft3.toString()); + return ft3; + }, ft).toString(); + String expected = "Deep(16 -> One(1 -> (1,1)), Deep(12 -> One(8 -> Node3(8 -> V3((4,4),(3,3),(8,8)))), Empty(), One(12 -> Node3(12 -> V3((5,5),(12,12),(7,7))))), Two(16 -> V2((16,16),(9,9))))"; + assertThat(actual, equalTo(expected)); + + } + + } From 8321b4f61053229fdcc84ae2e1939087b9890e0a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 3 Jun 2016 22:09:08 +1000 Subject: [PATCH 073/336] Added streaming of finger trees --- .../main/java/fj/data/fingertrees/Deep.java | 12 ++++ .../main/java/fj/data/fingertrees/Digit.java | 5 ++ .../main/java/fj/data/fingertrees/Empty.java | 5 ++ .../java/fj/data/fingertrees/FingerTree.java | 4 ++ .../main/java/fj/data/fingertrees/Four.java | 5 ++ .../main/java/fj/data/fingertrees/Node.java | 5 ++ .../main/java/fj/data/fingertrees/Node2.java | 5 ++ .../main/java/fj/data/fingertrees/Node3.java | 5 ++ .../main/java/fj/data/fingertrees/One.java | 6 ++ .../main/java/fj/data/fingertrees/Single.java | 5 ++ .../main/java/fj/data/fingertrees/Three.java | 4 ++ .../main/java/fj/data/fingertrees/Two.java | 5 ++ .../fj/data/fingertrees/FingerTreeTest.java | 64 +++++++++++++++---- 13 files changed, 116 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/fj/data/fingertrees/Deep.java b/core/src/main/java/fj/data/fingertrees/Deep.java index 3a08c670..f9d6eb83 100644 --- a/core/src/main/java/fj/data/fingertrees/Deep.java +++ b/core/src/main/java/fj/data/fingertrees/Deep.java @@ -2,6 +2,7 @@ import fj.*; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V2; import fj.data.vector.V3; import fj.data.vector.V4; @@ -9,6 +10,7 @@ import static fj.Function.constant; import static fj.data.List.list; import static fj.Function.flip; +import static fj.data.Stream.nil; /** * A finger tree with 1-4-digits on the left and right, and a finger tree of 2-3-nodes in the middle. @@ -525,4 +527,14 @@ public String toString() { return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return prefix().toStream().append(() -> + middle().match( + e -> Stream.nil(), + s -> s.value().toStream(), + d -> d.toStream().bind(p -> p.toStream()) + ) + ).append(() -> suffix.toStream()); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Digit.java b/core/src/main/java/fj/data/fingertrees/Digit.java index 31e7aa04..fe76d1df 100644 --- a/core/src/main/java/fj/data/fingertrees/Digit.java +++ b/core/src/main/java/fj/data/fingertrees/Digit.java @@ -2,6 +2,7 @@ import fj.*; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V2; import fj.data.vector.V3; import fj.data.vector.V4; @@ -165,4 +166,8 @@ final Option> init() { public String toString() { return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); } + + public abstract Stream toStream(); + + } diff --git a/core/src/main/java/fj/data/fingertrees/Empty.java b/core/src/main/java/fj/data/fingertrees/Empty.java index f4f79271..275b1cec 100644 --- a/core/src/main/java/fj/data/fingertrees/Empty.java +++ b/core/src/main/java/fj/data/fingertrees/Empty.java @@ -4,6 +4,7 @@ import fj.P2; import fj.P3; import fj.Show; +import fj.data.Stream; import static fj.Bottom.error; @@ -87,4 +88,8 @@ public String toString() { return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return Stream.nil(); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index c3dfbed9..aa72f020 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -3,9 +3,11 @@ import fj.*; import fj.data.Option; import fj.data.Seq; +import fj.data.Stream; import static fj.Monoid.intAdditionMonoid; import static fj.Monoid.intMaxMonoid; +import static fj.data.Stream.nil; /** * Provides 2-3 finger trees, a functional representation of persistent sequences supporting access to the ends in @@ -237,4 +239,6 @@ public static FingerTree> emptyIntMax() { return empty(intMaxMonoid, (P2 p) -> p._1()); } + public abstract Stream toStream(); + } diff --git a/core/src/main/java/fj/data/fingertrees/Four.java b/core/src/main/java/fj/data/fingertrees/Four.java index 635cb45f..31a40d72 100644 --- a/core/src/main/java/fj/data/fingertrees/Four.java +++ b/core/src/main/java/fj/data/fingertrees/Four.java @@ -5,6 +5,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V4; import fj.F; @@ -94,4 +95,8 @@ public String toString() { return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return values().toStream(); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Node.java b/core/src/main/java/fj/data/fingertrees/Node.java index c7e3e7a2..ff98b337 100644 --- a/core/src/main/java/fj/data/fingertrees/Node.java +++ b/core/src/main/java/fj/data/fingertrees/Node.java @@ -1,9 +1,11 @@ package fj.data.fingertrees; import fj.F; +import fj.P; import fj.P2; import fj.P3; import fj.data.Option; +import fj.data.Stream; import static fj.Function.curry; @@ -59,4 +61,7 @@ final Measured measured() { public abstract B match(final F, B> n2, final F, B> n3); public abstract int length(); + + public abstract Stream toStream(); + } diff --git a/core/src/main/java/fj/data/fingertrees/Node2.java b/core/src/main/java/fj/data/fingertrees/Node2.java index 4f47c7c5..56e668e7 100644 --- a/core/src/main/java/fj/data/fingertrees/Node2.java +++ b/core/src/main/java/fj/data/fingertrees/Node2.java @@ -4,6 +4,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V2; import fj.F; import fj.P2; @@ -72,4 +73,8 @@ public String toString() { return Show.nodeShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return as.toStream(); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Node3.java b/core/src/main/java/fj/data/fingertrees/Node3.java index 74a026c3..c803239f 100644 --- a/core/src/main/java/fj/data/fingertrees/Node3.java +++ b/core/src/main/java/fj/data/fingertrees/Node3.java @@ -4,6 +4,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V3; import fj.F; import fj.P2; @@ -80,4 +81,8 @@ public String toString() { return Show.nodeShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return as.toStream(); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/One.java b/core/src/main/java/fj/data/fingertrees/One.java index 098003d2..f3711ace 100644 --- a/core/src/main/java/fj/data/fingertrees/One.java +++ b/core/src/main/java/fj/data/fingertrees/One.java @@ -6,6 +6,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import static fj.data.Option.none; @@ -59,4 +60,9 @@ public int length() { public String toString() { return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); } + + public Stream toStream() { + return Stream.single(a); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Single.java b/core/src/main/java/fj/data/fingertrees/Single.java index 951d9976..57ea0897 100644 --- a/core/src/main/java/fj/data/fingertrees/Single.java +++ b/core/src/main/java/fj/data/fingertrees/Single.java @@ -5,6 +5,7 @@ import fj.P2; import fj.P3; import fj.Show; +import fj.data.Stream; import static fj.P.p; import static fj.Show.anyShow; @@ -106,4 +107,8 @@ public String toString() { return Show.fingerTreeShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return Stream.single(a); + } + } diff --git a/core/src/main/java/fj/data/fingertrees/Three.java b/core/src/main/java/fj/data/fingertrees/Three.java index 21a2fd2c..2db896b3 100644 --- a/core/src/main/java/fj/data/fingertrees/Three.java +++ b/core/src/main/java/fj/data/fingertrees/Three.java @@ -5,6 +5,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V3; import fj.F; @@ -83,5 +84,8 @@ public int length() { public String toString() { return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return values().toStream(); + } } diff --git a/core/src/main/java/fj/data/fingertrees/Two.java b/core/src/main/java/fj/data/fingertrees/Two.java index c88ff639..cb8a2162 100644 --- a/core/src/main/java/fj/data/fingertrees/Two.java +++ b/core/src/main/java/fj/data/fingertrees/Two.java @@ -5,6 +5,7 @@ import fj.P3; import fj.Show; import fj.data.Option; +import fj.data.Stream; import fj.data.vector.V2; import fj.F; @@ -75,4 +76,8 @@ public String toString() { return Show.digitShow(Show.anyShow(), Show.anyShow()).showS(this); } + public Stream toStream() { + return values().toStream(); + } + } diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 6ce46640..901c9c89 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -1,16 +1,14 @@ package fj.data.fingertrees; -import fj.Function; import fj.P; import fj.P2; +import fj.Show; import fj.data.List; -import fj.data.Seq; +import fj.data.Stream; import org.junit.Test; -import static fj.Monoid.intAdditionMonoid; -import static fj.Monoid.intMaxMonoid; import static fj.P.p; -import static fj.data.fingertrees.FingerTree.measured; +import static fj.Show.intShow; import static fj.test.Property.prop; import static fj.test.Property.property; import static java.lang.System.out; @@ -36,33 +34,71 @@ void validateSize(List list) { assertThat(ft.length(), equalTo(list.length())); } - @Test - public void testSeqString() { + public FingerTree midSeq() { FingerTree ft = FingerTree.emptyIntAddition(); -// out.println(ft.toString()); - String actual = List.range(1, 10).foldLeft(ft2 -> i -> { + // out.println(ft.toString()); + return List.range(1, 10).foldLeft(ft2 -> i -> { FingerTree ft3 = ft2.snoc(i); // out.println(ft3.toString()); return ft3; - }, ft).toString(); + }, ft); + } + + + + @Test + public void testSeqString() { +// FingerTree ft = FingerTree.emptyIntAddition(); +// out.println(ft.toString()); + String actual = midSeq().toString(); String expected = "Deep(9 -> One(1 -> 1), Deep(6 -> One(3 -> Node3(3 -> V3(2,3,4))), Empty(), One(3 -> Node3(3 -> V3(5,6,7)))), Two(2 -> V2(8,9)))"; assertThat(actual, equalTo(expected)); } - @Test - public void testQueueString() { + public FingerTree> midPriorityQueue() { FingerTree> ft = FingerTree.emptyIntMax(); // out.println(ft.toString()); - String actual = List.range(1, 10).foldLeft(ft2 -> i -> { + return List.range(1, 10).foldLeft(ft2 -> i -> { int j = i % 2 == 0 ? 2 * i : i; FingerTree> ft3 = ft2.snoc(P.p(j, j)); // out.println(ft3.toString()); return ft3; - }, ft).toString(); + }, ft); + } + + @Test + public void testQueueString() { +// FingerTree> ft = FingerTree.emptyIntMax(); +// out.println(ft.toString()); + String actual = midPriorityQueue().toString(); String expected = "Deep(16 -> One(1 -> (1,1)), Deep(12 -> One(8 -> Node3(8 -> V3((4,4),(3,3),(8,8)))), Empty(), One(12 -> Node3(12 -> V3((5,5),(12,12),(7,7))))), Two(16 -> V2((16,16),(9,9))))"; assertThat(actual, equalTo(expected)); } + @Test + public void stream() { + FingerTree ft = midSeq(); + out.println(ft); + Stream s = ft.toStream(); + System.out.println(s.toList()); + + out.println(midPriorityQueue()); + out.println(midPriorityQueue().toStream().toList()); + } + + @Test + public void split() { + + FingerTree ft = FingerTree.emptyIntAddition(); + FingerTree ft3 = List.range(1, 10).foldLeft(ft2 -> i -> ft2.snoc(i), ft); + P2, FingerTree> p = ft3.split(v -> v >= 3); + Show> fts = Show.fingerTreeShow(intShow, intShow); + Show, FingerTree>> s = Show.p2Show(fts, fts); + System.out.println(s.showS(p)); + System.out.println(p); + + + } } From a20a86ee841721b0e916d757e31a9c0409dad843 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 3 Jun 2016 22:25:57 +1000 Subject: [PATCH 074/336] Initial implementation of priority queue based on finger trees --- core/src/main/java/fj/data/PriorityQueue.java | 81 +++++++++++++++++++ .../test/java/fj/data/PriorityQueueTest.java | 30 +++++++ 2 files changed, 111 insertions(+) create mode 100644 core/src/main/java/fj/data/PriorityQueue.java create mode 100644 core/src/test/java/fj/data/PriorityQueueTest.java diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java new file mode 100644 index 00000000..35188120 --- /dev/null +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -0,0 +1,81 @@ +package fj.data; + +import fj.Equal; +import fj.F; +import fj.Monoid; +import fj.P; +import fj.P2; +import fj.P3; +import fj.data.fingertrees.FingerTree; + +/** + * Created by MarkPerry on 31 May 16. + */ +public class PriorityQueue { + + private final FingerTree> ftree; + private final Equal equal; + + private PriorityQueue(Equal e, FingerTree> ft) { + equal = e; + ftree = ft; + } + + public static PriorityQueue priorityQueue(Equal e, FingerTree> ft) { + return new PriorityQueue(e, ft); + } + + public static PriorityQueue empty(Monoid m, Equal e) { + return priorityQueue(e, FingerTree.empty(m, (P2 p) -> p._1())); + } + + public static PriorityQueue emptyInt() { + return priorityQueue(Equal.intEqual, FingerTree.empty(Monoid.intMaxMonoid, (P2 p) -> p._1())); + } + + public PriorityQueue map(F f) { + return priorityQueue(equal, + ftree.map(p2 -> p2.map2(a -> f.f(a)), + FingerTree.measured(ftree.measured().monoid(), (P2 p2) -> p2._1())) + ); + } + + public PriorityQueue filter(F f) { + return priorityQueue(equal, ftree.filter(p2 -> f.f(p2._2()))); + } + + public boolean isEmpty() { + return ftree.isEmpty(); + } + + public Option> top() { + K top = ftree.measure(); + P2>, FingerTree>> p = ftree.split(k -> equal.eq(top, k)); + return p._2().headOption(); + } + + public PriorityQueue enqueue(K k, A a) { + return priorityQueue(equal, ftree.cons(P.p(k, a))); + } + + public PriorityQueue enqueue(List> list) { + return list.foldLeft(pq -> p -> pq.enqueue(p._1(), p._2()), this); + } + + public PriorityQueue dequeue() { + K top = ftree.measure(); + P3>, P2, FingerTree>> p = ftree.split1(k -> equal.eq(k, top)); + return priorityQueue(equal, p._1().append(p._3())); + } + + public PriorityQueue dequeue(int n) { + int i = n; + PriorityQueue result = this; + while (i > 0) { + i--; + result = result.dequeue(); + } + return result; + } + +} diff --git a/core/src/test/java/fj/data/PriorityQueueTest.java b/core/src/test/java/fj/data/PriorityQueueTest.java new file mode 100644 index 00000000..1943d2ca --- /dev/null +++ b/core/src/test/java/fj/data/PriorityQueueTest.java @@ -0,0 +1,30 @@ +package fj.data; + +import fj.Equal; +import fj.Monoid; +import org.junit.Assert; +import org.junit.Test; + +import static fj.P.p; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +/** + * Created by MarkPerry on 1 Jun 16. + */ +public class PriorityQueueTest { + + @Test + public void test1() { + PriorityQueue pq = PriorityQueue.emptyInt(); + PriorityQueue pq2 = pq.enqueue(List.list(p(1, 1))); + System.out.println(pq2.toString()); + } + + @Test + public void empty() { + PriorityQueue pq = PriorityQueue.emptyInt(); + assertThat(pq.isEmpty(), is(true)); + } + +} From d630f99b1e881aa1e511b0a7d9418d12c3fea154 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 4 Jun 2016 23:00:33 +1000 Subject: [PATCH 075/336] Added priority queue show, toStream, toString. Fixed enqueue and dequeue --- core/src/main/java/fj/Show.java | 8 ++++- core/src/main/java/fj/data/PriorityQueue.java | 16 +++++++-- .../test/java/fj/data/PriorityQueueTest.java | 33 ++++++++++++++++--- 3 files changed, 49 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index b8bed494..9e55a1d6 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -377,7 +377,7 @@ public static Show> treeMapShow(final Show sk, final Sho * @return A show instance for the {@link P2 tuple-2} type. */ public static Show> p2MapShow(final Show sa, final Show sb) { - return p2Show(sa, sb, "(", ":", ")"); + return p2Show(sa, sb, "(", ": ", ")"); } /** @@ -590,6 +590,12 @@ public static Show> p5Show(final Show sa, f .append(sg.show(p._7())).snoc(',').append(sh.show(p._8())).snoc(')')); } + public static Show> priorityQueueShow(Show sk, Show sv) { + return show(pq -> { + return streamShow(p2MapShow(sk, sv), "PriorityQueue(", ", ", ")").show(pq.toStream()); + }); + } + /** * A show instance for a vector-2. * diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 35188120..67abdb88 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -6,6 +6,7 @@ import fj.P; import fj.P2; import fj.P3; +import fj.Show; import fj.data.fingertrees.FingerTree; /** @@ -55,7 +56,7 @@ public Option> top() { } public PriorityQueue enqueue(K k, A a) { - return priorityQueue(equal, ftree.cons(P.p(k, a))); + return priorityQueue(equal, ftree.snoc(P.p(k, a))); } public PriorityQueue enqueue(List> list) { @@ -64,8 +65,9 @@ public PriorityQueue enqueue(List> list) { public PriorityQueue dequeue() { K top = ftree.measure(); - P3>, P2, FingerTree>> p = ftree.split1(k -> equal.eq(k, top)); - return priorityQueue(equal, p._1().append(p._3())); + P2>, FingerTree>> p = ftree.split(k -> equal.eq(k, top)); + FingerTree> right = p._2(); + return right.isEmpty() ? this : priorityQueue(equal, p._1().append(right.tail())); } public PriorityQueue dequeue(int n) { @@ -78,4 +80,12 @@ public PriorityQueue dequeue(int n) { return result; } + public Stream> toStream() { + return ftree.toStream(); + } + + public String toString() { + return Show.priorityQueueShow(Show.anyShow(), Show.anyShow()).showS(this); + } + } diff --git a/core/src/test/java/fj/data/PriorityQueueTest.java b/core/src/test/java/fj/data/PriorityQueueTest.java index 1943d2ca..7e30cfc5 100644 --- a/core/src/test/java/fj/data/PriorityQueueTest.java +++ b/core/src/test/java/fj/data/PriorityQueueTest.java @@ -1,11 +1,11 @@ package fj.data; -import fj.Equal; -import fj.Monoid; -import org.junit.Assert; +import fj.P2; import org.junit.Test; import static fj.P.p; +import static java.lang.System.out; +import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; @@ -18,7 +18,7 @@ public class PriorityQueueTest { public void test1() { PriorityQueue pq = PriorityQueue.emptyInt(); PriorityQueue pq2 = pq.enqueue(List.list(p(1, 1))); - System.out.println(pq2.toString()); + out.println(pq2.toString()); } @Test @@ -27,4 +27,29 @@ public void empty() { assertThat(pq.isEmpty(), is(true)); } + @Test + public void top() { + PriorityQueue pq1 = PriorityQueue.emptyInt(); + Option> o = pq1.top(); + assertThat(o, is(Option.none())); + } + + @Test + public void dequeue() { + PriorityQueue pq1 = PriorityQueue.emptyInt().enqueue(List.list( + p(3, 6), p(10, 20), p(4, 8), p(1, 2) + )); + out.println(pq1); + assertThat(pq1.toString(), equalTo("PriorityQueue((3: 6), (10: 20), (4: 8), (1: 2))")); + + PriorityQueue pq2 = PriorityQueue.emptyInt(); + PriorityQueue pq3 = pq2.dequeue(); + out.println(pq3); + assertThat(pq3.toString(), equalTo("PriorityQueue()")); + + PriorityQueue pq4 = pq1.dequeue(); + out.println(pq4); + assertThat(pq4.toString(), equalTo("PriorityQueue((3: 6), (4: 8), (1: 2))")); + } + } From 63667ffc4606be7ee33bd59b469f03ca09e4b662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 14 Feb 2016 20:14:36 -0500 Subject: [PATCH 076/336] Add JUnit for DbState --- core/build.gradle | 2 + .../test/java/fj/control/db/TestDbState.java | 55 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 core/src/test/java/fj/control/db/TestDbState.java diff --git a/core/build.gradle b/core/build.gradle index 1a1763e7..b3e1756e 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -7,6 +7,8 @@ archivesBaseName = project.projectName dependencies { testCompile dependencyJunit + testCompile 'com.h2database:h2:1.4.191' + testCompile 'commons-dbutils:commons-dbutils:1.6' } performSigning(signingEnabled, signModule) diff --git a/core/src/test/java/fj/control/db/TestDbState.java b/core/src/test/java/fj/control/db/TestDbState.java new file mode 100644 index 00000000..00933921 --- /dev/null +++ b/core/src/test/java/fj/control/db/TestDbState.java @@ -0,0 +1,55 @@ +package fj.control.db; + +import fj.Unit; +import fj.data.Option; +import org.apache.commons.dbutils.DbUtils; +import org.junit.Test; + +import java.sql.*; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class TestDbState { + @Test + public void testWriter() throws SQLException { + final int TEN = 10; + DbState writer = DbState.writer(DbState.driverManager("jdbc:h2:mem:")); + + DB setup = new DB() { + @Override + public Unit run(Connection c) throws SQLException { + Statement s = null; + try { + s = c.createStatement(); + assertThat(s.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"), is(0)); + assertThat(s.executeUpdate("INSERT INTO TEST (ID, NAME) VALUES (" + TEN + ", 'FOO')"), is(1)); + } finally { + DbUtils.closeQuietly(s); + } + return Unit.unit(); + } + }; + DB> query = new DB>() { + @Override + public Option run(Connection c) throws SQLException { + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = c.prepareStatement("SELECT ID FROM TEST WHERE NAME = ?"); + ps.setString(1, "FOO"); + rs = ps.executeQuery(); + if (rs.next()) { + return Option.some(rs.getInt("ID")); + } else { + return Option.none(); + } + } finally { + DbUtils.closeQuietly(rs); + DbUtils.closeQuietly(ps); + } + } + }; + assertThat(writer.run(setup.bind(v -> query)).some(), is(TEN)); + } +} From b943873974c06794b61ae0ea1332d87a8da30b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 14 Feb 2016 16:04:49 -0500 Subject: [PATCH 077/336] Add JUnit for quickcheck Bool --- .../src/test/java/fj/test/TestBool.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 quickcheck/src/test/java/fj/test/TestBool.java diff --git a/quickcheck/src/test/java/fj/test/TestBool.java b/quickcheck/src/test/java/fj/test/TestBool.java new file mode 100644 index 00000000..2f29f69a --- /dev/null +++ b/quickcheck/src/test/java/fj/test/TestBool.java @@ -0,0 +1,20 @@ +package fj.test; + +import fj.data.test.PropertyAssert; +import org.junit.Test; + +import static fj.test.Arbitrary.arbBoolean; +import static fj.test.Arbitrary.arbitrary; +import static fj.test.Bool.bool; +import static fj.test.Property.property; + +public class TestBool { + + @Test + public void testBool() { + final Arbitrary arbBooleanR = arbitrary(arbBoolean.gen); + final Property p = property(arbBooleanR, arbBooleanR, (m1, m2) -> bool(m1.equals(m2)) + .implies(m1 == m2)); + PropertyAssert.assertResult(p); + } +} From e93d78a9d3116ab2f4f0a90a4174426ea858550a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 4 Jun 2016 14:44:03 -0400 Subject: [PATCH 078/336] Add tests for fj.Class --- core/src/test/java/fj/ClassTest.java | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 core/src/test/java/fj/ClassTest.java diff --git a/core/src/test/java/fj/ClassTest.java b/core/src/test/java/fj/ClassTest.java new file mode 100644 index 00000000..862c6fdd --- /dev/null +++ b/core/src/test/java/fj/ClassTest.java @@ -0,0 +1,53 @@ +package fj; + +import fj.data.List; +import fj.data.Natural; +import fj.data.Option; +import fj.data.Tree; +import org.junit.Test; + +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Iterator; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ClassTest { + @Test + public void testInheritance() { + Class c = Class.clas(Natural.class); + List> l = c.inheritance(); + assertThat(l.length(), is(3)); + } + + @Test + public void testClassParameters() { + Class c = Class.clas(Option.none().getClass()); + Tree cp = c.classParameters(); + assertThat(cp.length(), is(1)); + } + + @Test + public void testSuperclassParameters() { + Class c = Class.clas(Option.none().getClass()); + Tree cp = c.superclassParameters(); + assertThat(cp.length(), is(2)); + } + + @Test + public void testInterfaceParameters() { + Class c = Class.clas(Option.none().getClass()); + List l =c.interfaceParameters(); + assertThat(l.length(), is(0)); + } + + @Test + public void testTypeParameterTree() { + Class c = Class.clas(Option.none().getClass()); + Collection coll = c.classParameters().toCollection(); + for (Type t: coll) { + assertThat(Class.typeParameterTree(t).toString(), is("Tree(class fj.data.Option$None)")); + } + } +} From 8ada2aeb55b7d8b9a3b5e1600ab164320e6b2fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 6 Jun 2016 19:31:57 -0400 Subject: [PATCH 079/336] Exclude demo subproject from Coveralls --- demo/build.gradle | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/demo/build.gradle b/demo/build.gradle index 0b83f4f8..41841cfa 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -8,7 +8,13 @@ archivesBaseName = "${project.projectName}-${project.name}" configureAllRetroLambda() dependencies { - compile project(":core") - compile project(":quickcheck") + compile project(":core") + compile project(":quickcheck") testCompile dependencyJunit } + +test { + jacoco { + enabled = false + } +} \ No newline at end of file From d011bf169667e6451e2796aef3a6df7190a70184 Mon Sep 17 00:00:00 2001 From: Charles O'Farrell Date: Tue, 7 Jun 2016 22:09:15 +1000 Subject: [PATCH 080/336] Remove use of Arbitrary wrapper --- .../java/fj/demo/test/EqualsHashCode.java | 9 +- .../src/test/java/fj/data/ReaderTest.java | 4 +- .../src/test/java/fj/data/TestRngState.java | 6 +- .../src/test/java/fj/data/WriterTest.java | 7 +- .../fj/data/properties/ArrayProperties.java | 5 +- .../fj/data/properties/ListProperties.java | 17 +- .../fj/data/properties/SeqProperties.java | 9 +- .../fj/data/properties/SetProperties.java | 3 +- .../fj/data/properties/StreamProperties.java | 5 +- .../fj/data/properties/TreeMapProperties.java | 5 +- .../data/properties/ValidationProperties.java | 6 +- .../src/main/java/fj/test/Arbitrary.java | 601 +++++++++--------- .../src/main/java/fj/test/Coarbitrary.java | 70 +- quickcheck/src/main/java/fj/test/Gen.java | 12 +- .../src/main/java/fj/test/Property.java | 290 ++++----- .../src/test/java/fj/data/test/TestCheck.java | 3 +- .../src/test/java/fj/data/test/TestNull.java | 3 +- .../src/test/java/fj/test/TestBool.java | 4 +- 18 files changed, 513 insertions(+), 546 deletions(-) diff --git a/demo/src/main/java/fj/demo/test/EqualsHashCode.java b/demo/src/main/java/fj/demo/test/EqualsHashCode.java index c5b0a898..a9f0ef2c 100644 --- a/demo/src/main/java/fj/demo/test/EqualsHashCode.java +++ b/demo/src/main/java/fj/demo/test/EqualsHashCode.java @@ -1,10 +1,9 @@ package fj.demo.test; import static fj.Function.curry; -import fj.test.Arbitrary; +import fj.test.Gen; import static fj.test.Arbitrary.arbByte; import static fj.test.Arbitrary.arbCharacter; -import static fj.test.Arbitrary.arbitrary; import static fj.test.Bool.bool; import static fj.test.CheckResult.summary; import fj.test.Property; @@ -55,14 +54,14 @@ public int hashCode() { public static void main(final String[] args) { // Restrictive arbitrary for Byte, produces from three possible values. - final Arbitrary arbByteR = arbitrary(arbByte.gen.map(b -> (byte)(b % 3))); + final Gen arbByteR = arbByte.map(b -> (byte)(b % 3)); // Restrictive arbitrary for String, produces from twelve (2 * 3 * 2) possible values. - final Arbitrary arbStringR = arbitrary(arbCharacter.gen.bind(arbCharacter.gen, arbCharacter.gen, curry((c1, c2, c3) -> new String(new char[]{(char)(c1 % 2 + 'a'), (char)(c2 % 3 + 'a'), (char)(c3 % 2 + 'a')})))); + final Gen arbStringR = arbCharacter.bind(arbCharacter, arbCharacter, curry((c1, c2, c3) -> new String(new char[]{(char)(c1 % 2 + 'a'), (char)(c2 % 3 + 'a'), (char)(c3 % 2 + 'a')}))); // Arbitrary for MyClass that uses the restrictive arbitraries above. // We are using the monad pattern (bind) to make this a trivial exercise. - final Arbitrary arbMyClass = arbitrary(arbByteR.gen.bind(arbStringR.gen, curry(MyClass::new))); + final Gen arbMyClass = arbByteR.bind(arbStringR, curry(MyClass::new)); // Finally the property. // if m1 equals m2, then this implies that m1's hashCode is equal to m2's hashCode. diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 083716e9..05c858b8 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -52,7 +52,7 @@ public void testMapProp() { @Test public void testFlatMapProp() { - Arbitrary>> a = arbF(coarbInteger, arbReader()); + Gen>> a = arbF(coarbInteger, arbReader()); Property p = property( arbF(coarbInteger, arbInteger), a, @@ -108,7 +108,7 @@ public void testAssociativity() { PropertyAssert.assertResult(p); } - public Arbitrary> arbReader() { + public Gen> arbReader() { return Arbitrary.arbReader(coarbInteger, arbInteger); } diff --git a/props-core/src/test/java/fj/data/TestRngState.java b/props-core/src/test/java/fj/data/TestRngState.java index b8a17494..ddc319b9 100644 --- a/props-core/src/test/java/fj/data/TestRngState.java +++ b/props-core/src/test/java/fj/data/TestRngState.java @@ -79,11 +79,11 @@ public void testTraverse() { Assert.assertTrue(listIntEqual.eq(list, expected)); } - public static Arbitrary> arbState() { + public static Gen> arbState() { return Arbitrary.arbState(Arbitrary.arbLcgRng(), Coarbitrary.coarbLcgRng(), arbInteger); } - public static Arbitrary>> arbStateF() { + public static Gen>> arbStateF() { return arbF(Coarbitrary.coarbLcgRng(), arbP2(arbLcgRng(), arbInteger)); } @@ -91,7 +91,7 @@ public static Coarbitrary> coarbState() { return Coarbitrary.coarbState(Arbitrary.arbLcgRng(), (LcgRng s, Integer j) -> (long) (j >= 0 ? 2 * j : -2 * j + 1)); } - public static Arbitrary>> arbBindable() { + public static Gen>> arbBindable() { return arbF(coarbInteger, arbState()); } diff --git a/props-core/src/test/java/fj/data/WriterTest.java b/props-core/src/test/java/fj/data/WriterTest.java index 158a2314..a2af9952 100644 --- a/props-core/src/test/java/fj/data/WriterTest.java +++ b/props-core/src/test/java/fj/data/WriterTest.java @@ -4,6 +4,7 @@ import fj.F; import fj.data.test.PropertyAssert; import fj.test.Arbitrary; +import fj.test.Gen; import fj.test.Property; import org.junit.Assert; import org.junit.Test; @@ -62,12 +63,12 @@ public void testFlatMap() { } - public Arbitrary> arbWriterStringInt() { + public Gen> arbWriterStringInt() { return arbWriterString(arbInteger); } - public Arbitrary> arbWriterString(Arbitrary arb) { - return Arbitrary.arbitrary(arb.gen.map(a -> Writer.stringLogger().f(a))); + public Gen> arbWriterString(Gen arb) { + return arb.map(a -> Writer.stringLogger().f(a)); } // Left identity: return a >>= f == f a diff --git a/props-core/src/test/java/fj/data/properties/ArrayProperties.java b/props-core/src/test/java/fj/data/properties/ArrayProperties.java index c6aea391..feb5dcf4 100644 --- a/props-core/src/test/java/fj/data/properties/ArrayProperties.java +++ b/props-core/src/test/java/fj/data/properties/ArrayProperties.java @@ -3,7 +3,6 @@ import fj.*; import fj.data.Array; import fj.data.Either; -import fj.test.Arbitrary; import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -31,9 +30,9 @@ public class ArrayProperties { private static final Equal> eq = arrayEqual(intEqual); - private static final Arbitrary, Integer>> arbArrayWithIndex = arbitrary(arbArray(arbInteger).gen + private static final Gen, Integer>> arbArrayWithIndex = arbArray(arbInteger) .filter(Array::isNotEmpty) - .bind(array -> Gen.choose(0, array.length() - 1).map(i -> P.p(array, i)))); + .bind(array -> Gen.choose(0, array.length() - 1).map(i -> P.p(array, i))); public Property isEmpty() { return property(arbArray(arbInteger), array -> prop(array.isEmpty() != array.isNotEmpty())); diff --git a/props-core/src/test/java/fj/data/properties/ListProperties.java b/props-core/src/test/java/fj/data/properties/ListProperties.java index 825a5f17..9724488f 100644 --- a/props-core/src/test/java/fj/data/properties/ListProperties.java +++ b/props-core/src/test/java/fj/data/properties/ListProperties.java @@ -4,7 +4,6 @@ import fj.data.List; import fj.data.Stream; import fj.data.TreeMap; -import fj.test.Arbitrary; import fj.test.reflect.CheckParams; import fj.test.runner.PropertyTestRunner; import fj.test.Gen; @@ -36,9 +35,9 @@ public class ListProperties { private static final Equal> eq = listEqual(intEqual); - private static final Arbitrary, Integer>> arbListWithIndex = arbitrary(arbList(arbInteger).gen + private static final Gen, Integer>> arbListWithIndex = arbList(arbInteger) .filter(List::isNotEmpty) - .bind(list -> Gen.choose(0, list.length() - 1).map(i -> p(list, i)))); + .bind(list -> Gen.choose(0, list.length() - 1).map(i -> p(list, i))); public Property isEmpty() { return property(arbList(arbInteger), list -> prop(list.isEmpty() != list.isNotEmpty())); @@ -172,11 +171,11 @@ public Property appendLength() { @CheckParams(minSize = 2, maxSize = 10000) public Property indexTail() { - final Gen, Integer>> gen = arbList(arbInteger).gen + final Gen, Integer>> gen = arbList(arbInteger) .filter(list -> list.length() > 1) .bind(list -> Gen.choose(1, list.length() - 1).map(i -> p(list, i))); - return property(Arbitrary.arbitrary(gen), pair -> { + return property(gen, pair -> { final List list = pair._1(); final int i = pair._2(); return prop(intEqual.eq(list.index(i), list.tail().index(i - 1))); @@ -277,17 +276,17 @@ public Property groupByMonoid() { } public Property isPrefixOf() { - final Gen, Integer>> gen = arbList(arbInteger).gen.bind(list -> + final Gen, Integer>> gen = arbList(arbInteger).bind(list -> Gen.choose(0, list.length()).map(i -> p(list, i))); - return property(arbitrary(gen), pair -> prop(pair._1().take(pair._2()).isPrefixOf(intEqual, pair._1()))); + return property(gen, pair -> prop(pair._1().take(pair._2()).isPrefixOf(intEqual, pair._1()))); } public Property isSuffixOf() { - final Gen, Integer>> gen = arbList(arbInteger).gen.bind(list -> + final Gen, Integer>> gen = arbList(arbInteger).bind(list -> Gen.choose(0, list.length()).map(i -> p(list, i))); - return property(arbitrary(gen), pair -> prop(pair._1().drop(pair._2()).isSuffixOf(intEqual, pair._1()))); + return property(gen, pair -> prop(pair._1().drop(pair._2()).isSuffixOf(intEqual, pair._1()))); } public Property isPrefixOfShorter() { diff --git a/props-core/src/test/java/fj/data/properties/SeqProperties.java b/props-core/src/test/java/fj/data/properties/SeqProperties.java index 8e8076aa..eedbcc5c 100644 --- a/props-core/src/test/java/fj/data/properties/SeqProperties.java +++ b/props-core/src/test/java/fj/data/properties/SeqProperties.java @@ -6,7 +6,6 @@ import fj.data.Seq; import fj.test.reflect.CheckParams; import fj.test.runner.PropertyTestRunner; -import fj.test.Arbitrary; import fj.test.Gen; import fj.test.Property; import org.junit.runner.RunWith; @@ -21,9 +20,9 @@ @CheckParams(maxSize = 10000) public class SeqProperties { - private static final Arbitrary, Integer>> arbSeqWithIndex = arbitrary(arbSeq(arbInteger).gen + private static final Gen, Integer>> arbSeqWithIndex = arbSeq(arbInteger) .filter(Seq::isNotEmpty) - .bind(seq -> Gen.choose(0, seq.length() - 1).map(i -> P.p(seq, i)))); + .bind(seq -> Gen.choose(0, seq.length() - 1).map(i -> P.p(seq, i))); public Property consHead() { return property(arbSeq(arbInteger), arbInteger, (seq, n) -> prop(seq.cons(n).head().equals(n))); @@ -107,12 +106,12 @@ public Property delete() { } public Property foldLeft() { - return property(arbSeq(arbitrary(Gen.value(1))), seq -> + return property(arbSeq(Gen.value(1)), seq -> prop(seq.foldLeft((acc, i) -> acc + i, 0) == seq.length())); } public Property foldRight() { - return property(arbSeq(arbitrary(Gen.value(1))), seq -> + return property(arbSeq(Gen.value(1)), seq -> prop(seq.foldRight((i, acc) -> acc + i, 0) == seq.length())); } diff --git a/props-core/src/test/java/fj/data/properties/SetProperties.java b/props-core/src/test/java/fj/data/properties/SetProperties.java index 84c7e40c..5349b650 100644 --- a/props-core/src/test/java/fj/data/properties/SetProperties.java +++ b/props-core/src/test/java/fj/data/properties/SetProperties.java @@ -6,6 +6,7 @@ import fj.data.Set; import fj.data.Stream; import fj.test.Arbitrary; +import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; import fj.test.runner.PropertyTestRunner; @@ -22,7 +23,7 @@ public class SetProperties { public final static int maxSize = 20; - public final static Arbitrary> as = Arbitrary.arbSet(Ord.intOrd, Arbitrary.arbInteger, maxSize); + public final static Gen> as = Arbitrary.arbSet(Ord.intOrd, Arbitrary.arbInteger, maxSize); public final static Equal> eq = Equal.listEqual(Equal.intEqual); Property setToListIsSorted() { diff --git a/props-core/src/test/java/fj/data/properties/StreamProperties.java b/props-core/src/test/java/fj/data/properties/StreamProperties.java index f68df0bc..07bc7897 100644 --- a/props-core/src/test/java/fj/data/properties/StreamProperties.java +++ b/props-core/src/test/java/fj/data/properties/StreamProperties.java @@ -3,7 +3,6 @@ import fj.*; import fj.data.Either; import fj.data.Stream; -import fj.test.Arbitrary; import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -170,11 +169,11 @@ public Property reverse() { @CheckParams(minSize = 2, maxSize = 10000) public Property indexTail() { - final Gen, Integer>> gen = arbStream(arbInteger).gen + final Gen, Integer>> gen = arbStream(arbInteger) .filter(stream -> stream.length() > 1) .bind(stream -> Gen.choose(1, stream.length() - 1).map(i -> P.p(stream, i))); - return property(Arbitrary.arbitrary(gen), pair -> { + return property(gen, pair -> { final Stream stream = pair._1(); final int i = pair._2(); return prop(intEqual.eq(stream.index(i), stream.tail()._1().index(i - 1))); diff --git a/props-core/src/test/java/fj/data/properties/TreeMapProperties.java b/props-core/src/test/java/fj/data/properties/TreeMapProperties.java index 8dd718ee..eb71749b 100644 --- a/props-core/src/test/java/fj/data/properties/TreeMapProperties.java +++ b/props-core/src/test/java/fj/data/properties/TreeMapProperties.java @@ -6,7 +6,6 @@ import fj.data.List; import fj.data.Stream; import fj.data.TreeMap; -import fj.test.Arbitrary; import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -33,8 +32,8 @@ public class TreeMapProperties { private static final int smallMax = 5; private static final int midMax = 20; - public static final Arbitrary> smallArbTreeMapIS = arbTreeMap(intOrd, arbInteger, arbString, smallMax); - public static final Arbitrary> arbTreeMapIS = arbTreeMap(intOrd, arbInteger, arbString, midMax); + public static final Gen> smallArbTreeMapIS = arbTreeMap(intOrd, arbInteger, arbString, smallMax); + public static final Gen> arbTreeMapIS = arbTreeMap(intOrd, arbInteger, arbString, midMax); public static final Ord> p2Ord = Ord.p2Ord1(Ord.intOrd); Equal>> listEq = Equal.listEqual(p2Equal(intEqual, stringEqual)); diff --git a/props-core/src/test/java/fj/data/properties/ValidationProperties.java b/props-core/src/test/java/fj/data/properties/ValidationProperties.java index d9580cc4..f5205d73 100644 --- a/props-core/src/test/java/fj/data/properties/ValidationProperties.java +++ b/props-core/src/test/java/fj/data/properties/ValidationProperties.java @@ -4,7 +4,7 @@ import fj.Semigroup; import fj.data.List; import fj.data.Validation; -import fj.test.Arbitrary; +import fj.test.Gen; import fj.test.Property; import fj.test.runner.PropertyTestRunner; import org.junit.runner.RunWith; @@ -20,7 +20,7 @@ public class ValidationProperties { public Property partition() { - Arbitrary>> al = arbList(arbValidation(arbUSASCIIString, arbInteger)); + Gen>> al = arbList(arbValidation(arbUSASCIIString, arbInteger)); return Property.property(al, list -> { P2, List> p = Validation.partition(list); boolean b1 = p._1().length() + p._2().length() == list.length(); @@ -31,7 +31,7 @@ public Property partition() { } public Property sequenceNonCumulative() { - Arbitrary>> al = arbList(arbValidation(arbUSASCIIString, arbInteger)); + Gen>> al = arbList(arbValidation(arbUSASCIIString, arbInteger)); return Property.property(al, list -> { Validation, List> v = Validation.sequenceNonCumulative(list); Property p1 = implies( diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index e2a00b29..0b82108f 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -74,31 +74,11 @@ import java.util.concurrent.SynchronousQueue; /** - * The type used to generate arbitrary values of the given type parameter (A). Common - * arbitrary implementations are provided. + * Common Gen helper functions. * * @version %build.number% */ -public final class Arbitrary { - /** - * The generator associated with this arbitrary. - */ - @SuppressWarnings("PublicField") - public final Gen gen; - - private Arbitrary(final Gen gen) { - this.gen = gen; - } - - /** - * Constructs and arbitrary with the given generator. - * - * @param g The generator to construct an arbitrary with. - * @return A new arbitrary that uses the given generator. - */ - public static Arbitrary arbitrary(final Gen g) { - return new Arbitrary<>(g); - } +public final class Arbitrary { /** * An arbitrary for functions. @@ -107,30 +87,30 @@ public static Arbitrary arbitrary(final Gen g) { * @param a The arbitrary for the function codomain. * @return An arbitrary for functions. */ - public static Arbitrary> arbF(final Coarbitrary c, final Arbitrary a) { - return arbitrary(promote(new F>() { + public static Gen> arbF(final Coarbitrary c, final Gen a) { + return promote(new F>() { public Gen f(final A x) { - return c.coarbitrary(x, a.gen); + return c.coarbitrary(x, a); } - })); + }); } - public static Arbitrary> arbReader(Coarbitrary aa, Arbitrary ab) { - return arbitrary(arbF(aa, ab).gen.map(Reader::unit)); + public static Gen> arbReader(Coarbitrary aa, Gen ab) { + return arbF(aa, ab).map(Reader::unit); } /** * An arbitrary for state. */ - public static Arbitrary> arbState(Arbitrary as, Coarbitrary cs, Arbitrary aa) { - return arbitrary(arbF(cs, arbP2(as, aa)).gen.map(State::unit)); + public static Gen> arbState(Gen as, Coarbitrary cs, Gen aa) { + return arbF(cs, arbP2(as, aa)).map(State::unit); } /** * An arbitrary for the LcgRng. */ - public static Arbitrary arbLcgRng() { - return arbitrary(Arbitrary.arbLong.gen.map(LcgRng::new)); + public static Gen arbLcgRng() { + return Arbitrary.arbLong.map(LcgRng::new); } /** @@ -139,8 +119,8 @@ public static Arbitrary arbLcgRng() { * @param a The arbitrary for the function codomain. * @return An arbitrary for functions. */ - public static Arbitrary> arbFInvariant(final Arbitrary a) { - return arbitrary(a.gen.map(Function.constant())); + public static Gen> arbFInvariant(final Gen a) { + return a.map(Function.constant()); } /** @@ -151,9 +131,9 @@ public static Arbitrary> arbFInvariant(final Arbitrary a) { * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-2. */ - public static Arbitrary> arbF2(final Coarbitrary ca, final Coarbitrary cb, - final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, a)).gen.map(Function.uncurryF2())); + public static Gen> arbF2(final Coarbitrary ca, final Coarbitrary cb, + final Gen a) { + return arbF(ca, arbF(cb, a)).map(Function.uncurryF2()); } /** @@ -162,9 +142,8 @@ public static Arbitrary> arbF2(final Coarbitrary ca, fi * @param a The arbitrary for the function codomain. * @return An arbitrary for function-2. */ - public static Arbitrary> arbF2Invariant(final Arbitrary a) { - return arbitrary(a.gen.map( - compose(Function.uncurryF2(), compose(Function.constant(), Function.constant())))); + public static Gen> arbF2Invariant(final Gen a) { + return a.map(compose(Function.uncurryF2(), compose(Function.constant(), Function.constant()))); } /** @@ -176,9 +155,9 @@ public static Arbitrary> arbF2Invariant(final Arbitrary * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-3. */ - public static Arbitrary> arbF3(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, a))).gen.map(Function.uncurryF3())); + public static Gen> arbF3(final Coarbitrary ca, final Coarbitrary cb, + final Coarbitrary cc, final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, a))).map(Function.uncurryF3()); } /** @@ -187,11 +166,11 @@ public static Arbitrary> arbF3(final Coarbitrary * @param a The arbitrary for the function codomain. * @return An arbitrary for function-3. */ - public static Arbitrary> arbF3Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF3(), compose(Function.constant(), + public static Gen> arbF3Invariant(final Gen a) { + return a.map(compose(Function.uncurryF3(), compose(Function.constant(), compose( Function.constant(), - Function.constant()))))); + Function.constant())))); } /** @@ -204,10 +183,10 @@ public static Arbitrary> arbF3Invariant(final Arbitr * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-4. */ - public static Arbitrary> arbF4(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Coarbitrary cd, - final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, a)))).gen.map(Function.uncurryF4())); + public static Gen> arbF4(final Coarbitrary ca, final Coarbitrary cb, + final Coarbitrary cc, final Coarbitrary cd, + final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, arbF(cd, a)))).map(Function.uncurryF4()); } /** @@ -216,12 +195,12 @@ public static Arbitrary> arbF4(final Coarbitra * @param a The arbitrary for the function codomain. * @return An arbitrary for function-4. */ - public static Arbitrary> arbF4Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF4(), + public static Gen> arbF4Invariant(final Gen a) { + return a.map(compose(Function.uncurryF4(), compose(Function.constant(), compose(Function.constant(), compose(Function.constant(), - Function.constant())))))); + Function.constant()))))); } /** @@ -235,14 +214,13 @@ public static Arbitrary> arbF4Invariant(final * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-5. */ - public static Arbitrary> arbF5(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Arbitrary a) { - return arbitrary( - arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, a))))).gen.map(Function.uncurryF5())); + public static Gen> arbF5(final Coarbitrary ca, + final Coarbitrary cb, + final Coarbitrary cc, + final Coarbitrary cd, + final Coarbitrary ce, + final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, a))))).map(Function.uncurryF5()); } /** @@ -251,13 +229,13 @@ public static Arbitrary> arbF4Invariant(final * @param a The arbitrary for the function codomain. * @return An arbitrary for function-5. */ - public static Arbitrary> arbF5Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF5(), + public static Gen> arbF5Invariant(final Gen a) { + return a.map(compose(Function.uncurryF5(), compose(Function.constant(), compose(Function.constant(), compose(Function.constant(), compose(Function.constant(), - Function.constant()))))))); + Function.constant())))))); } /** @@ -272,15 +250,15 @@ public static Arbitrary> arbF4Invariant(final * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-6. */ - public static Arbitrary> arbF6(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, a)))))).gen.map( - Function.uncurryF6())); + public static Gen> arbF6(final Coarbitrary ca, + final Coarbitrary cb, + final Coarbitrary cc, + final Coarbitrary cd, + final Coarbitrary ce, + final Coarbitrary cf, + final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, a)))))).map( + Function.uncurryF6()); } /** @@ -289,14 +267,14 @@ public static Arbitrary> arbF4Invariant(final * @param a The arbitrary for the function codomain. * @return An arbitrary for function-6. */ - public static Arbitrary> arbF6Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF6(), + public static Gen> arbF6Invariant(final Gen a) { + return a.map(compose(Function.uncurryF6(), compose(Function.>>>>>constant(), compose(Function.>>>>constant(), compose(Function.>>>constant(), compose(Function.>>constant(), compose(Function.>constant(), - Function.constant())))))))); + Function.constant()))))))); } /** @@ -312,16 +290,16 @@ public static Arbitrary> arbF4Invariant(final * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-7. */ - public static Arbitrary> arbF7(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg, - final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, a))))))).gen.map( - Function.uncurryF7())); + public static Gen> arbF7(final Coarbitrary ca, + final Coarbitrary cb, + final Coarbitrary cc, + final Coarbitrary cd, + final Coarbitrary ce, + final Coarbitrary cf, + final Coarbitrary cg, + final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, a))))))).map( + Function.uncurryF7()); } /** @@ -330,15 +308,15 @@ public static Arbitrary> arbF4Invariant(final * @param a The arbitrary for the function codomain. * @return An arbitrary for function-7. */ - public static Arbitrary> arbF7Invariant(final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF7(), + public static Gen> arbF7Invariant(final Gen a) { + return a.map(compose(Function.uncurryF7(), compose(Function.>>>>>>constant(), compose(Function.>>>>>constant(), compose(Function.>>>>constant(), compose(Function.>>>constant(), compose(Function.>>constant(), compose(Function.>constant(), - Function.constant()))))))))); + Function.constant())))))))); } /** @@ -355,17 +333,17 @@ public static Arbitrary> arbF4Invariant(final * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-8. */ - public static Arbitrary> arbF8(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg, - final Coarbitrary ch, - final Arbitrary a) { - return arbitrary(arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, arbF(ch, a)))))))).gen.map( - Function.uncurryF8())); + public static Gen> arbF8(final Coarbitrary ca, + final Coarbitrary cb, + final Coarbitrary cc, + final Coarbitrary cd, + final Coarbitrary ce, + final Coarbitrary cf, + final Coarbitrary cg, + final Coarbitrary ch, + final Gen a) { + return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, arbF(ch, a)))))))).map( + Function.uncurryF8()); } /** @@ -374,9 +352,9 @@ public static Arbitrary> arbF4Invariant(final * @param a The arbitrary for the function codomain. * @return An arbitrary for function-8. */ - public static Arbitrary> arbF8Invariant( - final Arbitrary a) { - return arbitrary(a.gen.map(compose(Function.uncurryF8(), + public static Gen> arbF8Invariant( + final Gen a) { + return a.map(compose(Function.uncurryF8(), compose(Function.>>>>>>>constant(), compose(Function.>>>>>>constant(), compose(Function.>>>>>constant(), @@ -386,25 +364,25 @@ public static Arbitrary> arbF4Invariant(final compose( Function.>>constant(), compose(Function.>constant(), - Function.constant())))))))))); + Function.constant()))))))))); } /** * An arbitrary implementation for boolean values. */ - public static final Arbitrary arbBoolean = arbitrary(elements(true, false)); + public static final Gen arbBoolean = elements(true, false); /** * An arbitrary implementation for integer values. */ - public static final Arbitrary arbInteger = arbitrary(sized(i -> choose(-i, i))); + public static final Gen arbInteger = sized(i -> choose(-i, i)); /** * An arbitrary implementation for integer values that checks boundary values (0, 1, -1, * max, min, max - 1, min + 1) with a frequency of 1% each then generates from {@link * #arbInteger} the remainder of the time (93%). */ - public static final Arbitrary arbIntegerBoundaries = arbitrary(sized(new F>() { + public static final Gen arbIntegerBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value(0)), @@ -414,22 +392,22 @@ public Gen f(final Integer i) { p(1, value(Integer.MIN_VALUE)), p(1, value(Integer.MAX_VALUE - 1)), p(1, value(Integer.MIN_VALUE + 1)), - p(93, arbInteger.gen))); + p(93, arbInteger))); } - })); + }); /** * An arbitrary implementation for long values. */ - public static final Arbitrary arbLong = - arbitrary(arbInteger.gen.bind(arbInteger.gen, i1 -> i2 -> (long) i1 << 32L & i2)); + public static final Gen arbLong = + arbInteger.bind(arbInteger, i1 -> i2 -> (long) i1 << 32L & i2); /** * An arbitrary implementation for long values that checks boundary values (0, 1, -1, max, * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbLong} * the remainder of the time (93%). */ - public static final Arbitrary arbLongBoundaries = arbitrary(sized(new F>() { + public static final Gen arbLongBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value(0L)), @@ -439,21 +417,21 @@ public Gen f(final Integer i) { p(1, value(Long.MIN_VALUE)), p(1, value(Long.MAX_VALUE - 1L)), p(1, value(Long.MIN_VALUE + 1L)), - p(93, arbLong.gen))); + p(93, arbLong))); } - })); + }); /** * An arbitrary implementation for byte values. */ - public static final Arbitrary arbByte = arbitrary(arbInteger.gen.map(i -> (byte) i.intValue())); + public static final Gen arbByte = arbInteger.map(i -> (byte) i.intValue()); /** * An arbitrary implementation for byte values that checks boundary values (0, 1, -1, max, * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbByte} * the remainder of the time (93%). */ - public static final Arbitrary arbByteBoundaries = arbitrary(sized(new F>() { + public static final Gen arbByteBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value((byte) 0)), @@ -463,21 +441,21 @@ public Gen f(final Integer i) { p(1, value(Byte.MIN_VALUE)), p(1, value((byte) (Byte.MAX_VALUE - 1))), p(1, value((byte) (Byte.MIN_VALUE + 1))), - p(93, arbByte.gen))); + p(93, arbByte))); } - })); + }); /** * An arbitrary implementation for short values. */ - public static final Arbitrary arbShort = arbitrary(arbInteger.gen.map(i -> (short) i.intValue())); + public static final Gen arbShort = arbInteger.map(i -> (short) i.intValue()); /** * An arbitrary implementation for short values that checks boundary values (0, 1, -1, max, * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbShort} * the remainder of the time (93%). */ - public static final Arbitrary arbShortBoundaries = arbitrary(sized(new F>() { + public static final Gen arbShortBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value((short) 0)), @@ -487,42 +465,42 @@ public Gen f(final Integer i) { p(1, value(Short.MIN_VALUE)), p(1, value((short) (Short.MAX_VALUE - 1))), p(1, value((short) (Short.MIN_VALUE + 1))), - p(93, arbShort.gen))); + p(93, arbShort))); } - })); + }); /** * An arbitrary implementation for character values. */ - public static final Arbitrary arbCharacter = arbitrary(choose(0, 65536).map(i -> (char) i.intValue())); + public static final Gen arbCharacter = choose(0, 65536).map(i -> (char) i.intValue()); /** * An arbitrary implementation for character values that checks boundary values (max, min, * max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbCharacter} * the remainder of the time (96%). */ - public static final Arbitrary arbCharacterBoundaries = arbitrary(sized(new F>() { + public static final Gen arbCharacterBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value(Character.MIN_VALUE)), p(1, value((char) (Character.MIN_VALUE + 1))), p(1, value(Character.MAX_VALUE)), p(1, value((char) (Character.MAX_VALUE - 1))), - p(95, arbCharacter.gen))); + p(95, arbCharacter))); } - })); + }); /** * An arbitrary implementation for double values. */ - public static final Arbitrary arbDouble = arbitrary(sized(i -> choose((double) -i, i))); + public static final Gen arbDouble = sized(i -> choose((double) -i, i)); /** * An arbitrary implementation for double values that checks boundary values (0, 1, -1, max, * min, min (normal), NaN, -infinity, infinity, max - 1) with a frequency of 1% each then * generates from {@link #arbDouble} the remainder of the time (91%). */ - public static final Arbitrary arbDoubleBoundaries = arbitrary(sized(new F>() { + public static final Gen arbDoubleBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value(0D)), @@ -534,21 +512,21 @@ public Gen f(final Integer i) { p(1, value(Double.NEGATIVE_INFINITY)), p(1, value(Double.POSITIVE_INFINITY)), p(1, value(Double.MAX_VALUE - 1D)), - p(91, arbDouble.gen))); + p(91, arbDouble))); } - })); + }); /** * An arbitrary implementation for float values. */ - public static final Arbitrary arbFloat = arbitrary(arbDouble.gen.map(d -> (float) d.doubleValue())); + public static final Gen arbFloat = arbDouble.map(d -> (float) d.doubleValue()); /** * An arbitrary implementation for float values that checks boundary values (0, 1, -1, max, * min, NaN, -infinity, infinity, max - 1) with a frequency of 1% each then generates from * {@link #arbFloat} the remainder of the time (91%). */ - public static final Arbitrary arbFloatBoundaries = arbitrary(sized(new F>() { + public static final Gen arbFloatBoundaries = sized(new F>() { @SuppressWarnings("unchecked") public Gen f(final Integer i) { return frequency(list(p(1, value(0F)), @@ -560,41 +538,41 @@ public Gen f(final Integer i) { p(1, value(Float.NEGATIVE_INFINITY)), p(1, value(Float.POSITIVE_INFINITY)), p(1, value(Float.MAX_VALUE - 1F)), - p(91, arbFloat.gen))); + p(91, arbFloat))); } - })); + }); /** * An arbitrary implementation for string values. */ - public static final Arbitrary arbString = - arbitrary(arbList(arbCharacter).gen.map(List::asString)); + public static final Gen arbString = + arbList(arbCharacter).map(List::asString); /** * An arbitrary implementation for string values with characters in the US-ASCII range. */ - public static final Arbitrary arbUSASCIIString = - arbitrary(arbList(arbCharacter).gen.map(cs -> asString(cs.map(c -> (char) (c % 128))))); + public static final Gen arbUSASCIIString = + arbList(arbCharacter).map(cs -> asString(cs.map(c -> (char) (c % 128)))); /** * An arbitrary implementation for string values with alpha-numeric characters. */ - public static final Arbitrary arbAlphaNumString = - arbitrary(arbList(arbitrary(elements(range(charEnumerator, 'a', 'z').append( + public static final Gen arbAlphaNumString = + arbList(elements(range(charEnumerator, 'a', 'z').append( range(charEnumerator, 'A', 'Z')).append( - range(charEnumerator, '0', '9')).toArray().array(Character[].class)))).gen.map(asString())); + range(charEnumerator, '0', '9')).toArray().array(Character[].class))).map(asString()); /** * An arbitrary implementation for string buffer values. */ - public static final Arbitrary arbStringBuffer = - arbitrary(arbString.gen.map(StringBuffer::new)); + public static final Gen arbStringBuffer = + arbString.map(StringBuffer::new); /** * An arbitrary implementation for string builder values. */ - public static final Arbitrary arbStringBuilder = - arbitrary(arbString.gen.map(StringBuilder::new)); + public static final Gen arbStringBuilder = + arbString.map(StringBuilder::new); /** * Returns an arbitrary implementation for generators. @@ -602,13 +580,13 @@ public Gen f(final Integer i) { * @param aa an arbitrary implementation for the type over which the generator is defined. * @return An arbitrary implementation for generators. */ - public static Arbitrary> arbGen(final Arbitrary aa) { - return arbitrary(sized(i -> { + public static Gen> arbGen(final Gen aa) { + return sized(i -> { if (i == 0) return fail(); else - return aa.gen.map(Gen::value).resize(i - 1); - })); + return aa.map(Gen::value).resize(i - 1); + }); } /** @@ -617,10 +595,10 @@ public static Arbitrary> arbGen(final Arbitrary aa) { * @param aa an arbitrary implementation for the type over which the optional value is defined. * @return An arbitrary implementation for optional values. */ - public static Arbitrary> arbOption(final Arbitrary aa) { - return arbitrary(sized(i -> i == 0 ? + public static Gen> arbOption(final Gen aa) { + return sized(i -> i == 0 ? value(Option.none()) : - aa.gen.map(Option::some).resize(i - 1))); + aa.map(Option::some).resize(i - 1)); } /** @@ -633,10 +611,10 @@ public static Arbitrary> arbOption(final Arbitrary aa) { * @return An arbitrary implementation for the disjoint union. */ @SuppressWarnings("unchecked") - public static Arbitrary> arbEither(final Arbitrary aa, final Arbitrary ab) { - final Gen> left = aa.gen.map(Either::left); - final Gen> right = ab.gen.map(Either::right); - return arbitrary(oneOf(list(left, right))); + public static Gen> arbEither(final Gen aa, final Gen ab) { + final Gen> left = aa.map(Either::left); + final Gen> right = ab.map(Either::right); + return oneOf(list(left, right)); } /** @@ -645,47 +623,47 @@ public static Arbitrary> arbEither(final Arbitrary aa, fi * @param aa An arbitrary implementation for the type over which the list is defined. * @return An arbitrary implementation for lists. */ - public static Arbitrary> arbList(final Arbitrary aa) { - return arbitrary(listOf(aa.gen)); + public static Gen> arbList(final Gen aa) { + return listOf(aa); } /** * Returns an arbitrary list of integers. */ - public static Arbitrary> arbListInteger() { - return arbitrary(listOf(arbInteger.gen)); + public static Gen> arbListInteger() { + return listOf(arbInteger); } /** * Returns an arbitrary list of strings. */ - public static Arbitrary> arbListString() { - return arbitrary(listOf(arbString.gen)); + public static Gen> arbListString() { + return listOf(arbString); } /** * Returns an arbitrary list of booleans. */ - public static Arbitrary> arbListBoolean() { - return arbitrary(listOf(arbBoolean.gen)); + public static Gen> arbListBoolean() { + return listOf(arbBoolean); } /** * Returns an arbitrary list of doubles. */ - public static Arbitrary> arbListDouble() { - return arbitrary(listOf(arbDouble.gen)); + public static Gen> arbListDouble() { + return listOf(arbDouble); } - public static Arbitrary> arbNonEmptyList(final Arbitrary aa) { - return arbitrary(Gen.listOf1(aa.gen).map(list -> NonEmptyList.fromList(list).some())); + public static Gen> arbNonEmptyList(final Gen aa) { + return Gen.listOf1(aa).map(list -> NonEmptyList.fromList(list).some()); } /** * Returns an arbitrary Validation for the given arbitrary parameters. */ - public static Arbitrary> arbValidation(final Arbitrary aa, final Arbitrary ab) { - return arbitrary(arbBoolean.gen.bind(bool -> bool ? ab.gen.map(Validation::success) : aa.gen.map(Validation::fail))); + public static Gen> arbValidation(final Gen aa, final Gen ab) { + return arbBoolean.bind(bool -> bool ? ab.map(Validation::success) : aa.map(Validation::fail)); } /** @@ -694,8 +672,8 @@ public static Arbitrary> arbValidation(final Arbitrary Arbitrary> arbStream(final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(List::toStream)); + public static Gen> arbStream(final Gen aa) { + return arbList(aa).map(List::toStream); } /** @@ -704,8 +682,8 @@ public static Arbitrary> arbStream(final Arbitrary aa) { * @param aa An arbitrary implementation for the type over which the array is defined. * @return An arbitrary implementation for arrays. */ - public static Arbitrary> arbArray(final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(List::toArray)); + public static Gen> arbArray(final Gen aa) { + return arbList(aa).map(List::toArray); } /** @@ -715,17 +693,16 @@ public static Arbitrary> arbArray(final Arbitrary aa) { * @return An arbitrary implementation for sequences. */ @SuppressWarnings("unchecked") - public static Arbitrary> arbSeq(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(Seq::iterableSeq)); + public static Gen> arbSeq(final Gen aa) { + return arbArray(aa).map(Seq::iterableSeq); } - public static Arbitrary> arbSet(Ord ord, final Arbitrary aa) { - return arbitrary(arbList(aa).gen.map(list -> Set.iterableSet(ord, list))); + public static Gen> arbSet(Ord ord, final Gen aa) { + return arbList(aa).map(list -> Set.iterableSet(ord, list)); } - public static Arbitrary> arbSet(Ord ord, final Arbitrary aa, int max) { - Gen> g = choose(0, max).bind(i -> Gen.sequenceN(i, aa.gen)).map(list -> Set.iterableSet(ord, list)); - return arbitrary(g); + public static Gen> arbSet(Ord ord, final Gen aa, int max) { + return choose(0, max).bind(i -> Gen.sequenceN(i, aa)).map(list -> Set.iterableSet(ord, list)); } @@ -735,14 +712,14 @@ public static Arbitrary> arbSet(Ord ord, final Arbitrary aa, in * @param as An arbitrary used for the throwable message. * @return An arbitrary implementation for throwables. */ - public static Arbitrary arbThrowable(final Arbitrary as) { - return arbitrary(as.gen.map(Throwable::new)); + public static Gen arbThrowable(final Gen as) { + return as.map(Throwable::new); } /** * An arbitrary implementation for throwables. */ - public static final Arbitrary arbThrowable = arbThrowable(arbString); + public static final Gen arbThrowable = arbThrowable(arbString); // BEGIN java.util @@ -752,33 +729,33 @@ public static Arbitrary arbThrowable(final Arbitrary as) { * @param aa An arbitrary implementation for the type over which the array list is defined. * @return An arbitrary implementation for array lists. */ - public static Arbitrary> arbArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(Array::toJavaList)); + public static Gen> arbArrayList(final Gen aa) { + return arbArray(aa).map(Array::toJavaList); } /** * An arbitrary implementation for bit sets. */ - public static final Arbitrary arbBitSet = - arbitrary(arbList(arbBoolean).gen.map(bs -> { + public static final Gen arbBitSet = + arbList(arbBoolean).map(bs -> { final BitSet s = new BitSet(bs.length()); bs.zipIndex().foreachDoEffect(bi -> s.set(bi._2(), bi._1())); return s; - })); + }); /** * An arbitrary implementation for calendars. */ - public static final Arbitrary arbCalendar = arbitrary(arbLong.gen.map(i -> { + public static final Gen arbCalendar = arbLong.map(i -> { final Calendar c = Calendar.getInstance(); c.setTimeInMillis(i); return c; - })); + }); /** * An arbitrary implementation for dates. */ - public static final Arbitrary arbDate = arbitrary(arbLong.gen.map(Date::new)); + public static final Gen arbDate = arbLong.map(Date::new); /** * Returns an arbitrary implementation for a Java enumeration. @@ -786,8 +763,8 @@ public static Arbitrary> arbArrayList(final Arbitrary aa) { * @param clazz The type of enum to return an arbtrary of. * @return An arbitrary for instances of the supplied enum type. */ - public static > Arbitrary arbEnumValue(final Class clazz) { - return arbitrary(elements(clazz.getEnumConstants())); + public static > Gen arbEnumValue(final Class clazz) { + return elements(clazz.getEnumConstants()); } /** @@ -798,9 +775,9 @@ public static > Arbitrary arbEnumValue(final Class clazz * defined. * @return An arbitrary implementation for enum maps. */ - public static , V> Arbitrary> arbEnumMap(final Arbitrary ak, - final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(EnumMap::new)); + public static , V> Gen> arbEnumMap(final Gen ak, + final Gen av) { + return arbHashtable(ak, av).map(EnumMap::new); } /** @@ -809,19 +786,19 @@ public static , V> Arbitrary> arbEnumMap(final A * @param aa An arbitrary implementation for the type over which the enum set is defined. * @return An arbitrary implementation for enum sets. */ - public static > Arbitrary> arbEnumSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> copyOf(a.asJavaList()))); + public static > Gen> arbEnumSet(final Gen aa) { + return arbArray(aa).map(a -> copyOf(a.asJavaList())); } /** * An arbitrary implementation for gregorian calendars. */ - public static final Arbitrary arbGregorianCalendar = - arbitrary(arbLong.gen.map(i -> { + public static final Gen arbGregorianCalendar = + arbLong.map(i -> { final GregorianCalendar c = new GregorianCalendar(); c.setTimeInMillis(i); return c; - })); + }); /** * Returns an arbitrary implementation for hash maps. @@ -831,8 +808,8 @@ public static > Arbitrary> arbEnumSet(final Arbitra * defined. * @return An arbitrary implementation for hash maps. */ - public static Arbitrary> arbHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(HashMap::new)); + public static Gen> arbHashMap(final Gen ak, final Gen av) { + return arbHashtable(ak, av).map(HashMap::new); } /** @@ -841,8 +818,8 @@ public static Arbitrary> arbHashMap(final Arbitrary ak, * @param aa An arbitrary implementation for the type over which the hash set is defined. * @return An arbitrary implementation for hash sets. */ - public static Arbitrary> arbHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new HashSet<>(a.asJavaList()))); + public static Gen> arbHashSet(final Gen aa) { + return arbArray(aa).map(a -> new HashSet<>(a.asJavaList())); } /** @@ -854,14 +831,14 @@ public static Arbitrary> arbHashSet(final Arbitrary aa) { * defined. * @return An arbitrary implementation for hash tables. */ - public static Arbitrary> arbHashtable(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbList(ak).gen.bind(arbList(av).gen, ks -> vs -> { + public static Gen> arbHashtable(final Gen ak, final Gen av) { + return arbList(ak).bind(arbList(av), ks -> vs -> { final Hashtable t = new Hashtable<>(); ks.zip(vs).foreachDoEffect(kv -> t.put(kv._1(), kv._2())); return t; - })); + }); } /** @@ -873,9 +850,9 @@ public static Arbitrary> arbHashtable(final Arbitrary * are defined. * @return An arbitrary implementation for identity hash maps. */ - public static Arbitrary> arbIdentityHashMap(final Arbitrary ak, - final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(IdentityHashMap::new)); + public static Gen> arbIdentityHashMap(final Gen ak, + final Gen av) { + return arbHashtable(ak, av).map(IdentityHashMap::new); } /** @@ -887,8 +864,8 @@ public static Arbitrary> arbIdentityHashMap(final A * defined. * @return An arbitrary implementation for linked hash maps. */ - public static Arbitrary> arbLinkedHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(LinkedHashMap::new)); + public static Gen> arbLinkedHashMap(final Gen ak, final Gen av) { + return arbHashtable(ak, av).map(LinkedHashMap::new); } /** @@ -897,8 +874,8 @@ public static Arbitrary> arbLinkedHashMap(final Arbit * @param aa An arbitrary implementation for the type over which the hash set is defined. * @return An arbitrary implementation for hash sets. */ - public static Arbitrary> arbLinkedHashSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedHashSet<>(a.asJavaList()))); + public static Gen> arbLinkedHashSet(final Gen aa) { + return arbArray(aa).map(a -> new LinkedHashSet<>(a.asJavaList())); } /** @@ -907,8 +884,8 @@ public static Arbitrary> arbLinkedHashSet(final Arbitrary Arbitrary> arbLinkedList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedList<>(a.asJavaList()))); + public static Gen> arbLinkedList(final Gen aa) { + return arbArray(aa).map(a -> new LinkedList<>(a.asJavaList())); } /** @@ -917,15 +894,15 @@ public static Arbitrary> arbLinkedList(final Arbitrary aa) * @param aa An arbitrary implementation for the type over which the priority queue is defined. * @return An arbitrary implementation for priority queues. */ - public static Arbitrary> arbPriorityQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityQueue<>(a.asJavaList()))); + public static Gen> arbPriorityQueue(final Gen aa) { + return arbArray(aa).map(a -> new PriorityQueue<>(a.asJavaList())); } /** * An arbitrary implementation for properties. */ - public static final Arbitrary arbProperties = - arbitrary(arbHashtable(arbString, arbString).gen.map(ht -> { + public static final Gen arbProperties = + arbHashtable(arbString, arbString).map(ht -> { final Properties p = new Properties(); for (final Map.Entry entry : ht.entrySet()) { @@ -933,7 +910,7 @@ public static Arbitrary> arbPriorityQueue(final Arbitrary Arbitrary> arbPriorityQueue(final Arbitrary Arbitrary> arbStack(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> { + public static Gen> arbStack(final Gen aa) { + return arbArray(aa).map(a -> { final Stack s = new Stack<>(); s.addAll(a.asJavaList()); return s; - })); + }); } /** @@ -957,45 +934,45 @@ public static Arbitrary> arbStack(final Arbitrary aa) { * defined. * @return An arbitrary implementation for tree maps. */ - public static Arbitrary> arbJavaTreeMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(java.util.TreeMap::new)); + public static Gen> arbJavaTreeMap(final Gen ak, final Gen av) { + return arbHashtable(ak, av).map(java.util.TreeMap::new); } /** * Returns an arbitrary implementation for tree maps. */ - public static Arbitrary> arbTreeMap(Ord ord, Arbitrary>> al) { - return arbitrary(al.gen.map(list -> fj.data.TreeMap.iterableTreeMap(ord, list))); + public static Gen> arbTreeMap(Ord ord, Gen>> al) { + return al.map(list -> fj.data.TreeMap.iterableTreeMap(ord, list)); } /** * Returns an arbitrary implementation for tree maps. */ - public static Arbitrary> arbTreeMap(Ord ord, Arbitrary ak, Arbitrary av) { + public static Gen> arbTreeMap(Ord ord, Gen ak, Gen av) { return arbTreeMap(ord, arbList(arbP2(ak, av))); } /** * Returns an arbitrary implementation for tree maps where the map size is the given arbitrary integer. */ - public static Arbitrary> arbTreeMap(Ord ord, Arbitrary ak, Arbitrary av, Arbitrary ai) { - Gen>> gl2 = ai.gen.bind(i -> { + public static Gen> arbTreeMap(Ord ord, Gen ak, Gen av, Gen ai) { + Gen>> gl2 = ai.bind(i -> { if (i < 0) { throw Bottom.error("Undefined: arbitrary natural is negative (" + i + ")"); } - return Gen.sequenceN(Math.max(i, 0), arbP2(ak, av).gen); + return Gen.sequenceN(Math.max(i, 0), arbP2(ak, av)); }); - return arbTreeMap(ord, arbitrary(gl2)); + return arbTreeMap(ord, gl2); } /** * Returns an arbitrary implementation for tree maps where the size is less than or equal to the max size. */ - public static Arbitrary> arbTreeMap(Ord ord, Arbitrary ak, Arbitrary av, int maxSize) { + public static Gen> arbTreeMap(Ord ord, Gen ak, Gen av, int maxSize) { if (maxSize < 0) { throw Bottom.error("Undefined: arbitrary natural is negative (" + maxSize + ")"); } - return arbTreeMap(ord, ak, av, arbitrary(choose(0, maxSize))); + return arbTreeMap(ord, ak, av, choose(0, maxSize)); } /** @@ -1004,8 +981,8 @@ public static Arbitrary> arbTreeMap(Ord ord, Arb * @param aa An arbitrary implementation for the type over which the tree set is defined. * @return An arbitrary implementation for tree sets. */ - public static Arbitrary> arbTreeSet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new TreeSet<>(a.asJavaList()))); + public static Gen> arbTreeSet(final Gen aa) { + return arbArray(aa).map(a -> new TreeSet<>(a.asJavaList())); } /** @@ -1015,8 +992,8 @@ public static Arbitrary> arbTreeSet(final Arbitrary aa) { * @return An arbitrary implementation for vectors. */ @SuppressWarnings("UseOfObsoleteCollectionType") - public static Arbitrary> arbVector(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new Vector<>(a.asJavaList()))); + public static Gen> arbVector(final Gen aa) { + return arbArray(aa).map(a -> new Vector<>(a.asJavaList())); } /** @@ -1028,8 +1005,8 @@ public static Arbitrary> arbVector(final Arbitrary aa) { * defined. * @return An arbitrary implementation for weak hash maps. */ - public static Arbitrary> arbWeakHashMap(final Arbitrary ak, final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(WeakHashMap::new)); + public static Gen> arbWeakHashMap(final Gen ak, final Gen av) { + return arbHashtable(ak, av).map(WeakHashMap::new); } // END java.util @@ -1043,10 +1020,10 @@ public static Arbitrary> arbWeakHashMap(final Arbitrary * defined. * @return An arbitrary implementation for array blocking queues. */ - public static Arbitrary> arbArrayBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.bind(arbInteger.gen, arbBoolean.gen, + public static Gen> arbArrayBlockingQueue(final Gen aa) { + return arbArray(aa).bind(arbInteger, arbBoolean, a -> capacity -> fair -> new ArrayBlockingQueue(a.length() + abs(capacity), - fair, a.asJavaList()))); + fair, a.asJavaList())); } /** @@ -1058,9 +1035,9 @@ public static Arbitrary> arbArrayBlockingQueue(final A * are defined. * @return An arbitrary implementation for concurrent hash maps. */ - public static Arbitrary> arbConcurrentHashMap(final Arbitrary ak, - final Arbitrary av) { - return arbitrary(arbHashtable(ak, av).gen.map(ConcurrentHashMap::new)); + public static Gen> arbConcurrentHashMap(final Gen ak, + final Gen av) { + return arbHashtable(ak, av).map(ConcurrentHashMap::new); } /** @@ -1070,8 +1047,8 @@ public static Arbitrary> arbConcurrentHashMap(fin * defined. * @return An arbitrary implementation for concurrent linked queues. */ - public static Arbitrary> arbConcurrentLinkedQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new ConcurrentLinkedQueue<>(a.asJavaList()))); + public static Gen> arbConcurrentLinkedQueue(final Gen aa) { + return arbArray(aa).map(a -> new ConcurrentLinkedQueue<>(a.asJavaList())); } /** @@ -1081,8 +1058,8 @@ public static Arbitrary> arbConcurrentLinkedQueue(f * defined. * @return An arbitrary implementation for copy-on-write array lists. */ - public static Arbitrary> arbCopyOnWriteArrayList(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArrayList<>(a.asJavaList()))); + public static Gen> arbCopyOnWriteArrayList(final Gen aa) { + return arbArray(aa).map(a -> new CopyOnWriteArrayList<>(a.asJavaList())); } /** @@ -1092,8 +1069,8 @@ public static Arbitrary> arbCopyOnWriteArrayList(fin * defined. * @return An arbitrary implementation for copy-on-write array sets. */ - public static Arbitrary> arbCopyOnWriteArraySet(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new CopyOnWriteArraySet<>(a.asJavaList()))); + public static Gen> arbCopyOnWriteArraySet(final Gen aa) { + return arbArray(aa).map(a -> new CopyOnWriteArraySet<>(a.asJavaList())); } /** @@ -1102,8 +1079,8 @@ public static Arbitrary> arbCopyOnWriteArraySet(final * @param aa An arbitrary implementation for the type over which the delay queue is defined. * @return An arbitrary implementation for delay queues. */ - public static Arbitrary> arbDelayQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new DelayQueue<>(a.asJavaList()))); + public static Gen> arbDelayQueue(final Gen aa) { + return arbArray(aa).map(a -> new DelayQueue<>(a.asJavaList())); } /** @@ -1113,8 +1090,8 @@ public static Arbitrary> arbDelayQueue(final A * defined. * @return An arbitrary implementation for linked blocking queues. */ - public static Arbitrary> arbLinkedBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new LinkedBlockingQueue<>(a.asJavaList()))); + public static Gen> arbLinkedBlockingQueue(final Gen aa) { + return arbArray(aa).map(a -> new LinkedBlockingQueue<>(a.asJavaList())); } /** @@ -1124,8 +1101,8 @@ public static Arbitrary> arbLinkedBlockingQueue(final * defined. * @return An arbitrary implementation for priority blocking queues. */ - public static Arbitrary> arbPriorityBlockingQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.map(a -> new PriorityBlockingQueue<>(a.asJavaList()))); + public static Gen> arbPriorityBlockingQueue(final Gen aa) { + return arbArray(aa).map(a -> new PriorityBlockingQueue<>(a.asJavaList())); } /** @@ -1135,12 +1112,12 @@ public static Arbitrary> arbPriorityBlockingQueue(f * defined. * @return An arbitrary implementation for priority blocking queues. */ - public static Arbitrary> arbSynchronousQueue(final Arbitrary aa) { - return arbitrary(arbArray(aa).gen.bind(arbBoolean.gen, a -> fair -> { + public static Gen> arbSynchronousQueue(final Gen aa) { + return arbArray(aa).bind(arbBoolean, a -> fair -> { final SynchronousQueue q = new SynchronousQueue<>(fair); q.addAll(a.asJavaList()); return q; - })); + }); } // END java.util.concurrent @@ -1150,17 +1127,17 @@ public static Arbitrary> arbSynchronousQueue(final Arbit /** * An arbitrary implementation for SQL dates. */ - public static final Arbitrary arbSQLDate = arbitrary(arbLong.gen.map(java.sql.Date::new)); + public static final Gen arbSQLDate = arbLong.map(java.sql.Date::new); /** * An arbitrary implementation for SQL times. */ - public static final Arbitrary Arbitrary> arbSynchronousQueue(final Arbit /** * An arbitrary implementation for big integers. */ - public static final Arbitrary arbBigInteger = - arbitrary(arbArray(arbByte).gen.bind(arbByte.gen, a -> b -> { + public static final Gen arbBigInteger = + arbArray(arbByte).bind(arbByte, a -> b -> { final byte[] x = new byte[a.length() + 1]; for (int i = 0; i < a.array().length; i++) { @@ -1180,20 +1157,20 @@ public static Arbitrary> arbSynchronousQueue(final Arbit x[a.length()] = b; return new BigInteger(x); - })); + }); /** * An arbitrary implementation for big decimals. */ - public static final Arbitrary arbBigDecimal = - arbitrary(arbBigInteger.gen.map(BigDecimal::new)); + public static final Gen arbBigDecimal = + arbBigInteger.map(BigDecimal::new); // END java.math /** * An arbitrary implementation for locales. */ - public static final Arbitrary arbLocale = arbitrary(elements(getAvailableLocales())); + public static final Gen arbLocale = elements(getAvailableLocales()); /** * Returns an arbitrary implementation for product-1 values. @@ -1201,8 +1178,8 @@ public static Arbitrary> arbSynchronousQueue(final Arbit * @param aa An arbitrary implementation for the type over which the product-1 is defined. * @return An arbitrary implementation for product-1 values. */ - public static Arbitrary> arbP1(final Arbitrary aa) { - return arbitrary(aa.gen.map(P::p)); + public static Gen> arbP1(final Gen aa) { + return aa.map(P::p); } /** @@ -1214,8 +1191,8 @@ public static Arbitrary> arbP1(final Arbitrary aa) { * defined. * @return An arbitrary implementation for product-2 values. */ - public static Arbitrary> arbP2(final Arbitrary aa, final Arbitrary ab) { - return arbitrary(aa.gen.bind(ab.gen, a -> b -> p(a, b))); + public static Gen> arbP2(final Gen aa, final Gen ab) { + return aa.bind(ab, a -> b -> p(a, b)); } /** @@ -1229,9 +1206,9 @@ public static Arbitrary> arbP2(final Arbitrary aa, final Arbi * defined. * @return An arbitrary implementation for product-3 values. */ - public static Arbitrary> arbP3(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, a -> b -> c -> p(a, b, c))); + public static Gen> arbP3(final Gen aa, final Gen ab, + final Gen ac) { + return aa.bind(ab, ac, a -> b -> c -> p(a, b, c)); } /** @@ -1247,9 +1224,9 @@ public static Arbitrary> arbP3(final Arbitrary aa, fina * defined. * @return An arbitrary implementation for product-4 values. */ - public static Arbitrary> arbP4(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac, final Arbitrary ad) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, a -> b -> c -> d -> p(a, b, c, d))); + public static Gen> arbP4(final Gen aa, final Gen ab, + final Gen ac, final Gen ad) { + return aa.bind(ab, ac, ad, a -> b -> c -> d -> p(a, b, c, d)); } /** @@ -1267,10 +1244,10 @@ public static Arbitrary> arbP4(final Arbitrary aa * defined. * @return An arbitrary implementation for product-5 values. */ - public static Arbitrary> arbP5(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac, final Arbitrary ad, - final Arbitrary ae) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, a -> b -> c -> d -> e -> p(a, b, c, d, e))); + public static Gen> arbP5(final Gen aa, final Gen ab, + final Gen ac, final Gen ad, + final Gen ae) { + return aa.bind(ab, ac, ad, ae, a -> b -> c -> d -> e -> p(a, b, c, d, e)); } /** @@ -1290,12 +1267,12 @@ public static Arbitrary> arbP5(final Arbitrary * defined. * @return An arbitrary implementation for product-6 values. */ - public static Arbitrary> arbP6(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac, final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, - a -> b -> c -> d -> e -> f -> p(a, b, c, d, e, f))); + public static Gen> arbP6(final Gen aa, final Gen ab, + final Gen ac, final Gen ad, + final Gen ae, + final Gen af) { + return aa.bind(ab, ac, ad, ae, af, + a -> b -> c -> d -> e -> f -> p(a, b, c, d, e, f)); } /** @@ -1317,15 +1294,15 @@ public static Arbitrary> arbP5(final Arbitrary * defined. * @return An arbitrary implementation for product-7 values. */ - public static Arbitrary> arbP7(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, ag.gen, - a -> b -> c -> d -> e -> f -> g -> p(a, b, c, d, e, f, g))); + public static Gen> arbP7(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag) { + return aa.bind(ab, ac, ad, ae, af, ag, + a -> b -> c -> d -> e -> f -> g -> p(a, b, c, d, e, f, g)); } /** @@ -1349,15 +1326,15 @@ public static Arbitrary> arbP5(final Arbitrary * defined. * @return An arbitrary implementation for product-8 values. */ - public static Arbitrary> arbP8(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah) { - return arbitrary(aa.gen.bind(ab.gen, ac.gen, ad.gen, ae.gen, af.gen, ag.gen, ah.gen, - a -> b -> c -> d -> e -> f -> g -> h -> p(a, b, c, d, e, f, g, h))); + public static Gen> arbP8(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah) { + return aa.bind(ab, ac, ad, ae, af, ag, ah, + a -> b -> c -> d -> e -> f -> g -> h -> p(a, b, c, d, e, f, g, h)); } } diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java index d158a90f..14c7acb4 100644 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ b/quickcheck/src/main/java/fj/test/Coarbitrary.java @@ -116,10 +116,10 @@ public Gen coarbitrary(final B b, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function. */ - public static Coarbitrary> coarbF(final Arbitrary a, final Coarbitrary c) { + public static Coarbitrary> coarbF(final Gen a, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F f, final Gen g) { - return a.gen.bind(a1 -> c.coarbitrary(f.f(a1), g)); + return a.bind(a1 -> c.coarbitrary(f.f(a1), g)); } }; } @@ -132,7 +132,7 @@ public Gen coarbitrary(final F f, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-2. */ - public static Coarbitrary> coarbF2(final Arbitrary aa, final Arbitrary ab, + public static Coarbitrary> coarbF2(final Gen aa, final Gen ab, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F2 f, final Gen g) { @@ -150,8 +150,8 @@ public Gen coarbitrary(final F2 f, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-3. */ - public static Coarbitrary> coarbF3(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac, final Coarbitrary c) { + public static Coarbitrary> coarbF3(final Gen aa, final Gen ab, + final Gen ac, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F3 f, final Gen g) { return coarbF(aa, coarbF(ab, coarbF(ac, c))).coarbitrary(curry(f), g); @@ -169,8 +169,8 @@ public Gen coarbitrary(final F3 f, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-4. */ - public static Coarbitrary> coarbF4(final Arbitrary aa, final Arbitrary ab, - final Arbitrary ac, final Arbitrary ad, + public static Coarbitrary> coarbF4(final Gen aa, final Gen ab, + final Gen ac, final Gen ad, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F4 f, final Gen g) { @@ -190,11 +190,11 @@ public Gen coarbitrary(final F4 f, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-5. */ - public static Coarbitrary> coarbF5(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, + public static Coarbitrary> coarbF5(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F5 f, final Gen g) { @@ -215,12 +215,12 @@ public Gen coarbitrary(final F5 f, final Gen g) { * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-6. */ - public static Coarbitrary> coarbF6(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, + public static Coarbitrary> coarbF6(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F6 f, final Gen g) { @@ -242,13 +242,13 @@ public Gen coarbitrary(final F6 f, final Gen g) * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-7. */ - public static Coarbitrary> coarbF7(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, + public static Coarbitrary> coarbF7(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F7 f, final Gen g) { @@ -272,14 +272,14 @@ public Gen coarbitrary(final F7 f, final Gen * @param c A coarbitrary for the codomain of the function. * @return A coarbitrary for a function-8. */ - public static Coarbitrary> coarbF8(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah, + public static Coarbitrary> coarbF8(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, final Coarbitrary c) { return new Coarbitrary>() { public Gen coarbitrary(final F8 f, final Gen g) { @@ -468,11 +468,11 @@ public Gen coarbitrary(LcgRng rng, Gen g) { /** * A coarbitrary for state. */ - public static Coarbitrary> coarbState(Arbitrary as, F2 f) { + public static Coarbitrary> coarbState(Gen as, F2 f) { return new Coarbitrary>() { @Override public Gen coarbitrary(State s1, Gen g) { - return as.gen.bind(r -> { + return as.bind(r -> { P2 p = s1.run(r); return variant(f.f(p._1(), p._2()), g); }); diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 6db7b304..1ea9be0a 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -50,21 +50,20 @@ class Person { * invoking the {@link #bind(F)} methods — in this case, {@link #bind(Gen , Gen , F)} the one * that takes two generator arguments}, since the class has one more than two fields (the bind * method is invoked on a generator adding the extra one to the count as they are composed). The - * class fields are of types for which there exist generators (on {@link Arbitrary} so those can be + * class fields are of types for which there exist generators (on {@link Gen} so those can be * used to compose a generator for Person:

-static Arbitrary<Person> personArbitrary() {
-  final Gen<Person> personGenerator = arbInteger.gen.bind(arbString().gen, arbBoolean().gen,
+static Gen<Person> personArbitrary() {
+  return arbInteger.bind(arbString(), arbBoolean(),
       // compose the generators
       {int age => {String name => {boolean male => new Person(age, name, male)}}};
-  return arbitrary(personGenerator);
 }
 
*

* The example above uses Java 7 closure syntax. Here is the same example using objects instead:

-static Arbitrary<Person> personArbitrary() {
-  final Gen<Person> personGenerator = arbInteger.gen.bind(arbString.gen, arbBoolean.gen,
+static Gen<Person> personArbitrary() {
+  return arbInteger.bind(arbString, arbBoolean,
       // compose the generators
       new F<Integer, F<String, F<Boolean, Person>>>() {
         public F<String, F<Boolean, Person>> f(final Integer age) {
@@ -79,7 +78,6 @@ public Person f(final Boolean male) {
           };
         }
       });
-  return arbitrary(personGenerator);
 }
 
* diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 274a7453..0f77f85e 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -443,8 +443,8 @@ public boolean failed(final Option> o) { * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static
Property propertyP(final Arbitrary aa, final Shrink sa, final F> f) { - return forall(aa.gen, sa, f); + public static Property propertyP(final Gen aa, final Shrink sa, final F> f) { + return forall(aa, sa, f); } /** @@ -457,7 +457,7 @@ public static Property propertyP(final Arbitrary aa, final Shrink sa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, final Shrink sa, final F f) { + public static Property property(final Gen aa, final Shrink sa, final F f) { return propertyP(aa, sa, P1.curry(f)); } @@ -470,7 +470,7 @@ public static Property property(final Arbitrary aa, final Shrink sa, f * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property propertyP(final Arbitrary aa, final F> f) { + public static Property propertyP(final Gen aa, final F> f) { return propertyP(aa, Shrink.empty(), f); } @@ -483,7 +483,7 @@ public static Property propertyP(final Arbitrary aa, final F Property property(final Arbitrary aa, final F f) { + public static Property property(final Gen aa, final F f) { return propertyP(aa, P1.curry(f)); } @@ -500,7 +500,7 @@ public static Property property(final Arbitrary aa, final F * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F>> f) { + public static Property propertyP(final Gen aa, final Gen ab, final Shrink sa, final Shrink sb, final F>> f) { return property(aa, sa, a -> { return propertyP(ab, sb, b -> { return f.f(a).f(b); @@ -520,7 +520,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F> f) { + public static Property property(final Gen aa, final Gen ab, final Shrink sa, final Shrink sb, final F> f) { return propertyP(aa, ab, sa, sb, compose2(P.p1(), f)); } @@ -534,7 +534,7 @@ public static Property property(final Arbitrary aa, final Arbitrary * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final F>> f) { + public static Property propertyP(final Gen aa, final Gen ab, final F>> f) { return property(aa, a -> propertyP(ab, b -> f.f(a).f(b))); } @@ -548,7 +548,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final F> f) { + public static Property property(final Gen aa, final Gen ab, final F> f) { return propertyP(aa, ab, compose2(P.p1(), f)); } @@ -564,7 +564,7 @@ public static Property property(final Arbitrary aa, final Arbitrary * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F2> f) { + public static Property propertyP(final Gen aa, final Gen ab, final Shrink sa, final Shrink sb, final F2> f) { return propertyP(aa, ab, sa, sb, curry(f)); } @@ -580,7 +580,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final Shrink sa, final Shrink sb, final F2 f) { + public static Property property(final Gen aa, final Gen ab, final Shrink sa, final Shrink sb, final F2 f) { return propertyP(aa, ab, sa, sb, compose2(P.p1(), curry(f))); } @@ -594,7 +594,7 @@ public static Property property(final Arbitrary aa, final Arbitrary * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property propertyP(final Arbitrary aa, final Arbitrary ab, final F2> f) { + public static Property propertyP(final Gen aa, final Gen ab, final F2> f) { return propertyP(aa, ab, curry(f)); } @@ -608,7 +608,7 @@ public static Property propertyP(final Arbitrary aa, final Arbitrary Property property(final Arbitrary aa, final Arbitrary ab, final F2 f) { + public static Property property(final Gen aa, final Gen ab, final F2 f) { return propertyP(aa, ab, compose2(P.p1(), curry(f))); } @@ -626,9 +626,9 @@ public static Property property(final Arbitrary aa, final Arbitrary * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, final Shrink sa, final Shrink sb, final Shrink sc, @@ -649,9 +649,9 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, final F>> f) { return property(aa, ab, a -> b -> property(ac, c -> f.f(a).f(b).f(c))); } @@ -670,9 +670,9 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, final Shrink sa, final Shrink sb, final Shrink sc, @@ -691,9 +691,9 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, final F3 f) { return property(aa, ab, ac, curry(f)); } @@ -714,10 +714,10 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, final Shrink sa, final Shrink sb, final Shrink sc, @@ -740,10 +740,10 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, final F>>> f) { return property(aa, ab, ac, a -> b -> c -> property(ad, d -> f.f(a).f(b).f(c).f(d))); } @@ -764,10 +764,10 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, final Shrink sa, final Shrink sb, final Shrink sc, @@ -788,10 +788,10 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, final F4 f) { return property(aa, ab, ac, ad, curry(f)); } @@ -814,11 +814,11 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, final Shrink sa, final Shrink sb, final Shrink sc, @@ -843,11 +843,11 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, final F>>>> f) { return property(aa, ab, ac, ad, a -> b -> c -> d -> property(ae, e -> f.f(a).f(b).f(c).f(d).f(e))); } @@ -870,11 +870,11 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, final Shrink sa, final Shrink sb, final Shrink sc, @@ -897,11 +897,11 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, final F5 f) { return property(aa, ab, ac, ad, ae, curry(f)); } @@ -926,12 +926,12 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, final Shrink sa, final Shrink sb, final Shrink sc, @@ -958,12 +958,12 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, final F>>>>> f) { return property(aa, ab, ac, ad, ae, a -> b -> c -> d -> e -> property(af, f$ -> f.f(a).f(b).f(c).f(d).f(e).f(f$))); } @@ -988,12 +988,12 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, final Shrink sa, final Shrink sb, final Shrink sc, @@ -1018,12 +1018,12 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, final F6 f) { return property(aa, ab, ac, ad, ae, af, curry(f)); } @@ -1050,13 +1050,13 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, final Shrink sa, final Shrink sb, final Shrink sc, @@ -1085,13 +1085,13 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, final F>>>>>> f) { return property(aa, ab, ac, ad, ae, af, a -> b -> c -> d -> e -> f$ -> property(ag, g -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g))); } @@ -1118,13 +1118,13 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, final Shrink sa, final Shrink sb, final Shrink sc, @@ -1151,13 +1151,13 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, final F7 f) { return property(aa, ab, ac, ad, ae, af, ag, curry(f)); } @@ -1186,14 +1186,14 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, final Shrink sa, final Shrink sb, final Shrink sc, @@ -1224,14 +1224,14 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, final F>>>>>>> f) { return property(aa, ab, ac, ad, ae, af, ag, a -> b -> c -> d -> e -> f$ -> g -> property(ah, h -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h))); } @@ -1260,14 +1260,14 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, final Shrink sa, final Shrink sb, final Shrink sc, @@ -1296,14 +1296,14 @@ public static Property property(final Arbitrary aa, * @return A property where its result is derived from universal quantification across the * application of its arguments. */ - public static Property property(final Arbitrary aa, - final Arbitrary ab, - final Arbitrary ac, - final Arbitrary ad, - final Arbitrary ae, - final Arbitrary af, - final Arbitrary ag, - final Arbitrary ah, + public static Property property(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, final F8 f) { return property(aa, ab, ac, ad, ae, af, ag, ah, curry(f)); } diff --git a/quickcheck/src/test/java/fj/data/test/TestCheck.java b/quickcheck/src/test/java/fj/data/test/TestCheck.java index 10c59a1c..6bfaeaf7 100644 --- a/quickcheck/src/test/java/fj/data/test/TestCheck.java +++ b/quickcheck/src/test/java/fj/data/test/TestCheck.java @@ -10,7 +10,6 @@ import org.junit.*; import static fj.Function.compose; -import static fj.test.Arbitrary.*; import static fj.test.Arbitrary.arbLong; import static fj.test.Coarbitrary.coarbInteger; import static fj.test.Coarbitrary.coarbLong; @@ -26,7 +25,7 @@ public void testExceptionsThrownFromGeneratorsArePropagated() { throw new RuntimeException("test failure"); }); - Property p = property(arbitrary(failingGen), (Integer i) -> { + Property p = property(failingGen, (Integer i) -> { return prop(i == 0); }); diff --git a/quickcheck/src/test/java/fj/data/test/TestNull.java b/quickcheck/src/test/java/fj/data/test/TestNull.java index 6f7795aa..0346407d 100644 --- a/quickcheck/src/test/java/fj/data/test/TestNull.java +++ b/quickcheck/src/test/java/fj/data/test/TestNull.java @@ -10,7 +10,6 @@ import org.junit.Test; import static fj.Function.compose; -import static fj.test.Arbitrary.*; import static fj.test.Arbitrary.arbLong; import static fj.test.Coarbitrary.coarbInteger; import static fj.test.Coarbitrary.coarbLong; @@ -24,7 +23,7 @@ public class TestNull { @Test public void testShowNullParameters() { - Property p = property(arbitrary(Gen.value(null)), (Integer i) -> { + Property p = property(Gen.value(null), (Integer i) -> { return prop(i != null); }); CheckResult.summary.println(p.check()); diff --git a/quickcheck/src/test/java/fj/test/TestBool.java b/quickcheck/src/test/java/fj/test/TestBool.java index 2f29f69a..a2b9cae7 100644 --- a/quickcheck/src/test/java/fj/test/TestBool.java +++ b/quickcheck/src/test/java/fj/test/TestBool.java @@ -4,7 +4,6 @@ import org.junit.Test; import static fj.test.Arbitrary.arbBoolean; -import static fj.test.Arbitrary.arbitrary; import static fj.test.Bool.bool; import static fj.test.Property.property; @@ -12,8 +11,7 @@ public class TestBool { @Test public void testBool() { - final Arbitrary arbBooleanR = arbitrary(arbBoolean.gen); - final Property p = property(arbBooleanR, arbBooleanR, (m1, m2) -> bool(m1.equals(m2)) + final Property p = property(arbBoolean, arbBoolean, (m1, m2) -> bool(m1.equals(m2)) .implies(m1 == m2)); PropertyAssert.assertResult(p); } From 7f46d9df703c4ba4b8b28b0bc4c35273bf134b4b Mon Sep 17 00:00:00 2001 From: Charles O'Farrell Date: Wed, 8 Jun 2016 06:31:15 +1000 Subject: [PATCH 081/336] Rename Coarbitrary to Cogen --- .../java/fj/demo/test/ListFunctorLaws.java | 6 +- .../src/test/java/fj/data/ReaderTest.java | 18 +- .../src/test/java/fj/data/TestRngState.java | 14 +- .../src/test/java/fj/data/WriterTest.java | 12 +- .../src/main/java/fj/test/Arbitrary.java | 142 +- .../src/main/java/fj/test/Coarbitrary.java | 1184 ----------------- quickcheck/src/main/java/fj/test/Cogen.java | 1184 +++++++++++++++++ .../src/test/java/fj/data/test/TestCheck.java | 2 - .../src/test/java/fj/data/test/TestNull.java | 2 - 9 files changed, 1280 insertions(+), 1284 deletions(-) delete mode 100644 quickcheck/src/main/java/fj/test/Coarbitrary.java create mode 100644 quickcheck/src/main/java/fj/test/Cogen.java diff --git a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java index 6f17f827..46f7bdb0 100644 --- a/demo/src/main/java/fj/demo/test/ListFunctorLaws.java +++ b/demo/src/main/java/fj/demo/test/ListFunctorLaws.java @@ -15,8 +15,8 @@ import fj.function.Effect1; import fj.test.CheckResult; import static fj.test.CheckResult.summary; -import static fj.test.Coarbitrary.coarbInteger; -import static fj.test.Coarbitrary.coarbLong; +import static fj.test.Cogen.cogenInteger; +import static fj.test.Cogen.cogenLong; import fj.test.Property; import static fj.test.Property.prop; import static fj.test.Property.property; @@ -42,7 +42,7 @@ For any list, mapping the identity function (\x -> x) produces the same list. public final class ListFunctorLaws { final Property identity = property(arbList(arbString), x -> prop(listEqual(stringEqual).eq(x, x.map(Function.identity())))); - final Property composition = property(arbF(coarbInteger, arbString), arbF(coarbLong, arbInteger), arbList(arbLong), (f, g, x) -> { + final Property composition = property(arbF(cogenInteger, arbString), arbF(cogenLong, arbInteger), arbList(arbLong), (f, g, x) -> { final List s1 = x.map(compose(f, g)); final List s2 = x.map(g).map(f); return prop(listEqual(stringEqual).eq(s1, s2)); diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 05c858b8..8494336e 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -8,7 +8,7 @@ import static fj.F1Functions.bind; import static fj.F1Functions.map; import static fj.test.Arbitrary.*; -import static fj.test.Coarbitrary.coarbInteger; +import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; import static fj.test.Property.property; import static org.junit.Assert.assertTrue; @@ -39,8 +39,8 @@ public void testFlatMap() { @Test public void testMapProp() { Property p = property( - arbF(coarbInteger, arbInteger), - arbF(coarbInteger, arbInteger), + arbF(cogenInteger, arbInteger), + arbF(cogenInteger, arbInteger), arbInteger, (f, g, i) -> { int expected = map(f, g).f(i); @@ -52,9 +52,9 @@ public void testMapProp() { @Test public void testFlatMapProp() { - Gen>> a = arbF(coarbInteger, arbReader()); + Gen>> a = arbF(cogenInteger, arbReader()); Property p = property( - arbF(coarbInteger, arbInteger), + arbF(cogenInteger, arbInteger), a, arbInteger, (f, g, i) -> { @@ -72,7 +72,7 @@ public void testLeftIdentity() { Property p = Property.property( arbInteger, arbInteger, - arbF(coarbInteger, arbReader()), + arbF(cogenInteger, arbReader()), (i, j, f) -> { int a = Reader.constant(i).flatMap(f).f(j); int b = f.f(i).f(j); @@ -99,8 +99,8 @@ public void testAssociativity() { Property p = Property.property( arbInteger, arbReader(), - arbF(coarbInteger, arbReader()), - arbF(coarbInteger, arbReader()), + arbF(cogenInteger, arbReader()), + arbF(cogenInteger, arbReader()), (i, r, f, g) -> { boolean b2 = r.flatMap(f).flatMap(g).f(i) == r.flatMap(x -> f.f(x).flatMap(g)).f(i); return prop(b2); @@ -109,7 +109,7 @@ public void testAssociativity() { } public Gen> arbReader() { - return Arbitrary.arbReader(coarbInteger, arbInteger); + return Arbitrary.arbReader(cogenInteger, arbInteger); } diff --git a/props-core/src/test/java/fj/data/TestRngState.java b/props-core/src/test/java/fj/data/TestRngState.java index ddc319b9..5f5f81bb 100644 --- a/props-core/src/test/java/fj/data/TestRngState.java +++ b/props-core/src/test/java/fj/data/TestRngState.java @@ -2,7 +2,7 @@ import fj.*; import fj.test.Arbitrary; -import fj.test.Coarbitrary; +import fj.test.Cogen; import fj.test.Gen; import fj.test.Property; import org.junit.Assert; @@ -12,7 +12,7 @@ import static fj.data.Stream.unfold; import static fj.data.test.PropertyAssert.assertResult; import static fj.test.Arbitrary.*; -import static fj.test.Coarbitrary.coarbInteger; +import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; import static fj.test.Property.property; import static fj.test.Variant.variant; @@ -80,19 +80,19 @@ public void testTraverse() { } public static Gen> arbState() { - return Arbitrary.arbState(Arbitrary.arbLcgRng(), Coarbitrary.coarbLcgRng(), arbInteger); + return Arbitrary.arbState(Arbitrary.arbLcgRng(), Cogen.cogenLcgRng(), arbInteger); } public static Gen>> arbStateF() { - return arbF(Coarbitrary.coarbLcgRng(), arbP2(arbLcgRng(), arbInteger)); + return arbF(Cogen.cogenLcgRng(), arbP2(arbLcgRng(), arbInteger)); } - public static Coarbitrary> coarbState() { - return Coarbitrary.coarbState(Arbitrary.arbLcgRng(), (LcgRng s, Integer j) -> (long) (j >= 0 ? 2 * j : -2 * j + 1)); + public static Cogen> cogenState() { + return Cogen.cogenState(Arbitrary.arbLcgRng(), (LcgRng s, Integer j) -> (long) (j >= 0 ? 2 * j : -2 * j + 1)); } public static Gen>> arbBindable() { - return arbF(coarbInteger, arbState()); + return arbF(cogenInteger, arbState()); } // Left identity: return i >>= f == f i diff --git a/props-core/src/test/java/fj/data/WriterTest.java b/props-core/src/test/java/fj/data/WriterTest.java index a2af9952..5f0ac122 100644 --- a/props-core/src/test/java/fj/data/WriterTest.java +++ b/props-core/src/test/java/fj/data/WriterTest.java @@ -11,7 +11,7 @@ import static fj.data.test.PropertyAssert.assertResult; import static fj.test.Arbitrary.*; -import static fj.test.Coarbitrary.coarbInteger; +import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; import static fj.test.Property.property; import static org.junit.Assert.assertTrue; @@ -46,7 +46,7 @@ public void testTellProp() { @Test public void testMap() { - Property p = property(arbInteger, arbF(coarbInteger, arbInteger), (i, f) -> { + Property p = property(arbInteger, arbF(cogenInteger, arbInteger), (i, f) -> { boolean b = eq.eq(defaultWriter.f(i).map(f), defaultWriter.f(f.f(i))); return prop(b); }); @@ -55,7 +55,7 @@ public void testMap() { @Test public void testFlatMap() { - Property p = property(arbInteger,arbF(coarbInteger, arbWriterStringInt()), (i, f) -> { + Property p = property(arbInteger,arbF(cogenInteger, arbWriterStringInt()), (i, f) -> { boolean b = eq.eq(Writer.stringLogger().f(i).flatMap(f), f.f(i)); return prop(b); }); @@ -76,7 +76,7 @@ public Gen> arbWriterString(Gen arb) { public void testLeftIdentity() { Property p = Property.property( arbInteger, - arbF(coarbInteger, arbWriterStringInt()), + arbF(cogenInteger, arbWriterStringInt()), (i, f) -> { return prop(eq.eq(defaultWriter.f(i).flatMap(f), f.f(i))); }); @@ -98,8 +98,8 @@ public void testRightIdentity() { public void testAssociativity() { Property p = Property.property( arbWriterStringInt(), - arbF(coarbInteger, arbWriterStringInt()), - arbF(coarbInteger, arbWriterStringInt()), + arbF(cogenInteger, arbWriterStringInt()), + arbF(cogenInteger, arbWriterStringInt()), (w, f, g) -> { boolean t = eq.eq(w.flatMap(f).flatMap(g), w.flatMap(x -> f.f(x).flatMap(g))); return prop(t); diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 0b82108f..d8f88bed 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -83,26 +83,26 @@ public final class Arbitrary { /** * An arbitrary for functions. * - * @param c The coarbitrary for the function domain. + * @param c The cogen for the function domain. * @param a The arbitrary for the function codomain. * @return An arbitrary for functions. */ - public static Gen> arbF(final Coarbitrary c, final Gen a) { + public static Gen> arbF(final Cogen c, final Gen a) { return promote(new F>() { public Gen f(final A x) { - return c.coarbitrary(x, a); + return c.cogen(x, a); } }); } - public static Gen> arbReader(Coarbitrary aa, Gen ab) { + public static Gen> arbReader(Cogen aa, Gen ab) { return arbF(aa, ab).map(Reader::unit); } /** * An arbitrary for state. */ - public static Gen> arbState(Gen as, Coarbitrary cs, Gen aa) { + public static Gen> arbState(Gen as, Cogen cs, Gen aa) { return arbF(cs, arbP2(as, aa)).map(State::unit); } @@ -126,12 +126,12 @@ public static Gen> arbFInvariant(final Gen a) { /** * An arbitrary for function-2. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-2. */ - public static Gen> arbF2(final Coarbitrary ca, final Coarbitrary cb, + public static Gen> arbF2(final Cogen ca, final Cogen cb, final Gen a) { return arbF(ca, arbF(cb, a)).map(Function.uncurryF2()); } @@ -149,14 +149,14 @@ public static Gen> arbF2Invariant(final Gen a) { /** * An arbitrary for function-3. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-3. */ - public static Gen> arbF3(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Gen a) { + public static Gen> arbF3(final Cogen ca, final Cogen cb, + final Cogen cc, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, a))).map(Function.uncurryF3()); } @@ -176,15 +176,15 @@ public static Gen> arbF3Invariant(final Gen a) { /** * An arbitrary for function-4. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. - * @param cd A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. + * @param cd A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-4. */ - public static Gen> arbF4(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Coarbitrary cd, + public static Gen> arbF4(final Cogen ca, final Cogen cb, + final Cogen cc, final Cogen cd, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, arbF(cd, a)))).map(Function.uncurryF4()); } @@ -206,19 +206,19 @@ public static Gen> arbF4Invariant(final Gen /** * An arbitrary for function-5. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. - * @param cd A coarbitrary for the part of the domain of the function. - * @param ce A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. + * @param cd A cogen for the part of the domain of the function. + * @param ce A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-5. */ - public static Gen> arbF5(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, + public static Gen> arbF5(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, a))))).map(Function.uncurryF5()); } @@ -241,21 +241,21 @@ public static Gen> arbF4Invariant(final Gen /** * An arbitrary for function-6. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. - * @param cd A coarbitrary for the part of the domain of the function. - * @param ce A coarbitrary for the part of the domain of the function. - * @param cf A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. + * @param cd A cogen for the part of the domain of the function. + * @param ce A cogen for the part of the domain of the function. + * @param cf A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-6. */ - public static Gen> arbF6(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, + public static Gen> arbF6(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, a)))))).map( Function.uncurryF6()); @@ -280,23 +280,23 @@ public static Gen> arbF4Invariant(final Gen /** * An arbitrary for function-7. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. - * @param cd A coarbitrary for the part of the domain of the function. - * @param ce A coarbitrary for the part of the domain of the function. - * @param cf A coarbitrary for the part of the domain of the function. - * @param cg A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. + * @param cd A cogen for the part of the domain of the function. + * @param ce A cogen for the part of the domain of the function. + * @param cf A cogen for the part of the domain of the function. + * @param cg A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-7. */ - public static Gen> arbF7(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg, + public static Gen> arbF7(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf, + final Cogen cg, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, a))))))).map( Function.uncurryF7()); @@ -322,25 +322,25 @@ public static Gen> arbF4Invariant(final Gen /** * An arbitrary for function-8. * - * @param ca A coarbitrary for the part of the domain of the function. - * @param cb A coarbitrary for the part of the domain of the function. - * @param cc A coarbitrary for the part of the domain of the function. - * @param cd A coarbitrary for the part of the domain of the function. - * @param ce A coarbitrary for the part of the domain of the function. - * @param cf A coarbitrary for the part of the domain of the function. - * @param cg A coarbitrary for the part of the domain of the function. - * @param ch A coarbitrary for the part of the domain of the function. + * @param ca A cogen for the part of the domain of the function. + * @param cb A cogen for the part of the domain of the function. + * @param cc A cogen for the part of the domain of the function. + * @param cd A cogen for the part of the domain of the function. + * @param ce A cogen for the part of the domain of the function. + * @param cf A cogen for the part of the domain of the function. + * @param cg A cogen for the part of the domain of the function. + * @param ch A cogen for the part of the domain of the function. * @param a An arbitrary for the codomain of the function. * @return An arbitrary for function-8. */ - public static Gen> arbF8(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg, - final Coarbitrary ch, + public static Gen> arbF8(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf, + final Cogen cg, + final Cogen ch, final Gen a) { return arbF(ca, arbF(cb, arbF(cc, arbF(cd, arbF(ce, arbF(cf, arbF(cg, arbF(ch, a)))))))).map( Function.uncurryF8()); diff --git a/quickcheck/src/main/java/fj/test/Coarbitrary.java b/quickcheck/src/main/java/fj/test/Coarbitrary.java deleted file mode 100644 index 14c7acb4..00000000 --- a/quickcheck/src/main/java/fj/test/Coarbitrary.java +++ /dev/null @@ -1,1184 +0,0 @@ -package fj.test; - -import fj.*; - -import static fj.Function.curry; -import static fj.P.p; - -import fj.data.*; - -import static fj.data.Array.array; -import static fj.data.Array.iterableArray; -import static fj.data.List.fromString; -import static fj.data.List.nil; - -import static fj.test.Variant.variant; - -import static java.lang.Double.doubleToRawLongBits; -import static java.lang.Float.floatToRawIntBits; -import java.math.BigDecimal; -import java.math.BigInteger; -import java.sql.Time; -import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.BitSet; -import java.util.Calendar; -import java.util.Date; -import java.util.EnumMap; -import java.util.EnumSet; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.IdentityHashMap; -import java.util.LinkedHashMap; -import java.util.LinkedHashSet; -import java.util.LinkedList; -import java.util.Map; -import java.util.PriorityQueue; -import java.util.Properties; -import java.util.Stack; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.Vector; -import java.util.WeakHashMap; -import java.util.concurrent.ArrayBlockingQueue; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.concurrent.CopyOnWriteArraySet; -import java.util.concurrent.DelayQueue; -import java.util.concurrent.Delayed; -import java.util.concurrent.LinkedBlockingQueue; -import java.util.concurrent.PriorityBlockingQueue; -import java.util.concurrent.SynchronousQueue; - -/** - * Transforms a type and a generator to produce a new generator. This function is used to generate - * {@link Arbitrary arbitrary} functions. - * - * @version %build.number% - */ -public abstract class Coarbitrary { - /** - * Transforms the given value and generator to a new generator with a high probability of being - * independent. - * - * @param a The value to produce the generator from. - * @param g The generator to produce the new generator from. - * @return A new generator with a high probability of being independent. - */ - public abstract Gen coarbitrary(A a, Gen g); - - - /** - * A curried version of {@link #coarbitrary(Object, Gen)}. - * - * @param a The value to produce the generator from. - * @return A curried version of {@link #coarbitrary(Object, Gen)}. - */ - public final F, Gen> coarbitrary(final A a) { - return g -> coarbitrary(a, g); - } - - /** - * Composes the given function with this coarbitrary to produce a new coarbitrary. - * - * @param f The function to compose. - * @return A new coarbitrary composed with the given function. - */ - public final Coarbitrary compose(final F f) { - return new Coarbitrary() { - public Gen coarbitrary(final B b, final Gen g) { - return Coarbitrary.this.coarbitrary(f.f(b), g); - } - }; - } - - /** - * Contra-maps this coarbitrary using the given function. - * - * @param f The function to co-map with. - * @return A contra-mapped coarbitrary. - */ - public final Coarbitrary contramap(final F f) { - return new Coarbitrary() { - public Gen coarbitrary(final B b, final Gen g) { - return Coarbitrary.this.coarbitrary(f.f(b), g); - } - }; - } - - /** - * A coarbitrary for a function. - * - * @param a An arbitrary for the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function. - */ - public static Coarbitrary> coarbF(final Gen a, final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F f, final Gen g) { - return a.bind(a1 -> c.coarbitrary(f.f(a1), g)); - } - }; - } - - /** - * A coarbitrary for a function-2. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-2. - */ - public static Coarbitrary> coarbF2(final Gen aa, final Gen ab, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F2 f, final Gen g) { - return coarbF(aa, coarbF(ab, c)).coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-3. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-3. - */ - public static Coarbitrary> coarbF3(final Gen aa, final Gen ab, - final Gen ac, final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F3 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, c))).coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-4. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param ad An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-4. - */ - public static Coarbitrary> coarbF4(final Gen aa, final Gen ab, - final Gen ac, final Gen ad, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F4 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, c)))).coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-5. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param ad An arbitrary for part of the domain of the function. - * @param ae An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-5. - */ - public static Coarbitrary> coarbF5(final Gen aa, - final Gen ab, - final Gen ac, - final Gen ad, - final Gen ae, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F5 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, c))))).coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-6. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param ad An arbitrary for part of the domain of the function. - * @param ae An arbitrary for part of the domain of the function. - * @param af An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-6. - */ - public static Coarbitrary> coarbF6(final Gen aa, - final Gen ab, - final Gen ac, - final Gen ad, - final Gen ae, - final Gen af, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F6 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, c)))))).coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-7. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param ad An arbitrary for part of the domain of the function. - * @param ae An arbitrary for part of the domain of the function. - * @param af An arbitrary for part of the domain of the function. - * @param ag An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-7. - */ - public static Coarbitrary> coarbF7(final Gen aa, - final Gen ab, - final Gen ac, - final Gen ad, - final Gen ae, - final Gen af, - final Gen ag, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F7 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, c))))))) - .coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for a function-8. - * - * @param aa An arbitrary for part of the domain of the function. - * @param ab An arbitrary for part of the domain of the function. - * @param ac An arbitrary for part of the domain of the function. - * @param ad An arbitrary for part of the domain of the function. - * @param ae An arbitrary for part of the domain of the function. - * @param af An arbitrary for part of the domain of the function. - * @param ag An arbitrary for part of the domain of the function. - * @param ah An arbitrary for part of the domain of the function. - * @param c A coarbitrary for the codomain of the function. - * @return A coarbitrary for a function-8. - */ - public static Coarbitrary> coarbF8(final Gen aa, - final Gen ab, - final Gen ac, - final Gen ad, - final Gen ae, - final Gen af, - final Gen ag, - final Gen ah, - final Coarbitrary c) { - return new Coarbitrary>() { - public Gen coarbitrary(final F8 f, final Gen g) { - return coarbF(aa, coarbF(ab, coarbF(ac, coarbF(ad, coarbF(ae, coarbF(af, coarbF(ag, coarbF(ah, c)))))))) - .coarbitrary(curry(f), g); - } - }; - } - - /** - * A coarbitrary for booleans. - */ - public static final Coarbitrary coarbBoolean = new Coarbitrary() { - public Gen coarbitrary(final Boolean b, final Gen g) { - return variant(b ? 0 : 1, g); - } - }; - - /** - * A coarbitrary for integers. - */ - public static final Coarbitrary coarbInteger = new Coarbitrary() { - public Gen coarbitrary(final Integer i, final Gen g) { - return variant(i >= 0 ? 2 * i : -2 * i + 1, g); - } - }; - - /** - * A coarbitrary for bytes. - */ - public static final Coarbitrary coarbByte = new Coarbitrary() { - public Gen coarbitrary(final Byte b, final Gen g) { - return variant(b >= 0 ? 2 * b : -2 * b + 1, g); - } - }; - - /** - * A coarbitrary for shorts. - */ - public static final Coarbitrary coarbShort = new Coarbitrary() { - public Gen coarbitrary(final Short s, final Gen g) { - return variant(s >= 0 ? 2 * s : -2 * s + 1, g); - } - }; - - /** - * A coarbitrary for longs. - */ - public static final Coarbitrary coarbLong = new Coarbitrary() { - public Gen coarbitrary(final Long l, final Gen g) { - return variant(l >= 0L ? 2L * l : -2L * l + 1L, g); - } - }; - - /** - * A coarbitrary for characters. - */ - public static final Coarbitrary coarbCharacter = new Coarbitrary() { - public Gen coarbitrary(final Character c, final Gen g) { - return variant(c << 1, g); - } - }; - - /** - * A coarbitrary for floats. - */ - public static final Coarbitrary coarbFloat = new Coarbitrary() { - public Gen coarbitrary(final Float f, final Gen g) { - return coarbInteger.coarbitrary(floatToRawIntBits(f), g); - } - }; - - /** - * A coarbitrary for doubles. - */ - public static final Coarbitrary coarbDouble = new Coarbitrary() { - public Gen coarbitrary(final Double d, final Gen g) { - return coarbLong.coarbitrary(doubleToRawLongBits(d), g); - } - }; - - /** - * A coarbitrary for the optional value. - * - * @param ca A coarbitrary for the type of the optional value. - * @return A coarbitrary for the optional value. - */ - public static Coarbitrary> coarbOption(final Coarbitrary ca) { - return new Coarbitrary>() { - public Gen coarbitrary(final Option o, final Gen g) { - return o.isNone() ? variant(0, g) : variant(1, ca.coarbitrary(o.some(), g)); - } - }; - } - - /** - * A coarbitrary for the disjoint union. - * - * @param ca A coarbitrary for one side of the disjoint union. - * @param cb A coarbitrary for one side of the disjoint union. - * @return A coarbitrary for the disjoint union. - */ - public static Coarbitrary> coarbEither(final Coarbitrary ca, final Coarbitrary cb) { - return new Coarbitrary>() { - public Gen coarbitrary(final Either e, final Gen g) { - return e.isLeft() ? - variant(0, ca.coarbitrary(e.left().value(), g)) : - variant(1, cb.coarbitrary(e.right().value(), g)); - } - }; - } - - /** - * A coarbitrary for lists. - * - * @param ca A coarbitrary for the elements of the list. - * @return A coarbitrary for lists. - */ - public static Coarbitrary> coarbList(final Coarbitrary ca) { - return new Coarbitrary>() { - public Gen coarbitrary(final List as, final Gen g) { - return as.isEmpty() ? - variant(0, g) : - variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail(), g))); - } - }; - } - - /** - * A coarbitrary for strings. - */ - public static final Coarbitrary coarbString = new Coarbitrary() { - public Gen coarbitrary(final String s, final Gen g) { - return coarbList(coarbCharacter).coarbitrary(fromString(s), g); - } - }; - - /** - * A coarbitrary for string buffers. - */ - public static final Coarbitrary coarbStringBuffer = new Coarbitrary() { - public Gen coarbitrary(final StringBuffer s, final Gen g) { - return coarbString.coarbitrary(s.toString(), g); - } - }; - - /** - * A coarbitrary for string builders. - */ - public static final Coarbitrary coarbStringBuilder = new Coarbitrary() { - public Gen coarbitrary(final StringBuilder s, final Gen g) { - return coarbString.coarbitrary(s.toString(), g); - } - }; - - /** - * A coarbitrary for streams. - * - * @param ca A coarbitrary for the elements of the stream. - * @return A coarbitrary for streams. - */ - public static Coarbitrary> coarbStream(final Coarbitrary ca) { - return new Coarbitrary>() { - public Gen coarbitrary(final Stream as, final Gen g) { - return as.isEmpty() ? - variant(0, g) : - variant(1, ca.coarbitrary(as.head(), coarbitrary(as.tail()._1(), g))); - } - }; - } - - /** - * A coarbitrary for the provided LcgRng - * @return A coarbitrary for the provided LcgRng. - */ - public static Coarbitrary coarbLcgRng() { - return new Coarbitrary() { - @Override - public Gen coarbitrary(LcgRng rng, Gen g) { - long i = rng.getSeed(); - return variant(i >= 0 ? 2 * i : -2 * i + 1, g); - } - }; - } - - /** - * A coarbitrary for state. - */ - public static Coarbitrary> coarbState(Gen as, F2 f) { - return new Coarbitrary>() { - @Override - public Gen coarbitrary(State s1, Gen g) { - return as.bind(r -> { - P2 p = s1.run(r); - return variant(f.f(p._1(), p._2()), g); - }); - } - }; - } - - /** - * A coarbitrary for arrays. - * - * @param ca A coarbitrary for the elements of the array. - * @return A coarbitrary for arrays. - */ - public static Coarbitrary> coarbArray(final Coarbitrary ca) { - return new Coarbitrary>() { - public Gen coarbitrary(final Array as, final Gen g) { - return coarbList(ca).coarbitrary(as.toList(), g); - } - }; - } - - /** - * A coarbitrary for throwables. - * - * @param cs A coarbitrary for the throwable message. - * @return A coarbitrary for throwables. - */ - public static Coarbitrary coarbThrowable(final Coarbitrary cs) { - return cs.contramap(new F() { - public String f(final Throwable t) { - return t.getMessage(); - } - }); - } - - /** - * A coarbitrary for throwables. - */ - public static final Coarbitrary coarbThrowable = - coarbThrowable(coarbString); - - // BEGIN java.util - - /** - * A coarbitrary for array lists. - * - * @param ca A coarbitrary for the elements of the array list. - * @return A coarbitrary for array lists. - */ - public static Coarbitrary> coarbArrayList(final Coarbitrary ca) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final ArrayList as, final Gen g) { - return coarbArray(ca).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for bit sets. - */ - public static final Coarbitrary coarbBitSet = new Coarbitrary() { - public Gen coarbitrary(final BitSet s, final Gen g) { - List x = nil(); - - for (int i = 0; i < s.size(); i++) { - x = x.snoc(s.get(i)); - } - - return coarbList(coarbBoolean).coarbitrary(x, g); - } - }; - - /** - * A coarbitrary for calendars. - */ - public static final Coarbitrary coarbCalendar = new Coarbitrary() { - public Gen coarbitrary(final Calendar c, final Gen g) { - return coarbLong.coarbitrary(c.getTime().getTime(), g); - } - }; - - /** - * A coarbitrary for dates. - */ - public static final Coarbitrary coarbDate = new Coarbitrary() { - public Gen coarbitrary(final Date d, final Gen g) { - return coarbLong.coarbitrary(d.getTime(), g); - } - }; - - /** - * A coarbitrary for enum maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for enum maps. - */ - public static , V> Coarbitrary> coarbEnumMap(final Coarbitrary ck, - final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final EnumMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for enum sets. - * - * @param c A coarbitrary for the elements of the enum set. - * @return A coarbitrary for enum sets. - */ - public static > Coarbitrary> coarbEnumSet(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final EnumSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); - } - }; - } - - /** - * A coarbitrary for gregorian calendars. - */ - public static final Coarbitrary coarbGregorianCalendar = new Coarbitrary() { - public Gen coarbitrary(final GregorianCalendar c, final Gen g) { - return coarbLong.coarbitrary(c.getTime().getTime(), g); - } - }; - - /** - * A coarbitrary for hash maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for hash maps. - */ - public static Coarbitrary> coarbHashMap(final Coarbitrary ck, final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final HashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for hash sets. - * - * @param c A coarbitrary for the elements of the hash set. - * @return A coarbitrary for hash sets. - */ - public static Coarbitrary> coarbHashSet(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final HashSet as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for hash tables. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for hash tables. - */ - public static Coarbitrary> coarbHashtable(final Coarbitrary ck, final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final Hashtable h, final Gen g) { - List> x = nil(); - - for (final Map.Entry entry : h.entrySet()) { - x = x.snoc(p(entry.getKey(), entry.getValue())); - } - - return coarbList(coarbP2(ck, cv)).coarbitrary(x, g); - } - }; - } - - /** - * A coarbitrary for identity hash maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for identity hash maps. - */ - public static Coarbitrary> coarbIdentityHashMap(final Coarbitrary ck, - final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final IdentityHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for linked hash maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for linked hash maps. - */ - public static Coarbitrary> coarbLinkedHashMap(final Coarbitrary ck, - final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final LinkedHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for linked hash sets. - * - * @param c A coarbitrary for the elements of the linked hash set. - * @return A coarbitrary for linked hash sets. - */ - public static Coarbitrary> coarbLinkedHashSet(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final LinkedHashSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); - } - }; - } - - /** - * A coarbitrary for linked lists. - * - * @param c A coarbitrary for the elements of the linked list. - * @return A coarbitrary for linked lists. - */ - public static Coarbitrary> coarbLinkedList(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final LinkedList as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for priority queues. - * - * @param c A coarbitrary for the elements of the priority queue. - * @return A coarbitrary for priority queues. - */ - public static Coarbitrary> coarbPriorityQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final PriorityQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for properties. - */ - public static final Coarbitrary coarbProperties = new Coarbitrary() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final Properties p, final Gen g) { - final Hashtable t = new Hashtable<>(); - - for (final Object s : p.keySet()) { - t.put((String) s, p.getProperty((String) s)); - } - - return coarbHashtable(coarbString, coarbString).coarbitrary(t, g); - } - }; - - /** - * A coarbitrary for stacks. - * - * @param c A coarbitrary for the elements of the stack. - * @return A coarbitrary for stacks. - */ - public static Coarbitrary> coarbStack(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final Stack as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for tree maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for tree maps. - */ - public static Coarbitrary> coarbTreeMap(final Coarbitrary ck, final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final TreeMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for tree sets. - * - * @param c A coarbitrary for the elements of the tree set. - * @return A coarbitrary for tree sets. - */ - public static Coarbitrary> coarbTreeSet(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final TreeSet as, final Gen g) { - return coarbHashSet(c).coarbitrary(new HashSet<>(as), g); - } - }; - } - - /** - * A coarbitrary for vectors. - * - * @param c A coarbitrary for the elements of the vector. - * @return A coarbitrary for vectors. - */ - public static Coarbitrary> coarbVector(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"}) - public Gen coarbitrary(final Vector as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for weak hash maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for weak hash maps. - */ - public static Coarbitrary> coarbWeakHashMap(final Coarbitrary ck, - final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final WeakHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - // END java.util - - // BEGIN java.util.concurrent - - /** - * A coarbitrary for array blocking queues. - * - * @param c A coarbitrary for the elements of the array blocking queue. - * @return A coarbitrary for array blocking queues. - */ - public static Coarbitrary> coarbArrayBlockingQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final ArrayBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for concurrent hash maps. - * - * @param ck A coarbitrary for the map keys. - * @param cv A coarbitrary for the map values. - * @return A coarbitrary for concurrent hash maps. - */ - public static Coarbitrary> coarbConcurrentHashMap(final Coarbitrary ck, - final Coarbitrary cv) { - return new Coarbitrary>() { - @SuppressWarnings("UseOfObsoleteCollectionType") - public Gen coarbitrary(final ConcurrentHashMap m, final Gen g) { - return coarbHashtable(ck, cv).coarbitrary(new Hashtable<>(m), g); - } - }; - } - - /** - * A coarbitrary for concurrent linked queues. - * - * @param c A coarbitrary for the elements of the concurrent linked queue. - * @return A coarbitrary for concurrent linked queues. - */ - public static Coarbitrary> coarbConcurrentLinkedQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final ConcurrentLinkedQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for copy-on-write array lists. - * - * @param c A coarbitrary for the elements of the copy-on-write array list. - * @return A coarbitrary for copy-on-write array lists. - */ - public static Coarbitrary> coarbCopyOnWriteArrayList(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final CopyOnWriteArrayList as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for copy-on-write array sets. - * - * @param c A coarbitrary for the elements of the copy-on-write array set. - * @return A coarbitrary for copy-on-write array sets. - */ - public static Coarbitrary> coarbCopyOnWriteArraySet(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final CopyOnWriteArraySet as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for delay queues. - * - * @param c A coarbitrary for the elements of the delay queue. - * @return A coarbitrary for delay queues. - */ - public static Coarbitrary> coarbDelayQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final DelayQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for linked blocking queues. - * - * @param c A coarbitrary for the elements of the linked blocking queue. - * @return A coarbitrary for linked blocking queues. - */ - public static Coarbitrary> coarbLinkedBlockingQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final LinkedBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for priority blocking queues. - * - * @param c A coarbitrary for the elements of the priority blocking queue. - * @return A coarbitrary for priority blocking queues. - */ - public static Coarbitrary> coarbPriorityBlockingQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final PriorityBlockingQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - /** - * A coarbitrary for synchronous queues. - * - * @param c A coarbitrary for the elements of the synchronous queue. - * @return A coarbitrary for synchronous queues. - */ - public static Coarbitrary> coarbSynchronousQueue(final Coarbitrary c) { - return new Coarbitrary>() { - @SuppressWarnings("unchecked") - public Gen coarbitrary(final SynchronousQueue as, final Gen g) { - return coarbArray(c).coarbitrary(iterableArray(as), g); - } - }; - } - - // END java.util.concurrent - - // BEGIN java.sql - - public static final Coarbitrary coarbSQLDate = new Coarbitrary() { - public Gen coarbitrary(final java.sql.Date d, final Gen g) { - return coarbLong.coarbitrary(d.getTime(), g); - } - }; - - public static final Coarbitrary coarbTimestamp = new Coarbitrary() { - public Gen coarbitrary(final Timestamp t, final Gen g) { - return coarbLong.coarbitrary(t.getTime(), g); - } - }; - - public static final Coarbitrary Coarbitrary> coarbP1(final Coarbitrary ca) { - return new Coarbitrary>() { - public Gen coarbitrary(final P1 p, final Gen g) { - return ca.coarbitrary(p._1(), g); - } - }; - } - - /** - * A coarbitrary for product-2 values. - * - * @param ca A coarbitrary for one of the types over which the product-2 is defined. - * @param cb A coarbitrary for one of the types over which the product-2 is defined. - * @return A coarbitrary for product-2 values. - */ - public static Coarbitrary> coarbP2(final Coarbitrary ca, final Coarbitrary cb) { - return new Coarbitrary>() { - public Gen coarbitrary(final P2 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), g)); - } - }; - } - - /** - * A coarbitrary for product-3 values. - * - * @param ca A coarbitrary for one of the types over which the product-3 is defined. - * @param cb A coarbitrary for one of the types over which the product-3 is defined. - * @param cc A coarbitrary for one of the types over which the product-3 is defined. - * @return A coarbitrary for product-3 values. - */ - public static Coarbitrary> coarbP3(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc) { - return new Coarbitrary>() { - public Gen coarbitrary(final P3 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), g))); - } - }; - } - - /** - * A coarbitrary for product-4 values. - * - * @param ca A coarbitrary for one of the types over which the product-4 is defined. - * @param cb A coarbitrary for one of the types over which the product-4 is defined. - * @param cc A coarbitrary for one of the types over which the product-4 is defined. - * @param cd A coarbitrary for one of the types over which the product-4 is defined. - * @return A coarbitrary for product-4 values. - */ - public static Coarbitrary> coarbP4(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Coarbitrary cd) { - return new Coarbitrary>() { - public Gen coarbitrary(final P4 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), g)))); - } - }; - } - - /** - * A coarbitrary for product-5 values. - * - * @param ca A coarbitrary for one of the types over which the product-5 is defined. - * @param cb A coarbitrary for one of the types over which the product-5 is defined. - * @param cc A coarbitrary for one of the types over which the product-5 is defined. - * @param cd A coarbitrary for one of the types over which the product-5 is defined. - * @param ce A coarbitrary for one of the types over which the product-5 is defined. - * @return A coarbitrary for product-5 values. - */ - public static Coarbitrary> coarbP5(final Coarbitrary ca, final Coarbitrary cb, - final Coarbitrary cc, final Coarbitrary cd, - final Coarbitrary ce) { - return new Coarbitrary>() { - public Gen coarbitrary(final P5 p, final Gen g) { - return ca.coarbitrary(p._1(), - cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), g))))); - } - }; - } - - /** - * A coarbitrary for product-6 values. - * - * @param ca A coarbitrary for one of the types over which the product-6 is defined. - * @param cb A coarbitrary for one of the types over which the product-6 is defined. - * @param cc A coarbitrary for one of the types over which the product-6 is defined. - * @param cd A coarbitrary for one of the types over which the product-6 is defined. - * @param ce A coarbitrary for one of the types over which the product-6 is defined. - * @param cf A coarbitrary for one of the types over which the product-6 is defined. - * @return A coarbitrary for product-6 values. - */ - public static Coarbitrary> coarbP6(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf) { - return new Coarbitrary>() { - public Gen coarbitrary(final P6 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), - cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), g)))))); - } - }; - } - - /** - * A coarbitrary for product-7 values. - * - * @param ca A coarbitrary for one of the types over which the product-7 is defined. - * @param cb A coarbitrary for one of the types over which the product-7 is defined. - * @param cc A coarbitrary for one of the types over which the product-7 is defined. - * @param cd A coarbitrary for one of the types over which the product-7 is defined. - * @param ce A coarbitrary for one of the types over which the product-7 is defined. - * @param cf A coarbitrary for one of the types over which the product-7 is defined. - * @param cg A coarbitrary for one of the types over which the product-7 is defined. - * @return A coarbitrary for product-7 values. - */ - public static Coarbitrary> coarbP7(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg) { - return new Coarbitrary>() { - public Gen coarbitrary(final P7 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), - cd.coarbitrary(p._4(), ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), g))))))); - } - }; - } - - /** - * A coarbitrary for product-8 values. - * - * @param ca A coarbitrary for one of the types over which the product-8 is defined. - * @param cb A coarbitrary for one of the types over which the product-8 is defined. - * @param cc A coarbitrary for one of the types over which the product-8 is defined. - * @param cd A coarbitrary for one of the types over which the product-8 is defined. - * @param ce A coarbitrary for one of the types over which the product-8 is defined. - * @param cf A coarbitrary for one of the types over which the product-8 is defined. - * @param cg A coarbitrary for one of the types over which the product-8 is defined. - * @param ch A coarbitrary for one of the types over which the product-8 is defined. - * @return A coarbitrary for product-8 values. - */ - public static Coarbitrary> coarbP8(final Coarbitrary ca, - final Coarbitrary cb, - final Coarbitrary cc, - final Coarbitrary cd, - final Coarbitrary ce, - final Coarbitrary cf, - final Coarbitrary cg, - final Coarbitrary ch) { - return new Coarbitrary>() { - public Gen coarbitrary(final P8 p, final Gen g) { - return ca.coarbitrary(p._1(), cb.coarbitrary(p._2(), cc.coarbitrary(p._3(), cd.coarbitrary(p._4(), - ce.coarbitrary(p._5(), cf.coarbitrary(p._6(), cg.coarbitrary(p._7(), ch.coarbitrary(p._8(), g)))))))); - } - }; - } -} diff --git a/quickcheck/src/main/java/fj/test/Cogen.java b/quickcheck/src/main/java/fj/test/Cogen.java new file mode 100644 index 00000000..c4c3b0a0 --- /dev/null +++ b/quickcheck/src/main/java/fj/test/Cogen.java @@ -0,0 +1,1184 @@ +package fj.test; + +import fj.*; + +import static fj.Function.curry; +import static fj.P.p; + +import fj.data.*; + +import static fj.data.Array.array; +import static fj.data.Array.iterableArray; +import static fj.data.List.fromString; +import static fj.data.List.nil; + +import static fj.test.Variant.variant; + +import static java.lang.Double.doubleToRawLongBits; +import static java.lang.Float.floatToRawIntBits; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.Calendar; +import java.util.Date; +import java.util.EnumMap; +import java.util.EnumSet; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Hashtable; +import java.util.IdentityHashMap; +import java.util.LinkedHashMap; +import java.util.LinkedHashSet; +import java.util.LinkedList; +import java.util.Map; +import java.util.PriorityQueue; +import java.util.Properties; +import java.util.Stack; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.Vector; +import java.util.WeakHashMap; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.concurrent.CopyOnWriteArraySet; +import java.util.concurrent.DelayQueue; +import java.util.concurrent.Delayed; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.PriorityBlockingQueue; +import java.util.concurrent.SynchronousQueue; + +/** + * Transforms a type and a generator to produce a new generator. This function is used to generate + * {@link Gen gen} functions. + * + * @version %build.number% + */ +public abstract class Cogen { + /** + * Transforms the given value and generator to a new generator with a high probability of being + * independent. + * + * @param a The value to produce the generator from. + * @param g The generator to produce the new generator from. + * @return A new generator with a high probability of being independent. + */ + public abstract Gen cogen(A a, Gen g); + + + /** + * A curried version of {@link #cogen(Object, Gen)}. + * + * @param a The value to produce the generator from. + * @return A curried version of {@link #cogen(Object, Gen)}. + */ + public final F, Gen> cogen(final A a) { + return g -> cogen(a, g); + } + + /** + * Composes the given function with this cogen to produce a new cogen. + * + * @param f The function to compose. + * @return A new cogen composed with the given function. + */ + public final Cogen compose(final F f) { + return new Cogen() { + public Gen cogen(final B b, final Gen g) { + return Cogen.this.cogen(f.f(b), g); + } + }; + } + + /** + * Contra-maps this cogen using the given function. + * + * @param f The function to co-map with. + * @return A contra-mapped cogen. + */ + public final Cogen contramap(final F f) { + return new Cogen() { + public Gen cogen(final B b, final Gen g) { + return Cogen.this.cogen(f.f(b), g); + } + }; + } + + /** + * A cogen for a function. + * + * @param a A gen for the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function. + */ + public static Cogen> cogenF(final Gen a, final Cogen c) { + return new Cogen>() { + public Gen cogen(final F f, final Gen g) { + return a.bind(a1 -> c.cogen(f.f(a1), g)); + } + }; + } + + /** + * A cogen for a function-2. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-2. + */ + public static Cogen> cogenF2(final Gen aa, final Gen ab, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F2 f, final Gen g) { + return cogenF(aa, cogenF(ab, c)).cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-3. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-3. + */ + public static Cogen> cogenF3(final Gen aa, final Gen ab, + final Gen ac, final Cogen c) { + return new Cogen>() { + public Gen cogen(final F3 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, c))).cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-4. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param ad A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-4. + */ + public static Cogen> cogenF4(final Gen aa, final Gen ab, + final Gen ac, final Gen ad, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F4 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, cogenF(ad, c)))).cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-5. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param ad A gen for part of the domain of the function. + * @param ae A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-5. + */ + public static Cogen> cogenF5(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F5 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, cogenF(ad, cogenF(ae, c))))).cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-6. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param ad A gen for part of the domain of the function. + * @param ae A gen for part of the domain of the function. + * @param af A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-6. + */ + public static Cogen> cogenF6(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F6 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, cogenF(ad, cogenF(ae, cogenF(af, c)))))).cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-7. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param ad A gen for part of the domain of the function. + * @param ae A gen for part of the domain of the function. + * @param af A gen for part of the domain of the function. + * @param ag A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-7. + */ + public static Cogen> cogenF7(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F7 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, cogenF(ad, cogenF(ae, cogenF(af, cogenF(ag, c))))))) + .cogen(curry(f), g); + } + }; + } + + /** + * A cogen for a function-8. + * + * @param aa A gen for part of the domain of the function. + * @param ab A gen for part of the domain of the function. + * @param ac A gen for part of the domain of the function. + * @param ad A gen for part of the domain of the function. + * @param ae A gen for part of the domain of the function. + * @param af A gen for part of the domain of the function. + * @param ag A gen for part of the domain of the function. + * @param ah A gen for part of the domain of the function. + * @param c A cogen for the codomain of the function. + * @return A cogen for a function-8. + */ + public static Cogen> cogenF8(final Gen aa, + final Gen ab, + final Gen ac, + final Gen ad, + final Gen ae, + final Gen af, + final Gen ag, + final Gen ah, + final Cogen c) { + return new Cogen>() { + public Gen cogen(final F8 f, final Gen g) { + return cogenF(aa, cogenF(ab, cogenF(ac, cogenF(ad, cogenF(ae, cogenF(af, cogenF(ag, cogenF(ah, c)))))))) + .cogen(curry(f), g); + } + }; + } + + /** + * A cogen for booleans. + */ + public static final Cogen cogenBoolean = new Cogen() { + public Gen cogen(final Boolean b, final Gen g) { + return variant(b ? 0 : 1, g); + } + }; + + /** + * A cogen for integers. + */ + public static final Cogen cogenInteger = new Cogen() { + public Gen cogen(final Integer i, final Gen g) { + return variant(i >= 0 ? 2 * i : -2 * i + 1, g); + } + }; + + /** + * A cogen for bytes. + */ + public static final Cogen cogenByte = new Cogen() { + public Gen cogen(final Byte b, final Gen g) { + return variant(b >= 0 ? 2 * b : -2 * b + 1, g); + } + }; + + /** + * A cogen for shorts. + */ + public static final Cogen cogenShort = new Cogen() { + public Gen cogen(final Short s, final Gen g) { + return variant(s >= 0 ? 2 * s : -2 * s + 1, g); + } + }; + + /** + * A cogen for longs. + */ + public static final Cogen cogenLong = new Cogen() { + public Gen cogen(final Long l, final Gen g) { + return variant(l >= 0L ? 2L * l : -2L * l + 1L, g); + } + }; + + /** + * A cogen for characters. + */ + public static final Cogen cogenCharacter = new Cogen() { + public Gen cogen(final Character c, final Gen g) { + return variant(c << 1, g); + } + }; + + /** + * A cogen for floats. + */ + public static final Cogen cogenFloat = new Cogen() { + public Gen cogen(final Float f, final Gen g) { + return cogenInteger.cogen(floatToRawIntBits(f), g); + } + }; + + /** + * A cogen for doubles. + */ + public static final Cogen cogenDouble = new Cogen() { + public Gen cogen(final Double d, final Gen g) { + return cogenLong.cogen(doubleToRawLongBits(d), g); + } + }; + + /** + * A cogen for the optional value. + * + * @param ca A cogen for the type of the optional value. + * @return A cogen for the optional value. + */ + public static Cogen> cogenOption(final Cogen ca) { + return new Cogen>() { + public Gen cogen(final Option o, final Gen g) { + return o.isNone() ? variant(0, g) : variant(1, ca.cogen(o.some(), g)); + } + }; + } + + /** + * A cogen for the disjoint union. + * + * @param ca A cogen for one side of the disjoint union. + * @param cb A cogen for one side of the disjoint union. + * @return A cogen for the disjoint union. + */ + public static Cogen> cogenEither(final Cogen ca, final Cogen cb) { + return new Cogen>() { + public Gen cogen(final Either e, final Gen g) { + return e.isLeft() ? + variant(0, ca.cogen(e.left().value(), g)) : + variant(1, cb.cogen(e.right().value(), g)); + } + }; + } + + /** + * A cogen for lists. + * + * @param ca A cogen for the elements of the list. + * @return A cogen for lists. + */ + public static Cogen> cogenList(final Cogen ca) { + return new Cogen>() { + public Gen cogen(final List as, final Gen g) { + return as.isEmpty() ? + variant(0, g) : + variant(1, ca.cogen(as.head(), cogen(as.tail(), g))); + } + }; + } + + /** + * A cogen for strings. + */ + public static final Cogen cogenString = new Cogen() { + public Gen cogen(final String s, final Gen g) { + return cogenList(cogenCharacter).cogen(fromString(s), g); + } + }; + + /** + * A cogen for string buffers. + */ + public static final Cogen cogenStringBuffer = new Cogen() { + public Gen cogen(final StringBuffer s, final Gen g) { + return cogenString.cogen(s.toString(), g); + } + }; + + /** + * A cogen for string builders. + */ + public static final Cogen cogenStringBuilder = new Cogen() { + public Gen cogen(final StringBuilder s, final Gen g) { + return cogenString.cogen(s.toString(), g); + } + }; + + /** + * A cogen for streams. + * + * @param ca A cogen for the elements of the stream. + * @return A cogen for streams. + */ + public static Cogen> cogenStream(final Cogen ca) { + return new Cogen>() { + public Gen cogen(final Stream as, final Gen g) { + return as.isEmpty() ? + variant(0, g) : + variant(1, ca.cogen(as.head(), cogen(as.tail()._1(), g))); + } + }; + } + + /** + * A cogen for the provided LcgRng + * @return A cogen for the provided LcgRng. + */ + public static Cogen cogenLcgRng() { + return new Cogen() { + @Override + public Gen cogen(LcgRng rng, Gen g) { + long i = rng.getSeed(); + return variant(i >= 0 ? 2 * i : -2 * i + 1, g); + } + }; + } + + /** + * A cogen for state. + */ + public static Cogen> cogenState(Gen as, F2 f) { + return new Cogen>() { + @Override + public Gen cogen(State s1, Gen g) { + return as.bind(r -> { + P2 p = s1.run(r); + return variant(f.f(p._1(), p._2()), g); + }); + } + }; + } + + /** + * A cogen for arrays. + * + * @param ca A cogen for the elements of the array. + * @return A cogen for arrays. + */ + public static Cogen> cogenArray(final Cogen ca) { + return new Cogen>() { + public Gen cogen(final Array as, final Gen g) { + return cogenList(ca).cogen(as.toList(), g); + } + }; + } + + /** + * A cogen for throwables. + * + * @param cs A cogen for the throwable message. + * @return A cogen for throwables. + */ + public static Cogen cogenThrowable(final Cogen cs) { + return cs.contramap(new F() { + public String f(final Throwable t) { + return t.getMessage(); + } + }); + } + + /** + * A cogen for throwables. + */ + public static final Cogen cogenThrowable = + cogenThrowable(cogenString); + + // BEGIN java.util + + /** + * A cogen for array lists. + * + * @param ca A cogen for the elements of the array list. + * @return A cogen for array lists. + */ + public static Cogen> cogenArrayList(final Cogen ca) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final ArrayList as, final Gen g) { + return cogenArray(ca).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for bit sets. + */ + public static final Cogen cogenBitSet = new Cogen() { + public Gen cogen(final BitSet s, final Gen g) { + List x = nil(); + + for (int i = 0; i < s.size(); i++) { + x = x.snoc(s.get(i)); + } + + return cogenList(cogenBoolean).cogen(x, g); + } + }; + + /** + * A cogen for calendars. + */ + public static final Cogen cogenCalendar = new Cogen() { + public Gen cogen(final Calendar c, final Gen g) { + return cogenLong.cogen(c.getTime().getTime(), g); + } + }; + + /** + * A cogen for dates. + */ + public static final Cogen cogenDate = new Cogen() { + public Gen cogen(final Date d, final Gen g) { + return cogenLong.cogen(d.getTime(), g); + } + }; + + /** + * A cogen for enum maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for enum maps. + */ + public static , V> Cogen> cogenEnumMap(final Cogen ck, + final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final EnumMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for enum sets. + * + * @param c A cogen for the elements of the enum set. + * @return A cogen for enum sets. + */ + public static > Cogen> cogenEnumSet(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final EnumSet as, final Gen g) { + return cogenHashSet(c).cogen(new HashSet<>(as), g); + } + }; + } + + /** + * A cogen for gregorian calendars. + */ + public static final Cogen cogenGregorianCalendar = new Cogen() { + public Gen cogen(final GregorianCalendar c, final Gen g) { + return cogenLong.cogen(c.getTime().getTime(), g); + } + }; + + /** + * A cogen for hash maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for hash maps. + */ + public static Cogen> cogenHashMap(final Cogen ck, final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final HashMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for hash sets. + * + * @param c A cogen for the elements of the hash set. + * @return A cogen for hash sets. + */ + public static Cogen> cogenHashSet(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final HashSet as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for hash tables. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for hash tables. + */ + public static Cogen> cogenHashtable(final Cogen ck, final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final Hashtable h, final Gen g) { + List> x = nil(); + + for (final Map.Entry entry : h.entrySet()) { + x = x.snoc(p(entry.getKey(), entry.getValue())); + } + + return cogenList(cogenP2(ck, cv)).cogen(x, g); + } + }; + } + + /** + * A cogen for identity hash maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for identity hash maps. + */ + public static Cogen> cogenIdentityHashMap(final Cogen ck, + final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final IdentityHashMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for linked hash maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for linked hash maps. + */ + public static Cogen> cogenLinkedHashMap(final Cogen ck, + final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final LinkedHashMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for linked hash sets. + * + * @param c A cogen for the elements of the linked hash set. + * @return A cogen for linked hash sets. + */ + public static Cogen> cogenLinkedHashSet(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final LinkedHashSet as, final Gen g) { + return cogenHashSet(c).cogen(new HashSet<>(as), g); + } + }; + } + + /** + * A cogen for linked lists. + * + * @param c A cogen for the elements of the linked list. + * @return A cogen for linked lists. + */ + public static Cogen> cogenLinkedList(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final LinkedList as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for priority queues. + * + * @param c A cogen for the elements of the priority queue. + * @return A cogen for priority queues. + */ + public static Cogen> cogenPriorityQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final PriorityQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for properties. + */ + public static final Cogen cogenProperties = new Cogen() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final Properties p, final Gen g) { + final Hashtable t = new Hashtable<>(); + + for (final Object s : p.keySet()) { + t.put((String) s, p.getProperty((String) s)); + } + + return cogenHashtable(cogenString, cogenString).cogen(t, g); + } + }; + + /** + * A cogen for stacks. + * + * @param c A cogen for the elements of the stack. + * @return A cogen for stacks. + */ + public static Cogen> cogenStack(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final Stack as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for tree maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for tree maps. + */ + public static Cogen> cogenTreeMap(final Cogen ck, final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final TreeMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for tree sets. + * + * @param c A cogen for the elements of the tree set. + * @return A cogen for tree sets. + */ + public static Cogen> cogenTreeSet(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final TreeSet as, final Gen g) { + return cogenHashSet(c).cogen(new HashSet<>(as), g); + } + }; + } + + /** + * A cogen for vectors. + * + * @param c A cogen for the elements of the vector. + * @return A cogen for vectors. + */ + public static Cogen> cogenVector(final Cogen c) { + return new Cogen>() { + @SuppressWarnings({"unchecked", "UseOfObsoleteCollectionType"}) + public Gen cogen(final Vector as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for weak hash maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for weak hash maps. + */ + public static Cogen> cogenWeakHashMap(final Cogen ck, + final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final WeakHashMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + // END java.util + + // BEGIN java.util.concurrent + + /** + * A cogen for array blocking queues. + * + * @param c A cogen for the elements of the array blocking queue. + * @return A cogen for array blocking queues. + */ + public static Cogen> cogenArrayBlockingQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final ArrayBlockingQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for concurrent hash maps. + * + * @param ck A cogen for the map keys. + * @param cv A cogen for the map values. + * @return A cogen for concurrent hash maps. + */ + public static Cogen> cogenConcurrentHashMap(final Cogen ck, + final Cogen cv) { + return new Cogen>() { + @SuppressWarnings("UseOfObsoleteCollectionType") + public Gen cogen(final ConcurrentHashMap m, final Gen g) { + return cogenHashtable(ck, cv).cogen(new Hashtable<>(m), g); + } + }; + } + + /** + * A cogen for concurrent linked queues. + * + * @param c A cogen for the elements of the concurrent linked queue. + * @return A cogen for concurrent linked queues. + */ + public static Cogen> cogenConcurrentLinkedQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final ConcurrentLinkedQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for copy-on-write array lists. + * + * @param c A cogen for the elements of the copy-on-write array list. + * @return A cogen for copy-on-write array lists. + */ + public static Cogen> cogenCopyOnWriteArrayList(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final CopyOnWriteArrayList as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for copy-on-write array sets. + * + * @param c A cogen for the elements of the copy-on-write array set. + * @return A cogen for copy-on-write array sets. + */ + public static Cogen> cogenCopyOnWriteArraySet(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final CopyOnWriteArraySet as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for delay queues. + * + * @param c A cogen for the elements of the delay queue. + * @return A cogen for delay queues. + */ + public static Cogen> cogenDelayQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final DelayQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for linked blocking queues. + * + * @param c A cogen for the elements of the linked blocking queue. + * @return A cogen for linked blocking queues. + */ + public static Cogen> cogenLinkedBlockingQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final LinkedBlockingQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for priority blocking queues. + * + * @param c A cogen for the elements of the priority blocking queue. + * @return A cogen for priority blocking queues. + */ + public static Cogen> cogenPriorityBlockingQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final PriorityBlockingQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + /** + * A cogen for synchronous queues. + * + * @param c A cogen for the elements of the synchronous queue. + * @return A cogen for synchronous queues. + */ + public static Cogen> cogenSynchronousQueue(final Cogen c) { + return new Cogen>() { + @SuppressWarnings("unchecked") + public Gen cogen(final SynchronousQueue as, final Gen g) { + return cogenArray(c).cogen(iterableArray(as), g); + } + }; + } + + // END java.util.concurrent + + // BEGIN java.sql + + public static final Cogen cogenSQLDate = new Cogen() { + public Gen cogen(final java.sql.Date d, final Gen g) { + return cogenLong.cogen(d.getTime(), g); + } + }; + + public static final Cogen cogenTimestamp = new Cogen() { + public Gen cogen(final Timestamp t, final Gen g) { + return cogenLong.cogen(t.getTime(), g); + } + }; + + public static final Cogen Cogen> cogenP1(final Cogen ca) { + return new Cogen>() { + public Gen cogen(final P1 p, final Gen g) { + return ca.cogen(p._1(), g); + } + }; + } + + /** + * A cogen for product-2 values. + * + * @param ca A cogen for one of the types over which the product-2 is defined. + * @param cb A cogen for one of the types over which the product-2 is defined. + * @return A cogen for product-2 values. + */ + public static Cogen> cogenP2(final Cogen ca, final Cogen cb) { + return new Cogen>() { + public Gen cogen(final P2 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), g)); + } + }; + } + + /** + * A cogen for product-3 values. + * + * @param ca A cogen for one of the types over which the product-3 is defined. + * @param cb A cogen for one of the types over which the product-3 is defined. + * @param cc A cogen for one of the types over which the product-3 is defined. + * @return A cogen for product-3 values. + */ + public static Cogen> cogenP3(final Cogen ca, final Cogen cb, + final Cogen cc) { + return new Cogen>() { + public Gen cogen(final P3 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), cc.cogen(p._3(), g))); + } + }; + } + + /** + * A cogen for product-4 values. + * + * @param ca A cogen for one of the types over which the product-4 is defined. + * @param cb A cogen for one of the types over which the product-4 is defined. + * @param cc A cogen for one of the types over which the product-4 is defined. + * @param cd A cogen for one of the types over which the product-4 is defined. + * @return A cogen for product-4 values. + */ + public static Cogen> cogenP4(final Cogen ca, final Cogen cb, + final Cogen cc, final Cogen cd) { + return new Cogen>() { + public Gen cogen(final P4 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), cc.cogen(p._3(), cd.cogen(p._4(), g)))); + } + }; + } + + /** + * A cogen for product-5 values. + * + * @param ca A cogen for one of the types over which the product-5 is defined. + * @param cb A cogen for one of the types over which the product-5 is defined. + * @param cc A cogen for one of the types over which the product-5 is defined. + * @param cd A cogen for one of the types over which the product-5 is defined. + * @param ce A cogen for one of the types over which the product-5 is defined. + * @return A cogen for product-5 values. + */ + public static Cogen> cogenP5(final Cogen ca, final Cogen cb, + final Cogen cc, final Cogen cd, + final Cogen ce) { + return new Cogen>() { + public Gen cogen(final P5 p, final Gen g) { + return ca.cogen(p._1(), + cb.cogen(p._2(), cc.cogen(p._3(), cd.cogen(p._4(), ce.cogen(p._5(), g))))); + } + }; + } + + /** + * A cogen for product-6 values. + * + * @param ca A cogen for one of the types over which the product-6 is defined. + * @param cb A cogen for one of the types over which the product-6 is defined. + * @param cc A cogen for one of the types over which the product-6 is defined. + * @param cd A cogen for one of the types over which the product-6 is defined. + * @param ce A cogen for one of the types over which the product-6 is defined. + * @param cf A cogen for one of the types over which the product-6 is defined. + * @return A cogen for product-6 values. + */ + public static Cogen> cogenP6(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf) { + return new Cogen>() { + public Gen cogen(final P6 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), + cc.cogen(p._3(), cd.cogen(p._4(), ce.cogen(p._5(), cf.cogen(p._6(), g)))))); + } + }; + } + + /** + * A cogen for product-7 values. + * + * @param ca A cogen for one of the types over which the product-7 is defined. + * @param cb A cogen for one of the types over which the product-7 is defined. + * @param cc A cogen for one of the types over which the product-7 is defined. + * @param cd A cogen for one of the types over which the product-7 is defined. + * @param ce A cogen for one of the types over which the product-7 is defined. + * @param cf A cogen for one of the types over which the product-7 is defined. + * @param cg A cogen for one of the types over which the product-7 is defined. + * @return A cogen for product-7 values. + */ + public static Cogen> cogenP7(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf, + final Cogen cg) { + return new Cogen>() { + public Gen cogen(final P7 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), cc.cogen(p._3(), + cd.cogen(p._4(), ce.cogen(p._5(), cf.cogen(p._6(), cg.cogen(p._7(), g))))))); + } + }; + } + + /** + * A cogen for product-8 values. + * + * @param ca A cogen for one of the types over which the product-8 is defined. + * @param cb A cogen for one of the types over which the product-8 is defined. + * @param cc A cogen for one of the types over which the product-8 is defined. + * @param cd A cogen for one of the types over which the product-8 is defined. + * @param ce A cogen for one of the types over which the product-8 is defined. + * @param cf A cogen for one of the types over which the product-8 is defined. + * @param cg A cogen for one of the types over which the product-8 is defined. + * @param ch A cogen for one of the types over which the product-8 is defined. + * @return A cogen for product-8 values. + */ + public static Cogen> cogenP8(final Cogen ca, + final Cogen cb, + final Cogen cc, + final Cogen cd, + final Cogen ce, + final Cogen cf, + final Cogen cg, + final Cogen ch) { + return new Cogen>() { + public Gen cogen(final P8 p, final Gen g) { + return ca.cogen(p._1(), cb.cogen(p._2(), cc.cogen(p._3(), cd.cogen(p._4(), + ce.cogen(p._5(), cf.cogen(p._6(), cg.cogen(p._7(), ch.cogen(p._8(), g)))))))); + } + }; + } +} diff --git a/quickcheck/src/test/java/fj/data/test/TestCheck.java b/quickcheck/src/test/java/fj/data/test/TestCheck.java index 6bfaeaf7..935f1127 100644 --- a/quickcheck/src/test/java/fj/data/test/TestCheck.java +++ b/quickcheck/src/test/java/fj/data/test/TestCheck.java @@ -11,8 +11,6 @@ import static fj.Function.compose; import static fj.test.Arbitrary.arbLong; -import static fj.test.Coarbitrary.coarbInteger; -import static fj.test.Coarbitrary.coarbLong; import static fj.test.Property.prop; import static fj.test.Property.property; import static org.junit.Assert.*; diff --git a/quickcheck/src/test/java/fj/data/test/TestNull.java b/quickcheck/src/test/java/fj/data/test/TestNull.java index 0346407d..0fd44c6a 100644 --- a/quickcheck/src/test/java/fj/data/test/TestNull.java +++ b/quickcheck/src/test/java/fj/data/test/TestNull.java @@ -11,8 +11,6 @@ import static fj.Function.compose; import static fj.test.Arbitrary.arbLong; -import static fj.test.Coarbitrary.coarbInteger; -import static fj.test.Coarbitrary.coarbLong; import static fj.test.Property.prop; import static fj.test.Property.property; From e87d5be36daac7f52ffd44bb99a04ee13666fdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 6 Jun 2016 20:26:23 -0400 Subject: [PATCH 082/336] Add DB.db method with Try1 --- core/src/main/java/fj/control/db/DB.java | 16 ++++++++++++ .../test/java/fj/control/db/TestDbState.java | 25 +++++++++---------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/fj/control/db/DB.java b/core/src/main/java/fj/control/db/DB.java index a7ba6a7f..4e16710e 100644 --- a/core/src/main/java/fj/control/db/DB.java +++ b/core/src/main/java/fj/control/db/DB.java @@ -2,6 +2,7 @@ import fj.F; import fj.Function; +import fj.function.Try1; import java.sql.Connection; import java.sql.SQLException; @@ -35,6 +36,21 @@ public A run(final Connection c) { }; } + /** + * Constructs a database action as a function from a database connection to a value. + * + * @param t A function from a database connection to a value allowed to throw + * SQLException + * @return A database action representing the given function. + */ + public static DB db(final Try1 t){ + return new DB() { + public A run(final Connection c) throws SQLException { + return t.f(c); + } + }; + } + /** * Returns the callable-valued function projection of this database action. * diff --git a/core/src/test/java/fj/control/db/TestDbState.java b/core/src/test/java/fj/control/db/TestDbState.java index 00933921..188eae3d 100644 --- a/core/src/test/java/fj/control/db/TestDbState.java +++ b/core/src/test/java/fj/control/db/TestDbState.java @@ -2,6 +2,7 @@ import fj.Unit; import fj.data.Option; +import fj.function.Try1; import org.apache.commons.dbutils.DbUtils; import org.junit.Test; @@ -16,20 +17,18 @@ public void testWriter() throws SQLException { final int TEN = 10; DbState writer = DbState.writer(DbState.driverManager("jdbc:h2:mem:")); - DB setup = new DB() { - @Override - public Unit run(Connection c) throws SQLException { - Statement s = null; - try { - s = c.createStatement(); - assertThat(s.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"), is(0)); - assertThat(s.executeUpdate("INSERT INTO TEST (ID, NAME) VALUES (" + TEN + ", 'FOO')"), is(1)); - } finally { - DbUtils.closeQuietly(s); - } - return Unit.unit(); + DB setup = DB.db((Try1) c -> { + Statement s = null; + try { + s = c.createStatement(); + assertThat(s.executeUpdate("CREATE TABLE TEST(ID INT PRIMARY KEY, NAME VARCHAR(255))"), is(0)); + assertThat(s.executeUpdate("INSERT INTO TEST (ID, NAME) VALUES (" + TEN + ", 'FOO')"), is(1)); + } finally { + DbUtils.closeQuietly(s); } - }; + return Unit.unit(); + }); + DB> query = new DB>() { @Override public Option run(Connection c) throws SQLException { From bcc0b711fbaaeed4912912ff7e8b569025ef446c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 14 Jun 2016 07:55:24 +0200 Subject: [PATCH 083/336] Remove extra type parameters on methods in P2.Optic. Fix #273 --- core/src/main/java/fj/P2.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index 521fc14d..abe4d0d5 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -335,7 +335,7 @@ public static PLens, P2, A, C> _1p() { /** * Monomorphic lens targeted on _1. */ - public static Lens, A> _1() { + public static Lens, A> _1() { return new Lens<>(_1p()); } @@ -349,7 +349,7 @@ public static PLens, P2, B, C> _2p() { /** * Monomorphic lens targeted on _1. */ - public static Lens, B> _2() { + public static Lens, B> _2() { return new Lens<>(_2p()); } From 7a9f3d98c6f7f42eb567d237375ed1d2188b4fe6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 14 Jun 2016 08:17:12 +0200 Subject: [PATCH 084/336] Document version deprecated for toJavaArray methods. Fix #264 Also suppress unchecked warnings (#269) for them. --- core/src/main/java/fj/data/Array.java | 3 ++- core/src/main/java/fj/data/List.java | 3 ++- core/src/main/java/fj/data/Stream.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index b6538ba5..7e937200 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -135,8 +135,9 @@ public Object[] array() { * affectation of the result of this method to a non generic array * will result in runtime error (ClassCastException). * - * @deprecated use {@link #array(Class)} + * @deprecated As of release 4.6, use {@link #array(Class)}. */ + @SuppressWarnings("unchecked") @Deprecated public A[] toJavaArray() { return (A[]) array(); diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index cfd95898..2b1a728e 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -216,8 +216,9 @@ public final Object[] toArrayObject() { * affectation of the result of this method to a non generic array * will result in runtime error (ClassCastException). * - * @deprecated use {@link #array(Class)} + * @deprecated As of release 4.6, use {@link #array(Class)}. */ + @SuppressWarnings("unchecked") @Deprecated public final A[] toJavaArray() { return (A[]) toArrayObject(); diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index 01e1756b..ca4c870a 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -922,10 +922,11 @@ public final Option toOption() { * affectation of the result of this method to a non generic array * will result in runtime error (ClassCastException). * - * @deprecated use {@link #array(Class)} + * @deprecated As of release 4.6, use {@link #array(Class)}. */ @Deprecated public final A[] toJavaArray() { + @SuppressWarnings("unchecked") final A[] array = (A[]) new Object[length()]; int i = 0; for (A a: this) { From 7b84ad992b2b651cad5158de3b5e1d011cbb96b5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 14 Jun 2016 08:22:13 +0200 Subject: [PATCH 085/336] Fix unchecked conversion warnings. Fix #269. --- core/src/test/java/fj/ClassTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/fj/ClassTest.java b/core/src/test/java/fj/ClassTest.java index 862c6fdd..2959e351 100644 --- a/core/src/test/java/fj/ClassTest.java +++ b/core/src/test/java/fj/ClassTest.java @@ -23,28 +23,28 @@ public void testInheritance() { @Test public void testClassParameters() { - Class c = Class.clas(Option.none().getClass()); + Class c = Class.clas(Option.none().getClass()); Tree cp = c.classParameters(); assertThat(cp.length(), is(1)); } @Test public void testSuperclassParameters() { - Class c = Class.clas(Option.none().getClass()); + Class c = Class.clas(Option.none().getClass()); Tree cp = c.superclassParameters(); assertThat(cp.length(), is(2)); } @Test public void testInterfaceParameters() { - Class c = Class.clas(Option.none().getClass()); - List l =c.interfaceParameters(); + Class c = Class.clas(Option.none().getClass()); + List> l =c.interfaceParameters(); assertThat(l.length(), is(0)); } @Test public void testTypeParameterTree() { - Class c = Class.clas(Option.none().getClass()); + Class c = Class.clas(Option.none().getClass()); Collection coll = c.classParameters().toCollection(); for (Type t: coll) { assertThat(Class.typeParameterTree(t).toString(), is("Tree(class fj.data.Option$None)")); From 8eac39a9ebbff5082ef98bd70bcaf8cb25038a0a Mon Sep 17 00:00:00 2001 From: mrbackend Date: Mon, 6 Jun 2016 17:17:43 +0200 Subject: [PATCH 086/336] Stack safe State --- core/src/main/java/fj/data/State.java | 213 ++++----- .../test/java/fj/data/StateProperties.java | 409 ++++++++++++++++++ 2 files changed, 516 insertions(+), 106 deletions(-) create mode 100644 props-core/src/test/java/fj/data/StateProperties.java diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 3128ae6c..1b30a55e 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -1,118 +1,119 @@ package fj.data; -import fj.*; +import fj.F; +import fj.P2; +import fj.Unit; +import fj.control.Trampoline; +import static fj.P.lazy; import static fj.P.p; +import static fj.control.Trampoline.suspend; +import static fj.data.List.cons; /** * Created by MarkPerry on 7/07/2014. */ public final class State { - private final F> run; - - private State(F> f) { - run = f; - } - - public P2 run(S s) { - return run.f(s); - } - - public static State unit(F> f) { - return new State<>(f); - } - - public static State units(F f) { - return unit((S s) -> { - S s2 = f.f(s); - return p(s2, s2); - }); - } - - public static State constant(A a) { - return unit(s -> p(s, a)); - } - - public State map(F f) { - return unit((S s) -> { - P2 p2 = run(s); - B b = f.f(p2._2()); - return p(p2._1(), b); - }); - } - - public static State modify(F f) { - return State.init().flatMap(s -> unit(s2 -> p(f.f(s), Unit.unit()))); - } - - public State mapState(F, P2> f) { - return unit(s -> f.f(run(s))); - } - - public static State flatMap(State mb, F> f) { - return mb.flatMap(f); - } - - public State flatMap(F> f) { - return unit((S s) -> { - P2 p = run(s); - A a = p._2(); - S s2 = p._1(); - State smb = f.f(a); - return smb.run(s2); - }); - } - - public static State init() { - return unit(s -> p(s, s)); - } - - public State gets() { - return unit(s -> { - P2 p = run(s); - S s2 = p._1(); - return p(s2, s2); - }); - } - - public static State put(S s) { - return unit((S z) -> p(s, Unit.unit())); - } - - public A eval(S s) { - return run(s)._2(); - } - - public S exec(S s) { - return run(s)._1(); - } - - public State withs(F f) { - return unit(F1Functions.andThen(f, run)); - } - - public static State gets(F f) { - return State.init().map(f); - } - - /** - * Evaluate each action in the sequence from left to right, and collect the results. - */ - public static State> sequence(List> list) { - return list.foldLeft((State> acc, State ma) -> - acc.flatMap((List xs) -> ma.map(xs::snoc) - ), constant(List.nil())); - } - - /** - * Map each element of a structure to an action, evaluate these actions from left to right - * and collect the results. - */ - public static State> traverse(List list, F> f) { - return list.foldLeft((State> acc, A a) -> - acc.flatMap(bs -> f.f(a).map(bs::snoc) - ), constant(List.nil())); - } + public static State unit(F> runF) { + return new State<>(s -> Trampoline.pure(runF.f(s))); + } + + public static State init() { + return unit(s -> dup(s)); + } + + public static State units(F f) { + return unit(s -> dup(f.f(s))); + } + + private static P2 dup(S s) { + return p(s, s); + } + + public static State constant(A a) { + return unit(s -> p(s, a)); + } + + public static State gets(F f) { + return unit(s -> p(s, f.f(s))); + } + + public static State put(S s) { + return unit(ignoredS -> p(s, Unit.unit())); + } + + public static State modify(F f) { + return unit(s -> p(f.f(s), Unit.unit())); + } + + public static State flatMap(State ts, F> f) { + return ts.flatMap(f); + } + + /** + * Evaluate each action in the sequence from left to right, and collect the results. + */ + public static State> sequence(List> list) { + return list + .foldLeft( + (acc, ts) -> acc.flatMap(as -> ts.map(a -> cons(a, as))), + State.>constant(List.nil())) + .map(as -> as.reverse()); + } + + /** + * Map each element of a structure to an action, evaluate these actions from left to right + * and collect the results. + */ + public static State> traverse(List list, F> f) { + return list + .foldLeft( + (acc, a) -> acc.flatMap(bs -> f.f(a).map(b -> cons(b, bs))), + State.>constant(List.nil())) + .map(bs -> bs.reverse()); + } + + private static State suspended(F>> runF) { + return new State<>(s -> suspend(lazy(() -> runF.f(s)))); + } + + private final F>> runF; + + private State(F>> runF) { + this.runF = runF; + } + + public P2 run(S s) { + return runF.f(s).run(); + } + + public A eval(S s) { + return run(s)._2(); + } + + public S exec(S s) { + return run(s)._1(); + } + + public State gets() { + return mapState(result -> p(result._1(), result._1())); + } + + public State map(F f) { + return mapState(result -> p(result._1(), f.f(result._2()))); + } + + public State mapState(F, P2> f) { + return suspended(s -> runF.f(s).map(result -> f.f(result))); + } + + public State withs(F f) { + return suspended(s -> runF.f(f.f(s))); + } + + public State flatMap(F> f) { + return suspended(s -> runF.f(s).bind(result -> Trampoline.pure(f.f(result._2()).run(result._1())))); + } } diff --git a/props-core/src/test/java/fj/data/StateProperties.java b/props-core/src/test/java/fj/data/StateProperties.java new file mode 100644 index 00000000..3fb0e2ba --- /dev/null +++ b/props-core/src/test/java/fj/data/StateProperties.java @@ -0,0 +1,409 @@ +package fj.data; + +import fj.F; +import fj.P2; +import fj.Unit; +import fj.test.Arbitrary; +import fj.test.Coarbitrary; +import fj.test.Gen; +import fj.test.Property; +import fj.test.reflect.CheckParams; +import fj.test.runner.PropertyTestRunner; +import org.junit.runner.RunWith; + +import static fj.P.p; +import static fj.data.List.range; +import static fj.test.Arbitrary.arbF; +import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbList; +import static fj.test.Arbitrary.arbP2; +import static fj.test.Arbitrary.arbitrary; +import static fj.test.Coarbitrary.coarbInteger; +import static fj.test.Coarbitrary.coarbP2; +import static fj.test.Property.prop; +import static fj.test.Property.property; + +@RunWith(PropertyTestRunner.class) +public final class StateProperties { + + public Property unit() { + return property( + arbRunF(coarbInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testUnit(runF, initS))); + } + + private static boolean testUnit(F> runF, S initS) { + State instance = State.unit(runF); + P2 actual = instance.run(initS); + P2 expected = runF.f(initS); + return actual.equals(expected); + } + + public Property init() { + return property( + arbInteger, + initS -> prop(testInit(initS))); + } + + private static boolean testInit(S initS) { + State instance = State.init(); + P2 actual = instance.run(initS); + P2 expected = p(initS, initS); + return actual.equals(expected); + } + + public Property units() { + return property( + arbF(coarbInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testUnits(f, initS))); + } + + private static boolean testUnits(F f, S initS) { + State instance = State.units(f); + P2 actual = instance.run(initS); + S expectedS = f.f(initS); + P2 expected = p(expectedS, expectedS); + return actual.equals(expected); + } + + public Property constant() { + return property( + arbInteger, + arbInteger, + (a, initS) -> prop(testConstant(a, initS))); + } + + private static boolean testConstant(A a, S initS) { + State instance = State.constant(a); + P2 actual = instance.run(initS); + P2 expected = p(initS, a); + return actual.equals(expected); + } + + public Property staticGets() { + return property( + arbF(coarbInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testStaticGets(f, initS))); + } + + private static boolean testStaticGets(F f, S initS) { + State instance = State.gets(f); + P2 actual = instance.run(initS); + P2 expected = p(initS, f.f(initS)); + return actual.equals(expected); + } + + public Property put() { + return property( + arbInteger, + arbInteger, + (newS, initS) -> prop(testPut(newS, initS))); + } + + private static boolean testPut(S newS, S initS) { + State instance = State.put(newS); + P2 actual = instance.run(initS); + P2 expected = p(newS, Unit.unit()); + return actual.equals(expected); + } + + public Property modify() { + return property( + arbF(coarbInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testModify(f, initS))); + } + + private static boolean testModify(F f, S initS) { + State instance = State.modify(f); + P2 actual = instance.run(initS); + P2 expected = p(f.f(initS), Unit.unit()); + return actual.equals(expected); + } + + public Property staticFlatMap() { + return property( + arbRunF(coarbInteger, arbInteger, arbInteger), + arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), + arbInteger, + (runF, f, initS) -> prop(testStaticFlatMap(runF, f, initS))); + } + + private static boolean testStaticFlatMap(F> runF, F> f, S initS) { + State instance = State.flatMap(State.unit(runF), f); + P2 actual = instance.run(initS); + P2 intermediateExpected = runF.f(initS); + P2 expected = f.f(intermediateExpected._2()).run(intermediateExpected._1()); + return actual.equals(expected); + } + + public Property sequence() { + return property( + arbList(arbState(coarbInteger, arbInteger, arbInteger)), + arbInteger, + (states, initS) -> prop(testSequence(states, initS))); + } + + private static boolean testSequence(List> states, S initS) { + State> instance = State.sequence(states); + P2> actual = instance.run(initS); + + S expectedFinalS = initS; + List expectedAs = List.nil(); + List> remainingStates = states; + while (remainingStates.isNotEmpty()) { + P2 nextResult = remainingStates.head().run(expectedFinalS); + expectedFinalS = nextResult._1(); + expectedAs = List.cons(nextResult._2(), expectedAs); + remainingStates = remainingStates.tail(); + } + expectedAs = expectedAs.reverse(); + + P2> expected = p(expectedFinalS, expectedAs); + return actual.equals(expected); + } + + public Property traverse() { + return property( + arbList(arbInteger), + arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), + arbInteger, + (as, f, initS) -> prop(testTraverse(as, f, initS))); + + } + + private static boolean testTraverse(List as, F> f, S initS) { + State> instance = State.traverse(as, f); + P2> actual = instance.run(initS); + + S expectedFinalS = initS; + List expectedFinalBs = List.nil(); + List currAs = as; + while (currAs.isNotEmpty()) { + P2 nextStateAndB = f.f(currAs.head()).run(expectedFinalS); + expectedFinalS = nextStateAndB._1(); + expectedFinalBs = List.cons(nextStateAndB._2(), expectedFinalBs); + currAs = currAs.tail(); + } + expectedFinalBs = expectedFinalBs.reverse(); + P2> expected = p(expectedFinalS, expectedFinalBs); + + return actual.equals(expected); + } + + public Property run() { + return property( + arbRunF(coarbInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testRun(runF, initS))); + } + + private static boolean testRun(F> runF, S initS) { + State instance = State.unit(runF); + P2 actual = instance.run(initS); + P2 expected = runF.f(initS); + return actual.equals(expected); + } + + public Property eval() { + return property( + arbRunF(coarbInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testEval(runF, initS))); + } + + private static boolean testEval(F> runF, S initS) { + State instance = State.unit(runF); + A actual = instance.eval(initS); + A expected = runF.f(initS)._2(); + return actual.equals(expected); + } + + public Property exec() { + return property( + arbRunF(coarbInteger, arbInteger, arbUnit), + arbInteger, + (runF, initS) -> prop(testExec(runF, initS))); + } + + private static boolean testExec(F> runF, S initS) { + State instance = State.unit(runF); + S actual = instance.exec(initS); + S expected = runF.f(initS)._1(); + return actual.equals(expected); + } + + public Property getsProperty() { + return property( + arbState(coarbInteger, arbInteger, arbInteger), + arbInteger, + (state, initS) -> prop(testGets(state, initS))); + } + + private static boolean testGets(State state, S initS) { + State instance = state.gets(); + P2 actual = instance.run(initS); + P2 expected = p(state.run(initS)._1(), state.run(initS)._1()); + return actual.equals(expected); + } + + public Property map() { + return property( + arbState(coarbInteger, arbInteger, arbInteger), + arbF(coarbInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testMap(state, f, initS))); + } + + private static boolean testMap(State state, F f, S initS) { + State instance = state.map(f); + P2 actual = instance.run(initS); + P2 expected = state.run(initS).map2(f); + return actual.equals(expected); + } + + public Property mapState() { + return property( + arbState(coarbInteger, arbInteger, arbInteger), + arbMapStateF(coarbInteger, coarbInteger, arbInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testMapState(state, f, initS))); + } + + private static boolean testMapState(State state, F, P2> f, S initS) { + State instance = state.mapState(f); + P2 actual = instance.run(initS); + P2 expected = f.f(state.run(initS)); + return actual.equals(expected); + } + + public Property withs() { + return property( + arbState(coarbInteger, arbInteger, arbInteger), + arbF(coarbInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testWiths(state, f, initS))); + } + + private static boolean testWiths(State state, F f, S initS) { + State instance = state.withs(f); + P2 actual = instance.run(initS); + P2 expected = state.run(f.f(initS)); + return actual.equals(expected); + } + + public Property flatMap() { + return property( + arbState(coarbInteger, arbInteger, arbInteger), + arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), + arbInteger, + (state, f, initS) -> prop(testFlatMap(state, f, initS))); + } + + private static boolean testFlatMap(State state, F> f, S initS) { + State instance = state.flatMap(f); + P2 actual = instance.run(initS); + P2 expected = f.f(state.run(initS)._2()).run(state.run(initS)._1()); + return actual.equals(expected); + } + + @CheckParams(minSuccessful = 1) + public Property getsStackSafety() { + return property( + arbHugeState( + arbState(coarbInteger, arbInteger, arbInteger), + currState -> arbitrary(Gen.value(currState.gets()))), + arbInteger, + (instance, initS) -> prop(testNoStackOverflow(instance, initS))); + } + + @CheckParams(minSuccessful = 1) + public Property mapStackSafety() { + return property( + arbHugeState( + arbState(coarbInteger, arbInteger, arbInteger), + currState -> arbitrary(Gen.gen(s -> r -> currState.map(arbF(coarbInteger, arbInteger).gen.gen(s, r))))), + arbInteger, + (instance, initS) -> prop(testNoStackOverflow(instance, initS))); + } + + @CheckParams(minSuccessful = 1) + public Property mapStateStackSafety() { + return property( + arbHugeState( + arbState(coarbInteger, arbInteger, arbInteger), + currState -> arbitrary(Gen.gen(s -> r -> + currState.mapState(arbMapStateF(coarbInteger, coarbInteger, arbInteger, arbInteger).gen.gen(s, r))))), + arbInteger, + (instance, initS) -> prop(testNoStackOverflow(instance, initS))); + } + + @CheckParams(minSuccessful = 1) + public Property withsStackSafety() { + return property( + arbHugeState( + arbState(coarbInteger, arbInteger, arbInteger), + currState -> arbitrary(Gen.gen(s -> r -> currState.withs(arbF(coarbInteger, arbInteger).gen.gen(s, r))))), + arbInteger, + (instance, initS) -> prop(testNoStackOverflow(instance, initS))); + } + + @CheckParams(minSuccessful = 1) + public Property flatMapStackSafety() { + return property( + arbHugeState( + arbState(coarbInteger, arbInteger, arbInteger), + currState -> arbitrary(Gen.gen(s -> r -> + currState.flatMap(arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)).gen.gen(s, r))))), + arbInteger, + (instance, initS) -> prop(testNoStackOverflow(instance, initS))); + } + + private static boolean testNoStackOverflow(State instance, S initS) { + instance.run(initS); + return true; + } + + private static final Arbitrary arbUnit = arbitrary(Gen.value(Unit.unit())); + + private static Arbitrary>> arbRunF( + Coarbitrary coarbInitS, + Arbitrary arbNextS, + Arbitrary arbValue) { + + return arbF(coarbInitS, arbP2(arbNextS, arbValue)); + } + + private static Arbitrary, P2>> arbMapStateF( + Coarbitrary coarbInitS, + Coarbitrary coarbInitValue, + Arbitrary arbNextS, + Arbitrary arbNextValue) { + + return arbF(coarbP2(coarbInitS, coarbInitValue), arbP2(arbNextS, arbNextValue)); + } + + private static Arbitrary> arbState( + Coarbitrary coarbInitS, + Arbitrary arbNextS, + Arbitrary arbValue) { + + Arbitrary>> arbRunF = arbRunF(coarbInitS, arbNextS, arbValue); + return arbitrary(Gen.gen(s -> r -> State.unit(arbRunF.gen.gen(s, r)))); + } + + private static final int HUGE_SIZE = 10000; + + private static Arbitrary> arbHugeState( + Arbitrary> arbInitState, + F, Arbitrary>> nextArbStateF) { + + return arbitrary(Gen.gen(s -> r -> range(0, HUGE_SIZE).foldLeft( + (acc, x) -> nextArbStateF.f(acc).gen.gen(s, r), + arbInitState.gen.gen(s, r)))); + } + +} From 2833a566c61cbeaf677d0519d823f7b7ab78b8bd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 14 Jun 2016 21:58:34 +0200 Subject: [PATCH 087/336] Remove use of Arbitrary wrapper --- .../test/java/fj/data/StateProperties.java | 381 +++++++++--------- 1 file changed, 189 insertions(+), 192 deletions(-) diff --git a/props-core/src/test/java/fj/data/StateProperties.java b/props-core/src/test/java/fj/data/StateProperties.java index 3fb0e2ba..c5ce2a2e 100644 --- a/props-core/src/test/java/fj/data/StateProperties.java +++ b/props-core/src/test/java/fj/data/StateProperties.java @@ -3,8 +3,7 @@ import fj.F; import fj.P2; import fj.Unit; -import fj.test.Arbitrary; -import fj.test.Coarbitrary; +import fj.test.Cogen; import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -17,21 +16,16 @@ import static fj.test.Arbitrary.arbInteger; import static fj.test.Arbitrary.arbList; import static fj.test.Arbitrary.arbP2; -import static fj.test.Arbitrary.arbitrary; -import static fj.test.Coarbitrary.coarbInteger; -import static fj.test.Coarbitrary.coarbP2; +import static fj.test.Cogen.cogenInteger; +import static fj.test.Cogen.cogenP2; import static fj.test.Property.prop; import static fj.test.Property.property; @RunWith(PropertyTestRunner.class) public final class StateProperties { - public Property unit() { - return property( - arbRunF(coarbInteger, arbInteger, arbInteger), - arbInteger, - (runF, initS) -> prop(testUnit(runF, initS))); - } + private static final Gen arbUnit = Gen.value(Unit.unit()); + private static final int HUGE_SIZE = 10000; private static boolean testUnit(F> runF, S initS) { State instance = State.unit(runF); @@ -40,12 +34,6 @@ private static boolean testUnit(F> runF, S initS) { return actual.equals(expected); } - public Property init() { - return property( - arbInteger, - initS -> prop(testInit(initS))); - } - private static boolean testInit(S initS) { State instance = State.init(); P2 actual = instance.run(initS); @@ -53,13 +41,6 @@ private static boolean testInit(S initS) { return actual.equals(expected); } - public Property units() { - return property( - arbF(coarbInteger, arbInteger), - arbInteger, - (f, initS) -> prop(testUnits(f, initS))); - } - private static boolean testUnits(F f, S initS) { State instance = State.units(f); P2 actual = instance.run(initS); @@ -68,13 +49,6 @@ private static boolean testUnits(F f, S initS) { return actual.equals(expected); } - public Property constant() { - return property( - arbInteger, - arbInteger, - (a, initS) -> prop(testConstant(a, initS))); - } - private static boolean testConstant(A a, S initS) { State instance = State.constant(a); P2 actual = instance.run(initS); @@ -82,13 +56,6 @@ private static boolean testConstant(A a, S initS) { return actual.equals(expected); } - public Property staticGets() { - return property( - arbF(coarbInteger, arbInteger), - arbInteger, - (f, initS) -> prop(testStaticGets(f, initS))); - } - private static boolean testStaticGets(F f, S initS) { State instance = State.gets(f); P2 actual = instance.run(initS); @@ -96,13 +63,6 @@ private static boolean testStaticGets(F f, S initS) { return actual.equals(expected); } - public Property put() { - return property( - arbInteger, - arbInteger, - (newS, initS) -> prop(testPut(newS, initS))); - } - private static boolean testPut(S newS, S initS) { State instance = State.put(newS); P2 actual = instance.run(initS); @@ -110,13 +70,6 @@ private static boolean testPut(S newS, S initS) { return actual.equals(expected); } - public Property modify() { - return property( - arbF(coarbInteger, arbInteger), - arbInteger, - (f, initS) -> prop(testModify(f, initS))); - } - private static boolean testModify(F f, S initS) { State instance = State.modify(f); P2 actual = instance.run(initS); @@ -124,14 +77,6 @@ private static boolean testModify(F f, S initS) { return actual.equals(expected); } - public Property staticFlatMap() { - return property( - arbRunF(coarbInteger, arbInteger, arbInteger), - arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), - arbInteger, - (runF, f, initS) -> prop(testStaticFlatMap(runF, f, initS))); - } - private static boolean testStaticFlatMap(F> runF, F> f, S initS) { State instance = State.flatMap(State.unit(runF), f); P2 actual = instance.run(initS); @@ -140,13 +85,6 @@ private static boolean testStaticFlatMap(F> runF, F prop(testSequence(states, initS))); - } - private static boolean testSequence(List> states, S initS) { State> instance = State.sequence(states); P2> actual = instance.run(initS); @@ -166,15 +104,6 @@ private static boolean testSequence(List> states, S initS) { return actual.equals(expected); } - public Property traverse() { - return property( - arbList(arbInteger), - arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), - arbInteger, - (as, f, initS) -> prop(testTraverse(as, f, initS))); - - } - private static boolean testTraverse(List as, F> f, S initS) { State> instance = State.traverse(as, f); P2> actual = instance.run(initS); @@ -194,13 +123,6 @@ private static boolean testTraverse(List as, F> f, S return actual.equals(expected); } - public Property run() { - return property( - arbRunF(coarbInteger, arbInteger, arbInteger), - arbInteger, - (runF, initS) -> prop(testRun(runF, initS))); - } - private static boolean testRun(F> runF, S initS) { State instance = State.unit(runF); P2 actual = instance.run(initS); @@ -208,13 +130,6 @@ private static boolean testRun(F> runF, S initS) { return actual.equals(expected); } - public Property eval() { - return property( - arbRunF(coarbInteger, arbInteger, arbInteger), - arbInteger, - (runF, initS) -> prop(testEval(runF, initS))); - } - private static boolean testEval(F> runF, S initS) { State instance = State.unit(runF); A actual = instance.eval(initS); @@ -222,13 +137,6 @@ private static boolean testEval(F> runF, S initS) { return actual.equals(expected); } - public Property exec() { - return property( - arbRunF(coarbInteger, arbInteger, arbUnit), - arbInteger, - (runF, initS) -> prop(testExec(runF, initS))); - } - private static boolean testExec(F> runF, S initS) { State instance = State.unit(runF); S actual = instance.exec(initS); @@ -236,13 +144,6 @@ private static boolean testExec(F> runF, S initS) { return actual.equals(expected); } - public Property getsProperty() { - return property( - arbState(coarbInteger, arbInteger, arbInteger), - arbInteger, - (state, initS) -> prop(testGets(state, initS))); - } - private static boolean testGets(State state, S initS) { State instance = state.gets(); P2 actual = instance.run(initS); @@ -250,14 +151,6 @@ private static boolean testGets(State state, S initS) { return actual.equals(expected); } - public Property map() { - return property( - arbState(coarbInteger, arbInteger, arbInteger), - arbF(coarbInteger, arbInteger), - arbInteger, - (state, f, initS) -> prop(testMap(state, f, initS))); - } - private static boolean testMap(State state, F f, S initS) { State instance = state.map(f); P2 actual = instance.run(initS); @@ -265,14 +158,6 @@ private static boolean testMap(State state, F f, S initS) return actual.equals(expected); } - public Property mapState() { - return property( - arbState(coarbInteger, arbInteger, arbInteger), - arbMapStateF(coarbInteger, coarbInteger, arbInteger, arbInteger), - arbInteger, - (state, f, initS) -> prop(testMapState(state, f, initS))); - } - private static boolean testMapState(State state, F, P2> f, S initS) { State instance = state.mapState(f); P2 actual = instance.run(initS); @@ -280,14 +165,6 @@ private static boolean testMapState(State state, F, P2< return actual.equals(expected); } - public Property withs() { - return property( - arbState(coarbInteger, arbInteger, arbInteger), - arbF(coarbInteger, arbInteger), - arbInteger, - (state, f, initS) -> prop(testWiths(state, f, initS))); - } - private static boolean testWiths(State state, F f, S initS) { State instance = state.withs(f); P2 actual = instance.run(initS); @@ -295,14 +172,6 @@ private static boolean testWiths(State state, F f, S initS) { return actual.equals(expected); } - public Property flatMap() { - return property( - arbState(coarbInteger, arbInteger, arbInteger), - arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)), - arbInteger, - (state, f, initS) -> prop(testFlatMap(state, f, initS))); - } - private static boolean testFlatMap(State state, F> f, S initS) { State instance = state.flatMap(f); P2 actual = instance.run(initS); @@ -310,12 +179,184 @@ private static boolean testFlatMap(State state, F return actual.equals(expected); } + private static boolean testNoStackOverflow(State instance, S initS) { + instance.run(initS); + return true; + } + + private static Gen>> arbRunF( + Cogen cogenInitS, + Gen arbNextS, + Gen arbValue) { + + return arbF(cogenInitS, arbP2(arbNextS, arbValue)); + } + + private static Gen, P2>> arbMapStateF( + Cogen cogenInitS, + Cogen cogenInitValue, + Gen arbNextS, + Gen arbNextValue) { + + return arbF(cogenP2(cogenInitS, cogenInitValue), arbP2(arbNextS, arbNextValue)); + } + + private static Gen> arbState( + Cogen cogenInitS, + Gen arbNextS, + Gen arbValue) { + + Gen>> arbRunF = arbRunF(cogenInitS, arbNextS, arbValue); + return Gen.gen(s -> r -> State.unit(arbRunF.gen(s, r))); + } + + private static Gen> arbHugeState( + Gen> arbInitState, + F, Gen>> nextArbStateF) { + + return Gen.gen(s -> r -> range(0, HUGE_SIZE).foldLeft( + (acc, x) -> nextArbStateF.f(acc).gen(s, r), + arbInitState.gen(s, r))); + } + + public Property unit() { + return property( + arbRunF(cogenInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testUnit(runF, initS))); + } + + public Property init() { + return property( + arbInteger, + initS -> prop(testInit(initS))); + } + + public Property units() { + return property( + arbF(cogenInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testUnits(f, initS))); + } + + public Property constant() { + return property( + arbInteger, + arbInteger, + (a, initS) -> prop(testConstant(a, initS))); + } + + public Property staticGets() { + return property( + arbF(cogenInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testStaticGets(f, initS))); + } + + public Property put() { + return property( + arbInteger, + arbInteger, + (newS, initS) -> prop(testPut(newS, initS))); + } + + public Property modify() { + return property( + arbF(cogenInteger, arbInteger), + arbInteger, + (f, initS) -> prop(testModify(f, initS))); + } + + public Property staticFlatMap() { + return property( + arbRunF(cogenInteger, arbInteger, arbInteger), + arbF(cogenInteger, arbState(cogenInteger, arbInteger, arbInteger)), + arbInteger, + (runF, f, initS) -> prop(testStaticFlatMap(runF, f, initS))); + } + + public Property sequence() { + return property( + arbList(arbState(cogenInteger, arbInteger, arbInteger)), + arbInteger, + (states, initS) -> prop(testSequence(states, initS))); + } + + public Property traverse() { + return property( + arbList(arbInteger), + arbF(cogenInteger, arbState(cogenInteger, arbInteger, arbInteger)), + arbInteger, + (as, f, initS) -> prop(testTraverse(as, f, initS))); + + } + + public Property run() { + return property( + arbRunF(cogenInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testRun(runF, initS))); + } + + public Property eval() { + return property( + arbRunF(cogenInteger, arbInteger, arbInteger), + arbInteger, + (runF, initS) -> prop(testEval(runF, initS))); + } + + public Property exec() { + return property( + arbRunF(cogenInteger, arbInteger, arbUnit), + arbInteger, + (runF, initS) -> prop(testExec(runF, initS))); + } + + public Property getsProperty() { + return property( + arbState(cogenInteger, arbInteger, arbInteger), + arbInteger, + (state, initS) -> prop(testGets(state, initS))); + } + + public Property map() { + return property( + arbState(cogenInteger, arbInteger, arbInteger), + arbF(cogenInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testMap(state, f, initS))); + } + + public Property mapState() { + return property( + arbState(cogenInteger, arbInteger, arbInteger), + arbMapStateF(cogenInteger, cogenInteger, arbInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testMapState(state, f, initS))); + } + + public Property withs() { + return property( + arbState(cogenInteger, arbInteger, arbInteger), + arbF(cogenInteger, arbInteger), + arbInteger, + (state, f, initS) -> prop(testWiths(state, f, initS))); + } + + public Property flatMap() { + return property( + arbState(cogenInteger, arbInteger, arbInteger), + arbF(cogenInteger, arbState(cogenInteger, arbInteger, arbInteger)), + arbInteger, + (state, f, initS) -> prop(testFlatMap(state, f, initS))); + } + @CheckParams(minSuccessful = 1) public Property getsStackSafety() { return property( arbHugeState( - arbState(coarbInteger, arbInteger, arbInteger), - currState -> arbitrary(Gen.value(currState.gets()))), + arbState(cogenInteger, arbInteger, arbInteger), + currState -> Gen.value(currState.gets())), arbInteger, (instance, initS) -> prop(testNoStackOverflow(instance, initS))); } @@ -324,8 +365,8 @@ public Property getsStackSafety() { public Property mapStackSafety() { return property( arbHugeState( - arbState(coarbInteger, arbInteger, arbInteger), - currState -> arbitrary(Gen.gen(s -> r -> currState.map(arbF(coarbInteger, arbInteger).gen.gen(s, r))))), + arbState(cogenInteger, arbInteger, arbInteger), + currState -> Gen.gen(s -> r -> currState.map(arbF(cogenInteger, arbInteger).gen(s, r)))), arbInteger, (instance, initS) -> prop(testNoStackOverflow(instance, initS))); } @@ -334,9 +375,9 @@ public Property mapStackSafety() { public Property mapStateStackSafety() { return property( arbHugeState( - arbState(coarbInteger, arbInteger, arbInteger), - currState -> arbitrary(Gen.gen(s -> r -> - currState.mapState(arbMapStateF(coarbInteger, coarbInteger, arbInteger, arbInteger).gen.gen(s, r))))), + arbState(cogenInteger, arbInteger, arbInteger), + currState -> Gen.gen(s -> r -> + currState.mapState(arbMapStateF(cogenInteger, cogenInteger, arbInteger, arbInteger).gen(s, r)))), arbInteger, (instance, initS) -> prop(testNoStackOverflow(instance, initS))); } @@ -345,8 +386,8 @@ public Property mapStateStackSafety() { public Property withsStackSafety() { return property( arbHugeState( - arbState(coarbInteger, arbInteger, arbInteger), - currState -> arbitrary(Gen.gen(s -> r -> currState.withs(arbF(coarbInteger, arbInteger).gen.gen(s, r))))), + arbState(cogenInteger, arbInteger, arbInteger), + currState -> Gen.gen(s -> r -> currState.withs(arbF(cogenInteger, arbInteger).gen(s, r)))), arbInteger, (instance, initS) -> prop(testNoStackOverflow(instance, initS))); } @@ -355,55 +396,11 @@ public Property withsStackSafety() { public Property flatMapStackSafety() { return property( arbHugeState( - arbState(coarbInteger, arbInteger, arbInteger), - currState -> arbitrary(Gen.gen(s -> r -> - currState.flatMap(arbF(coarbInteger, arbState(coarbInteger, arbInteger, arbInteger)).gen.gen(s, r))))), + arbState(cogenInteger, arbInteger, arbInteger), + currState -> Gen.gen(s -> r -> + currState.flatMap(arbF(cogenInteger, arbState(cogenInteger, arbInteger, arbInteger)).gen(s, r)))), arbInteger, (instance, initS) -> prop(testNoStackOverflow(instance, initS))); } - private static boolean testNoStackOverflow(State instance, S initS) { - instance.run(initS); - return true; - } - - private static final Arbitrary arbUnit = arbitrary(Gen.value(Unit.unit())); - - private static Arbitrary>> arbRunF( - Coarbitrary coarbInitS, - Arbitrary arbNextS, - Arbitrary arbValue) { - - return arbF(coarbInitS, arbP2(arbNextS, arbValue)); - } - - private static Arbitrary, P2>> arbMapStateF( - Coarbitrary coarbInitS, - Coarbitrary coarbInitValue, - Arbitrary arbNextS, - Arbitrary arbNextValue) { - - return arbF(coarbP2(coarbInitS, coarbInitValue), arbP2(arbNextS, arbNextValue)); - } - - private static Arbitrary> arbState( - Coarbitrary coarbInitS, - Arbitrary arbNextS, - Arbitrary arbValue) { - - Arbitrary>> arbRunF = arbRunF(coarbInitS, arbNextS, arbValue); - return arbitrary(Gen.gen(s -> r -> State.unit(arbRunF.gen.gen(s, r)))); - } - - private static final int HUGE_SIZE = 10000; - - private static Arbitrary> arbHugeState( - Arbitrary> arbInitState, - F, Arbitrary>> nextArbStateF) { - - return arbitrary(Gen.gen(s -> r -> range(0, HUGE_SIZE).foldLeft( - (acc, x) -> nextArbStateF.f(acc).gen.gen(s, r), - arbInitState.gen.gen(s, r)))); - } - } From 09b6713407a2f3e2d1eb2c2ebd72c402a8797262 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Sun, 12 Jun 2016 17:30:17 -0500 Subject: [PATCH 088/336] Implemented Equal, Hash, Arbitrary, and Shrink for Natural as well as the equals, hashCode and toString methods on Natural. Also fixed the subtract method on Natural as well as the Javadoc on the Natural Semigroup for addition. --- core/src/main/java/fj/Equal.java | 5 ++++ core/src/main/java/fj/Hash.java | 6 +++++ core/src/main/java/fj/Semigroup.java | 2 +- core/src/main/java/fj/data/Natural.java | 23 ++++++++++++++++++- .../src/main/java/fj/test/Arbitrary.java | 15 +++++++++++- quickcheck/src/main/java/fj/test/Shrink.java | 7 ++++++ 6 files changed, 55 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 2282b04e..465959e9 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -149,6 +149,11 @@ public static Equal anyEqual() { */ public static final Equal shortEqual = anyEqual(); + /** + * An equal instance for the Natural type. + */ + public static final Equal naturalEqual = bigintEqual.contramap(Natural::bigIntegerValue); + /** * An equal instance for the {@link String} type. */ diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 3e6c0ae8..14f8a9d7 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -115,6 +115,11 @@ public static Hash anyHash() { */ public static final Hash bigdecimalHash = anyHash(); + /** + * A hash instance for the {@link Natural} type. + */ + public static final Hash naturalHash = bigintHash.contramap(Natural::bigIntegerValue); + /** * A hash instance for the String type. */ @@ -535,4 +540,5 @@ public static Hash> v7Hash(final Hash ea) { public static Hash> v8Hash(final Hash ea) { return streamHash(ea).contramap(V8.toStream_()); } + } diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 1427f0e5..7c5538f2 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -219,7 +219,7 @@ public static Semigroup semigroup(final F2 sum) { semigroup(Natural::multiply); /** - * A semigroup that multiplies natural numbers. + * A semigroup that adds natural numbers. */ public static final Semigroup naturalAdditionSemigroup = semigroup(Natural::add); diff --git a/core/src/main/java/fj/data/Natural.java b/core/src/main/java/fj/data/Natural.java index 23080a49..e52f77ca 100644 --- a/core/src/main/java/fj/data/Natural.java +++ b/core/src/main/java/fj/data/Natural.java @@ -1,11 +1,16 @@ package fj.data; import static fj.Bottom.error; + +import fj.Equal; import fj.F; import static fj.Monoid.naturalAdditionMonoid; import static fj.Monoid.naturalMultiplicationMonoid; import static fj.Function.curry; + +import fj.Hash; +import fj.Show; import fj.data.vector.V2; import fj.data.vector.V; @@ -121,7 +126,7 @@ public Natural add(final Natural n) { * @return The difference between the two numbers, if this number is larger than the given one. Otherwise none. */ public Option subtract(final Natural n) { - return natural(n.value.subtract(value)); + return natural(value.subtract(n.value)); } /** @@ -286,4 +291,20 @@ public static Natural sum(final List ns) { public static Natural product(final List ns) { return naturalMultiplicationMonoid.sumLeft(ns); } + + + @Override + public int hashCode() { + return Hash.naturalHash.hash(this); + } + + @Override + public boolean equals(final Object that) { + return Equal.equals0(Natural.class, this, that, Equal.naturalEqual); + } + + @Override + public String toString() { + return Show.naturalShow.showS(this); + } } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index d8f88bed..ad671018 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -1,6 +1,8 @@ package fj.test; +import fj.Equal; import fj.F; +import fj.F1Functions; import fj.F2; import fj.F3; import fj.F4; @@ -11,6 +13,7 @@ import fj.Function; import fj.Bottom; +import static fj.Equal.longEqual; import static fj.Function.compose; import static fj.P.p; @@ -37,9 +40,12 @@ import fj.data.List; import fj.data.Set; import fj.data.TreeMap; +import fj.function.Booleans; import fj.function.Effect1; +import fj.function.Longs; import static fj.data.Stream.range; +import static fj.function.Booleans.not; import static fj.test.Gen.choose; import static fj.test.Gen.elements; import static fj.test.Gen.fail; @@ -469,6 +475,12 @@ public Gen f(final Integer i) { } }); + /** + * An arbitrary implementation for naturals. + */ + public static final Gen arbNatural = arbLong.filter(not(longEqual.eq(Long.MIN_VALUE))) + .map(Longs.abs).map(Natural::natural).map(o -> o.some()); + /** * An arbitrary implementation for character values. */ @@ -760,7 +772,7 @@ public static Gen> arbArrayList(final Gen aa) { /** * Returns an arbitrary implementation for a Java enumeration. * - * @param clazz The type of enum to return an arbtrary of. + * @param clazz The type of enum to return an arbitrary of. * @return An arbitrary for instances of the supplied enum type. */ public static > Gen arbEnumValue(final Class clazz) { @@ -1337,4 +1349,5 @@ public static Gen> arbP5(final Gen aa, fina return aa.bind(ab, ac, ad, ae, af, ag, ah, a -> b -> c -> d -> e -> f -> g -> h -> p(a, b, c, d, e, f, g, h)); } + } diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 2a2f0061..04fa6184 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -30,6 +30,7 @@ import fj.data.Either; import fj.data.Java; import fj.data.List; +import fj.data.Natural; import fj.data.Option; import fj.data.Stream; @@ -181,6 +182,11 @@ public static Shrink empty() { */ public static final Shrink shrinkDouble = shrinkLong.map(Long_Double, Double_Long); + /** + * A shrink strategy for naturals. + */ + public static final Shrink shrinkNatural = shrinkLong.map(l -> Natural.natural(l).orSome(Natural.ZERO), Natural::longValue); + /** * Returns a shrink strategy for optional values. A 'no value' is already fully * shrunk, otherwise, the shrinking occurs on the value with the given shrink strategy. @@ -846,4 +852,5 @@ public static Shrink> shrinkP5(final Shrink sg.shrink(p._7()), sh.shrink(p._8()), p8); }); } + } From 9e5b6ad23fa0ef0d9f1784396bfd86758f6b9215 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 15 Jun 2016 22:02:52 +0200 Subject: [PATCH 089/336] Remove unnecessary indirection in Equal#eq partial application. --- core/src/main/java/fj/Equal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 465959e9..a09dceba 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -65,7 +65,7 @@ public F2 eq() { * @return A function that returns true if the given argument equals the argument to this method. */ public F eq(final A a) { - return a1 -> eq(a, a1); + return f.f(a); } /** From 03308243564d722e665de1d2f80fbfcbf449f891 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 15 Jun 2016 21:38:09 -0500 Subject: [PATCH 090/336] Fixed issue #276 by modifying the BigInteger Shrink implementation to use the same logic as the Shrink implementation for Long. Also fixed some Javadoc typos. --- quickcheck/src/main/java/fj/test/Shrink.java | 47 ++++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 04fa6184..7990401e 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -39,6 +39,8 @@ import static fj.data.Stream.nil; import static java.lang.System.arraycopy; +import static java.math.BigInteger.ZERO; + import java.math.BigDecimal; import java.math.BigInteger; import java.sql.Time; @@ -354,7 +356,7 @@ public static Shrink> shrinkArrayList(final Shrink sa) { * A shrink strategy for enum maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for enum maps. */ public static , V> Shrink> shrinkEnumMap(final Shrink sk, final Shrink sv) { @@ -385,7 +387,7 @@ public static > Shrink> shrinkEnumSet(final Shrink< * A shrink strategy for hash maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for hash maps. */ public static Shrink> shrinkHashMap(final Shrink sk, final Shrink sv) { @@ -406,7 +408,7 @@ public static Shrink> shrinkHashSet(final Shrink sa) { * A shrink strategy for hash tables. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for hash tables. */ @SuppressWarnings("UseOfObsoleteCollectionType") @@ -430,7 +432,7 @@ public static Shrink> shrinkHashtable(final Shrink sk, * A shrink strategy for identity hash maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for identity hash maps. */ public static Shrink> shrinkIdentityHashMap(final Shrink sk, final Shrink sv) { @@ -441,7 +443,7 @@ public static Shrink> shrinkIdentityHashMap(final S * A shrink strategy for linked hash maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for linked hash maps. */ public static Shrink> shrinkLinkedHashMap(final Shrink sk, final Shrink sv) { @@ -514,7 +516,7 @@ public static Shrink> shrinkStack(final Shrink sa) { * A shrink strategy for tree maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for tree maps. */ public static Shrink> shrinkTreeMap(final Shrink sk, final Shrink sv) { @@ -545,7 +547,7 @@ public static Shrink> shrinkVector(final Shrink sa) { * A shrink strategy for weak hash maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for weak hash maps. */ public static Shrink> shrinkWeakHashMap(final Shrink sk, final Shrink sv) { @@ -570,7 +572,7 @@ public static Shrink> shrinkArrayBlockingQueue(final S * A shrink strategy for concurrent hash maps. * * @param sk The shrink strategy for keys. - * @param sv The shrink stratgey for values. + * @param sv The shrink strategy for values. * @return A shrink strategy for concurrent hash maps. */ public static Shrink> shrinkConcurrentHashMap(final Shrink sk, final Shrink sv) { @@ -676,23 +678,20 @@ public static Shrink> shrinkSynchronousQueue(final Shrin /** * A shrink strategy for big integers. */ - public static final Shrink shrinkBigInteger = - shrinkP2(shrinkByte, shrinkArray(shrinkByte)).map(bs -> { - final byte[] x = new byte[bs._2().length() + 1]; - - for (int i = 0; i < bs._2().array().length; i++) { - x[i] = bs._2().get(i); - } - - x[bs._2().length()] = bs._1(); + public static final Shrink shrinkBigInteger = shrink(i -> { + final Equal eq = Equal.bigintEqual; + final BigInteger two = BigInteger.valueOf(2L); + if (eq.eq(i, ZERO)) { + return nil(); + } else { + final Stream is = cons(ZERO, + () -> iterate(x -> x.divide(two), i) + .takeWhile(x2 -> eq.notEq(x2, ZERO)) + .map(i::subtract)); - return new BigInteger(x); - }, i -> { - final byte[] b = i.toByteArray(); - final Byte[] x = new Byte[b.length - 1]; - arraycopy(b, 0, x, 0, b.length - 1); - return p(b[0], array(x)); - }); + return Ord.bigintOrd.isLessThan(i, ZERO) ? cons(i.negate(), () -> is) : is; + } + }); /** * A shrink strategy for big decimals. From 56508b6f8ddea5f0e233b9732557ab846688ac6b Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Wed, 15 Jun 2016 23:14:12 -0500 Subject: [PATCH 091/336] Switched the the Gen and Shrink implementations for Natural to use BigInteger instead of Long. This will allow for generation of Naturals that are larger than Long.MAX_VALUE. The implementations had to be moved within their respective classes to avoid forward reference compilation errors. --- quickcheck/src/main/java/fj/test/Arbitrary.java | 11 +++++------ quickcheck/src/main/java/fj/test/Shrink.java | 10 ++++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index ad671018..d7a62523 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -475,12 +475,6 @@ public Gen f(final Integer i) { } }); - /** - * An arbitrary implementation for naturals. - */ - public static final Gen arbNatural = arbLong.filter(not(longEqual.eq(Long.MIN_VALUE))) - .map(Longs.abs).map(Natural::natural).map(o -> o.some()); - /** * An arbitrary implementation for character values. */ @@ -1179,6 +1173,11 @@ public static Gen> arbSynchronousQueue(final Gen aa) // END java.math + /** + * An arbitrary implementation for naturals. + */ + public static final Gen arbNatural = arbBigInteger.map(BigInteger::abs).map(Natural::natural).map(o -> o.some()); + /** * An arbitrary implementation for locales. */ diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 7990401e..77c95381 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -184,10 +184,6 @@ public static Shrink empty() { */ public static final Shrink shrinkDouble = shrinkLong.map(Long_Double, Double_Long); - /** - * A shrink strategy for naturals. - */ - public static final Shrink shrinkNatural = shrinkLong.map(l -> Natural.natural(l).orSome(Natural.ZERO), Natural::longValue); /** * Returns a shrink strategy for optional values. A 'no value' is already fully @@ -701,6 +697,12 @@ public static Shrink> shrinkSynchronousQueue(final Shrin // END java.math + /** + * A shrink strategy for naturals. + */ + public static final Shrink shrinkNatural = shrinkBigInteger.map(l -> Natural.natural(l).orSome(Natural.ZERO), Natural::bigIntegerValue); + + /** * Returns a shrinking strategy for product-1 values. * From 6bd372ba515463051167ddc09f66f9c7641dc53c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 15:28:24 +1000 Subject: [PATCH 092/336] Added functional to PriorityQueue --- core/src/main/java/fj/data/PriorityQueue.java | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 67abdb88..18292768 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -3,6 +3,7 @@ import fj.Equal; import fj.F; import fj.Monoid; +import fj.Ord; import fj.P; import fj.P2; import fj.P3; @@ -41,10 +42,14 @@ public PriorityQueue map(F f) { ); } - public PriorityQueue filter(F f) { + public PriorityQueue filterValues(F f) { return priorityQueue(equal, ftree.filter(p2 -> f.f(p2._2()))); } + public PriorityQueue filterKeys(F f) { + return priorityQueue(equal, ftree.filter(p2 -> f.f(p2._1()))); + } + public boolean isEmpty() { return ftree.isEmpty(); } @@ -63,6 +68,22 @@ public PriorityQueue enqueue(List> list) { return list.foldLeft(pq -> p -> pq.enqueue(p._1(), p._2()), this); } + public boolean contains(final K k1) { + return !ftree.split(k2 -> equal.eq(k1, k2))._2().isEmpty(); + } + + public PriorityQueue enqueue(Iterable> it) { + PriorityQueue result = this; + for (P2 p: it) { + result = result.enqueue(p); + } + return result; + } + + public PriorityQueue enqueue(P2 p) { + return enqueue(p._1(), p._2()); + } + public PriorityQueue dequeue() { K top = ftree.measure(); P2>, FingerTree>> p = ftree.split(k -> equal.eq(k, top)); @@ -70,6 +91,10 @@ public PriorityQueue dequeue() { return right.isEmpty() ? this : priorityQueue(equal, p._1().append(right.tail())); } + public P2>, PriorityQueue> dequeueTop() { + return P.p(top(), dequeue()); + } + public PriorityQueue dequeue(int n) { int i = n; PriorityQueue result = this; @@ -80,8 +105,16 @@ public PriorityQueue dequeue(int n) { return result; } + public boolean isGreaterThan(Ord ok, K k) { + return top().map(p -> ok.isGreaterThan(k, p._1())).orSome(true); + } + public Stream> toStream() { - return ftree.toStream(); + return top().map(p -> Stream.cons(p, () -> dequeue().toStream())).orSome(() -> Stream.nil()); + } + + public List> toList() { + return toStream().toList(); } public String toString() { From 2a2b8eac96f2d2660987634fcf87394c0756b92c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 15:30:56 +1000 Subject: [PATCH 093/336] Added priority queue properties --- .../test/java/fj/data/PriorityQueueTest.java | 37 ------- .../properties/PriorityQueueProperties.java | 100 ++++++++++++++++++ 2 files changed, 100 insertions(+), 37 deletions(-) create mode 100644 props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java diff --git a/core/src/test/java/fj/data/PriorityQueueTest.java b/core/src/test/java/fj/data/PriorityQueueTest.java index 7e30cfc5..d7f532ed 100644 --- a/core/src/test/java/fj/data/PriorityQueueTest.java +++ b/core/src/test/java/fj/data/PriorityQueueTest.java @@ -14,42 +14,5 @@ */ public class PriorityQueueTest { - @Test - public void test1() { - PriorityQueue pq = PriorityQueue.emptyInt(); - PriorityQueue pq2 = pq.enqueue(List.list(p(1, 1))); - out.println(pq2.toString()); - } - - @Test - public void empty() { - PriorityQueue pq = PriorityQueue.emptyInt(); - assertThat(pq.isEmpty(), is(true)); - } - - @Test - public void top() { - PriorityQueue pq1 = PriorityQueue.emptyInt(); - Option> o = pq1.top(); - assertThat(o, is(Option.none())); - } - - @Test - public void dequeue() { - PriorityQueue pq1 = PriorityQueue.emptyInt().enqueue(List.list( - p(3, 6), p(10, 20), p(4, 8), p(1, 2) - )); - out.println(pq1); - assertThat(pq1.toString(), equalTo("PriorityQueue((3: 6), (10: 20), (4: 8), (1: 2))")); - - PriorityQueue pq2 = PriorityQueue.emptyInt(); - PriorityQueue pq3 = pq2.dequeue(); - out.println(pq3); - assertThat(pq3.toString(), equalTo("PriorityQueue()")); - - PriorityQueue pq4 = pq1.dequeue(); - out.println(pq4); - assertThat(pq4.toString(), equalTo("PriorityQueue((3: 6), (4: 8), (1: 2))")); - } } diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java new file mode 100644 index 00000000..92b45264 --- /dev/null +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -0,0 +1,100 @@ +package fj.data.properties; + +import fj.Ord; +import fj.P; +import fj.P2; +import fj.data.List; +import fj.data.Option; +import fj.data.PriorityQueue; +import fj.data.Set; +import fj.test.Arbitrary; +import fj.test.Property; +import fj.test.reflect.CheckParams; +import fj.test.runner.PropertyTestRunner; +import org.junit.runner.RunWith; + +import static fj.data.Option.some; +import static fj.data.PriorityQueue.emptyInt; +import static fj.test.Arbitrary.arbAlphaNumString; +import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbSet; +import static fj.test.Arbitrary.arbitrary; +import static fj.test.Property.impliesBoolean; +import static fj.test.Property.prop; +import static fj.test.Property.property; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * Created by MarkPerry on 18 Jun 16. + */ +@RunWith(PropertyTestRunner.class) +@CheckParams(maxSize = 100) +public class PriorityQueueProperties { + + public static Arbitrary> arbPriorityQueueIntegerString = arbUniqueQueue(arbAlphaNumString); + + public static Arbitrary> arbUniqueQueue(Arbitrary aa) { + Arbitrary> as = arbSet(Ord.intOrd, arbInteger); + Arbitrary> ints = arbitrary(as.gen.map(si -> si.toList())); + Arbitrary>> alp = arbitrary( + ints.gen.bind(li -> aa.gen.map(s -> li.map(i -> P.p(i, s)))) + ); + return arbitrary(alp.gen.map(l -> PriorityQueue.emptyInt().enqueue(l))); + } + + Property empty() { + PriorityQueue pq = emptyInt(); + return prop(pq.isEmpty()); + } + + Property addRemove() { + return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { + Option> o = q.top(); + Option> o2 = q.enqueue(i, s).dequeue().top(); + return Property.impliesBoolean( + q.isGreaterThan(Ord.intOrd, i), +// o.map(p -> i > p._1()).orSome(true), + () -> o.equals(o2) + ); + }); + } + + Property emptyTop() { + return prop(emptyInt().top().isNone()); + } + + Property addTop() { + return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { + Option> actual = q.enqueue(i, s).top(); + return impliesBoolean( + q.isGreaterThan(Ord.intOrd, i), +// q.top().map(p -> p._1() < i).orSome(true), + actual.equals(some(P.p(i, s)))); + }); + } + + Property sorted() { + Arbitrary> as = arbSet(Ord.intOrd, arbInteger); + Arbitrary> ints = arbitrary(as.gen.map(si -> si.toList())); + Arbitrary>> alp = arbitrary( + ints.gen.bind(li -> arbAlphaNumString.gen.map(s -> li.map(i -> P.p(i, s)))) + ); + return property(alp, list -> { + PriorityQueue q = PriorityQueue.emptyInt().enqueue(list); + List> expected = list.sort(Ord.p2Ord1(Ord.intOrd.reverse())); + List> actual = q.toStream().toList(); + assertThat(actual, equalTo(expected)); + System.out.println(actual); + return prop(actual.equals(expected)); + }); + } + + public Property sorted2() { + return property(arbPriorityQueueIntegerString, pq -> { + List> expected = pq.toList().sort(Ord.p2Ord1(Ord.intOrd.reverse())); + return prop(expected.equals(pq.toList())); + }); + } + +} From 1a7f3e672cfeeaf6fc3de66fdeeecbf671fd973a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 15:31:24 +1000 Subject: [PATCH 094/336] Added finger tree toStream property? --- .../fj/data/fingertrees/FingerTreeProperties.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java index a4265be6..b7ed83f5 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java @@ -1,5 +1,7 @@ package fj.data.fingertrees; +import fj.P2; +import fj.data.Stream; import fj.test.Property; import fj.test.reflect.CheckParams; import fj.test.runner.PropertyTestRunner; @@ -17,10 +19,18 @@ @CheckParams(maxSize = 10000) public class FingerTreeProperties { - public Property size() { + Property size() { return property(arbList(arbInteger), list -> prop(list.foldLeft((acc, i) -> acc.snoc(i), FingerTree.emptyIntAddition()).length() == list.length()) ); } + Property stream() { + return property(arbList(arbInteger), list -> { + Stream s1 = list.foldLeft((acc, i) -> acc.snoc(i), FingerTree.emptyIntAddition()).toStream(); + Stream s2 = list.toStream(); + return prop(s1.equals(s2)); + }); + } + } From e0839e19d59d54cac5d2f02681c9a839d29c38e5 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 17:39:28 +1000 Subject: [PATCH 095/336] Merge in upstream changes to remove arbitrary wrapper --- .../properties/PriorityQueueProperties.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index 92b45264..9f4be0da 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -8,6 +8,7 @@ import fj.data.PriorityQueue; import fj.data.Set; import fj.test.Arbitrary; +import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; import fj.test.runner.PropertyTestRunner; @@ -18,7 +19,6 @@ import static fj.test.Arbitrary.arbAlphaNumString; import static fj.test.Arbitrary.arbInteger; import static fj.test.Arbitrary.arbSet; -import static fj.test.Arbitrary.arbitrary; import static fj.test.Property.impliesBoolean; import static fj.test.Property.prop; import static fj.test.Property.property; @@ -32,15 +32,15 @@ @CheckParams(maxSize = 100) public class PriorityQueueProperties { - public static Arbitrary> arbPriorityQueueIntegerString = arbUniqueQueue(arbAlphaNumString); + public static Gen> arbPriorityQueueIntegerString = arbUniqueQueue(arbAlphaNumString); - public static Arbitrary> arbUniqueQueue(Arbitrary aa) { - Arbitrary> as = arbSet(Ord.intOrd, arbInteger); - Arbitrary> ints = arbitrary(as.gen.map(si -> si.toList())); - Arbitrary>> alp = arbitrary( - ints.gen.bind(li -> aa.gen.map(s -> li.map(i -> P.p(i, s)))) + public static Gen> arbUniqueQueue(Gen aa) { + Gen> as = arbSet(Ord.intOrd, arbInteger); + Gen> ints = (as.map(si -> si.toList())); + Gen>> alp = ( + ints.bind(li -> aa.map(s -> li.map(i -> P.p(i, s)))) ); - return arbitrary(alp.gen.map(l -> PriorityQueue.emptyInt().enqueue(l))); + return (alp.map(l -> PriorityQueue.emptyInt().enqueue(l))); } Property empty() { @@ -75,10 +75,10 @@ Property addTop() { } Property sorted() { - Arbitrary> as = arbSet(Ord.intOrd, arbInteger); - Arbitrary> ints = arbitrary(as.gen.map(si -> si.toList())); - Arbitrary>> alp = arbitrary( - ints.gen.bind(li -> arbAlphaNumString.gen.map(s -> li.map(i -> P.p(i, s)))) + Gen> as = arbSet(Ord.intOrd, arbInteger); + Gen> ints = (as.map(si -> si.toList())); + Gen>> alp = ( + ints.bind(li -> arbAlphaNumString.map(s -> li.map(i -> P.p(i, s)))) ); return property(alp, list -> { PriorityQueue q = PriorityQueue.emptyInt().enqueue(list); From e3d8fce63b2587d3fae0a769c82b00b8311dfc7d Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 20:31:59 +1000 Subject: [PATCH 096/336] Added priority queue and related methods javadoc --- core/src/main/java/fj/Monoid.java | 15 ++++- core/src/main/java/fj/data/PriorityQueue.java | 66 ++++++++++++++++++- .../java/fj/data/fingertrees/FingerTree.java | 12 ++++ .../test/java/fj/data/PriorityQueueTest.java | 18 ----- .../properties/PriorityQueueProperties.java | 39 +++++------ 5 files changed, 107 insertions(+), 43 deletions(-) delete mode 100644 core/src/test/java/fj/data/PriorityQueueTest.java diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index d9bf40b5..3436d5a3 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -401,8 +401,14 @@ public static Monoid> ioMonoid(final Monoid ma) { return monoid(Semigroup.ioSemigroup(ma.semigroup()), IOFunctions.unit(ma.zero())); } + /** + * A monoid for the maximum of two integers. + */ public static final Monoid intMaxMonoid = monoid(Semigroup.intMaximumSemigroup, Integer.MIN_VALUE); + /** + * A monoid for the minimum of two integers. + */ public static final Monoid intMinMonoid = monoid(Semigroup.intMinimumSemigroup, Integer.MAX_VALUE); /** @@ -420,7 +426,14 @@ public static Monoid> setMonoid(final Ord o) { return monoid(Semigroup.setSemigroup(), Set.empty(o)); } - public static Monoid ordMonoid(Ord o, A zero) { + + /** + * A monoid for the maximum of elements with ordering o. + * + * @param o An ordering of elements. + * @param zero The minimum element. + */ + public static Monoid ordMaxMonoid(final Ord o, final A zero) { return monoid(o.max, zero); } diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 18292768..51abcabf 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -11,6 +11,8 @@ import fj.data.fingertrees.FingerTree; /** + * A priority queue implementation backed by a {@link fj.data.fingertrees.FingerTree}. The finger tree nodes are annotated with type K, are combined using a monoid of K and both the key and value are stored in the leaf. Priorities of the same value are returned FIFO (first in, first out). + * * Created by MarkPerry on 31 May 16. */ public class PriorityQueue { @@ -23,18 +25,33 @@ private PriorityQueue(Equal e, FingerTree> ft) { ftree = ft; } + /** + * Creates a priority queue from a finger tree. + */ public static PriorityQueue priorityQueue(Equal e, FingerTree> ft) { return new PriorityQueue(e, ft); } + /** + * Creates an empty priority queue. + * + * @param m A monoid to combine node annotations. + * @param e A value to compare key equality. + */ public static PriorityQueue empty(Monoid m, Equal e) { return priorityQueue(e, FingerTree.empty(m, (P2 p) -> p._1())); } + /** + * An empty priority queue with integer priorities. + */ public static PriorityQueue emptyInt() { return priorityQueue(Equal.intEqual, FingerTree.empty(Monoid.intMaxMonoid, (P2 p) -> p._1())); } + /** + * Maps the values in each node with function f. + */ public PriorityQueue map(F f) { return priorityQueue(equal, ftree.map(p2 -> p2.map2(a -> f.f(a)), @@ -42,36 +59,60 @@ public PriorityQueue map(F f) { ); } + /** + * Filters nodes based on the value inside each node. + */ public PriorityQueue filterValues(F f) { return priorityQueue(equal, ftree.filter(p2 -> f.f(p2._2()))); } + /** + * Filters the nodes based on the annotation of each node. + */ public PriorityQueue filterKeys(F f) { return priorityQueue(equal, ftree.filter(p2 -> f.f(p2._1()))); } + /** + * Is the tree empty? + */ public boolean isEmpty() { return ftree.isEmpty(); } + /** + * If the tree is not empty, returns the node with highest priority otherwise returns nothing. + */ public Option> top() { K top = ftree.measure(); P2>, FingerTree>> p = ftree.split(k -> equal.eq(top, k)); return p._2().headOption(); } + /** + * Adds a node with priority k and value a. This operation take O(1). + */ public PriorityQueue enqueue(K k, A a) { return priorityQueue(equal, ftree.snoc(P.p(k, a))); } + /** + * Adds nodes using the list of products with priority k and value a. This operation takes O(list.length()). + */ public PriorityQueue enqueue(List> list) { return list.foldLeft(pq -> p -> pq.enqueue(p._1(), p._2()), this); } - public boolean contains(final K k1) { - return !ftree.split(k2 -> equal.eq(k1, k2))._2().isEmpty(); + /** + * Does the priority k exist already? + */ + public boolean contains(final K k) { + return !ftree.split(k2 -> equal.eq(k, k2))._2().isEmpty(); } + /** + * Adds nodes using the iterable of products with priority k and value a. + */ public PriorityQueue enqueue(Iterable> it) { PriorityQueue result = this; for (P2 p: it) { @@ -80,10 +121,16 @@ public PriorityQueue enqueue(Iterable> it) { return result; } + /** + * Adds a node with priority k and value a. This operation take O(1). + */ public PriorityQueue enqueue(P2 p) { return enqueue(p._1(), p._2()); } + /** + * Removes the node with the highest priority. + */ public PriorityQueue dequeue() { K top = ftree.measure(); P2>, FingerTree>> p = ftree.split(k -> equal.eq(k, top)); @@ -91,10 +138,16 @@ public PriorityQueue dequeue() { return right.isEmpty() ? this : priorityQueue(equal, p._1().append(right.tail())); } + /** + * Returns a tuple of the node with the highest priority and the rest of the priority queue. + */ public P2>, PriorityQueue> dequeueTop() { return P.p(top(), dequeue()); } + /** + * Removes the top n elements with the highest priority. + */ public PriorityQueue dequeue(int n) { int i = n; PriorityQueue result = this; @@ -105,14 +158,23 @@ public PriorityQueue dequeue(int n) { return result; } + /** + * Does the priority k have greater priority than the top of the queue? + */ public boolean isGreaterThan(Ord ok, K k) { return top().map(p -> ok.isGreaterThan(k, p._1())).orSome(true); } + /** + * Returns a stream of products with priority k and value a. + */ public Stream> toStream() { return top().map(p -> Stream.cons(p, () -> dequeue().toStream())).orSome(() -> Stream.nil()); } + /** + * Returns a list of products with priority k and value a. + */ public List> toList() { return toStream().toList(); } diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index aa72f020..ee985611 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -231,10 +231,22 @@ public static FingerTree emptyIntAddition() { return empty(intAdditionMonoid, Function.constant(1)); } + /** + * Creates an empty finger tree with elements of type A and node annotations + * of type V. + * + * @param m A monoid to combine node annotations + * @param f Function to convert node element to annotation. + * @return An empty finger tree. + */ public static FingerTree empty(Monoid m, F f) { return FingerTree.mkTree(measured(m, f)).empty(); } + /** + * Returns a finger tree which combines the integer node annotations with the + * maximum function. A priority queue with integer priorities. + */ public static FingerTree> emptyIntMax() { return empty(intMaxMonoid, (P2 p) -> p._1()); } diff --git a/core/src/test/java/fj/data/PriorityQueueTest.java b/core/src/test/java/fj/data/PriorityQueueTest.java deleted file mode 100644 index d7f532ed..00000000 --- a/core/src/test/java/fj/data/PriorityQueueTest.java +++ /dev/null @@ -1,18 +0,0 @@ -package fj.data; - -import fj.P2; -import org.junit.Test; - -import static fj.P.p; -import static java.lang.System.out; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -/** - * Created by MarkPerry on 1 Jun 16. - */ -public class PriorityQueueTest { - - -} diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index 9f4be0da..aae27f67 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -7,7 +7,6 @@ import fj.data.Option; import fj.data.PriorityQueue; import fj.data.Set; -import fj.test.Arbitrary; import fj.test.Gen; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -22,8 +21,6 @@ import static fj.test.Property.impliesBoolean; import static fj.test.Property.prop; import static fj.test.Property.property; -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; /** * Created by MarkPerry on 18 Jun 16. @@ -34,6 +31,9 @@ public class PriorityQueueProperties { public static Gen> arbPriorityQueueIntegerString = arbUniqueQueue(arbAlphaNumString); + /** + * Returns a queue with unique integer priorities. + */ public static Gen> arbUniqueQueue(Gen aa) { Gen> as = arbSet(Ord.intOrd, arbInteger); Gen> ints = (as.map(si -> si.toList())); @@ -48,49 +48,44 @@ Property empty() { return prop(pq.isEmpty()); } + /** + * Adding a priority that is at the top and then removing it returns the original top. + */ Property addRemove() { return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { Option> o = q.top(); Option> o2 = q.enqueue(i, s).dequeue().top(); return Property.impliesBoolean( q.isGreaterThan(Ord.intOrd, i), -// o.map(p -> i > p._1()).orSome(true), () -> o.equals(o2) ); }); } + /** + * An empty queue has no top. + */ Property emptyTop() { return prop(emptyInt().top().isNone()); } + /** + * Adding a value with the highest priority makes it the top item. + */ Property addTop() { return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { Option> actual = q.enqueue(i, s).top(); return impliesBoolean( q.isGreaterThan(Ord.intOrd, i), -// q.top().map(p -> p._1() < i).orSome(true), actual.equals(some(P.p(i, s)))); }); } - Property sorted() { - Gen> as = arbSet(Ord.intOrd, arbInteger); - Gen> ints = (as.map(si -> si.toList())); - Gen>> alp = ( - ints.bind(li -> arbAlphaNumString.map(s -> li.map(i -> P.p(i, s)))) - ); - return property(alp, list -> { - PriorityQueue q = PriorityQueue.emptyInt().enqueue(list); - List> expected = list.sort(Ord.p2Ord1(Ord.intOrd.reverse())); - List> actual = q.toStream().toList(); - assertThat(actual, equalTo(expected)); - System.out.println(actual); - return prop(actual.equals(expected)); - }); - } - - public Property sorted2() { + /** + * Sorting a list returns the same as putting the list into a priority queue and getting + * the queue as a list. + */ + public Property sorted() { return property(arbPriorityQueueIntegerString, pq -> { List> expected = pq.toList().sort(Ord.p2Ord1(Ord.intOrd.reverse())); return prop(expected.equals(pq.toList())); From c9788d4a21c90444e06914ca834e2aa6f51bc72c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 22:14:13 +1000 Subject: [PATCH 097/336] Make sorting a list stable --- core/src/main/java/fj/data/List.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 2b1a728e..d1f5ae63 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -962,7 +962,7 @@ List merge(List xs, List ys, final Ord o) { final A x = xs.head(); final A y = ys.head(); - if (o.isLessThan(x, y)) { + if (o.isLessThan(x, y) || o.eq(x, y)) { buf.snoc(x); xs = xs.tail(); } else { From 72d980f73cb053723a000fa0cae85accc1207075 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 22:15:35 +1000 Subject: [PATCH 098/336] Added priority queue top N, equal to top, greater than top --- core/src/main/java/fj/data/PriorityQueue.java | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 51abcabf..0559ca00 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -10,6 +10,8 @@ import fj.Show; import fj.data.fingertrees.FingerTree; +import static fj.data.List.list; + /** * A priority queue implementation backed by a {@link fj.data.fingertrees.FingerTree}. The finger tree nodes are annotated with type K, are combined using a monoid of K and both the key and value are stored in the leaf. Priorities of the same value are returned FIFO (first in, first out). * @@ -89,6 +91,16 @@ public Option> top() { return p._2().headOption(); } + public List> topN() { + Stream> s = toStream(); + if (s.isEmpty()) { + return List.nil(); + } else { + final K k = s.head()._1(); + return s.takeWhile(p -> equal.eq(k, p._1())).toList(); + } + } + /** * Adds a node with priority k and value a. This operation take O(1). */ @@ -159,10 +171,18 @@ public PriorityQueue dequeue(int n) { } /** - * Does the priority k have greater priority than the top of the queue? + * Does the top of the queue have lower priority than k? */ + public boolean isLessThan(Ord ok, K k) { + return top().map(p -> ok.isLessThan(p._1(), k)).orSome(true); + } + public boolean isGreaterThan(Ord ok, K k) { - return top().map(p -> ok.isGreaterThan(k, p._1())).orSome(true); + return top().map(p -> ok.isGreaterThan(p._1(), k)).orSome(false); + } + + public boolean isEqual(Ord ok, K k) { + return top().map(p -> ok.eq(p._1(), k)).orSome(false); } /** From e5bc0e1bddb3df23966077bab0b6b67fcb1b41b2 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 22:16:11 +1000 Subject: [PATCH 099/336] FIFO priority queue properties where the key is equal to the top key --- .../properties/PriorityQueueProperties.java | 48 ++++++++++++++----- 1 file changed, 36 insertions(+), 12 deletions(-) diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index aae27f67..ba387cad 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -17,10 +17,14 @@ import static fj.data.PriorityQueue.emptyInt; import static fj.test.Arbitrary.arbAlphaNumString; import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbList; +import static fj.test.Arbitrary.arbP2; import static fj.test.Arbitrary.arbSet; import static fj.test.Property.impliesBoolean; import static fj.test.Property.prop; import static fj.test.Property.property; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; /** * Created by MarkPerry on 18 Jun 16. @@ -29,7 +33,7 @@ @CheckParams(maxSize = 100) public class PriorityQueueProperties { - public static Gen> arbPriorityQueueIntegerString = arbUniqueQueue(arbAlphaNumString); + public static Gen> arbPriorityQueueIntegerString = arbQueue(arbAlphaNumString); /** * Returns a queue with unique integer priorities. @@ -43,6 +47,11 @@ public static Gen> arbUniqueQueue(Gen aa) { return (alp.map(l -> PriorityQueue.emptyInt().enqueue(l))); } + public static Gen> arbQueue(Gen aa) { + Gen>> g = arbList(arbP2(arbInteger, aa)); + return g.map(l -> PriorityQueue.emptyInt().enqueue(l)); + } + Property empty() { PriorityQueue pq = emptyInt(); return prop(pq.isEmpty()); @@ -53,11 +62,10 @@ Property empty() { */ Property addRemove() { return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { - Option> o = q.top(); - Option> o2 = q.enqueue(i, s).dequeue().top(); - return Property.impliesBoolean( - q.isGreaterThan(Ord.intOrd, i), - () -> o.equals(o2) + Option> t1 = q.top(); + Option> t2 = q.enqueue(i, s).dequeue().top(); + return prop(q.isLessThan(Ord.intOrd, i) ? + t1.equals(t2) : t2.map(p -> p._1() >= i).orSome(true) ); }); } @@ -75,20 +83,36 @@ Property emptyTop() { Property addTop() { return property(arbPriorityQueueIntegerString, arbInteger, arbAlphaNumString, (q, i, s) -> { Option> actual = q.enqueue(i, s).top(); - return impliesBoolean( - q.isGreaterThan(Ord.intOrd, i), - actual.equals(some(P.p(i, s)))); + return prop(q.isLessThan(Ord.intOrd, i) ? actual.equals(some(P.p(i, s))) : actual.equals(q.top())); }); } /** - * Sorting a list returns the same as putting the list into a priority queue and getting - * the queue as a list. + * Sorting a list returns the same as putting the list into a priority queue and getting the queue as a list. */ public Property sorted() { return property(arbPriorityQueueIntegerString, pq -> { List> expected = pq.toList().sort(Ord.p2Ord1(Ord.intOrd.reverse())); - return prop(expected.equals(pq.toList())); + List> actual = pq.toList(); + assertThat(actual, equalTo(expected)); + return prop(actual.equals(expected)); + }); + } + + /** + * Where the top n of the queue has just one element then: + * - Enqueueing and then topN of the queue should return a list of the top and the new item + * - Enqueuing and then dequeueing and then topping the queue should return the new item + */ + Property singleTopSame() { + return property(arbPriorityQueueIntegerString, arbAlphaNumString, (pq, s) -> { + Option o1 = pq.top().map(p -> p._1()); + return o1.map(j -> { + boolean b = pq.topN().length() == 1; + Property p1 = impliesBoolean(b, () -> pq.enqueue(j, s).dequeue().top().equals(some(P.p(j, s)))); + Property p2 = impliesBoolean(b, () -> pq.enqueue(j, s).topN().equals(List.list(pq.top().some(), P.p(j, s)))); + return p1.and(p2); + }).orSome(prop(true)); }); } From fc9f9bd0a5b7a933d5ec6b4c726aaf9928672ef9 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 18 Jun 2016 23:07:56 +1000 Subject: [PATCH 100/336] Added Ord.isLessThanOrEqualTo to Ord --- core/src/main/java/fj/Ord.java | 13 +++++++++++++ core/src/main/java/fj/data/List.java | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 41b87f94..e9fb2d4b 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -92,6 +92,19 @@ public boolean isLessThan(final A a1, final A a2) { return compare(a1, a2) == Ordering.LT; } + /** + * Returns true if the first given argument is less than or equal to the second given argument, + * false otherwise. + * + * @param a1 An instance to compare for ordering to another. + * @param a2 An instance to compare for ordering to another. + * @return true if the first given argument is less than or equal to the second given argument, + * false otherwise. + */ + public boolean isLessThanOrEqualTo(final A a1, final A a2) { + return isLessThan(a1, a2) || eq(a1, a2); + } + /** * Returns true if the first given argument is greater than the second given * argument, false otherwise. diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index d1f5ae63..c2d21b06 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -962,7 +962,7 @@ List merge(List xs, List ys, final Ord o) { final A x = xs.head(); final A y = ys.head(); - if (o.isLessThan(x, y) || o.eq(x, y)) { + if (o.isLessThanOrEqualTo(x, y)) { buf.snoc(x); xs = xs.tail(); } else { From 50433620e595ee70ab6aaa74ca6bed243b6ad382 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Tue, 7 Jun 2016 22:01:00 -0400 Subject: [PATCH 101/336] Add test for IO --- core/src/test/java/fj/IOTest.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 core/src/test/java/fj/IOTest.java diff --git a/core/src/test/java/fj/IOTest.java b/core/src/test/java/fj/IOTest.java new file mode 100644 index 00000000..f965204c --- /dev/null +++ b/core/src/test/java/fj/IOTest.java @@ -0,0 +1,30 @@ +package fj; + +import fj.data.IO; +import fj.data.IOFunctions; +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.StringReader; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + + +public class IOTest { + + @Test + public void testLift() throws IOException { + final IO readName = () -> new BufferedReader(new StringReader("foo")).readLine(); + final F> upperCaseAndPrint = F1Functions., String>o(this::println).f(String::toUpperCase); + final IO readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint); + assertThat(readAndPrintUpperCasedName.run(), is("FOO")); + } + + public IO println(final String s) { + return () -> { + return s; + }; + } +} From 371831331cdc41486c0814f801e497ab12a26ed6 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 19 Jun 2016 23:58:40 +1000 Subject: [PATCH 102/336] Added asserts, remove commented out and printlns from FingerTreeTest --- .../fj/data/fingertrees/FingerTreeTest.java | 40 +++++-------------- 1 file changed, 10 insertions(+), 30 deletions(-) diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 901c9c89..2a64b44b 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -20,6 +20,8 @@ */ public class FingerTreeTest { + public static final int SIZE = 10; + @Test public void size() { validateSize(List.list(-92, 68, 54, -77, -18, 67)); @@ -36,20 +38,11 @@ void validateSize(List list) { public FingerTree midSeq() { FingerTree ft = FingerTree.emptyIntAddition(); - // out.println(ft.toString()); - return List.range(1, 10).foldLeft(ft2 -> i -> { - FingerTree ft3 = ft2.snoc(i); -// out.println(ft3.toString()); - return ft3; - }, ft); + return List.range(1, SIZE).foldLeft(ft2 -> i -> ft2.snoc(i), ft); } - - @Test public void testSeqString() { -// FingerTree ft = FingerTree.emptyIntAddition(); -// out.println(ft.toString()); String actual = midSeq().toString(); String expected = "Deep(9 -> One(1 -> 1), Deep(6 -> One(3 -> Node3(3 -> V3(2,3,4))), Empty(), One(3 -> Node3(3 -> V3(5,6,7)))), Two(2 -> V2(8,9)))"; assertThat(actual, equalTo(expected)); @@ -57,47 +50,34 @@ public void testSeqString() { public FingerTree> midPriorityQueue() { FingerTree> ft = FingerTree.emptyIntMax(); -// out.println(ft.toString()); - return List.range(1, 10).foldLeft(ft2 -> i -> { + return List.range(1, SIZE).foldLeft(ft2 -> i -> { int j = i % 2 == 0 ? 2 * i : i; FingerTree> ft3 = ft2.snoc(P.p(j, j)); -// out.println(ft3.toString()); return ft3; }, ft); } @Test public void testQueueString() { -// FingerTree> ft = FingerTree.emptyIntMax(); -// out.println(ft.toString()); String actual = midPriorityQueue().toString(); String expected = "Deep(16 -> One(1 -> (1,1)), Deep(12 -> One(8 -> Node3(8 -> V3((4,4),(3,3),(8,8)))), Empty(), One(12 -> Node3(12 -> V3((5,5),(12,12),(7,7))))), Two(16 -> V2((16,16),(9,9))))"; assertThat(actual, equalTo(expected)); - } @Test public void stream() { FingerTree ft = midSeq(); - out.println(ft); - Stream s = ft.toStream(); - System.out.println(s.toList()); - - out.println(midPriorityQueue()); - out.println(midPriorityQueue().toStream().toList()); + assertThat(ft.toStream().toList(), equalTo(List.range(1, SIZE))); } @Test public void split() { - + int splitPoint = 3; FingerTree ft = FingerTree.emptyIntAddition(); - FingerTree ft3 = List.range(1, 10).foldLeft(ft2 -> i -> ft2.snoc(i), ft); - P2, FingerTree> p = ft3.split(v -> v >= 3); - Show> fts = Show.fingerTreeShow(intShow, intShow); - Show, FingerTree>> s = Show.p2Show(fts, fts); - System.out.println(s.showS(p)); - System.out.println(p); - + FingerTree ft3 = List.range(1, SIZE).foldLeft(ft2 -> i -> ft2.snoc(i), ft); + P2, FingerTree> p = ft3.split(v -> v >= splitPoint); + assertThat(p._1().toStream().toList(), equalTo(List.range(1, splitPoint))); + assertThat(p._2().toStream().toList(), equalTo(List.range(splitPoint, SIZE))); } From a506f0619cffc9a4b0820ada03f69012280195b4 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 20 Jun 2016 00:15:03 +1000 Subject: [PATCH 103/336] Implemented suggestons from @jbgi for PriorityQueue --- core/src/main/java/fj/data/PriorityQueue.java | 24 ++++++++++++------- .../properties/PriorityQueueProperties.java | 1 - 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 0559ca00..49d185c9 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -13,11 +13,15 @@ import static fj.data.List.list; /** - * A priority queue implementation backed by a {@link fj.data.fingertrees.FingerTree}. The finger tree nodes are annotated with type K, are combined using a monoid of K and both the key and value are stored in the leaf. Priorities of the same value are returned FIFO (first in, first out). + * A priority queue implementation backed by a + * {@link fj.data.fingertrees.FingerTree}. The finger tree nodes are + * annotated with type K, are combined using a monoid of K and both the + * key and value are stored in the leaf. Priorities of the same value + * are returned FIFO (first in, first out). * * Created by MarkPerry on 31 May 16. */ -public class PriorityQueue { +public final class PriorityQueue { private final FingerTree> ftree; private final Equal equal; @@ -31,7 +35,7 @@ private PriorityQueue(Equal e, FingerTree> ft) { * Creates a priority queue from a finger tree. */ public static PriorityQueue priorityQueue(Equal e, FingerTree> ft) { - return new PriorityQueue(e, ft); + return new PriorityQueue<>(e, ft); } /** @@ -41,14 +45,14 @@ public static PriorityQueue priorityQueue(Equal e, FingerTree PriorityQueue empty(Monoid m, Equal e) { - return priorityQueue(e, FingerTree.empty(m, (P2 p) -> p._1())); + return priorityQueue(e, FingerTree.empty(m, P2.__1())); } /** * An empty priority queue with integer priorities. */ public static PriorityQueue emptyInt() { - return priorityQueue(Equal.intEqual, FingerTree.empty(Monoid.intMaxMonoid, (P2 p) -> p._1())); + return empty(Monoid.intMaxMonoid, Equal.intEqual); } /** @@ -56,8 +60,9 @@ public static PriorityQueue emptyInt() { */ public PriorityQueue map(F f) { return priorityQueue(equal, - ftree.map(p2 -> p2.map2(a -> f.f(a)), - FingerTree.measured(ftree.measured().monoid(), (P2 p2) -> p2._1())) + ftree.map(P2.map2_(f), + FingerTree.measured(ftree.measured().monoid(), P2.__1()) + ) ); } @@ -91,6 +96,9 @@ public Option> top() { return p._2().headOption(); } + /** + * Returns all the elements of the queue with the highest (same) priority. + */ public List> topN() { Stream> s = toStream(); if (s.isEmpty()) { @@ -153,7 +161,7 @@ public PriorityQueue dequeue() { /** * Returns a tuple of the node with the highest priority and the rest of the priority queue. */ - public P2>, PriorityQueue> dequeueTop() { + public P2>, PriorityQueue> topDequeue() { return P.p(top(), dequeue()); } diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index ba387cad..2bde7e6e 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -94,7 +94,6 @@ public Property sorted() { return property(arbPriorityQueueIntegerString, pq -> { List> expected = pq.toList().sort(Ord.p2Ord1(Ord.intOrd.reverse())); List> actual = pq.toList(); - assertThat(actual, equalTo(expected)); return prop(actual.equals(expected)); }); } From d2bd8cb2e91df657cee587b9fff87e016c59ce31 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 09:11:18 +0200 Subject: [PATCH 104/336] Added F1Functions#dimap (profunctor pattern) --- core/src/main/java/fj/F1Functions.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 7b97675a..3b46642f 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -677,4 +677,11 @@ public static F contramap(F target, F f) { return andThen(f, target); } + /** + * Both map (with g) and contramap (with f) the target function. (Profunctor pattern) + */ + public static F dimap(F target, F f, F g) { + return c -> g.f(target.f(f.f(c))); + } + } From d1f24b3609640fa41d08be8628fbc80611a3216b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 10:39:53 +0200 Subject: [PATCH 105/336] avoid andThen indirection in F1 map and contramap --- core/src/main/java/fj/F1Functions.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java index 3b46642f..00bdf515 100644 --- a/core/src/main/java/fj/F1Functions.java +++ b/core/src/main/java/fj/F1Functions.java @@ -670,11 +670,11 @@ public static ArrayList mapJ(final F f, final ArrayList as) { } public static F map(F target, F f) { - return andThen(target, f); + return o(f, target); } public static F contramap(F target, F f) { - return andThen(f, target); + return o(target, f); } /** From 435109241022928961c01f877ee3a22e5438adab Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 10:41:18 +0200 Subject: [PATCH 106/336] add an uncurried version of Function.apply for better perf. --- core/src/main/java/fj/Function.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index 87888fad..f95b1c87 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -718,7 +718,18 @@ public static F bind(final F ma, final F> f) { * @return A new function after applying the given higher-order function to the given function. */ public static F apply(final F> cab, final F ca) { - return bind(cab, f -> compose(f, ca)); + return apply(uncurryF2(cab), ca); + } + + /** + * Performs function application within a higher-order function (applicative functor pattern). + * + * @param cab The higher-order function to apply a function to. + * @param ca A function to apply within a higher-order function. + * @return A new function after applying the given higher-order function to the given function. + */ + public static F apply(final F2 cab, final F ca) { + return c -> cab.f(c, ca.f(c)); } /** From 0704e22c5707ef8c6dbb1b459816bfba4a682ce9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 10:50:08 +0200 Subject: [PATCH 107/336] Ord: Take better advantage of the curried comparison function. also improved isLessThanOrEqualTo and simplified Ord instances of Comparable types. --- core/src/main/java/fj/Ord.java | 107 +++++++++++---------------------- 1 file changed, 34 insertions(+), 73 deletions(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index e9fb2d4b..04cc46b9 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -14,6 +14,8 @@ import java.math.BigInteger; import java.util.Comparator; +import static fj.Function.apply; +import static fj.Function.compose; import static fj.Function.curry; import static fj.Semigroup.semigroup; @@ -27,6 +29,8 @@ public final class Ord { private Ord(final F> f) { this.f = f; + this.max = a1 -> apply((a2, o) -> o == Ordering.GT ? a1 : a2, f.f(a1)); + this.min = a1 -> apply((a2, o) -> o == Ordering.LT ? a1 : a2, f.f(a1)); } /** @@ -66,7 +70,7 @@ public boolean eq(final A a1, final A a2) { * @return An Equal for this order. */ public Equal equal() { - return Equal.equal(curry(this::eq)); + return Equal.equal(a -> compose(o -> o == Ordering.EQ, f.f(a))); } /** @@ -102,7 +106,7 @@ public boolean isLessThan(final A a1, final A a2) { * false otherwise. */ public boolean isLessThanOrEqualTo(final A a1, final A a2) { - return isLessThan(a1, a2) || eq(a1, a2); + return compare(a1, a2) != Ordering.GT; } /** @@ -125,7 +129,7 @@ public boolean isGreaterThan(final A a1, final A a2) { * @return A function that returns true if its argument is less than the argument to this method. */ public F isLessThan(final A a) { - return a2 -> compare(a2, a) == Ordering.LT; + return compose(o -> o != Ordering.LT, f.f(a)); } /** @@ -135,7 +139,7 @@ public F isLessThan(final A a) { * @return A function that returns true if its argument is greater than the argument to this method. */ public F isGreaterThan(final A a) { - return a2 -> compare(a2, a) == Ordering.GT; + return compose(o -> o != Ordering.GT, f.f(a)); } /** @@ -164,19 +168,19 @@ public A min(final A a1, final A a2) { /** * A function that returns the greater of its two arguments. */ - public final F> max = curry(this::max); + public final F> max; /** * A function that returns the lesser of its two arguments. */ - public final F> min = curry(this::min); + public final F> min; public final Semigroup minSemigroup() { - return semigroup(this::min); + return semigroup(min); } public final Semigroup maxSemigroup() { - return semigroup(this::max); + return semigroup(max); } public final Ord reverse() { return ord(Function.flip(f)); } @@ -194,92 +198,52 @@ public static Ord ord(final F> f) { /** * An order instance for the boolean type. */ - public static final Ord booleanOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord booleanOrd = comparableOrd(); /** * An order instance for the byte type. */ - public static final Ord byteOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord byteOrd = comparableOrd(); /** * An order instance for the char type. */ - public static final Ord charOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord charOrd = comparableOrd(); /** * An order instance for the double type. */ - public static final Ord doubleOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord doubleOrd = comparableOrd(); /** * An order instance for the float type. */ - public static final Ord floatOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord floatOrd = comparableOrd(); /** * An order instance for the int type. */ - public static final Ord intOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord intOrd = comparableOrd(); /** * An order instance for the BigInteger type. */ - public static final Ord bigintOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord bigintOrd = comparableOrd(); /** * An order instance for the BigDecimal type. */ - public static final Ord bigdecimalOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord bigdecimalOrd = comparableOrd(); /** * An order instance for the long type. */ - public static final Ord longOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord longOrd = comparableOrd(); /** * An order instance for the short type. */ - public static final Ord shortOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord shortOrd = comparableOrd(); /** * An order instance for the {@link Ordering} type. @@ -297,23 +261,17 @@ public static Ord ord(final F> f) { /** * An order instance for the {@link String} type. */ - public static final Ord stringOrd = ord( - a1 -> a2 -> { - final int x = a1.compareTo(a2); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; - }); + public static final Ord stringOrd = comparableOrd(); /** * An order instance for the {@link StringBuffer} type. */ - public static final Ord stringBufferOrd = - ord(a1 -> a2 -> stringOrd.compare(a1.toString(), a2.toString())); + public static final Ord stringBufferOrd = stringOrd.contramap(StringBuffer::toString); /** * An order instance for the {@link StringBuffer} type. */ - public static final Ord stringBuilderOrd = - ord(a1 -> a2 -> stringOrd.compare(a1.toString(), a2.toString())); + public static final Ord stringBuilderOrd = stringOrd.contramap(StringBuilder::toString); /** * An order instance for the {@link Option} type. @@ -527,9 +485,9 @@ public static > Ord comparableOrd() { * @see #hashEqualsOrd() */ public static Ord hashOrd() { - return ord(a -> a2 -> { - final int x = a.hashCode() - a2.hashCode(); - return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT; + return ord(a -> { + int aHash = a.hashCode(); + return a2 -> Ordering.fromInt(Integer.compare(aHash, a2.hashCode())); }); } @@ -541,9 +499,12 @@ public static Ord hashOrd() { * @return An order instance that is based on {@link Object#hashCode()} and {@link Object#equals}. */ public static Ord hashEqualsOrd() { - return ord(a -> a2 -> { - final int x = a.hashCode() - a2.hashCode(); - return x < 0 ? Ordering.LT : x == 0 && a.equals(a2) ? Ordering.EQ : Ordering.GT; + return ord(a -> { + int aHash = a.hashCode(); + return a2 -> { + final int a2Hash = a2.hashCode(); + return aHash < a2Hash ? Ordering.LT : aHash == a2Hash && a.equals(a2) ? Ordering.EQ : Ordering.GT; + }; }); } From 3812a832501f4b7be4024347c1e8f1fa89c45125 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 14:51:08 +0200 Subject: [PATCH 108/336] Add uncons to FingerTree --- .../main/java/fj/data/fingertrees/FingerTree.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index ee985611..160b5508 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -167,6 +167,18 @@ public final Option headOption() { return isEmpty() ? Option.none() : Option.some(head()); } + /** + * Performs a reduction on this finger tree using the given arguments. + * + * @param nil The value to return if this finger tree is empty. + * @param cons The function to apply to the head and tail of this finger tree if it is not empty. + * @return A reduction on this finger tree. + */ + public final B uncons(B nil, F2, B> cons) { + return isEmpty() ? nil : cons.f(head(), tail()); + } + + /** * The last element of this tree. This is an O(1) operation. * From f21c310653b6f06d6d05c70030c6bbe1807408cd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 19 Jun 2016 14:55:24 +0200 Subject: [PATCH 109/336] Add PriorityQueue.unqueue and use it to implement some other methods. + some other minor refactoring. --- core/src/main/java/fj/data/PriorityQueue.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 49d185c9..2649a253 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -2,15 +2,17 @@ import fj.Equal; import fj.F; +import fj.F2; import fj.Monoid; import fj.Ord; import fj.P; import fj.P2; -import fj.P3; import fj.Show; import fj.data.fingertrees.FingerTree; -import static fj.data.List.list; +import static fj.Function.compose; +import static fj.data.Option.none; +import static fj.data.Option.some; /** * A priority queue implementation backed by a @@ -91,22 +93,17 @@ public boolean isEmpty() { * If the tree is not empty, returns the node with highest priority otherwise returns nothing. */ public Option> top() { - K top = ftree.measure(); - P2>, FingerTree>> p = ftree.split(k -> equal.eq(top, k)); - return p._2().headOption(); + return unqueue(none(), (top, tail) -> some(top)); } /** * Returns all the elements of the queue with the highest (same) priority. */ public List> topN() { - Stream> s = toStream(); - if (s.isEmpty()) { - return List.nil(); - } else { - final K k = s.head()._1(); - return s.takeWhile(p -> equal.eq(k, p._1())).toList(); - } + return toStream().uncons( + List.nil(), + top -> tail -> List.cons(top, tail._1().takeWhile(compose(equal.eq(top._1()), P2.__1())).toList()) + ); } /** @@ -127,7 +124,7 @@ public PriorityQueue enqueue(List> list) { * Does the priority k exist already? */ public boolean contains(final K k) { - return !ftree.split(k2 -> equal.eq(k, k2))._2().isEmpty(); + return !ftree.split(equal.eq(k))._2().isEmpty(); } /** @@ -152,17 +149,30 @@ public PriorityQueue enqueue(P2 p) { * Removes the node with the highest priority. */ public PriorityQueue dequeue() { - K top = ftree.measure(); - P2>, FingerTree>> p = ftree.split(k -> equal.eq(k, top)); - FingerTree> right = p._2(); - return right.isEmpty() ? this : priorityQueue(equal, p._1().append(right.tail())); + return unqueue(this, (top, tail) -> tail); } /** * Returns a tuple of the node with the highest priority and the rest of the priority queue. */ public P2>, PriorityQueue> topDequeue() { - return P.p(top(), dequeue()); + return unqueue(P.p(none(), this), (top, tail) -> P.p(some(top), tail)); + } + + /** + * Performs a reduction on this priority queue using the given arguments. + * + * @param empty The value to return if this queue is empty. + * @param topDequeue The function to apply to the top priority element and the tail of the queue (without its top element). + * @return A reduction on this queue. + */ + public B unqueue(B empty, F2, PriorityQueue, B> topDequeue) { + K top = ftree.measure(); + P2>, FingerTree>> p = ftree.split(equal.eq(top)); + return p._2().uncons( + empty, + (head, tail) -> topDequeue.f(head, priorityQueue(equal, p._1().append(tail))) + ); } /** @@ -182,22 +192,22 @@ public PriorityQueue dequeue(int n) { * Does the top of the queue have lower priority than k? */ public boolean isLessThan(Ord ok, K k) { - return top().map(p -> ok.isLessThan(p._1(), k)).orSome(true); + return top().option(true, p -> ok.isLessThan(p._1(), k)); } public boolean isGreaterThan(Ord ok, K k) { - return top().map(p -> ok.isGreaterThan(p._1(), k)).orSome(false); + return top().option(false, p -> ok.isGreaterThan(p._1(), k)); } public boolean isEqual(Ord ok, K k) { - return top().map(p -> ok.eq(p._1(), k)).orSome(false); + return top().option(false, p -> ok.eq(p._1(), k)); } /** * Returns a stream of products with priority k and value a. */ public Stream> toStream() { - return top().map(p -> Stream.cons(p, () -> dequeue().toStream())).orSome(() -> Stream.nil()); + return unqueue(Stream.nil(), (top, tail) -> Stream.cons(top, () -> tail.toStream())); } /** From 17efc98972b07644248ae8dec8d3bcbdd56fe66a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:04:58 +0200 Subject: [PATCH 110/336] remove old workaround for javac bugs that have been fixed. --- core/src/main/java/fj/control/Trampoline.java | 14 ++++++-------- core/src/main/java/fj/data/List.java | 5 +---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index cd477dd0..37491c3b 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -52,14 +52,12 @@ public Trampoline bind(final F> f) { // The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result // gets shifted into the continuation. public Either>, A> resume() { - return left(sub.resume().either(p -> p.map(ot -> { - // WARNING: In JDK 8, update 25 (current version) the following code is a - // workaround for an internal JDK compiler error, likely due to - // https:bugs.openjdk.java.net/browse/JDK-8062253. - F, Trampoline> f = o -> o.foldNormal(cont, t -> t._1().bind(cont)); - F, Trampoline> g = c -> codense(c.sub, o -> c.cont.f(o).bind(cont)); - return ot.fold(f, g); - }), o -> P.lazy(() -> cont.f(o)))); + return left(sub.resume().either(p -> p.map(ot -> + ot.fold( + o -> o.foldNormal(cont, t -> t._1().bind(cont)), + c -> codense(c.sub, o -> c.cont.f(o).bind(cont)) + ) + ), o -> P.lazy(() -> cont.f(o)))); } } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index c2d21b06..c7e1562f 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -88,10 +88,7 @@ public final Iterator iterator() { * @return The length of this list. */ public final int length() { - // WARNING: In JDK 8, update 25 (current version) the following code triggers an internal JDK compiler error, likely due to https://bugs.openjdk.java.net/browse/JDK-8062253. The code below is a workaround for this compiler bug. - // return foldLeft(i -> a -> i + 1, 0); - F2 f = (i, a) -> i + 1; - return foldLeft(f, 0); + return foldLeft((i, a) -> i + 1, 0); } /** From 9983ab260fe7a7efb297106f8f967906a5360570 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:23:31 +0200 Subject: [PATCH 111/336] Use uncurried version of foldLeft as default implementation to avoid creation of closures in tight loop. --- core/src/main/java/fj/data/List.java | 30 +++++++++---------- core/src/main/java/fj/data/PriorityQueue.java | 2 +- core/src/main/java/fj/data/Stream.java | 30 ++++++++----------- 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index c2d21b06..48e93e32 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -751,13 +751,7 @@ public final Trampoline foldRightC(final F2 f, final B b) { * @return The final result after the left-fold reduction. */ public final B foldLeft(final F> f, final B b) { - B x = b; - - for (List xs = this; !xs.isEmpty(); xs = xs.tail()) { - x = f.f(x).f(xs.head()); - } - - return x; + return foldLeft(uncurryF2(f), b); } /** @@ -768,7 +762,13 @@ public final B foldLeft(final F> f, final B b) { * @return The final result after the left-fold reduction. */ public final B foldLeft(final F2 f, final B b) { - return foldLeft(curry(f), b); + B x = b; + + for (List xs = this; !xs.isEmpty(); xs = xs.tail()) { + x = f.f(x, xs.head()); + } + + return x; } /** @@ -779,7 +779,9 @@ public final B foldLeft(final F2 f, final B b) { * @return The final result after the left-fold reduction. */ public final A foldLeft1(final F2 f) { - return foldLeft1(curry(f)); + if (isEmpty()) + throw error("Undefined: foldLeft1 on empty list"); + return tail().foldLeft(f, head()); } /** @@ -790,9 +792,7 @@ public final A foldLeft1(final F2 f) { * @return The final result after the left-fold reduction. */ public final A foldLeft1(final F> f) { - if (isEmpty()) - throw error("Undefined: foldLeft1 on empty list"); - return tail().foldLeft(f, head()); + return foldLeft1(uncurryF2(f)); } /** @@ -801,7 +801,7 @@ public final A foldLeft1(final F> f) { * @return A new list that is the reverse of this one. */ public final List reverse() { - return foldLeft(as -> a -> cons(a, as), List.nil()); + return foldLeft((as, a) -> cons(a, as), nil()); } /** @@ -904,7 +904,7 @@ public final List> partition(final int n) { * @param f Predicate function. */ public final P2, List> partition(F f) { - P2, List> p2 = foldLeft(acc -> a -> + P2, List> p2 = foldLeft((acc, a) -> f.f(a) ? p(acc._1().cons(a), acc._2()) : p(acc._1(), acc._2().cons(a)), p(nil(), nil()) ); @@ -1393,7 +1393,7 @@ public final TreeMap groupBy( final D groupingIdentity, final F2 groupingAcc, final Ord keyOrd) { - return this.foldLeft(map -> element -> { + return this.foldLeft((map, element) -> { final B key = keyFunction.f(element); final C value = valueFunction.f(element); return map.set(key, map.get(key) diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 2649a253..21f6ed6f 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -117,7 +117,7 @@ public PriorityQueue enqueue(K k, A a) { * Adds nodes using the list of products with priority k and value a. This operation takes O(list.length()). */ public PriorityQueue enqueue(List> list) { - return list.foldLeft(pq -> p -> pq.enqueue(p._1(), p._2()), this); + return list.foldLeft((pq, p) -> pq.enqueue(p._1(), p._2()), this); } /** diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index ca4c870a..ae37d714 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -22,11 +22,7 @@ import java.util.*; import static fj.Bottom.error; -import static fj.Function.compose; -import static fj.Function.constant; -import static fj.Function.curry; -import static fj.Function.flip; -import static fj.Function.identity; +import static fj.Function.*; import static fj.P.p; import static fj.P.p2; import static fj.Unit.unit; @@ -167,12 +163,7 @@ public final B foldRight1(final F2 f, final B b) { * @return The final result after the left-fold reduction. */ public final B foldLeft(final F> f, final B b) { - B x = b; - - for (Stream xs = this; !xs.isEmpty(); xs = xs.tail()._1()) - x = f.f(x).f(xs.head()); - - return x; + return foldLeft(uncurryF2(f), b); } /** @@ -183,7 +174,12 @@ public final B foldLeft(final F> f, final B b) { * @return The final result after the left-fold reduction. */ public final B foldLeft(final F2 f, final B b) { - return foldLeft(curry(f), b); + B x = b; + + for (Stream xs = this; !xs.isEmpty(); xs = xs.tail()._1()) + x = f.f(x, xs.head()); + + return x; } /** @@ -194,7 +190,9 @@ public final B foldLeft(final F2 f, final B b) { * @return The final result after the left-fold reduction. */ public final A foldLeft1(final F2 f) { - return foldLeft1(curry(f)); + if (isEmpty()) + throw error("Undefined: foldLeft1 on empty list"); + return tail()._1().foldLeft(f, head()); } /** @@ -205,9 +203,7 @@ public final A foldLeft1(final F2 f) { * @return The final result after the left-fold reduction. */ public final A foldLeft1(final F> f) { - if (isEmpty()) - throw error("Undefined: foldLeft1 on empty list"); - return tail()._1().foldLeft(f, head()); + return foldLeft1(uncurryF2(f)); } /** @@ -1188,7 +1184,7 @@ public final P2, Stream> split(final F p) { * @return A new stream that is the reverse of this one. */ public final Stream reverse() { - return foldLeft(as -> a -> cons(a, () -> as), Stream.nil()); + return foldLeft((as, a) -> cons(a, () -> as), Stream.nil()); } /** From cab3299d677dda81ade19849e18119e24ba35ea9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:29:33 +0200 Subject: [PATCH 112/336] Add first class either catamorphism --- core/src/main/java/fj/data/Either.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index a4f0fc02..c0c143af 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -737,6 +737,17 @@ public static Either right(final B b) { return new Right<>(b); } + /** + * First class catamorphism for either. Folds over this either breaking into left or right. + * + * @param left The function to call if this is left. + * @param right The function to call if this is right. + * @return The reducing function. + */ + public static F, X> cata(final F left, final F right) { + return e -> e.either(left, right); + } + /** * @return A function that maps another function across an either's left projection. */ From 7c2605ec48ce183b388d9d9a1b71bd936de63658 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:54:48 +0200 Subject: [PATCH 113/336] Add first class option catamorphism --- core/src/main/java/fj/data/Option.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 4cdb411f..f1b228d0 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -688,6 +688,18 @@ public static F> fromNull() { return Option::fromNull; } + /** + * First-class catamorphism for Option: return a function that will performs + * a reduction on an optional value using the given arguments. + * + * @param none The value to return if this optional value has no value. + * @param some The function to apply to the value of this optional value. + * @return the reducing function. + */ + public static final F, B> cata(final B none, final F some) { + return o -> o.option(none, some); + } + /** * Joins the given optional value of optional value using a bind operation. * From 25d10ea69eb94036f98bfbcb022aa7442edbfb9b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 23:29:43 +0200 Subject: [PATCH 114/336] Initial implementation of optimizable definitions for Equal --- core/src/main/java/fj/Equal.java | 167 ++++++++++++++++++++++++------- 1 file changed, 130 insertions(+), 37 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index a09dceba..bb10f442 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -1,8 +1,19 @@ package fj; -import static fj.Function.curry; - -import fj.data.*; +import fj.data.Array; +import fj.data.Either; +import fj.data.LazyString; +import fj.data.List; +import fj.data.Natural; +import fj.data.NonEmptyList; +import fj.data.Option; +import fj.data.Seq; +import fj.data.Set; +import fj.data.Stream; +import fj.data.Tree; +import fj.data.TreeMap; +import fj.data.Validation; +import fj.data.Writer; import fj.data.hlist.HList; import fj.data.vector.V2; import fj.data.vector.V3; @@ -12,8 +23,12 @@ import fj.data.vector.V7; import fj.data.vector.V8; -import java.math.BigInteger; import java.math.BigDecimal; +import java.math.BigInteger; + +import static fj.Function.compose; +import static fj.Function.constant; +import static fj.Function.curry; /** * Tests for equality between two objects. @@ -21,10 +36,37 @@ * @version %build.number% */ public final class Equal { - private final F> f; - private Equal(final F> f) { - this.f = f; + /** + * Primitives functions of Equal: minimal definition and overridable methods. + */ + interface Definition { + + F equal(A a); + + default boolean equal(A a1, A a2) { + return equal(a1).f(a2); + } + } + + /** + * Primitives functions of Equal: alternative minimal definition and overridable methods. + */ + interface AlternateDefinition extends Definition { + + @Override + default F equal(A a) { + return a2 -> equal(a, a2); + } + + @Override + boolean equal(A a1, A a2); + } + + private final Definition def; + + private Equal(final Definition def) { + this.def = def; } /** @@ -35,7 +77,7 @@ private Equal(final F> f) { * @return true if the two given arguments are equal, false otherwise. */ public boolean eq(final A a1, final A a2) { - return f.f(a1).f(a2); + return def.equal(a1, a2); } /** @@ -46,7 +88,7 @@ public boolean eq(final A a1, final A a2) { * @return true if the two given arguments are not equal, false otherwise. */ public boolean notEq(final A a1, final A a2) { - return !eq(a1, a2); + return !def.equal(a1, a2); } /** @@ -55,7 +97,7 @@ public boolean notEq(final A a1, final A a2) { * @return A function that returns true if the two given arguments are equal. */ public F2 eq() { - return this::eq; + return def::equal; } /** @@ -65,7 +107,7 @@ public F2 eq() { * @return A function that returns true if the given argument equals the argument to this method. */ public F eq(final A a) { - return f.f(a); + return def.equal(a); } /** @@ -75,7 +117,18 @@ public F eq(final A a) { * @return A new equal. */ public Equal contramap(final F f) { - return equal(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); + Definition eaDef = def; + return equalDef(new Definition(){ + @Override + public F equal(B b) { + return compose(eaDef.equal(f.f(b)), f); + } + + @Override + public boolean equal(B b1, B b2) { + return eaDef.equal(f.f(b1), f.f(b2)); + } + }); } /** @@ -85,7 +138,27 @@ public Equal contramap(final F f) { * @return An equal instance from the given function. */ public static Equal equal(final F> f) { - return new Equal<>(f); + return new Equal<>(f::f); + } + + /** + * Constructs an equal instance from the given definition. + * + * @param definition The minimal definition of the equal instance. + * @return An equal instance from the given function. + */ + public static Equal equalDef(final Definition definition) { + return new Equal<>(definition); + } + + /** + * Constructs an equal instance from the given definition. + * + * @param definition The minimal definition of the equal instance. + * @return An equal instance from the given function. + */ + public static Equal equalAltDef(final AlternateDefinition definition) { + return new Equal<>(definition); } /** @@ -96,7 +169,17 @@ public static Equal equal(final F> f) { * equality. */ public static Equal anyEqual() { - return equal(a1 -> a1::equals); + return equalDef(new Definition() { + @Override + public F equal(A a) { + return a::equals; + } + + @Override + public boolean equal(A a1, A a2) { + return a1.equals(a2); + } + }); } /** @@ -163,7 +246,7 @@ public static Equal anyEqual() { * An equal instance for the {@link StringBuffer} type. */ public static final Equal stringBufferEqual = - equal(sb1 -> sb2 -> { + equalAltDef((sb1, sb2) -> { if (sb1.length() == sb2.length()) { for (int i = 0; i < sb1.length(); i++) if (sb1.charAt(i) != sb2.charAt(i)) @@ -177,7 +260,7 @@ public static Equal anyEqual() { * An equal instance for the {@link StringBuilder} type. */ public static final Equal stringBuilderEqual = - equal(sb1 -> sb2 -> { + equalAltDef((sb1, sb2) -> { if (sb1.length() == sb2.length()) { for (int i = 0; i < sb1.length(); i++) if (sb1.charAt(i) != sb2.charAt(i)) @@ -195,8 +278,12 @@ public static Equal anyEqual() { * @return An equal instance for the {@link Either} type. */ public static Equal> eitherEqual(final Equal ea, final Equal eb) { - return equal(e1 -> e2 -> e1.isLeft() && e2.isLeft() && ea.f.f(e1.left().value()).f(e2.left().value()) || - e1.isRight() && e2.isRight() && eb.f.f(e1.right().value()).f(e2.right().value())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + return equalDef(e1 -> e1.either( + a1 -> Either.cata(eaDef.equal(a1), (B __) -> false), + b1 -> Either.cata((A __)-> false, ebDef.equal(b1)) + )); } /** @@ -217,12 +304,13 @@ public static Equal> validationEqual(final Equal ea, * @return An equal instance for the {@link List} type. */ public static Equal> listEqual(final Equal ea) { - return equal(a1 -> a2 -> { + Definition eaDef = ea.def; + return equalAltDef((a1, a2) -> { List x1 = a1; List x2 = a2; while (x1.isNotEmpty() && x2.isNotEmpty()) { - if (!ea.eq(x1.head(), x2.head())) + if (!eaDef.equal(x1.head(), x2.head())) return false; x1 = x1.tail(); @@ -250,12 +338,15 @@ public static Equal> nonEmptyListEqual(final Equal ea) { * @return An equal instance for the {@link Option} type. */ public static Equal> optionEqual(final Equal ea) { - return equal(o1 -> o2 -> o1.isNone() && o2.isNone() || - o1.isSome() && o2.isSome() && ea.f.f(o1.some()).f(o2.some())); + Definition eaDef = ea.def; + return equalDef(o1 -> o1.option( + Option.isNone_(), + a1 -> Option.cata(false, eaDef.equal(a1)) + )); } public static Equal> seqEqual(final Equal e) { - return equal(s1 -> s2 -> streamEqual(e).eq(s1.toStream(), s2.toStream())); + return streamEqual(e).contramap(Seq::toStream); } /** @@ -265,12 +356,13 @@ public static Equal> seqEqual(final Equal e) { * @return An equal instance for the {@link Stream} type. */ public static Equal> streamEqual(final Equal ea) { - return equal(a1 -> a2 -> { + Definition eaDef = ea.def; + return equalAltDef((a1, a2) -> { Stream x1 = a1; Stream x2 = a2; while (x1.isNotEmpty() && x2.isNotEmpty()) { - if (!ea.eq(x1.head(), x2.head())) + if (!eaDef.equal(x1.head(), x2.head())) return false; x1 = x1.tail()._1(); @@ -288,10 +380,11 @@ public static Equal> streamEqual(final Equal ea) { * @return An equal instance for the {@link Array} type. */ public static Equal> arrayEqual(final Equal ea) { - return equal(a1 -> a2 -> { + Definition eaDef = ea.def; + return equalAltDef((a1, a2) -> { if (a1.length() == a2.length()) { for (int i = 0; i < a1.length(); i++) { - if (!ea.eq(a1.get(i), a2.get(i))) + if (!eaDef.equal(a1.get(i), a2.get(i))) return false; } return true; @@ -307,7 +400,7 @@ public static Equal> arrayEqual(final Equal ea) { * @return An equal instance for the {@link Tree} type. */ public static Equal> treeEqual(final Equal ea) { - return Equal.equal(curry((t1, t2) -> ea.eq(t1.root(), t2.root()) && p1Equal(streamEqual(Equal.treeEqual(ea))).eq(t2.subForest(), t1.subForest()))); + return equalAltDef((t1, t2) -> ea.eq(t1.root(), t2.root()) && p1Equal(streamEqual(treeEqual(ea))).eq(t2.subForest(), t1.subForest())); } /** @@ -317,7 +410,7 @@ public static Equal> treeEqual(final Equal ea) { * @return An equal instance for a product-1. */ public static Equal> p1Equal(final Equal ea) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1())); + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1())); } /** @@ -328,7 +421,7 @@ public static Equal> p1Equal(final Equal ea) { * @return An equal instance for a product-2. */ public static Equal> p2Equal(final Equal ea, final Equal eb) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2())); + return equalAltDef((p1, p2)-> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2())); } /** @@ -340,7 +433,7 @@ public static Equal> p2Equal(final Equal ea, final Equal e * @return An equal instance for a product-3. */ public static Equal> p3Equal(final Equal ea, final Equal eb, final Equal ec) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3())); + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3())); } /** @@ -354,7 +447,7 @@ public static Equal> p3Equal(final Equal ea, final Equa */ public static Equal> p4Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && ed.eq(p1._4(), p2._4())); } @@ -371,7 +464,7 @@ public static Equal> p4Equal(final Equal ea, fina public static Equal> p5Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed, final Equal ee) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5())); } @@ -389,7 +482,7 @@ public static Equal> p5Equal(final Equal ea public static Equal> p6Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed, final Equal ee, final Equal ef) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6())); } @@ -409,7 +502,7 @@ public static Equal> p5Equal(final Equal ea final Equal ec, final Equal ed, final Equal ee, final Equal ef, final Equal eg) { - return equal(p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && + return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6()) && eg.eq(p1._7(), p2._7())); } @@ -435,8 +528,8 @@ public static Equal> p5Equal(final Equal ea final Equal ef, final Equal eg, final Equal eh) { - return equal( - p1 -> p2 -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && + return equalAltDef( + (p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6()) && eg.eq(p1._7(), p2._7()) && eh.eq(p1._8(), p2._8())); } From 6945c784a98afccec1089f570f72d20f5cbcb193 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 22 Jun 2016 20:40:36 +0200 Subject: [PATCH 115/336] Finish migrating Equal to use optimizable definition --- core/src/main/java/fj/Equal.java | 114 ++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index bb10f442..e5b2ebb1 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -54,13 +54,13 @@ default boolean equal(A a1, A a2) { */ interface AlternateDefinition extends Definition { + @Override + boolean equal(A a1, A a2); + @Override default F equal(A a) { return a2 -> equal(a, a2); } - - @Override - boolean equal(A a1, A a2); } private final Definition def; @@ -144,7 +144,7 @@ public static Equal equal(final F> f) { /** * Constructs an equal instance from the given definition. * - * @param definition The minimal definition of the equal instance. + * @param definition a definition of the equal instance. * @return An equal instance from the given function. */ public static Equal equalDef(final Definition definition) { @@ -152,12 +152,12 @@ public static Equal equalDef(final Definition definition) { } /** - * Constructs an equal instance from the given definition. + * Constructs an equal instance from the given (alternative) definition. * - * @param definition The minimal definition of the equal instance. + * @param definition a definition of the equal instance. * @return An equal instance from the given function. */ - public static Equal equalAltDef(final AlternateDefinition definition) { + public static Equal equalDef(final AlternateDefinition definition) { return new Equal<>(definition); } @@ -246,7 +246,7 @@ public boolean equal(A a1, A a2) { * An equal instance for the {@link StringBuffer} type. */ public static final Equal stringBufferEqual = - equalAltDef((sb1, sb2) -> { + equalDef((sb1, sb2) -> { if (sb1.length() == sb2.length()) { for (int i = 0; i < sb1.length(); i++) if (sb1.charAt(i) != sb2.charAt(i)) @@ -260,7 +260,7 @@ public boolean equal(A a1, A a2) { * An equal instance for the {@link StringBuilder} type. */ public static final Equal stringBuilderEqual = - equalAltDef((sb1, sb2) -> { + equalDef((sb1, sb2) -> { if (sb1.length() == sb2.length()) { for (int i = 0; i < sb1.length(); i++) if (sb1.charAt(i) != sb2.charAt(i)) @@ -305,7 +305,7 @@ public static Equal> validationEqual(final Equal ea, */ public static Equal> listEqual(final Equal ea) { Definition eaDef = ea.def; - return equalAltDef((a1, a2) -> { + return equalDef((a1, a2) -> { List x1 = a1; List x2 = a2; @@ -357,7 +357,7 @@ public static Equal> seqEqual(final Equal e) { */ public static Equal> streamEqual(final Equal ea) { Definition eaDef = ea.def; - return equalAltDef((a1, a2) -> { + return equalDef((a1, a2) -> { Stream x1 = a1; Stream x2 = a2; @@ -381,7 +381,7 @@ public static Equal> streamEqual(final Equal ea) { */ public static Equal> arrayEqual(final Equal ea) { Definition eaDef = ea.def; - return equalAltDef((a1, a2) -> { + return equalDef((a1, a2) -> { if (a1.length() == a2.length()) { for (int i = 0; i < a1.length(); i++) { if (!eaDef.equal(a1.get(i), a2.get(i))) @@ -400,7 +400,18 @@ public static Equal> arrayEqual(final Equal ea) { * @return An equal instance for the {@link Tree} type. */ public static Equal> treeEqual(final Equal ea) { - return equalAltDef((t1, t2) -> ea.eq(t1.root(), t2.root()) && p1Equal(streamEqual(treeEqual(ea))).eq(t2.subForest(), t1.subForest())); + Definition eaDef = ea.def; + return equalDef(new AlternateDefinition>() { + + final Definition>>> subForestEqDef = p1Equal(streamEqual(equalDef(this))).def; + + @Override + public boolean equal(Tree t1, Tree t2) { + return eaDef.equal(t1.root(), t2.root()) + && subForestEqDef.equal(t1.subForest(), t2.subForest()); + + } + }); } /** @@ -410,7 +421,7 @@ public static Equal> treeEqual(final Equal ea) { * @return An equal instance for a product-1. */ public static Equal> p1Equal(final Equal ea) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1())); + return ea.contramap(P1.__1()); } /** @@ -421,7 +432,9 @@ public static Equal> p1Equal(final Equal ea) { * @return An equal instance for a product-2. */ public static Equal> p2Equal(final Equal ea, final Equal eb) { - return equalAltDef((p1, p2)-> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + return equalDef((p1, p2)-> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2())); } /** @@ -433,7 +446,10 @@ public static Equal> p2Equal(final Equal ea, final Equal e * @return An equal instance for a product-3. */ public static Equal> p3Equal(final Equal ea, final Equal eb, final Equal ec) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3())); } /** @@ -447,8 +463,12 @@ public static Equal> p3Equal(final Equal ea, final Equa */ public static Equal> p4Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && - ed.eq(p1._4(), p2._4())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + Definition edDef = ed.def; + return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3()) && + edDef.equal(p1._4(), p2._4())); } /** @@ -464,8 +484,13 @@ public static Equal> p4Equal(final Equal ea, fina public static Equal> p5Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed, final Equal ee) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && - ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + Definition edDef = ed.def; + Definition eeDef = ee.def; + return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3()) && + edDef.equal(p1._4(), p2._4()) && eeDef.equal(p1._5(), p2._5())); } /** @@ -482,8 +507,14 @@ public static Equal> p5Equal(final Equal ea public static Equal> p6Equal(final Equal ea, final Equal eb, final Equal ec, final Equal ed, final Equal ee, final Equal ef) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && - ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + Definition edDef = ed.def; + Definition eeDef = ee.def; + Definition efDef = ef.def; + return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3()) && + edDef.equal(p1._4(), p2._4()) && eeDef.equal(p1._5(), p2._5()) && efDef.equal(p1._6(), p2._6())); } /** @@ -502,9 +533,16 @@ public static Equal> p5Equal(final Equal ea final Equal ec, final Equal ed, final Equal ee, final Equal ef, final Equal eg) { - return equalAltDef((p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && - ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6()) && - eg.eq(p1._7(), p2._7())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + Definition edDef = ed.def; + Definition eeDef = ee.def; + Definition efDef = ef.def; + Definition egDef = eg.def; + return equalDef((p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3()) && + edDef.equal(p1._4(), p2._4()) && eeDef.equal(p1._5(), p2._5()) && efDef.equal(p1._6(), p2._6()) && + egDef.equal(p1._7(), p2._7())); } /** @@ -528,10 +566,18 @@ public static Equal> p5Equal(final Equal ea final Equal ef, final Equal eg, final Equal eh) { - return equalAltDef( - (p1, p2) -> ea.eq(p1._1(), p2._1()) && eb.eq(p1._2(), p2._2()) && ec.eq(p1._3(), p2._3()) && - ed.eq(p1._4(), p2._4()) && ee.eq(p1._5(), p2._5()) && ef.eq(p1._6(), p2._6()) && - eg.eq(p1._7(), p2._7()) && eh.eq(p1._8(), p2._8())); + Definition eaDef = ea.def; + Definition ebDef = eb.def; + Definition ecDef = ec.def; + Definition edDef = ed.def; + Definition eeDef = ee.def; + Definition efDef = ef.def; + Definition egDef = eg.def; + Definition ehDef = eh.def; + return equalDef( + (p1, p2) -> eaDef.equal(p1._1(), p2._1()) && ebDef.equal(p1._2(), p2._2()) && ecDef.equal(p1._3(), p2._3()) && + edDef.equal(p1._4(), p2._4()) && eeDef.equal(p1._5(), p2._5()) && efDef.equal(p1._6(), p2._6()) && + egDef.equal(p1._7(), p2._7()) && ehDef.equal(p1._8(), p2._8())); } /** @@ -622,7 +668,9 @@ public static Equal> v8Equal(final Equal ea) { * @return an equal instance for a heterogeneous list. */ public static > Equal> hListEqual(final Equal e, final Equal l) { - return equal(curry((HList.HCons c1, HList.HCons c2) -> e.eq(c1.head(), c2.head()) && l.eq(c1.tail(), c2.tail()))); + Definition eDef = e.def; + Definition lDef = l.def; + return equalDef((c1, c2) -> eDef.equal(c1.head(), c2.head()) && lDef.equal(c1.tail(), c2.tail())); } /** @@ -632,15 +680,15 @@ public static > Equal> hListEqual(final * @return An equal instance for sets. */ public static Equal> setEqual(final Equal e) { - return equal(curry((Set a, Set b) -> streamEqual(e).eq(a.toStream(), b.toStream()))); + return streamEqual(e).contramap(Set::toStream); } public static Equal> treeMapEqual(Equal k, Equal v) { - return equal(t1 -> t2 -> streamEqual(p2Equal(k, v)).eq(t1.toStream(), t2.toStream())); + return streamEqual(p2Equal(k, v)).contramap(TreeMap::toStream); } public static Equal> writerEqual(Equal eq1, Equal eq2) { - return equal(w1 -> w2 -> p2Equal(eq1, eq2).eq(w1.run(), w2.run())); + return p2Equal(eq1, eq2).contramap(Writer::run); } /** From 7ee7a49c2460fac22cf413afa346036031d2277e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 22 Jun 2016 21:06:09 +0200 Subject: [PATCH 116/336] Implement either catamorphism with method dispatch avoiding creation of Left/Right projections. Also some minor cleanup and refactoring to make more use of catamorphism. --- core/src/main/java/fj/data/Either.java | 113 +++++++++++++------------ 1 file changed, 59 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index a4f0fc02..ebfe3b2c 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -1,24 +1,29 @@ package fj.data; -import static fj.Bottom.error; +import fj.Equal; +import fj.F; +import fj.F0; +import fj.Function; +import fj.Hash; +import fj.P1; +import fj.Show; +import fj.Unit; +import fj.function.Effect1; -import fj.*; +import java.util.Collection; +import java.util.Iterator; +import static fj.Bottom.error; +import static fj.Function.compose; import static fj.Function.identity; import static fj.P.p; - -import fj.function.Effect1; - import static fj.Unit.unit; import static fj.data.Array.mkArray; +import static fj.data.List.cons_; import static fj.data.List.list; import static fj.data.List.single; -import static fj.data.List.cons_; import static fj.data.Option.some; -import java.util.Collection; -import java.util.Iterator; - /** * The Either type represents a value of one of two possible types (a disjoint union). * The data constructors; Left and Right represent the two possible @@ -72,11 +77,7 @@ public final RightProjection right() { * @param right The function to call if this is right. * @return The reduced value. */ - public final X either(final F left, final F right) { - return isLeft() ? - left.f(left().value()) : - right.f(right().value()); - } + public abstract X either(final F left, final F right); /** * Map the given functions across the appropriate side. @@ -86,9 +87,7 @@ public final X either(final F left, final F right) { * @return A new either value after mapping with the appropriate function applied. */ public final Either bimap(final F left, final F right) { - return isLeft() ? - left(left.f(left().value())) : - right(right.f(right().value())); + return either(compose(left_(), left), compose(right_(), right)); } @Override @@ -107,7 +106,7 @@ public final int hashCode() { * @return The value of this either swapped to the opposing side. */ public final Either swap() { - return isLeft() ? new Right<>(((Left) this).a) : new Left<>(((Right) this).b); + return either(right_(), left_()); } private static final class Left extends Either { @@ -124,6 +123,11 @@ public boolean isLeft() { public boolean isRight() { return false; } + + @Override + public X either(F left, F right) { + return left.f(a); + } } private static final class Right extends Either { @@ -140,6 +144,11 @@ public boolean isLeft() { public boolean isRight() { return true; } + + @Override + public X either(F left, F right) { + return right.f(b); + } } /** @@ -414,17 +423,17 @@ public Collection toCollection() { return toList().toCollection(); } - public Option> traverseOption(F> f) { + public Option> traverseOption(F> f) { return e.isLeft() ? - f.f(value()).map(Either::left) : - some(Either.right(e.right().value())); - } + f.f(value()).map(left_()) : + some(right(e.right().value())); + } - public Stream> traverseStream(F> f) { - return e.isLeft() ? - f.f(value()).map(Either::left) : - Stream.single(Either.right(e.right().value())); - } + public Stream> traverseStream(F> f) { + return e.isLeft() ? + f.f(value()).map(left_()) : + Stream.single(right(e.right().value())); + } } /** @@ -543,7 +552,6 @@ public Either bind(final F> f) { return e.isRight() ? f.f(value()) : new Left<>(e.left().value()); } - /** * Anonymous bind through this projection. * @@ -553,17 +561,18 @@ public Either bind(final F> f) { public Either sequence(final Either e) { return bind(Function.constant(e)); } + /** - * Traverse with function that produces List (non-determinism). - * - * @param f the function to traverse with - * @return An either after traversing through this projection. - */ - public List> traverseList(final F> f) { - return e.isRight() ? - f.f(value()).map(Either::right) : - list(left(e.left().value())); - } + * Traverse with function that produces List (non-determinism). + * + * @param f the function to traverse with + * @return An either after traversing through this projection. + */ + public List> traverseList(final F> f) { + return e.isRight() ? + f.f(value()).map(right_()) : + list(left(e.left().value())); + } /** * Traverse with a function that has IO effect @@ -573,19 +582,19 @@ public List> traverseList(final F> f) { */ public IO> traverseIO(final F> f) { return e.isRight() ? - IOFunctions.map(f.f(value()), Either::right) : + IOFunctions.map(f.f(value()), right_()) : IOFunctions.lazy(() -> left(e.left().value())); } public P1> traverseP1(final F> f) { return e.isRight() ? - f.f(value()).map(Either::right) : + f.f(value()).map(right_()) : p(left(e.left().value())); } public Option> traverseOption(final F> f) { return e.isRight() ? - f.f(value()).map(Either::right) : + f.f(value()).map(right_()) : some(left(e.left().value())); } @@ -758,8 +767,7 @@ public static F, F, Either>> rightMap_() { * @return An either after joining. */ public static Either joinLeft(final Either, B> e) { - final F, Either> id = identity(); - return e.left().bind(id); + return e.left().bind(identity()); } /** @@ -769,8 +777,7 @@ public static Either joinLeft(final Either, B> e) { * @return An either after joining. */ public static Either joinRight(final Either> e) { - final F, Either> id = identity(); - return e.right().bind(id); + return e.right().bind(identity()); } /** @@ -781,7 +788,7 @@ public static Either joinRight(final Either> e) { */ public static Either, X> sequenceLeft(final List> a) { return a.isEmpty() ? - Either.left(List.nil()) : + left(List.nil()) : a.head().left().bind(aa -> sequenceLeft(a.tail()).left().map(cons_(aa))); } @@ -793,7 +800,7 @@ public static Either, X> sequenceLeft(final List> a) */ public static Either> sequenceRight(final List> a) { return a.isEmpty() ? - Either.right(List.nil()) : + right(List.nil()) : a.head().right().bind(bb -> sequenceRight(a.tail()).right().map(cons_(bb))); } @@ -807,10 +814,10 @@ public final List> traverseListRight(final F> f) { } /** - * Traversable instance of LeftProjection of Either for List. - * - * @return traversed value - */ + * Traversable instance of LeftProjection of Either for List. + * + * @return traversed value + */ public final List> traverseListLeft(final F> f) { return left().traverseList(f); } @@ -869,8 +876,6 @@ public final Stream> traverseStreamLeft(final F> f return left().traverseStream(f); } - - /** * Takes an Either to its contained value within left or right. * @@ -878,7 +883,7 @@ public final Stream> traverseStreamLeft(final F> f * @return An Either to its contained value within left or right. */ public static A reduce(final Either e) { - return e.isLeft() ? e.left().value() : e.right().value(); + return e.either(identity(), identity()); } /** From 2aa3878bf8e803232da57788b75a055a9859606a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 22 Jun 2016 21:25:24 +0200 Subject: [PATCH 117/336] Definition interfaces should be public --- core/src/main/java/fj/Equal.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index e5b2ebb1..1db2c492 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -40,7 +40,7 @@ public final class Equal { /** * Primitives functions of Equal: minimal definition and overridable methods. */ - interface Definition { + public interface Definition { F equal(A a); @@ -52,7 +52,7 @@ default boolean equal(A a1, A a2) { /** * Primitives functions of Equal: alternative minimal definition and overridable methods. */ - interface AlternateDefinition extends Definition { + public interface AlternateDefinition extends Definition { @Override boolean equal(A a1, A a2); From 1c94e087fd35abe6f2224e1165183d065f6a9fc8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 22 Jun 2016 21:52:16 +0200 Subject: [PATCH 118/336] Initial refactoring of Ord to use Definition interface --- core/src/main/java/fj/Ord.java | 166 +++++++++++++++++++++++++-------- 1 file changed, 126 insertions(+), 40 deletions(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 04cc46b9..a2ffb7ca 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -16,6 +16,7 @@ import static fj.Function.apply; import static fj.Function.compose; +import static fj.Function.compose2; import static fj.Function.curry; import static fj.Semigroup.semigroup; @@ -25,12 +26,49 @@ * @version %build.number% */ public final class Ord { - private final F> f; - private Ord(final F> f) { - this.f = f; - this.max = a1 -> apply((a2, o) -> o == Ordering.GT ? a1 : a2, f.f(a1)); - this.min = a1 -> apply((a2, o) -> o == Ordering.LT ? a1 : a2, f.f(a1)); + /** + * Primitives functions of Ord: minimal definition and overridable methods. + */ + public interface Definition extends Equal.Definition { + + F compare(A a); + + default Ordering compare(A a1, A a2) { + return compare(a1).f(a2); + } + + @Override + default boolean equal(A a1, A a2) { + return compare(a1, a2) == Ordering.EQ; + } + + @Override + default F equal(A a) { + return compose(o -> o == Ordering.EQ, compare(a)); + } + } + + /** + * Primitives functions of Ord: alternative minimal definition and overridable methods. + */ + public interface AlternateDefinition extends Definition { + + Ordering compare(A a1, A a2); + + default F compare(A a1) { + return a2 -> compare(a1, a2); + } + + } + + + private final Definition def; + + private Ord(final Definition def) { + this.def = def; + this.max = a1 -> apply((a2, o) -> o == Ordering.GT ? a1 : a2, def.compare(a1)); + this.min = a1 -> apply((a2, o) -> o == Ordering.LT ? a1 : a2, def.compare(a1)); } /** @@ -39,7 +77,7 @@ private Ord(final F> f) { * @return A function that returns an ordering for its arguments. */ public F> compare() { - return f; + return def::compare; } /** @@ -50,7 +88,7 @@ public F> compare() { * @return An ordering for the given arguments. */ public Ordering compare(final A a1, final A a2) { - return f.f(a1).f(a2); + return def.compare(a1, a2); } /** @@ -61,7 +99,7 @@ public Ordering compare(final A a1, final A a2) { * @return true if the given arguments are equal, false otherwise. */ public boolean eq(final A a1, final A a2) { - return compare(a1, a2) == Ordering.EQ; + return def.compare(a1, a2) == Ordering.EQ; } /** @@ -70,7 +108,7 @@ public boolean eq(final A a1, final A a2) { * @return An Equal for this order. */ public Equal equal() { - return Equal.equal(a -> compose(o -> o == Ordering.EQ, f.f(a))); + return Equal.equalDef(def); } /** @@ -80,7 +118,18 @@ public Equal equal() { * @return A new ord. */ public Ord contramap(final F f) { - return ord(F1Functions.o(F1Functions.o(F1Functions.andThen(f), this.f), f)); + Definition selfDef = def; + return ordDef(new Definition() { + @Override + public F compare(B b) { + return compose(selfDef.compare(f.f(b)), f); + } + + @Override + public Ordering compare(B b1, B b2) { + return selfDef.compare(f.f(b1), f.f(b2)); + } + }); } /** @@ -93,7 +142,7 @@ public Ord contramap(final F f) { * false otherwise. */ public boolean isLessThan(final A a1, final A a2) { - return compare(a1, a2) == Ordering.LT; + return def.compare(a1, a2) == Ordering.LT; } /** @@ -106,7 +155,7 @@ public boolean isLessThan(final A a1, final A a2) { * false otherwise. */ public boolean isLessThanOrEqualTo(final A a1, final A a2) { - return compare(a1, a2) != Ordering.GT; + return def.compare(a1, a2) != Ordering.GT; } /** @@ -119,7 +168,7 @@ public boolean isLessThanOrEqualTo(final A a1, final A a2) { * argument, false otherwise. */ public boolean isGreaterThan(final A a1, final A a2) { - return compare(a1, a2) == Ordering.GT; + return def.compare(a1, a2) == Ordering.GT; } /** @@ -129,7 +178,7 @@ public boolean isGreaterThan(final A a1, final A a2) { * @return A function that returns true if its argument is less than the argument to this method. */ public F isLessThan(final A a) { - return compose(o -> o != Ordering.LT, f.f(a)); + return compose(o -> o != Ordering.LT, def.compare(a)); } /** @@ -139,7 +188,7 @@ public F isLessThan(final A a) { * @return A function that returns true if its argument is greater than the argument to this method. */ public F isGreaterThan(final A a) { - return compose(o -> o != Ordering.GT, f.f(a)); + return compose(o -> o != Ordering.GT, def.compare(a)); } /** @@ -183,7 +232,20 @@ public final Semigroup maxSemigroup() { return semigroup(max); } - public final Ord reverse() { return ord(Function.flip(f)); } + public final Ord reverse() { + Definition selfDef = def; + return ordDef(new Definition() { + @Override + public F compare(A a) { + return compose(Ordering::reverse, selfDef.compare(a)); + } + + @Override + public Ordering compare(A a1, A a2) { + return selfDef.compare(a2, a1); + } + }); + } /** * Returns an order instance that uses the given equality test and ordering function. @@ -192,9 +254,30 @@ public final Semigroup maxSemigroup() { * @return An order instance. */ public static Ord ord(final F> f) { - return new Ord<>(f); + return new Ord<>(f::f); } + /** + * Returns an order instance that uses the given minimal equality test and ordering definiion. + * + * @param def The order definition. + * @return An order instance. + */ + public static Ord ordDef(final Definition def) { + return new Ord<>(def); + } + + /** + * Returns an order instance that uses the given minimal equality test and ordering definiion. + * + * @param def The order definition. + * @return An order instance. + */ + public static Ord ordDef(final AlternateDefinition def) { + return new Ord<>(def); + } + + /** * An order instance for the boolean type. */ @@ -248,7 +331,7 @@ public static Ord ord(final F> f) { /** * An order instance for the {@link Ordering} type. */ - public static final Ord orderingOrd = Ord.ord(curry((o1, o2) -> o1 == o2 ? + public static final Ord orderingOrd = ordDef((o1, o2) -> o1 == o2 ? Ordering.EQ : o1 == Ordering.LT ? Ordering.LT : @@ -256,7 +339,7 @@ public static Ord ord(final F> f) { Ordering.GT : o1 == Ordering.EQ ? Ordering.LT : - Ordering.GT)); + Ordering.GT); /** * An order instance for the {@link String} type. @@ -280,13 +363,14 @@ public static Ord ord(final F> f) { * @return An order instance for the {@link Option} type. */ public static Ord> optionOrd(final Ord oa) { - return ord(o1 -> o2 -> o1.isNone() ? + Definition oaDef = oa.def; + return ordDef((o1, o2) -> o1.isNone() ? o2.isNone() ? Ordering.EQ : Ordering.LT : o2.isNone() ? Ordering.GT : - oa.f.f(o1.some()).f(o2.some())); + oaDef.compare(o1.some()).f(o2.some())); } /** @@ -297,13 +381,15 @@ public static Ord> optionOrd(final Ord oa) { * @return An order instance for the {@link Either} type. */ public static Ord> eitherOrd(final Ord oa, final Ord ob) { - return ord(e1 -> e2 -> e1.isLeft() ? + Definition oaDef = oa.def; + Definition obDef = ob.def; + return ordDef((e1, e2) -> e1.isLeft() ? e2.isLeft() ? - oa.f.f(e1.left().value()).f(e2.left().value()) : - Ordering.LT : + oaDef.compare(e1.left().value()).f(e2.left().value()) : + Ordering.LT : e2.isLeft() ? - Ordering.GT : - ob.f.f(e1.right().value()).f(e2.right().value())); + Ordering.GT : + obDef.compare(e1.right().value()).f(e2.right().value())); } /** @@ -324,7 +410,7 @@ public static Ord> validationOrd(final Ord oa, final * @return An order instance for the {@link List} type. */ public static Ord> listOrd(final Ord oa) { - return ord(l1 -> l2 -> { + return ordDef((l1, l2) -> { List x1 = l1; List x2 = l2; @@ -364,14 +450,15 @@ public static Ord> nonEmptyListOrd(final Ord oa) { * @return An order instance for the {@link Stream} type. */ public static Ord> streamOrd(final Ord oa) { - return ord(s1 -> s2 -> { + return ordDef((s1, s2) -> { if (s1.isEmpty()) return s2.isEmpty() ? Ordering.EQ : Ordering.LT; else if (s2.isEmpty()) return s1.isEmpty() ? Ordering.EQ : Ordering.GT; else { final Ordering c = oa.compare(s1.head(), s2.head()); - return c == Ordering.EQ ? streamOrd(oa).f.f(s1.tail()._1()).f(s2.tail()._1()) : c; + // FIXME: not stack safe + return c == Ordering.EQ ? streamOrd(oa).def.compare(s1.tail()._1()).f(s2.tail()._1()) : c; } }); } @@ -383,7 +470,7 @@ else if (s2.isEmpty()) * @return An order instance for the {@link Array} type. */ public static Ord> arrayOrd(final Ord oa) { - return ord(a1 -> a2 -> { + return ordDef((a1, a2) -> { int i = 0; //noinspection ForLoopWithMissingComponent for (; i < a1.length() && i < a2.length(); i++) { @@ -414,7 +501,7 @@ public static Ord> setOrd(final Ord oa) { /** * An order instance for the {@link Unit} type. */ - public static final Ord unitOrd = ord(curry((Unit u1, Unit u2) -> Ordering.EQ)); + public static final Ord unitOrd = ordDef((u1, u2) -> Ordering.EQ); /** * An order instance for a product-1. @@ -435,15 +522,15 @@ public static Ord> p1Ord(final Ord oa) { * @return An order instance for a product-2, with the first factor considered most significant. */ public static Ord> p2Ord(final Ord oa, final Ord ob) { - return ord(curry((P2 a, P2 b) -> oa.eq(a._1(), b._1()) ? ob.compare(a._2(), b._2()) : oa.compare(a._1(), b._1()))); + return ordDef((a, b) -> oa.eq(a._1(), b._1()) ? ob.compare(a._2(), b._2()) : oa.compare(a._1(), b._1())); } public static Ord> p2Ord1(Ord oa) { - return ord(p1 -> p2 -> oa.compare(p1._1(), p2._1())); + return ordDef((p1, p2) -> oa.compare(p1._1(), p2._1())); } public static Ord> p2Ord2(Ord ob) { - return ord(p1 -> p2 -> ob.compare(p1._2(), p2._2())); + return ordDef((p1, p2) -> ob.compare(p1._2(), p2._2())); } /** @@ -455,9 +542,9 @@ public static Ord> p2Ord2(Ord ob) { * @return An order instance for a product-3, with the first factor considered most significant. */ public static Ord> p3Ord(final Ord oa, final Ord ob, final Ord oc) { - return ord(curry((P3 a, P3 b) -> oa.eq(a._1(), b._1()) ? + return ordDef((a, b) -> oa.eq(a._1(), b._1()) ? p2Ord(ob, oc).compare(P.p(a._2(), a._3()), P.p(b._2(), b._3())) - : oa.compare(a._1(), b._1()))); + : oa.compare(a._1(), b._1())); } /** @@ -472,8 +559,7 @@ public static Ord> p3Ord(final Ord oa, final Ord ob, * @return An order instance for the Comparable interface. */ public static > Ord comparableOrd() { - - return ord(a1 -> a2 -> Ordering.fromInt(a1.compareTo(a2))); + return ordDef((a1, a2) -> Ordering.fromInt(a1.compareTo(a2))); } /** @@ -485,7 +571,7 @@ public static > Ord comparableOrd() { * @see #hashEqualsOrd() */ public static Ord hashOrd() { - return ord(a -> { + return ordDef(a -> { int aHash = a.hashCode(); return a2 -> Ordering.fromInt(Integer.compare(aHash, a2.hashCode())); }); @@ -499,7 +585,7 @@ public static Ord hashOrd() { * @return An order instance that is based on {@link Object#hashCode()} and {@link Object#equals}. */ public static Ord hashEqualsOrd() { - return ord(a -> { + return ordDef(a -> { int aHash = a.hashCode(); return a2 -> { final int a2Hash = a2.hashCode(); From f040341840ea037a851326c5b3d43cf6d1ac0cb8 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:29:33 +0200 Subject: [PATCH 119/336] Add first class either catamorphism --- core/src/main/java/fj/data/Either.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index a4f0fc02..c0c143af 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -737,6 +737,17 @@ public static Either right(final B b) { return new Right<>(b); } + /** + * First class catamorphism for either. Folds over this either breaking into left or right. + * + * @param left The function to call if this is left. + * @param right The function to call if this is right. + * @return The reducing function. + */ + public static F, X> cata(final F left, final F right) { + return e -> e.either(left, right); + } + /** * @return A function that maps another function across an either's left projection. */ From 59e35fa9d69a2154211516086bf28330baa26c34 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 21 Jun 2016 22:54:48 +0200 Subject: [PATCH 120/336] Add first class option catamorphism --- core/src/main/java/fj/data/Option.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 4cdb411f..f1b228d0 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -688,6 +688,18 @@ public static F> fromNull() { return Option::fromNull; } + /** + * First-class catamorphism for Option: return a function that will performs + * a reduction on an optional value using the given arguments. + * + * @param none The value to return if this optional value has no value. + * @param some The function to apply to the value of this optional value. + * @return the reducing function. + */ + public static final F, B> cata(final B none, final F some) { + return o -> o.option(none, some); + } + /** * Joins the given optional value of optional value using a bind operation. * From 18690a20a1a634f35ef178204e2cd4f8ee959db2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Fri, 1 Jul 2016 12:41:23 +0200 Subject: [PATCH 121/336] Use '_' suffix scheme for first class cata of Option and Either --- core/src/main/java/fj/Equal.java | 6 +++--- core/src/main/java/fj/data/Either.java | 2 +- core/src/main/java/fj/data/Option.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 1db2c492..c743f03e 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -281,8 +281,8 @@ public static Equal> eitherEqual(final Equal ea, final Eq Definition eaDef = ea.def; Definition ebDef = eb.def; return equalDef(e1 -> e1.either( - a1 -> Either.cata(eaDef.equal(a1), (B __) -> false), - b1 -> Either.cata((A __)-> false, ebDef.equal(b1)) + a1 -> Either.either_(eaDef.equal(a1), (B __) -> false), + b1 -> Either.either_((A __)-> false, ebDef.equal(b1)) )); } @@ -341,7 +341,7 @@ public static Equal> optionEqual(final Equal ea) { Definition eaDef = ea.def; return equalDef(o1 -> o1.option( Option.isNone_(), - a1 -> Option.cata(false, eaDef.equal(a1)) + a1 -> Option.option_(false, eaDef.equal(a1)) )); } diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index c0c143af..e3e9d5d9 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -744,7 +744,7 @@ public static Either right(final B b) { * @param right The function to call if this is right. * @return The reducing function. */ - public static F, X> cata(final F left, final F right) { + public static F, X> either_(final F left, final F right) { return e -> e.either(left, right); } diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index f1b228d0..54b4bb01 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -696,7 +696,7 @@ public static F> fromNull() { * @param some The function to apply to the value of this optional value. * @return the reducing function. */ - public static final F, B> cata(final B none, final F some) { + public static final F, B> option_(final B none, final F some) { return o -> o.option(none, some); } From 9f1cf575b62d8c924538e497b5f7fd8f24845d27 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Fri, 1 Jul 2016 12:41:23 +0200 Subject: [PATCH 122/336] Use '_' suffix scheme for first class cata of Option and Either --- core/src/main/java/fj/data/Either.java | 2 +- core/src/main/java/fj/data/Option.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index c0c143af..e3e9d5d9 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -744,7 +744,7 @@ public static Either right(final B b) { * @param right The function to call if this is right. * @return The reducing function. */ - public static F, X> cata(final F left, final F right) { + public static F, X> either_(final F left, final F right) { return e -> e.either(left, right); } diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index f1b228d0..54b4bb01 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -696,7 +696,7 @@ public static F> fromNull() { * @param some The function to apply to the value of this optional value. * @return the reducing function. */ - public static final F, B> cata(final B none, final F some) { + public static final F, B> option_(final B none, final F some) { return o -> o.option(none, some); } From a85308f4a3c2a16e8d5bde7f39a40f68e8f09e4a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 2 Jul 2016 01:02:38 +1000 Subject: [PATCH 123/336] Added release notes for 4.6, added placeholder for 4.7 release notes --- etc/release-notes/release-notes-4.6.adoc | 58 +++++++++++++++++++++--- etc/release-notes/release-notes-4.7.adoc | 28 ++++++++++++ 2 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 etc/release-notes/release-notes-4.7.adoc diff --git a/etc/release-notes/release-notes-4.6.adoc b/etc/release-notes/release-notes-4.6.adoc index d9bc2b3d..628457c5 100644 --- a/etc/release-notes/release-notes-4.6.adoc +++ b/etc/release-notes/release-notes-4.6.adoc @@ -1,23 +1,60 @@ = Release 4.6 -Proposed release: Jun 2016 +Proposed release: June 2016 == Enhancements -* TODO. +* Added various list permutation generation for Gen (#235). +* Reduced memory for hard memos (#257). +* Added a priority queue based on finger trees (#261). +* Construct a database action from a Connection to a value (#267). +* Added methods and instances on Natural for Equal, Hash, Arbitrary, Shirnk, equals, hashCode and toString (#274). +* Use BigIntegers for Natural Gen and Shrink, instead of Long (#278). +* Various optics for Option (#244). +* First class catamorphism for Either and Option (#286). +* Added IO walkthrough (#254). +* Added numerous Semigroup methods, Monoid.dual, conversion from Ord to Semigroup and NonEmptyList folds (#251). +* Added ignored Optional optic (#250). +* Added IO methods: as, voided, when and unless (#245). +* Added monoid instances for io and unit; added semigroup instances for first, last and io (#246). == Fixes -* TODO. +* Fixed Gen.pick (#235). Affects Gen.variant, Coarbitrary and dependencies. +* Fixed Rand.reseed (#237). +* IOFunctions.bracket runs finaliser (#240). +* Fixed backwards List.traverseIO (#248). +* Run IOW map, bind and append lazily (#252, 253). +* Make State class stack safe (#259). +* Removed extra type parameters in P2.Optic (#273). +* Fixed BigInteger.shrink (#276, 277). == Internal -* TODO. +* Upgrade to Gradle 2.13 (#243). +* Document version deprecated for all deprecated methods (#264). +* Fixed various unchecked conversion warnings (#269). +* Added tests for DbState (#234). +* Added test for quickcheck Bool (#233). +* Various improvements (using final classes, method references, diamond operators, type inference, import lists, replace anonymous classes with lambdas etc. - #238). +* Use Either catamorphism internally (#285). +* Use uncurried foldLeft as default implementation (#283). +* Removed workarounds for fixed javac bugs (#282). +* Added IO test (#272). +* Exclude the demo subproject from Coveralls code coverage metrics (#268). +* Added tests for fj.Class (#262). +* Use method reference in IOWalkthrough (#255). +* Update retro lambda plugin version from 3.2.0 to 3.2.5 (#247). == Breaking Changes -* TODO. +* Removed deprecated Equal.shallowEquals0 (#239). +* Removed use of Arbitrary wrapper (#271). + +== Deprecations + +* Array.toJavaArray (#241). == Documentation @@ -25,4 +62,13 @@ Proposed release: Jun 2016 == Contributors -* TODO. +* Mark Perry +* JB Giraudeau +* @mrbackend +* Brian McKenna +* Clinton Selke +* Gabor Liptak +* Ryan Johnson +* Charles O'Farrell +* Fabian Kramer + diff --git a/etc/release-notes/release-notes-4.7.adoc b/etc/release-notes/release-notes-4.7.adoc new file mode 100644 index 00000000..3c1b265f --- /dev/null +++ b/etc/release-notes/release-notes-4.7.adoc @@ -0,0 +1,28 @@ + += Release 4.7 + +Proposed release: September 2016 + +== Enhancements + +* TODO. + +== Fixes + +* TODO. + +== Internal + +* TODO. + +== Breaking Changes + +* TODO. + +== Documentation + +* TODO. + +== Contributors + +* TODO. From 901f48e82480e0933475ff00565a8ea7bfe9a3c9 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 2 Jul 2016 01:03:18 +1000 Subject: [PATCH 124/336] Added release note process step to go through Github issues and pull requests --- etc/release-process.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/etc/release-process.txt b/etc/release-process.txt index f62cb01f..e9bdbb15 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -2,6 +2,8 @@ Current Release Process ======================= +Go through the issues and pull requests and set the Label and Milestone field. Add information to /etc/release-notes/release-notes-.adoc. + Update build.gradle: * set isSnapshot to false * set useRetroLambda to true From 1efd9cbe5dd1afa577cff218b1a7a227d4458846 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 2 Jul 2016 01:03:49 +1000 Subject: [PATCH 125/336] Added deprecated release version for remaining methods --- quickcheck/src/main/java/fj/test/Gen.java | 5 +++++ quickcheck/src/main/java/fj/test/Rand.java | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 1ea9be0a..1e4a4c5e 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -2,6 +2,7 @@ import fj.F; import fj.Function; +import fj.Ord; import fj.P2; import fj.Unit; import fj.control.Trampoline; @@ -506,6 +507,8 @@ public static Gen pickOne(List as) { *

* Note: pick is synonymous with combinationOf * + * @deprecated As of release 4.6, use {@link #combinationOf} + * * @param n The number of elements to pick from the given list. * @param as The list from which to pick elements. * @return A generator of lists that picks the given number of elements from the given list. @@ -644,6 +647,8 @@ private static Gen> pick(Gen> indexesGen, Array as) *

* Note: someOf is synonymous with someCombinationOf * + * @deprecated As of release 4.6, use {@link #someCombinationOf} + * * @param as The list from which to pick values. * @return A generator of lists that produces some of the values of the given list. */ diff --git a/quickcheck/src/main/java/fj/test/Rand.java b/quickcheck/src/main/java/fj/test/Rand.java index 97f94596..f1849bb3 100644 --- a/quickcheck/src/main/java/fj/test/Rand.java +++ b/quickcheck/src/main/java/fj/test/Rand.java @@ -97,7 +97,9 @@ public Rand reseed(long seed) { * result. *

* Calling {@link #reseed(long)} on an instance returned from this method will - * result in an exception being thrown. Use {@link #rand(F, F, F)} instead. + * result in an exception being thrown. + * + * @deprecated As of release 4.6, use {@link #rand(F, F, F)}. * * @param f The integer random generator. * @param g The floating-point random generator. From 4f9083d909d4f8dc40c3bf4eb584c9e0803eef1e Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 2 Jul 2016 01:12:35 +1000 Subject: [PATCH 126/336] Changed 4.6 proposed release date to July 2016 --- etc/release-notes/release-notes-4.6.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/release-notes/release-notes-4.6.adoc b/etc/release-notes/release-notes-4.6.adoc index 628457c5..756c10e2 100644 --- a/etc/release-notes/release-notes-4.6.adoc +++ b/etc/release-notes/release-notes-4.6.adoc @@ -1,7 +1,7 @@ = Release 4.6 -Proposed release: June 2016 +Proposed release: July 2016 == Enhancements From d4746a413a00d69572abbf4adb24077a286fc96c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 2 Jul 2016 01:15:12 +1000 Subject: [PATCH 127/336] Added doc section to release notes for 4.6 --- etc/release-notes/release-notes-4.6.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/release-notes/release-notes-4.6.adoc b/etc/release-notes/release-notes-4.6.adoc index 756c10e2..c67cf8b7 100644 --- a/etc/release-notes/release-notes-4.6.adoc +++ b/etc/release-notes/release-notes-4.6.adoc @@ -58,7 +58,7 @@ Proposed release: July 2016 == Documentation -* TODO. +* Added IO walkthrough (as per enhancements, #254). == Contributors From 3c5bd85a34ebb2add4e56ad24c7e6b7a92e306cf Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 21:27:23 +1000 Subject: [PATCH 128/336] Do not use method introduced to Java 7 Integer.compare --- core/src/main/java/fj/Ord.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 04cc46b9..4c3ab5c5 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -487,7 +487,7 @@ public static > Ord comparableOrd() { public static Ord hashOrd() { return ord(a -> { int aHash = a.hashCode(); - return a2 -> Ordering.fromInt(Integer.compare(aHash, a2.hashCode())); + return a2 -> Ordering.fromInt(Integer.valueOf(aHash).compareTo(a2.hashCode())); }); } From 72289054848eee812add97d31c17bda92e6822af Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 21:28:01 +1000 Subject: [PATCH 129/336] Added first time contributors --- etc/CONTRIBUTORS | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/etc/CONTRIBUTORS b/etc/CONTRIBUTORS index 63be1827..06536883 100644 --- a/etc/CONTRIBUTORS +++ b/etc/CONTRIBUTORS @@ -214,3 +214,14 @@ jb@giraudeau.info Zheka Kozlov @orionll +@mrbackend + +Brian McKenna + +Clinton Selke + +Ryan Johnson + +Charles O'Farrell + +Fabian Kramer From 56597e33a0ede3c6a2b3c6647243c3a286c5d223 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 21:28:19 +1000 Subject: [PATCH 130/336] Changes to release 4.6 --- build.gradle | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 2744cd00..e11b2274 100644 --- a/build.gradle +++ b/build.gradle @@ -48,7 +48,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true + isSnapshot = false fjBaseVersion = "4.6" snapshotAppendix = "-SNAPSHOT" @@ -56,7 +56,7 @@ allprojects { fjConsumeVersion = "4.5" signModule = false - useRetroLambda = false + useRetroLambda = true projectTitle = "Functional Java" projectName = "functionaljava" diff --git a/gradle.properties b/gradle.properties index d4552a30..07c2b60c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = false +signingEnabled = true From b1796a9c008bb0978eae01b6e4766f35906b0fd8 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 21:48:51 +1000 Subject: [PATCH 131/336] Get ready for 4.7 snapshot --- build.gradle | 8 ++++---- gradle.properties | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index e11b2274..7d9efae1 100644 --- a/build.gradle +++ b/build.gradle @@ -48,15 +48,15 @@ allprojects { defaultTasks "build" ext { - isSnapshot = false - fjBaseVersion = "4.6" + isSnapshot = true + fjBaseVersion = "4.7" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.5" + fjConsumeVersion = "4.6" signModule = false - useRetroLambda = true + useRetroLambda = false projectTitle = "Functional Java" projectName = "functionaljava" diff --git a/gradle.properties b/gradle.properties index 07c2b60c..d4552a30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = true +signingEnabled = false From a8584ad52992724e44f6304d74009eea1c6656c8 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 23:01:25 +1000 Subject: [PATCH 132/336] Updated github readme for release 4.6 --- README.adoc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index 40fec847..9addaff8 100644 --- a/README.adoc +++ b/README.adoc @@ -13,7 +13,7 @@ The library is intended for use in production applications and is thoroughly tes Functional Java provides abstractions for the following types: * Basic Data Structures - total and partial functions, products, unit, option, unbiased and right biased unions (either and validation), void. -* Immutable Collections - array, list, vector, stream, set, map, finger tree, heterogenous list, difference list. +* Immutable Collections - array, list, vector, stream, set, map, priority queue, finger tree, heterogenous list, difference list. * Other Abstractions - monoid, semigroup, natural, random number generator, reader, writer, state, input/output, parser, zipper, specification based testing (quickcheck), actors, optics (lens, prism, fold, traversal and others), concurrency and type conversion. == URLs @@ -35,12 +35,12 @@ The Functional Java artifact is published to Maven Central using the group `org. * Java 8 specific support (`functionaljava-java8`) * property based testing (`functionaljava-quickcheck`) -The latest stable version is `4.5`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `4.6`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.5" -compile "org.functionaljava:functionaljava-java8:4.5" -compile "org.functionaljava:functionaljava-quickcheck:4.5" -compile "org.functionaljava:functionaljava-java-core:4.5" +compile "org.functionaljava:functionaljava:4.6" +compile "org.functionaljava:functionaljava-java8:4.6" +compile "org.functionaljava:functionaljava-quickcheck:4.6" +compile "org.functionaljava:functionaljava-java-core:4.6" ---- and in Maven: @@ -48,22 +48,22 @@ and in Maven: org.functionaljava functionaljava - 4.5 + 4.6 org.functionaljava functionaljava-java8 - 4.5 + 4.6 org.functionaljava functionaljava-quickcheck - 4.5 + 4.6 org.functionaljava functionaljava-java-core - 4.5 + 4.6 ---- @@ -71,7 +71,7 @@ and in Maven: FunctionalJava uses the Retro Lambda project to backport Java 8 lambdas to Java 6 bytecode. This requires access to both JDK 6 and 8. The build system requires the environment variables `JAVA6_HOME` and `JAVA8_HOME` to refer to the appropriate directories. -Building is done using Gradle 2.10. In the root directory run: +Building is done using Gradle 2.13. In the root directory run: ---- ./gradlew ---- @@ -100,6 +100,7 @@ A more complete description of the features mentioned above are: ** Immutable set implementation using a red/black tree (`fj.data.Set`). ** Immutable multi-way tree - aka rose tree (`fj.data.Tree`). ** Immutable tree-map using a red/black tree implementation (`fj.data.TreeMap`). +** Immutable priority queue using finger trees (`fj.data.PriorityQueue`). ** Difference lists, a highly performant list. * Other Abstractions ** Monoid (`fj.Monoid`). From 8069b9e82161a55ec3fc2c6724d6779315a1072a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 3 Jul 2016 23:34:01 +1000 Subject: [PATCH 133/336] Added 4.6 release date to release notes --- etc/release-notes/release-notes-4.6.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/release-notes/release-notes-4.6.adoc b/etc/release-notes/release-notes-4.6.adoc index c67cf8b7..c0d12558 100644 --- a/etc/release-notes/release-notes-4.6.adoc +++ b/etc/release-notes/release-notes-4.6.adoc @@ -1,7 +1,7 @@ = Release 4.6 -Proposed release: July 2016 +Proposed release: July 3 2016 == Enhancements From 726f0245f7812b2ab42b3e5cf0084523160c8626 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 4 Jul 2016 00:46:41 +1000 Subject: [PATCH 134/336] Modified language in release notes slightly --- etc/release-notes/release-notes-4.6.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/release-notes/release-notes-4.6.adoc b/etc/release-notes/release-notes-4.6.adoc index c0d12558..a33c1214 100644 --- a/etc/release-notes/release-notes-4.6.adoc +++ b/etc/release-notes/release-notes-4.6.adoc @@ -1,7 +1,7 @@ = Release 4.6 -Proposed release: July 3 2016 +Released: 3 July 2016 == Enhancements From 4e369f59032b4c4e695c155aed23b53da9ae4d4c Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 18 Jul 2016 22:05:50 +0200 Subject: [PATCH 135/336] Deprecate unsafe Ord instance and List#groupBy that use them. --- core/src/main/java/fj/Ord.java | 12 +++++++++--- core/src/main/java/fj/data/List.java | 12 ++++++++++-- demo/src/main/java/fj/demo/List_groupBy.java | 6 +++--- .../src/test/scala/fj/data/CheckList.scala | 2 +- .../test/java/fj/data/properties/ListProperties.java | 2 +- 5 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 4c3ab5c5..5c84c24e 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -478,12 +478,14 @@ public static > Ord comparableOrd() { /** * An order instance that uses {@link Object#hashCode()} for computing the order and equality, - * thus objects returning the same hashCode are considered to be equals (check {@link #hashEqualsOrd()} - * for an additional check on {@link Object#equals(Object)}). + * thus objects returning the same hashCode are considered to be equals. + * This is not safe and therefore this method is deprecated. * * @return An order instance that is based on {@link Object#hashCode()}. - * @see #hashEqualsOrd() + * + * @deprecated As of release 4.7. */ + @Deprecated public static Ord hashOrd() { return ord(a -> { int aHash = a.hashCode(); @@ -495,9 +497,13 @@ public static Ord hashOrd() { * An order instance that uses {@link Object#hashCode()} and {@link Object#equals} for computing * the order and equality. First the hashCode is compared, if this is equal, objects are compared * using {@link Object#equals}. + * WARNING: This ordering violate antisymmetry on hash collisions. * * @return An order instance that is based on {@link Object#hashCode()} and {@link Object#equals}. + * + * @deprecated As of release 4.7. */ + @Deprecated public static Ord hashEqualsOrd() { return ord(a -> { int aHash = a.hashCode(); diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index c49fd63a..ac846393 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -1299,11 +1299,15 @@ public final A mode(final Ord o) { /** * Groups the elements of this list by a given keyFunction into a {@link TreeMap}. - * The ordering of the keys is determined by {@link fj.Ord#hashOrd()}. + * The ordering of the keys is determined by {@link fj.Ord#hashOrd()} (ie. Object#hasCode). + * This is not safe and therefore this method is deprecated. * * @param keyFunction The function to select the keys for the map. * @return A TreeMap containing the keys with the accumulated list of matched elements. + * + * @deprecated As of release 4.7, use {@link #groupBy(F, Ord)} */ + @Deprecated public final TreeMap> groupBy(final F keyFunction) { return groupBy(keyFunction, Ord.hashOrd()); } @@ -1322,12 +1326,16 @@ public final TreeMap> groupBy(final F keyFunction, final Or /** * Groups the elements of this list by a given keyFunction into a {@link TreeMap} and transforms * the matching elements with the given valueFunction. The ordering of the keys is determined by - * {@link fj.Ord#hashOrd()}. + * {@link fj.Ord#hashOrd()} (ie. Object#hasCode). + * This is not safe and therefore this method is deprecated. * * @param keyFunction The function to select the keys for the map. * @param valueFunction The function to apply on each matching value. * @return A TreeMap containing the keys with the accumulated list of matched and mapped elements. + * + * @deprecated As of release 4.7, use {@link #groupBy(F, F, Ord)} */ + @Deprecated public final TreeMap> groupBy( final F keyFunction, final F valueFunction) { diff --git a/demo/src/main/java/fj/demo/List_groupBy.java b/demo/src/main/java/fj/demo/List_groupBy.java index f557ec74..b415e19c 100644 --- a/demo/src/main/java/fj/demo/List_groupBy.java +++ b/demo/src/main/java/fj/demo/List_groupBy.java @@ -18,7 +18,7 @@ public static void main(final String... args) { private static void keyDemo() { System.out.println("KeyDemo"); final List words = list("Hello", "World", "how", "are", "your", "doing"); - final TreeMap> lengthMap = words.groupBy(String::length); + final TreeMap> lengthMap = words.groupBy(String::length, Ord.intOrd); lengthMap.forEach(entry -> System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2()))); } @@ -26,7 +26,7 @@ private static void keyDemo() { private static void keyValueDemo() { System.out.println("KeyValueDemo"); final List xs = list(1, 2, 3, 4, 5, 6, 7, 8, 9); - final TreeMap> result = xs.groupBy(x -> x % 3, Integer::toBinaryString); + final TreeMap> result = xs.groupBy(x -> x % 3, Integer::toBinaryString, Ord.intOrd); result.forEach(entry -> System.out.println(String.format("Numbers with reminder %d are %s", entry._1(), entry._2()))); } @@ -35,7 +35,7 @@ private static void keyValueAccDemo() { System.out.println("KeyValueAccDemo"); final List words = list("Hello", "World", "how", "are", "your", "doing"); final TreeMap lengthCounts = - words.groupBy(String::length, Function.identity(), 0, (word, sum) -> sum + 1, Ord.hashOrd()); + words.groupBy(String::length, Function.identity(), 0, (word, sum) -> sum + 1, Ord.intOrd); lengthCounts.forEach(entry -> System.out.println(String.format("Words with %d chars: %s", entry._1(), entry._2()))); } diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckList.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckList.scala index 36bd99f0..d675db81 100644 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckList.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckList.scala @@ -187,7 +187,7 @@ object CheckList extends Properties("List") { join(a))) property("groupBy") = forAll((a: List[Int]) => { - val result = a.groupBy((x: Int) => (x % 2 == 0): lang.Boolean) + val result = a.groupBy((x: Int) => (x % 2 == 0): lang.Boolean, Ord.booleanOrd) result.get(true).forall((xs: List[Int]) => xs.forall((x: Int) => (x % 2 == 0): lang.Boolean): lang.Boolean) && result.get(false).forall((xs: List[Int]) => xs.forall((x: Int) => (x % 2 != 0): lang.Boolean): lang.Boolean) && a.map((x: Int) => (x % 2) == 0: lang.Boolean).nub().length() == result.size() diff --git a/props-core/src/test/java/fj/data/properties/ListProperties.java b/props-core/src/test/java/fj/data/properties/ListProperties.java index 9724488f..fad5f66f 100644 --- a/props-core/src/test/java/fj/data/properties/ListProperties.java +++ b/props-core/src/test/java/fj/data/properties/ListProperties.java @@ -255,7 +255,7 @@ public Property nub() { public Property groupBy() { return property(arbList(arbInteger), list -> { - final TreeMap> map = list.groupBy(i -> i % 2 == 0); + final TreeMap> map = list.groupBy(i -> i % 2 == 0, Ord.booleanOrd); final List list1 = map.get(true).orSome(nil()); final List list2 = map.get(false).orSome(nil()); return prop(list.length() == list1.length() + list2.length()) From 10b1c79a02162cb222e3d9de9b118ae2b32e769b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 18 Jul 2016 23:10:25 +0200 Subject: [PATCH 136/336] Improve performance of List#groupBy via a mutable buffer. Fix #288 --- core/src/main/java/fj/data/List.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index ac846393..a4fa19eb 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -1398,14 +1398,15 @@ public final TreeMap groupBy( final D groupingIdentity, final F2 groupingAcc, final Ord keyOrd) { - return this.foldLeft((map, element) -> { - final B key = keyFunction.f(element); - final C value = valueFunction.f(element); - return map.set(key, map.get(key) - .map(existing -> groupingAcc.f(value, existing)) - .orSome(groupingAcc.f(value, groupingIdentity))); - }, TreeMap.empty(keyOrd) - ); + java.util.TreeMap buffer = new java.util.TreeMap<>(keyOrd.toComparator()); + foreachDoEffect(element -> { + final B key = keyFunction.f(element); + final C value = valueFunction.f(element); + buffer.put(key, buffer.containsKey(key) + ? groupingAcc.f(value, buffer.get(key)) + : groupingAcc.f(value, groupingIdentity)); + }); + return TreeMap.fromMutableMap(keyOrd, buffer); } From 49c6f8d6fd51e92e32a0649205b3699aba1a60e6 Mon Sep 17 00:00:00 2001 From: JB Giraudeau Date: Fri, 22 Jul 2016 14:32:05 +0200 Subject: [PATCH 137/336] Fix #293 regression. isGreaterThan(A)/isLesserThan(A) were not using strict inequality --- core/src/main/java/fj/Ord.java | 4 ++-- core/src/test/java/fj/OrdTest.java | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 core/src/test/java/fj/OrdTest.java diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 5c84c24e..df654a23 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -129,7 +129,7 @@ public boolean isGreaterThan(final A a1, final A a2) { * @return A function that returns true if its argument is less than the argument to this method. */ public F isLessThan(final A a) { - return compose(o -> o != Ordering.LT, f.f(a)); + return compose(o -> o == Ordering.GT, f.f(a)); } /** @@ -139,7 +139,7 @@ public F isLessThan(final A a) { * @return A function that returns true if its argument is greater than the argument to this method. */ public F isGreaterThan(final A a) { - return compose(o -> o != Ordering.GT, f.f(a)); + return compose(o -> o == Ordering.LT, f.f(a)); } /** diff --git a/core/src/test/java/fj/OrdTest.java b/core/src/test/java/fj/OrdTest.java new file mode 100644 index 00000000..d218387a --- /dev/null +++ b/core/src/test/java/fj/OrdTest.java @@ -0,0 +1,27 @@ +package fj; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class OrdTest { + + @Test + public void isGreaterThan() { + F pred = Ord.longOrd.isGreaterThan(1L); + + assertThat(pred.f(0L), is(false)); + assertThat(pred.f(1L), is(false)); + assertThat(pred.f(2L), is(true)); + } + + @Test + public void isLessThan() { + F pred = Ord.longOrd.isLessThan(1L); + + assertThat(pred.f(0L), is(true)); + assertThat(pred.f(1L), is(false)); + assertThat(pred.f(2L), is(false)); + } +} From e6abe86c7527ffafae908710e14c2212ff865007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Thu, 15 Sep 2016 14:13:03 -0400 Subject: [PATCH 138/336] Add tests for Strings (#295) --- .../test/java/fj/function/StringsTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 core/src/test/java/fj/function/StringsTest.java diff --git a/core/src/test/java/fj/function/StringsTest.java b/core/src/test/java/fj/function/StringsTest.java new file mode 100644 index 00000000..92cf44d3 --- /dev/null +++ b/core/src/test/java/fj/function/StringsTest.java @@ -0,0 +1,67 @@ +package fj.function; + +import fj.Function; +import org.junit.Test; + +import static fj.F1Functions.o; +import static fj.Function.compose; +import static fj.function.Strings.*; +import static org.junit.Assert.*; +import static org.hamcrest.core.Is.is; + +public class StringsTest { + @Test + public void testLines() { + assertThat(compose(unlines(), lines()).f("one two three"), is("one two three")); + } + + @Test + public void testLinesEmpty() { + assertThat(o(unlines(), lines()).f(""), is("")); + } + + @Test + public void testLength() { + assertThat(length.f("functionaljava"), is(14)); + } + + @Test + public void testMatches() { + assertThat(matches.f("foo").f("foo"), is(true)); + } + + @Test + public void testContains() { + assertThat(contains.f("bar").f("foobar1"), is(true)); + } + + @Test(expected = NullPointerException.class) + public void testIsEmptyException() { + assertThat(isEmpty.f(null), is(true)); + } + + @Test + public void testIsEmpty() { + assertThat(isEmpty.f(""), is(true)); + } + + @Test + public void testIsNotNullOrEmpty() { + assertThat(isNotNullOrEmpty.f("foo"), is(true)); + } + + @Test + public void testIsNullOrEmpty() { + assertThat(isNullOrEmpty.f(null), is(true)); + } + + @Test + public void testIsNotNullOrBlank() { + assertThat(isNotNullOrBlank.f("foo"), is(true)); + } + + @Test + public void testIsNullOrBlank() { + assertThat(isNullOrBlank.f(" "), is(true)); + } +} From 2798b2c4101585a887a1ba9dc4608ac1d752f237 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 00:32:38 +0200 Subject: [PATCH 139/336] Avoid unecessary currying in uncurried version of foldRight. --- core/src/main/java/fj/data/List.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index a4fa19eb..da4a624e 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -716,7 +716,7 @@ public final List append(final List as) { * @return The final result after the right-fold reduction. */ public final B foldRight(final F> f, final B b) { - return reverse().foldLeft(flip(f), b); + return foldRight(uncurryF2(f), b); } /** @@ -727,7 +727,7 @@ public final B foldRight(final F> f, final B b) { * @return The final result after the right-fold reduction. */ public final B foldRight(final F2 f, final B b) { - return foldRight(curry(f), b); + return reverse().foldLeft(flip(f), b); } /** From bd665e14ac9f07333c1fcd81c56884de1c26dc9f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 00:34:09 +0200 Subject: [PATCH 140/336] NonEmtyList. Add uncurried version of foldRight/foldLeft + append(List). --- core/src/main/java/fj/data/NonEmptyList.java | 27 +++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index db994dc0..da06e0f4 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -8,6 +8,7 @@ import static fj.Function.flip; import static fj.Function.identity; +import static fj.Function.uncurryF2; import static fj.data.Option.some; import static fj.data.Option.somes; @@ -73,6 +74,16 @@ public NonEmptyList snoc(final A a) { */ public int length() { return 1 + tail.length(); } + /** + * Appends the given list to this list. + * + * @param as The list to append. + * @return A new list with the given list appended. + */ + public NonEmptyList append(final List as) { + return nel(head, tail.append(as)); + } + /** * Appends the given list to this list. * @@ -95,14 +106,28 @@ public final A foldRight1(final F> f) { return reverse().foldLeft1(flip(f)); } + /** + * Performs a right-fold reduction across this list. This function uses O(length) stack space. + */ + public final A foldRight1(final F2 f) { + return reverse().foldLeft1(flip(f)); + } + /** * Performs a left-fold reduction across this list. This function runs in constant space. */ public final A foldLeft1(final F> f) { + return foldLeft1(uncurryF2(f)); + } + + /** + * Performs a left-fold reduction across this list. This function runs in constant space. + */ + public final A foldLeft1(final F2 f) { A x = head; for (List xs = tail; !xs.isEmpty(); xs = xs.tail()) { - x = f.f(x).f(xs.head()); + x = f.f(x, xs.head()); } return x; From 87d9b30e8ecdb8775637426022e36c25601ca8e2 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 00:35:20 +0200 Subject: [PATCH 141/336] Stream: Avoid unecessary currying in uncurried version of foldRight. --- core/src/main/java/fj/data/Stream.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index ae37d714..b3fa156d 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -119,7 +119,7 @@ public final B uncons(final B nil, final F>, B>> cons) { * @return The final result after the right-fold reduction. */ public final B foldRight(final F, B>> f, final B b) { - return isEmpty() ? b : f.f(head()).f(P.lazy(() -> tail()._1().foldRight(f, b))); + return foldRight(uncurryF2(f), b); } /** @@ -130,7 +130,7 @@ public final B foldRight(final F, B>> f, final B b) { * @return The final result after the right-fold reduction. */ public final B foldRight(final F2, B> f, final B b) { - return foldRight(curry(f), b); + return isEmpty() ? b : f.f(head(), P.lazy(() -> tail()._1().foldRight(f, b))); } /** @@ -141,7 +141,7 @@ public final B foldRight(final F2, B> f, final B b) { * @return The final result after the right-fold reduction. */ public final B foldRight1(final F> f, final B b) { - return foldRight(compose(Function., B, B>andThen().f(P1.__1()), f), b); + return foldRight1(uncurryF2(f), b); } /** @@ -152,7 +152,7 @@ public final B foldRight1(final F> f, final B b) { * @return The final result after the right-fold reduction. */ public final B foldRight1(final F2 f, final B b) { - return foldRight1(curry(f), b); + return isEmpty() ? b : f.f(head(), tail()._1().foldRight1(f, b)); } /** From 7aa9e3b79989b3ce9d2388094913ea3f393b0686 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 00:45:32 +0200 Subject: [PATCH 142/336] Monoid/Semigroup: implement optimizable/optimized definitions. + add generic compose and xmap + deprecate double semigroups due to round errors. --- core/src/main/java/fj/Monoid.java | 781 ++++++++++++++++-- core/src/main/java/fj/Ord.java | 75 +- core/src/main/java/fj/Semigroup.java | 392 +++++++-- core/src/main/java/fj/data/optic/Fold.java | 2 +- .../main/java/fj/data/optic/PTraversal.java | 2 +- core/src/main/java/fj/function/Doubles.java | 17 +- .../java/fj/demo/concurrent/WordCount.java | 7 +- 7 files changed, 1097 insertions(+), 179 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 3436d5a3..a342b8c7 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -1,18 +1,22 @@ package fj; -import static fj.Function.curry; -import static fj.Function.flip; +import static fj.F1Functions.dimap; + import fj.data.Array; +import fj.data.DList; import fj.data.List; import fj.data.IO; -import fj.data.IOFunctions; import fj.data.Natural; import fj.data.Option; import fj.data.Set; import fj.data.Stream; -import static fj.Function.flip; -import static fj.Semigroup.multiply1p; +import static fj.Function.*; +import static fj.Semigroup.semigroupDef; +import static fj.Unit.unit; +import static fj.data.List.nil; +import static fj.data.Natural.natural; +import static fj.data.Option.none; import static fj.data.Stream.iterableStream; import java.math.BigInteger; @@ -30,20 +34,83 @@ * @version %build.number% */ public final class Monoid { - private final F> sum; - private final A zero; - private Monoid(final F> sum, final A zero) { - this.sum = sum; - this.zero = zero; + + private final Definition def; + + public interface Definition extends Semigroup.Definition { + + A empty(); + + + default A sum(F0> as) { + return as.f().foldLeft(this::append, empty()); + } + + @Override + default A sum(A a, F0> as) { + return sum(() -> Stream.cons(a, as)); + } + + default A multiply(int n, A a) { + return (n <= 0) + ? empty() + : Semigroup.Definition.super.multiply1p(n - 1, a); + } + + @Override + default A multiply1p(int n, A a) { + return n == Integer.MAX_VALUE + ? append(a, multiply(n, a)) + : multiply(n + 1, a); + } + + default Definition dual() { + return new Definition(){ + + @Override + public A empty() { + return Definition.this.empty(); + } + + @Override + public A append(A a1, A a2) { + return Definition.this.append(a2, a1); + } + + @Override + public A multiply(int n, A a) { + return Definition.this.multiply(n, a); + } + + @Override + public Definition dual() { + return Definition.this; + } + }; + } + } + + public interface AltDefinition extends Definition { + + @Override + F prepend(A a); + + @Override + default A append(A a1, A a2) { + return prepend(a1).f(a2); + } + } + + private Monoid(Definition def) { + this.def = def; } /** * Composes this monoid with another. */ public Monoid>compose(Monoid m) { - return monoid((P2 x) -> (P2 y) -> - P.p(sum(x._1(), y._1()), m.sum(x._2(), y._2())), P.p(zero, m.zero)); + return compose(m, P2.__1(), P2.__2(), P::p); } /** @@ -52,7 +119,81 @@ private Monoid(final F> sum, final A zero) { * @return A semigroup projection of this monoid. */ public Semigroup semigroup() { - return Semigroup.semigroup(sum); + return semigroupDef(def); + } + + /** + * Maps the given functions across this monoid as an invariant functor. + * + * @param f The covariant map. + * @param g The contra-variant map. + * @return A new monoid. + */ + public Monoid xmap(final F f, final F g) { + Monoid.Definition def = this.def; + B zero = f.f(def.empty()); + return monoidDef(new Definition() { + @Override + public B empty() { + return zero; + } + + @Override + public B append(B a1, B a2) { + return f.f(def.append(g.f(a1), g.f(a2))); + } + + @Override + public F prepend(B b) { + return dimap(def.prepend(g.f(b)), g, f); + } + + @Override + public B multiply(int n, B b) { + return f.f(def.multiply(n , g.f(b))); + } + + @Override + public B sum(F0> as) { + return f.f(def.sum(() -> as.f().map(g))); + } + }); + } + + + public Monoid compose(Monoid mb, final F a, final F b, final F2 c) { + Definition maDef = this.def; + Definition mbDef = mb.def; + C empty = c.f(maDef.empty(), mbDef.empty()); + return monoidDef(new Definition() { + + @Override + public C empty() { + return empty; + } + + @Override + public C append(C c1, C c2) { + return c.f(maDef.append(a.f(c1), a.f(c2)), mbDef.append(b.f(c1), b.f(c2))); + } + + @Override + public F prepend(C c1) { + F prependA = maDef.prepend(a.f(c1)); + F prependB = mbDef.prepend(b.f(c1)); + return c2 -> c.f(prependA.f(a.f(c2)), prependB.f(b.f(c2))); + } + + @Override + public C multiply(int n, C c1) { + return c.f(maDef.multiply(n, a.f(c1)), mbDef.multiply(n, b.f(c1))); + } + + @Override + public C sum(F0> cs) { + return c.f(maDef.sum(() -> cs.f().map(a)), mbDef.sum(() -> cs.f().map(b))); + } + }); } /** @@ -63,7 +204,7 @@ public Semigroup semigroup() { * @return The of the two given arguments. */ public A sum(final A a1, final A a2) { - return sum.f(a1).f(a2); + return def.append(a1, a2); } /** @@ -73,7 +214,7 @@ public A sum(final A a1, final A a2) { * @return A function that sums the given value according to this monoid. */ public F sum(final A a1) { - return sum.f(a1); + return def.prepend(a1); } /** @@ -82,7 +223,7 @@ public F sum(final A a1) { * @return A function that sums according to this monoid. */ public F> sum() { - return sum; + return def::prepend; } /** @@ -91,7 +232,7 @@ public F> sum() { * @return The zero value for this monoid. */ public A zero() { - return zero; + return def.empty(); } /** @@ -106,9 +247,7 @@ public A zero() { * {@code zero()} */ public A multiply(final int n, final A a) { - return (n <= 0) - ? zero - : multiply1p(sum, n - 1, a); + return def.multiply(n, a); } /** @@ -118,7 +257,7 @@ public A multiply(final int n, final A a) { * @return The sum of the given values. */ public A sumRight(final List as) { - return as.foldRight(sum, zero); + return as.foldRight(def::append, def.empty()); } /** @@ -128,7 +267,7 @@ public A sumRight(final List as) { * @return The sum of the given values. */ public A sumRight(final Stream as) { - return as.foldRight((a, ap1) -> sum(a, ap1._1()), zero); + return as.foldRight1(def::append, def.empty()); } /** @@ -138,7 +277,7 @@ public A sumRight(final Stream as) { * @return The sum of the given values. */ public A sumLeft(final List as) { - return as.foldLeft(sum, zero); + return as.foldLeft(def::append, def.empty()); } /** @@ -148,7 +287,7 @@ public A sumLeft(final List as) { * @return The sum of the given values. */ public A sumLeft(final Stream as) { - return as.foldLeft(sum, zero); + return def.sum(() -> as); } /** @@ -187,147 +326,495 @@ public F, A> sumLeftS() { */ public A join(final Iterable as, final A a) { final Stream s = iterableStream(as); - return s.isEmpty() ? - zero : - s.foldLeft1(Function.compose(sum, flip(sum).f(a))); + F prependA = def.prepend(a); + return s.isEmpty() + ? def.empty() + : s.foldLeft1((a1, a2) -> def.append(a1, prependA.f(a2))); } /** * Swaps the arguments when summing. */ public Monoid dual() { - return monoid(flip(sum), zero); + return monoidDef(def.dual()); + } + + /** + * Constructs a monoid from the given definition, which must follow the monoidal + * laws. + * + * @param def The definition for the monoid. + * @return A monoid instance that uses the given sun function and zero value. + */ + public static Monoid monoidDef(Definition def) { + return new Monoid<>(def); + } + + /** + * Constructs a monoid from the given definition, which must follow the monoidal + * laws. + * + * @param def The definition for the monoid. + * @return A monoid instance that uses the given sun function and zero value. + */ + public static Monoid monoidDef(AltDefinition def) { + return new Monoid<>(def); + } + + /** + * Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws. + * + * @param s The semigroup definition for the monoid. + * @param zero The zero for the monoid. + * @return A monoid instance that uses the given sun function and zero value. + */ + public static Monoid monoidDef(final Semigroup.Definition s, final A zero) { + return new Monoid<>(new Monoid.Definition() { + @Override + public A empty() { + return zero; + } + + @Override + public A sum(F0> as) { + return s.sum(zero, as); + } + + @Override + public A sum(A a, F0> as) { + return s.sum(a, as); + } + + @Override + public A multiply(int n, A a) { + return (n <= 0) + ? zero + : s.multiply1p(n - 1, a); + } + + @Override + public A multiply1p(int n, A a) { + return s.multiply1p(n, a); + } + + @Override + public A append(A a1, A a2) { + return s.append(a1, a2); + } + + @Override + public F prepend(A a) { + return s.prepend(a); + } + }); + } + + /** + * Constructs a monoid from the given semigroup definition and zero value, which must follow the monoidal laws. + * + * @param s The semigroup definition for the monoid. + * @param zero The zero for the monoid. + * @return A monoid instance that uses the given sun function and zero value. + */ + public static Monoid monoidDef(final Semigroup.AltDefinition s, final A zero) { + return monoidDef((Semigroup.Definition) s, zero); } /** * Constructs a monoid from the given sum function and zero value, which must follow the monoidal * laws. + * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} instead. * * @param sum The sum function for the monoid. * @param zero The zero for the monoid. * @return A monoid instance that uses the given sun function and zero value. */ + @Deprecated public static Monoid monoid(final F> sum, final A zero) { - return new Monoid<>(sum, zero); + return new Monoid<>(new AltDefinition() { + @Override + public F prepend(A a) { + return sum.f(a); + } + + @Override + public A empty() { + return zero; + } + }); } /** * Constructs a monoid from the given sum function and zero value, which must follow the monoidal * laws. + * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} instead. * * @param sum The sum function for the monoid. * @param zero The zero for the monoid. * @return A monoid instance that uses the given sun function and zero value. */ + @Deprecated public static Monoid monoid(final F2 sum, final A zero) { - return new Monoid<>(curry(sum), zero); + return new Monoid<>(new Definition() { + @Override + public A empty() { + return zero; + } + + @Override + public A append(A a1, A a2) { + return sum.f(a1, a2); + } + }); } /** * Constructs a monoid from the given semigroup and zero value, which must follow the monoidal laws. + * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} or {@link Semigroup#monoid(Object)} instead. * * @param s The semigroup for the monoid. * @param zero The zero for the monoid. * @return A monoid instance that uses the given sun function and zero value. */ + @Deprecated public static Monoid monoid(final Semigroup s, final A zero) { - return new Monoid<>(s.sum(), zero); + return s.monoid(zero); } + /** * A monoid that adds integers. */ - public static final Monoid intAdditionMonoid = monoid(Semigroup.intAdditionSemigroup, 0); + public static final Monoid intAdditionMonoid = monoidDef(new Definition() { + @Override + public Integer empty() { + return 0; + } + + @Override + public Integer append(Integer a1, Integer a2) { + return a1 + a2; + } + + @Override + public Integer multiply(int n, Integer i) { + return n <= 0 ? 0 : n * i; + } + }); /** * A monoid that multiplies integers. */ - public static final Monoid intMultiplicationMonoid = monoid(Semigroup.intMultiplicationSemigroup, 1); + public static final Monoid intMultiplicationMonoid = monoidDef(new Definition() { + @Override + public Integer empty() { + return 1; + } + + @Override + public Integer append(Integer i1, Integer i2) { + return i1 * i2; + } + + @Override + public Integer sum(F0> as) { + int x = 1; + for (Stream xs = as.f(); x != 0 && !xs.isEmpty(); xs = xs.tail()._1()) { + x *= xs.head(); + } + return x; + } + + @Override + public Integer multiply(int n, Integer integer) { + return n <= 0 ? 1 : (int) StrictMath.pow(integer.doubleValue(), n); + } + }); /** - * A monoid that adds doubles. + * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws */ - public static final Monoid doubleAdditionMonoid = monoid(Semigroup.doubleAdditionSemigroup, 0.0); + @Deprecated + public static final Monoid doubleAdditionMonoid = monoidDef((d1, d2) -> d1 + d2, 0.0); /** - * A monoid that multiplies doubles. + * @deprecated Since 4.7. Due to rounding errors, multiplication of doubles does not comply with monoid laws */ - public static final Monoid doubleMultiplicationMonoid = monoid(Semigroup.doubleMultiplicationSemigroup, 1.0); + @Deprecated + public static final Monoid doubleMultiplicationMonoid = monoidDef((d1, d2) -> d1 * d2, 1.0); /** * A monoid that adds big integers. */ - public static final Monoid bigintAdditionMonoid = monoid(Semigroup.bigintAdditionSemigroup, BigInteger.ZERO); + public static final Monoid bigintAdditionMonoid = monoidDef(new Definition() { + @Override + public BigInteger empty() { + return BigInteger.ZERO; + } + + @Override + public BigInteger append(BigInteger a1, BigInteger a2) { + return a1.add(a2); + } + + @Override + public BigInteger multiply(int n, BigInteger a) { + return n <= 0 ? BigInteger.ZERO : a.multiply(BigInteger.valueOf(n)); + } + }); /** * A monoid that multiplies big integers. */ - public static final Monoid bigintMultiplicationMonoid = - monoid(Semigroup.bigintMultiplicationSemigroup, BigInteger.ONE); + public static final Monoid bigintMultiplicationMonoid = monoidDef(new Definition() { + @Override + public BigInteger empty() { + return BigInteger.ONE; + } + + @Override + public BigInteger append(BigInteger a1, BigInteger a2) { + return a1.multiply(a2); + } + + @Override + public BigInteger multiply(int n, BigInteger a) { + return n <= 0 ? BigInteger.ONE : a.pow(n); + } + + }); /** * A monoid that adds big decimals. */ public static final Monoid bigdecimalAdditionMonoid = - monoid(Semigroup.bigdecimalAdditionSemigroup, BigDecimal.ZERO); + monoidDef(new Definition() { + @Override + public BigDecimal empty() { + return BigDecimal.ZERO; + } + + @Override + public BigDecimal append(BigDecimal a1, BigDecimal a2) { + return a1.add(a2); + } + + @Override + public BigDecimal multiply(int n, BigDecimal a) { + return n <= 0 ? BigDecimal.ZERO : a.multiply(BigDecimal.valueOf(n)); + } + }); /** * A monoid that multiplies big decimals. */ public static final Monoid bigdecimalMultiplicationMonoid = - monoid(Semigroup.bigdecimalMultiplicationSemigroup, BigDecimal.ONE); + monoidDef(new Definition() { + @Override + public BigDecimal empty() { + return BigDecimal.ONE; + } + + @Override + public BigDecimal append(BigDecimal a1, BigDecimal a2) { + return a1.multiply(a2); + } + + @Override + public BigDecimal multiply(int n, BigDecimal decimal) { + return n <= 0 ? BigDecimal.ONE : decimal.pow(n); + } + }); + + /** * A monoid that adds natural numbers. */ public static final Monoid naturalAdditionMonoid = - monoid(Semigroup.naturalAdditionSemigroup, Natural.ZERO); + monoidDef(new Definition() { + @Override + public Natural empty() { + return Natural.ZERO; + } + + @Override + public Natural append(Natural a1, Natural a2) { + return a1.add(a2); + } + + @Override + public Natural multiply(int n, Natural a) { + return natural(n).map(positiveN -> a.multiply(positiveN)).orSome(Natural.ZERO); + } + }); /** * A monoid that multiplies natural numbers. */ public static final Monoid naturalMultiplicationMonoid = - monoid(Semigroup.naturalMultiplicationSemigroup, Natural.ONE); + monoidDef(new Definition() { + @Override + public Natural empty() { + return Natural.ONE; + } + + @Override + public Natural append(Natural a1, Natural a2) { + return a1.multiply(a2); + } + }); /** * A monoid that adds longs. */ - public static final Monoid longAdditionMonoid = monoid(Semigroup.longAdditionSemigroup, 0L); + public static final Monoid longAdditionMonoid = monoidDef(new Definition() { + @Override + public Long empty() { + return 0L; + } + + @Override + public Long append(Long a1, Long a2) { + return a1 + a2; + } + + @Override + public Long multiply(int n, Long a) { + return n <= 0 ? 0L : n * a; + } + }); /** * A monoid that multiplies longs. */ - public static final Monoid longMultiplicationMonoid = monoid(Semigroup.longMultiplicationSemigroup, 1L); + public static final Monoid longMultiplicationMonoid = monoidDef(new Definition() { + @Override + public Long empty() { + return 1L; + } + + @Override + public Long append(Long i1, Long i2) { + return i1 * i2; + } + + @Override + public Long sum(F0> as) { + long x = 1L; + for (Stream xs = as.f(); x != 0L && !xs.isEmpty(); xs = xs.tail()._1()) { + x *= xs.head(); + } + return x; + } + + @Override + public Long multiply(int n, Long l) { + return n <= 0 ? 1L : (long) StrictMath.pow(l.doubleValue(), n); + } + }); /** * A monoid that ORs booleans. */ - public static final Monoid disjunctionMonoid = monoid(Semigroup.disjunctionSemigroup, false); + public static final Monoid disjunctionMonoid = monoidDef(new Definition() { + @Override + public Boolean empty() { + return false; + } + + @Override + public Boolean append(Boolean a1, Boolean a2) { + return a1 | a2; + } + + @Override + public Boolean sum(F0> as) { + return as.f().filter(identity()).isNotEmpty(); + } + + @Override + public Boolean multiply(int n, Boolean a) { + return n <= 0 ? false : a; + } + }); /** * A monoid that XORs booleans. */ - public static final Monoid exclusiveDisjunctionMonoid = monoid(Semigroup.exclusiveDisjunctionSemiGroup, false); + public static final Monoid exclusiveDisjunctionMonoid = monoidDef(new Definition() { + @Override + public Boolean empty() { + return false; + } + + @Override + public Boolean append(Boolean a1, Boolean a2) { + return a1 ^ a2; + } + + @Override + public Boolean multiply(int n, Boolean a) { + return a && (n == 1); + } + }); /** * A monoid that ANDs booleans. */ - public static final Monoid conjunctionMonoid = monoid(Semigroup.conjunctionSemigroup, true); + public static final Monoid conjunctionMonoid = monoidDef(new Definition() { + @Override + public Boolean empty() { + return true; + } + + @Override + public Boolean append(Boolean a1, Boolean a2) { + return a1 & a2; + } + + @Override + public Boolean multiply(int n, Boolean a) { + return a; + } + + @Override + public Boolean sum(F0> as) { + return as.f().filter(a -> !a).isEmpty(); + } + }); /** * A monoid that appends strings. */ - public static final Monoid stringMonoid = monoid(Semigroup.stringSemigroup, ""); + public static final Monoid stringMonoid = monoidDef(new Definition() { + @Override + public String empty() { + return ""; + } + + @Override + public String append(String a1, String a2) { + return a1.concat(a2); + } + + @Override + public String sum(F0> as) { + StringBuilder sb = new StringBuilder(); + as.f().foreachDoEffect(sb::append); + return sb.toString(); + } + }); /** * A monoid that appends string buffers. */ - public static final Monoid stringBufferMonoid = monoid(Semigroup.stringBufferSemigroup, new StringBuffer()); + public static final Monoid stringBufferMonoid = monoidDef((s1, s2) -> new StringBuffer(s1).append(s2), new StringBuffer(0)); /** * A monoid that appends string builders. */ - public static final Monoid stringBuilderMonoid = monoid(Semigroup.stringBuilderSemigroup, new StringBuilder()); + public static final Monoid stringBuilderMonoid = monoidDef((s1, s2) -> new StringBuilder(s1).append(s2), new StringBuilder(0)); /** * A monoid for functions. @@ -336,7 +823,18 @@ public static Monoid monoid(final Semigroup s, final A zero) { * @return A monoid for functions. */ public static Monoid> functionMonoid(final Monoid mb) { - return monoid(Semigroup.functionSemigroup(mb.semigroup()), Function.constant(mb.zero)); + Definition mbDef = mb.def; + return monoidDef(new Definition>() { + @Override + public F empty() { + return __ -> mbDef.empty(); + } + + @Override + public F append(F a1, F a2) { + return a -> mbDef.append(a1.f(a), a2.f(a)); + } + }); } /** @@ -345,16 +843,33 @@ public static Monoid> functionMonoid(final Monoid mb) { * @return A monoid for lists. */ public static Monoid> listMonoid() { - return monoid(Semigroup.listSemigroup(), List.nil()); + return monoidDef(new Definition>() { + @Override + public List empty() { + return nil(); + } + + @Override + public List append(List a1, List a2) { + return a1.append(a2); + } + + @Override + public List sum(F0>> as) { + return as.f().map(DList::listDList).foldLeft(DList::append, DList.nil()).run(); + } + }); } /** * A monoid for options. + * @deprecated since 4.7. Use {@link #firstOptionMonoid()}. * * @return A monoid for options. */ + @Deprecated public static Monoid> optionMonoid() { - return monoid(Semigroup.optionSemigroup(), Option.none()); + return firstOptionMonoid(); } /** @@ -363,7 +878,32 @@ public static Monoid> optionMonoid() { * @return A monoid for options that take the first available value. */ public static Monoid> firstOptionMonoid() { - return monoid(Semigroup.firstOptionSemigroup(), Option.none()); + return monoidDef(new Definition>() { + @Override + public Option empty() { + return none(); + } + + @Override + public Option append(Option a1, Option a2) { + return a1.orElse(a2); + } + + @Override + public F, Option> prepend(Option a1) { + return a1.isSome() ? __ -> a1 : identity(); + } + + @Override + public Option multiply(int n, Option as) { + return as; + } + + @Override + public Option sum(F0>> as) { + return as.f().filter(Option.isSome_()).orHead(Option::none); + } + }); } /** @@ -372,7 +912,27 @@ public static Monoid> firstOptionMonoid() { * @return A monoid for options that take the last available value. */ public static Monoid> lastOptionMonoid() { - return monoid(Semigroup.lastOptionSemigroup(), Option.none()); + return monoidDef(new Definition>() { + @Override + public Option empty() { + return none(); + } + + @Override + public Option append(Option a1, Option a2) { + return a2.orElse(a1); + } + + @Override + public F, Option> prepend(Option a1) { + return a1.isNone() ? identity() : a2 -> a2.orElse(a1); + } + + @Override + public Option multiply(int n, Option as) { + return as; + } + }); } /** @@ -381,7 +941,22 @@ public static Monoid> lastOptionMonoid() { * @return A monoid for streams. */ public static Monoid> streamMonoid() { - return monoid(Semigroup.streamSemigroup(), Stream.nil()); + return monoidDef(new Definition>() { + @Override + public Stream empty() { + return Stream.nil(); + } + + @Override + public Stream append(Stream a1, Stream a2) { + return a1.append(a2); + } + + @Override + public Stream sum(F0>> as) { + return Stream.join(as.f()); + } + }); } /** @@ -391,30 +966,91 @@ public static Monoid> streamMonoid() { */ @SuppressWarnings("unchecked") public static Monoid> arrayMonoid() { - return monoid(Semigroup.arraySemigroup(), Array.empty()); + return monoidDef(new Definition>() { + @Override + public Array empty() { + return Array.empty(); + } + + @Override + public Array append(Array a1, Array a2) { + return a1.append(a2); + } + }); } /** * A monoid for IO values. */ - public static Monoid> ioMonoid(final Monoid ma) { - return monoid(Semigroup.ioSemigroup(ma.semigroup()), IOFunctions.unit(ma.zero())); + public static Monoid> ioMonoid(final Monoid ma) { + Definition maDef = ma.def; + return monoidDef(new Definition>() { + @Override + public IO empty() { + return () -> maDef.empty(); + } + + @Override + public IO append(IO a1, IO a2) { + return () -> maDef.append(a1.run(), a2.run()); + } + }); } /** * A monoid for the maximum of two integers. */ - public static final Monoid intMaxMonoid = monoid(Semigroup.intMaximumSemigroup, Integer.MIN_VALUE); + public static final Monoid intMaxMonoid = monoidDef(new Definition() { + @Override + public Integer empty() { + return Integer.MIN_VALUE; + } + + @Override + public Integer append(Integer a1, Integer a2) { + return Math.max(a1, a2); + } + + @Override + public Integer multiply(int n, Integer a) { + return a; + } + }); /** * A monoid for the minimum of two integers. */ - public static final Monoid intMinMonoid = monoid(Semigroup.intMinimumSemigroup, Integer.MAX_VALUE); + public static final Monoid intMinMonoid = monoidDef(new Definition() { + @Override + public Integer empty() { + return Integer.MAX_VALUE; + } + + @Override + public Integer append(Integer a1, Integer a2) { + return Math.min(a1, a2); + } + + @Override + public Integer multiply(int n, Integer a) { + return a; + } + }); /** * A monoid for the Unit value. */ - public static final Monoid unitMonoid = monoid(Semigroup.unitSemigroup, Unit.unit()); + public static final Monoid unitMonoid = monoidDef(new Definition() { + @Override + public Unit empty() { + return unit(); + } + + @Override + public Unit append(Unit a1, Unit a2) { + return unit(); + } + }); /** * A monoid for sets. @@ -423,18 +1059,29 @@ public static Monoid> ioMonoid(final Monoid ma) { * @return A monoid for sets whose elements have the given order. */ public static Monoid> setMonoid(final Ord o) { - return monoid(Semigroup.setSemigroup(), Set.empty(o)); - } + return monoidDef(new Definition>() { + @Override + public Set empty() { + return Set.empty(o); + } + @Override + public Set append(Set a1, Set a2) { + return a1.union(a2); + } + }); + } /** * A monoid for the maximum of elements with ordering o. + * @deprecated since 4.7. Use {@link Ord#maxMonoid(Object)} * * @param o An ordering of elements. * @param zero The minimum element. */ + @Deprecated public static Monoid ordMaxMonoid(final Ord o, final A zero) { - return monoid(o.max, zero); + return o.maxMonoid(zero); } } diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 86d560b7..1764ea74 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -19,6 +19,7 @@ import static fj.Function.compose2; import static fj.Function.curry; import static fj.Semigroup.semigroup; +import static fj.Semigroup.semigroupDef; /** * Tests for ordering between two objects. @@ -30,7 +31,7 @@ public final class Ord { /** * Primitives functions of Ord: minimal definition and overridable methods. */ - public interface Definition extends Equal.Definition { + public interface Definition extends Equal.Definition, Semigroup.Definition { F compare(A a); @@ -38,6 +39,7 @@ default Ordering compare(A a1, A a2) { return compare(a1).f(a2); } + // equal: @Override default boolean equal(A a1, A a2) { return compare(a1, a2) == Ordering.EQ; @@ -47,6 +49,42 @@ default boolean equal(A a1, A a2) { default F equal(A a) { return compose(o -> o == Ordering.EQ, compare(a)); } + + // max semigroup: + @Override + default A append(A a1, A a2) { + return compare(a1, a2) == Ordering.GT ? a1 : a2; + } + + @Override + default A multiply1p(int n, A a) { + return a; + } + + @Override + default F prepend(A a1) { + return apply((a2, o) -> o == Ordering.GT ? a1 : a2, compare(a1)); + } + + @Override + default Definition dual() { + return new Definition() { + @Override + public F compare(A a) { + return compose(Ordering::reverse, Definition.this.compare(a)); + } + + @Override + public Ordering compare(A a1, A a2) { + return Definition.this.compare(a2, a1); + } + + @Override + public Definition dual() { + return Definition.this; + } + }; + } } /** @@ -60,6 +98,11 @@ default F compare(A a1) { return a2 -> compare(a1, a2); } + @Override + default F prepend(A a1) { + return a2 -> append(a1, a2); + } + } @@ -199,7 +242,7 @@ public F isGreaterThan(final A a) { * @return The greater of the two values. */ public A max(final A a1, final A a2) { - return isGreaterThan(a1, a2) ? a1 : a2; + return def.append(a1, a2); } @@ -216,6 +259,7 @@ public A min(final A a1, final A a2) { /** * A function that returns the greater of its two arguments. + * */ public final F> max; @@ -225,34 +269,33 @@ public A min(final A a1, final A a2) { public final F> min; public final Semigroup minSemigroup() { - return semigroup(min); + return semigroupDef(def.dual()); + } + + public final Monoid minMonoid(A zero) { + return Monoid.monoidDef(def.dual(), zero); } public final Semigroup maxSemigroup() { - return semigroup(max); + return semigroupDef(def); } - public final Ord reverse() { - Definition selfDef = def; - return ordDef(new Definition() { - @Override - public F compare(A a) { - return compose(Ordering::reverse, selfDef.compare(a)); - } + public final Monoid maxMonoid(A zero) { + return Monoid.monoidDef(def, zero); + } - @Override - public Ordering compare(A a1, A a2) { - return selfDef.compare(a2, a1); - } - }); + public final Ord reverse() { + return ordDef(def.dual()); } /** * Returns an order instance that uses the given equality test and ordering function. * + * @deprecated since 4.7. Use {@link #ordDef(Definition)}. * @param f The order function. * @return An order instance. */ + @Deprecated public static Ord ord(final F> f) { return new Ord<>(f::f); } diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 7c5538f2..cba1f04b 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -1,9 +1,9 @@ package fj; import fj.data.Array; +import fj.data.DList; import fj.data.List; import fj.data.IO; -import fj.data.IOFunctions; import fj.data.Natural; import fj.data.NonEmptyList; import fj.data.Option; @@ -13,8 +13,13 @@ import java.math.BigDecimal; import java.math.BigInteger; -import static fj.Function.curry; -import static fj.Function.flip; +import static fj.F1Functions.dimap; +import static fj.Function.constant; +import static fj.Function.identity; +import static fj.Monoid.*; +import static fj.data.DList.listDList; +import static fj.data.Option.none; +import static fj.data.Option.some; /** * Implementations must satisfy the law of associativity: @@ -25,10 +30,69 @@ * @version %build.number% */ public final class Semigroup { - private final F> sum; - private Semigroup(final F> sum) { - this.sum = sum; + public interface Definition { + + A append(A a1, A a2); + + default F prepend(A a) { + return a2 -> append(a, a2); + } + + default A sum(A a, F0> as) { + return as.f().foldLeft(this::append, a); + } + + default A multiply1p(int n, A a) { + if (n <= 0) { + return a; + } + + A xTmp = a; + int yTmp = n; + A zTmp = a; + while (true) { + if ((yTmp & 1) == 1) { + zTmp = append(xTmp, zTmp); + if (yTmp == 1) { + return zTmp; + } + } + xTmp = append(xTmp, xTmp); + yTmp = (yTmp) >>> 1; + } + } + + default Definition dual() { + return new Definition(){ + + @Override + public A append(A a1, A a2) { + return Definition.this.append(a2, a1); + } + + @Override + public A multiply1p(int n, A a) { + return Definition.this.multiply1p(n, a); + } + }; + } + } + + public interface AltDefinition extends Definition { + @Override + F prepend(A a); + + @Override + default A append(A a1, A a2) { + return prepend(a1).f(a2); + } + } + + private final Definition def; + + private Semigroup(final Definition def) { + this.def = def; } /** @@ -39,7 +103,7 @@ private Semigroup(final F> sum) { * @return The of the two given arguments. */ public A sum(final A a1, final A a2) { - return sum.f(a1).f(a2); + return def.append(a1, a2); } /** @@ -49,7 +113,7 @@ public A sum(final A a1, final A a2) { * @return A function that sums the given value according to this semigroup. */ public F sum(final A a1) { - return sum.f(a1); + return def.prepend(a1); } /** @@ -58,7 +122,7 @@ public F sum(final A a1) { * @return A function that sums according to this semigroup. */ public F> sum() { - return sum; + return def::prepend; } /** @@ -73,106 +137,213 @@ public F> sum() { * {@code zero()} */ public A multiply1p(int n, A a) { - return multiply1p(sum, n, a); + return def.multiply1p(n, a); } - // shared implementation between Semigroup and Monoid - static A multiply1p(F> sum, int n, A a) { - if (n <= 0) { - return a; - } - - A xTmp = a; - int yTmp = n; - A zTmp = a; - while (true) { - if ((yTmp & 1) == 1) { - zTmp = sum.f(xTmp).f(zTmp); - if (yTmp == 1) { - return zTmp; - } - } - xTmp = sum.f(xTmp).f(xTmp); - yTmp = yTmp >>> 1; - } - } /** * Sums the given values with left-fold. */ public A sumNel(final NonEmptyList as) { - return as.foldLeft1(sum); + return as.foldLeft1(def::append); + } + + /** + * Sums the given values with left-fold, shortcutting the computation as early as possible. + */ + public A sumStream(A a, F0> as) { + return def.sum(a, as); } /** * Swaps the arguments when summing. */ public Semigroup dual() { - return semigroup(flip(sum)); + return semigroupDef(def.dual()); } /** * Lifts the semigroup to obtain a trivial monoid. */ public Monoid> lift() { - return Monoid.monoid(a -> b -> Option.liftM2(sum).f(a).f(b).orElse(a).orElse(b), Option.none()); + Definition def = this.def; + return monoidDef(new Monoid.Definition>() { + @Override + public Option empty() { + return none(); + } + + @Override + public Option append(Option a1, Option a2) { + return a1.liftM2(a1, def::append).orElse(a1).orElse(a2); + } + + @Override + public Option multiply(int n, Option oa) { + return n > 0 ? oa.map(a -> def.multiply1p(n - 1, a)) : none(); + } + + @Override + public Option sum(F0>> oas) { + Stream as = oas.f().bind(Option::toStream); + return as.uncons(none(), h -> tail -> some(def.sum(h, tail::_1))); + } + }); + } + + /** + * Maps the given functions across this monoid as an invariant functor. + * + * @param f The covariant map. + * @param g The contra-variant map. + * @return A new monoid. + */ + public Semigroup xmap(final F f, final F g) { + Definition def = this.def; + return semigroupDef(new Definition() { + + @Override + public B append(B a1, B a2) { + return f.f(def.append(g.f(a1), g.f(a2))); + } + + @Override + public F prepend(B b) { + return dimap(def.prepend(g.f(b)), g, f); + } + + @Override + public B multiply1p(int n, B b) { + return f.f(def.multiply1p(n , g.f(b))); + } + + @Override + public B sum(B b, F0> bs) { + return f.f(def.sum(g.f(b), () -> bs.f().map(g))); + } + }); + } + + public Semigroup compose(Semigroup sb, final F b, final F a, final F2 c) { + Definition saDef = this.def; + Definition sbDef = sb.def; + return semigroupDef(new Definition() { + + @Override + public C append(C c1, C c2) { + return c.f(saDef.append(a.f(c1), a.f(c2)), sbDef.append(b.f(c1), b.f(c2))); + } + + @Override + public F prepend(C c1) { + F prependA = saDef.prepend(a.f(c1)); + F prependB = sbDef.prepend(b.f(c1)); + return c2 -> c.f(prependA.f(a.f(c2)), prependB.f(b.f(c2))); + } + + @Override + public C multiply1p(int n, C c1) { + return c.f(saDef.multiply1p(n, a.f(c1)), sbDef.multiply1p(n, b.f(c1))); + } + + @Override + public C sum(C c1, F0> cs) { + return c.f(saDef.sum(a.f(c1), () -> cs.f().map(a)), sbDef.sum(b.f(c1), () -> cs.f().map(b))); + } + }); + } + + /** + * Constructs a monoid from this semigroup and a zero value, which must follow the monoidal laws. + * + * @param zero The zero for the monoid. + * @return A monoid instance that uses the given sun function and zero value. + */ + public Monoid monoid(A zero) { + return monoidDef(this.def, zero); + } + + /** + * Constructs a semigroup from the given definition. + * + * @param def The definition to construct this semigroup with. + * @return A semigroup from the given definition. + */ + public static Semigroup semigroupDef(final Definition def) { + return new Semigroup<>(def); + } + + /** + * Constructs a semigroup from the given definition. + * + * @param def The definition to construct this semigroup with. + * @return A semigroup from the given definition. + */ + public static Semigroup semigroupDef(final AltDefinition def) { + return new Semigroup<>(def); } /** * Constructs a semigroup from the given function. + * @deprecated since 4.7. Use {@link #semigroupDef(Definition)}. * * @param sum The function to construct this semigroup with. * @return A semigroup from the given function. */ + @Deprecated public static Semigroup semigroup(final F> sum) { - return new Semigroup<>(sum); + return semigroupDef(sum::f); } /** * Constructs a semigroup from the given function. + * @deprecated since 4.7. Use {@link #semigroupDef(Definition)}. * * @param sum The function to construct this semigroup with. * @return A semigroup from the given function. */ + @Deprecated public static Semigroup semigroup(final F2 sum) { - return new Semigroup<>(curry(sum)); + return new Semigroup<>(sum::f); } + /** * A semigroup that adds integers. */ - public static final Semigroup intAdditionSemigroup = semigroup((i1, i2) -> i1 + i2); + public static final Semigroup intAdditionSemigroup = intAdditionMonoid.semigroup(); /** - * A semigroup that adds doubles. + * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws */ - public static final Semigroup doubleAdditionSemigroup = semigroup((d1, d2) -> d1 + d2); + @Deprecated + public static final Semigroup doubleAdditionSemigroup = semigroupDef((d1, d2) -> d1 + d2); /** * A semigroup that multiplies integers. */ - public static final Semigroup intMultiplicationSemigroup = semigroup((i1, i2) -> i1 * i2); + public static final Semigroup intMultiplicationSemigroup = intMultiplicationMonoid.semigroup(); /** - * A semigroup that multiplies doubles. + * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws */ - public static final Semigroup doubleMultiplicationSemigroup = semigroup((d1, d2) -> d1 * d2); + @Deprecated + public static final Semigroup doubleMultiplicationSemigroup = semigroupDef((d1, d2) -> d1 * d2); /** * A semigroup that yields the maximum of integers. */ - public static final Semigroup intMaximumSemigroup = Ord.intOrd.maxSemigroup(); + public static final Semigroup intMaximumSemigroup = intMaxMonoid.semigroup(); /** * A semigroup that yields the minimum of integers. */ - public static final Semigroup intMinimumSemigroup = Ord.intOrd.minSemigroup(); + public static final Semigroup intMinimumSemigroup = intMinMonoid.semigroup(); /** * A semigroup that adds big integers. */ - public static final Semigroup bigintAdditionSemigroup = - semigroup(BigInteger::add); + public static final Semigroup bigintAdditionSemigroup = bigintAdditionMonoid.semigroup(); /** * A semigroup that multiplies big integers. @@ -193,14 +364,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that adds big decimals. */ - public static final Semigroup bigdecimalAdditionSemigroup = - semigroup(BigDecimal::add); + public static final Semigroup bigdecimalAdditionSemigroup = bigdecimalAdditionMonoid.semigroup(); /** * A semigroup that multiplies big decimals. */ - public static final Semigroup bigdecimalMultiplicationSemigroup = - semigroup(BigDecimal::multiply); + public static final Semigroup bigdecimalMultiplicationSemigroup = bigdecimalMultiplicationMonoid.semigroup(); /** * A semigroup that yields the maximum of big decimals. @@ -215,14 +384,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that multiplies natural numbers. */ - public static final Semigroup naturalMultiplicationSemigroup = - semigroup(Natural::multiply); + public static final Semigroup naturalMultiplicationSemigroup = naturalMultiplicationMonoid.semigroup(); /** * A semigroup that adds natural numbers. */ - public static final Semigroup naturalAdditionSemigroup = - semigroup(Natural::add); + public static final Semigroup naturalAdditionSemigroup = naturalAdditionMonoid.semigroup(); /** * A semigroup that yields the maximum of natural numbers. @@ -237,12 +404,12 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that adds longs. */ - public static final Semigroup longAdditionSemigroup = semigroup((x, y) -> x + y); + public static final Semigroup longAdditionSemigroup = longAdditionMonoid.semigroup(); /** * A semigroup that multiplies longs. */ - public static final Semigroup longMultiplicationSemigroup = semigroup((x, y) -> x * y); + public static final Semigroup longMultiplicationSemigroup = longMultiplicationMonoid.semigroup(); /** * A semigroup that yields the maximum of longs. @@ -257,47 +424,80 @@ public static Semigroup semigroup(final F2 sum) { /** * A semigroup that ORs booleans. */ - public static final Semigroup disjunctionSemigroup = semigroup((b1, b2) -> b1 || b2); + public static final Semigroup disjunctionSemigroup = disjunctionMonoid.semigroup(); /** * A semigroup that XORs booleans. */ - public static final Semigroup exclusiveDisjunctionSemiGroup = semigroup((p, q) -> p ? !q : q); + public static final Semigroup exclusiveDisjunctionSemiGroup = exclusiveDisjunctionMonoid.semigroup(); /** * A semigroup that ANDs booleans. */ - public static final Semigroup conjunctionSemigroup = semigroup((b1, b2) -> b1 && b2); + public static final Semigroup conjunctionSemigroup = conjunctionMonoid.semigroup(); /** * A semigroup that appends strings. */ - public static final Semigroup stringSemigroup = semigroup((s1, s2) -> s1 + s2); + public static final Semigroup stringSemigroup = stringMonoid.semigroup(); /** * A semigroup that appends string buffers. */ - public static final Semigroup stringBufferSemigroup = - semigroup((s1, s2) -> new StringBuffer(s1).append(s2)); + public static final Semigroup stringBufferSemigroup = stringBufferMonoid.semigroup(); /** * A semigroup that appends string builders. */ - public static final Semigroup stringBuilderSemigroup = - semigroup((s1, s2) -> new StringBuilder(s1).append(s2)); + public static final Semigroup stringBuilderSemigroup = stringBuilderMonoid.semigroup(); /** * A semigroup which always uses the "first" (left-hand side) value. */ public static Semigroup firstSemigroup() { - return semigroup((a1, a2) -> a1); + return semigroupDef(new Definition() { + @Override + public A append(A a1, A a2) { + return a1; + } + + @Override + public F prepend(A a) { + return constant(a); + } + + @Override + public A multiply1p(int n, A a) { + return a; + } + + @Override + public A sum(A a, F0> as) { + return a; + } + }); } /** * A semigroup which always uses the "last" (right-hand side) value. */ public static Semigroup lastSemigroup() { - return semigroup((a1, a2) -> a2); + return semigroupDef(new Definition() { + @Override + public A append(A a1, A a2) { + return a2; + } + + @Override + public F prepend(A a) { + return identity(); + } + + @Override + public A multiply1p(int n, A a) { + return a; + } + }); } /** @@ -307,7 +507,8 @@ public static Semigroup lastSemigroup() { * @return A semigroup for functions. */ public static Semigroup> functionSemigroup(final Semigroup sb) { - return semigroup((a1, a2) -> a -> sb.sum(a1.f(a), a2.f(a))); + Definition sbDef = sb.def; + return semigroupDef((a1, a2) -> a -> sbDef.append(a1.f(a), a2.f(a))); } /** @@ -316,7 +517,7 @@ public static Semigroup> functionSemigroup(final Semigroup sb) * @return A semigroup for lists. */ public static Semigroup> listSemigroup() { - return semigroup(List::append); + return Monoid.listMonoid().semigroup(); } /** @@ -325,15 +526,29 @@ public static Semigroup> listSemigroup() { * @return A semigroup for non-empty lists. */ public static Semigroup> nonEmptyListSemigroup() { - return semigroup(NonEmptyList::append); + + return semigroupDef(new Definition>() { + @Override + public NonEmptyList append(NonEmptyList a1, NonEmptyList a2) { + return a1.append(a1); + } + + @Override + public NonEmptyList sum(NonEmptyList nea, F0>> neas) { + List tail = neas.f().map(nel -> listDList(nel.toList())).foldLeft(DList::append, DList.nil()).run(); + return nea.append(tail); + } + }); } /** * A semigroup for optional values. + * @deprecated since 4.7. Use {@link #firstOptionSemigroup()}. + * ** @return A semigroup for optional values. */ public static Semigroup> optionSemigroup() { - return semigroup((a1, a2) -> a1.isSome() ? a1 : a2); + return firstOptionSemigroup(); } /** @@ -342,7 +557,7 @@ public static Semigroup> optionSemigroup() { * @return A semigroup for optional values that take the first available value. */ public static Semigroup> firstOptionSemigroup() { - return semigroup((a1, a2) -> a1.orElse(a2)); + return Monoid.firstOptionMonoid().semigroup(); } /** @@ -351,7 +566,7 @@ public static Semigroup> firstOptionSemigroup() { * @return A semigroup for optional values that take the last available value. */ public static Semigroup> lastOptionSemigroup() { - return semigroup((a1, a2) -> a2.orElse(a1)); + return Monoid.lastOptionMonoid().semigroup(); } /** @@ -360,7 +575,7 @@ public static Semigroup> lastOptionSemigroup() { * @return A semigroup for streams. */ public static Semigroup> streamSemigroup() { - return semigroup((a1, a2) -> a1.append(a2)); + return Monoid.streamMonoid().semigroup(); } /** @@ -369,41 +584,58 @@ public static Semigroup> streamSemigroup() { * @return A semigroup for arrays. */ public static Semigroup> arraySemigroup() { - return semigroup(Array::append); + return Monoid.arrayMonoid().semigroup(); } /** - * A semigroup for unary products. + * A lazy semigroup for unary products. * * @param sa A semigroup for the product's type. * @return A semigroup for unary products. */ public static Semigroup> p1Semigroup(final Semigroup sa) { - return semigroup((a1, a2) -> P.lazy(() -> sa.sum(a1._1(), a2._1()))); + Definition def = sa.def; + return semigroupDef(new Definition>() { + @Override + public P1 append(P1 a1, P1 a2) { + return P.lazy(() -> def.append(a1._1(), a2._1())); + } + + @Override + public P1 multiply1p(int n, P1 ap1) { + return P.lazy(() -> def.multiply1p(n, ap1._1())); + } + + @Override + public P1 sum(P1 ap1, F0>> as) { + return P.lazy(() -> def.sum(ap1._1(), () -> as.f().map(P1.__1()))); + } + }); } /** - * A semigroup for binary products. + * A lazy semigroup for binary products. * * @param sa A semigroup for the product's first type. * @param sb A semigroup for the product's second type. * @return A semigroup for binary products. */ public static Semigroup> p2Semigroup(final Semigroup sa, final Semigroup sb) { - return semigroup((a1, a2) -> P.lazy(() -> sa.sum(a1._1(), a2._1()), () -> sb.sum(a1._2(), a2._2()))); + return semigroupDef((a1, a2) -> P.lazy(() -> sa.sum(a1._1(), a2._1()), () -> sb.sum(a1._2(), a2._2()))); } /** * A semigroup for IO values. */ public static Semigroup> ioSemigroup(final Semigroup sa) { - return semigroup((a1, a2) -> IOFunctions.liftM2(a1, a2, sa::sum)); + Definition def = sa.def; + return semigroupDef((a1, a2) -> () -> def.append(a1.run(), a2.run())); } /** * A semigroup for the Unit value. */ - public static final Semigroup unitSemigroup = semigroup((u1, u2) -> Unit.unit()); + public static final Semigroup unitSemigroup = unitMonoid.semigroup(); /** * A semigroup for sets. @@ -411,7 +643,7 @@ public static Semigroup> ioSemigroup(final Semigroup sa) { * @return a semigroup for sets. */ public static Semigroup> setSemigroup() { - return semigroup(Set::union); + return semigroupDef(Set::union); } } diff --git a/core/src/main/java/fj/data/optic/Fold.java b/core/src/main/java/fj/data/optic/Fold.java index af6b5739..691c779c 100644 --- a/core/src/main/java/fj/data/optic/Fold.java +++ b/core/src/main/java/fj/data/optic/Fold.java @@ -39,7 +39,7 @@ public final List getAll(final S s) { /** find the first target of a {@link Fold} matching the predicate */ public final F> find(final F p) { - return foldMap(Monoid.optionMonoid(), a -> p.f(a) ? Option.some(a) : Option.none()); + return foldMap(Monoid.firstOptionMonoid(), a -> p.f(a) ? Option.some(a) : Option.none()); } /** get the first target of a {@link Fold} */ diff --git a/core/src/main/java/fj/data/optic/PTraversal.java b/core/src/main/java/fj/data/optic/PTraversal.java index 50c1e14c..dbd8b0cd 100644 --- a/core/src/main/java/fj/data/optic/PTraversal.java +++ b/core/src/main/java/fj/data/optic/PTraversal.java @@ -104,7 +104,7 @@ public final List getAll(final S s) { /** find the first target of a {@link PTraversal} matching the predicate */ public final F> find(final F p) { - return foldMap(Monoid.optionMonoid(), a -> p.f(a) ? Option.some(a) : Option.none()); + return foldMap(Monoid.firstOptionMonoid(), a -> p.f(a) ? Option.some(a) : Option.none()); } /** get the first target of a {@link PTraversal} */ diff --git a/core/src/main/java/fj/function/Doubles.java b/core/src/main/java/fj/function/Doubles.java index 7bff2409..6fe1b033 100644 --- a/core/src/main/java/fj/function/Doubles.java +++ b/core/src/main/java/fj/function/Doubles.java @@ -6,11 +6,8 @@ import fj.data.Option; import static fj.Function.curry; -import static fj.Semigroup.doubleAdditionSemigroup; -import static fj.Semigroup.doubleMultiplicationSemigroup; import static fj.data.Option.none; import static fj.data.Option.some; -import static java.lang.Math.abs; /** * Curried functions over Doubles. @@ -25,17 +22,17 @@ private Doubles() { /** * Curried Double addition. */ - public static final F> add = doubleAdditionSemigroup.sum(); + public static final F> add = x -> y -> x + y; /** * Curried Double multiplication. */ - public static final F> multiply = doubleMultiplicationSemigroup.sum(); + public static final F> multiply = x -> y -> x * y; /** * Curried Double subtraction. */ - public static final F> subtract = curry((x, y) -> x - y); + public static final F> subtract = x -> y -> x - y; /** * Negation. @@ -50,12 +47,12 @@ private Doubles() { /** * Remainder. */ - public static final F> remainder = curry((a, b) -> a % b); + public static final F> remainder = x -> y -> x % y; /** * Power. */ - public static final F> power = curry(StrictMath::pow); + public static final F> power = x -> y -> StrictMath.pow(x, y); /** * Evenness. @@ -69,7 +66,7 @@ private Doubles() { * @return The sum of the doubless in the list. */ public static double sum(final List doubles) { - return Monoid.doubleAdditionMonoid.sumLeft(doubles); + return doubles.foldLeft((x, y) -> x + y, 0.0); } /** @@ -79,7 +76,7 @@ public static double sum(final List doubles) { * @return The product of the doubles in the list. */ public static double product(final List doubles) { - return Monoid.doubleMultiplicationMonoid.sumLeft(doubles); + return doubles.foldLeft((x, y) -> x * y, 1.0); } /** diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index 203b8feb..c90a0b2d 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -1,6 +1,7 @@ package fj.demo.concurrent; import static fj.Monoid.monoid; +import static fj.Monoid.monoidDef; import static fj.control.parallel.ParModule.parModule; import static fj.data.List.nil; import static java.util.concurrent.Executors.newFixedThreadPool; @@ -14,6 +15,7 @@ import java.io.StringWriter; import java.io.Writer; import java.nio.charset.Charset; +import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; @@ -307,10 +309,7 @@ public static Map getWordsAndCountsFromFilesInParallel( // Read documents and extract words and word counts of documents public static Promise> getWordsAndCountsFromFiles( final List fileNames, final F> fileNameToWordsAndCounts, final ParModule m) { - final F, F, Map>> MapSum = - a -> b -> plus(a, b); - final Monoid> monoid = monoid(MapSum, - new HashMap()); + final Monoid> monoid = monoidDef(WordCount::plus, Collections.emptyMap()); return m.parFoldMap(fileNames, fileNameToWordsAndCounts, monoid); } From 1970c3e04db3dcadaaa6b33accc3ff2cffc16358 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 26 Sep 2016 21:24:07 +0200 Subject: [PATCH 143/336] use more method references. make Stream conversions respect laziness. optimize collectors. --- java8/src/main/java/fj/data/Collectors.java | 4 +- java8/src/main/java/fj/data/Java8.java | 49 +++++++++++---------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/java8/src/main/java/fj/data/Collectors.java b/java8/src/main/java/fj/data/Collectors.java index 3f3d7e40..5ee9ead6 100644 --- a/java8/src/main/java/fj/data/Collectors.java +++ b/java8/src/main/java/fj/data/Collectors.java @@ -21,7 +21,7 @@ public static Collector, Array> toArray() { List.Buffer::new, List.Buffer::snoc, (acc1, acc2) -> acc1.append(acc2.toList()), - (buf) -> Array.iterableArray(buf.toList()) + (buf) -> buf.toList().toArray() ); } @@ -30,7 +30,7 @@ public static Collector, Stream> toStream() { List.Buffer::new, List.Buffer::snoc, (acc1, acc2) -> acc1.append(acc2.toList()), - (buf) -> Stream.iterableStream(buf.toList()) + (buf) -> buf.toList().toStream() ); } } diff --git a/java8/src/main/java/fj/data/Java8.java b/java8/src/main/java/fj/data/Java8.java index be776822..d2d23fb2 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/java8/src/main/java/fj/data/Java8.java @@ -2,6 +2,7 @@ import java.util.Iterator; import java.util.Optional; +import java.util.Spliterators; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; @@ -28,75 +29,75 @@ private Java8() { } public static P1 Supplier_P1(final Supplier s) { - return Java8.Supplier_P1().f(s); + return P.lazy(s::get); } public static F, P1> Supplier_P1() { - return s -> P.lazy(s::get); + return Java8::Supplier_P1; } public static Supplier P1_Supplier(final P1 p) { - return Java8.P1_Supplier().f(p); + return p::_1; } public static F, Supplier> P1_Supplier() { - return (p) -> p::_1; + return Java8::P1_Supplier; } public static F Function_F(final Function f) { - return Java8.Function_F().f(f); + return f::apply; } public static F, F> Function_F() { - return f -> f::apply; + return Java8::Function_F; } public static Function F_Function(final F f) { - return Java8.F_Function().f(f); + return f::f; } public static F, Function> F_Function() { - return f -> f::f; + return Java8::F_Function; } public static F2 BiFunction_F2(final BiFunction f) { - return Java8.BiFunction_F2().f(f); + return f::apply; } public static F, F2> BiFunction_F2() { - return f -> f::apply; + return Java8::BiFunction_F2; } public static BiFunction F2_BiFunction(final F2 f) { - return Java8.F2_BiFunction().f(f); + return f::f; } public static F, BiFunction> F2_BiFunction() { - return f -> f::f; + return Java8::F2_BiFunction; } public static Supplier> TryCatch0_Supplier(final Try0 t) { - return Java8.TryCatch0_Supplier().f(t); + return () -> Try.f(t)._1(); } public static F, Supplier>> TryCatch0_Supplier() { - return t -> () -> Try.f(t)._1(); + return Java8::TryCatch0_Supplier; } public static Function> TryCatch1_Function(final Try1 t) { - return Java8.TryCatch1_Function().f(t); + return a -> Try.f(t).f(a); } public static F, Function>> TryCatch1_Function() { - return t -> a -> Try.f(t).f(a); + return Java8::TryCatch1_Function; } public static BiFunction> TryCatch2_BiFunction(final Try2 t) { - return Java8.TryCatch2_BiFunction().f(t); + return (a, b) -> Try.f(t).f(a, b); } public static F, BiFunction>> TryCatch2_BiFunction() { - return t -> (a, b) -> Try.f(t).f(a, b); + return Java8::TryCatch2_BiFunction; } public static java.util.stream.Stream List_JavaStream(final List list) { @@ -104,19 +105,19 @@ public static java.util.stream.Stream List_JavaStream(final List list) } public static Option Optional_Option(final Optional o) { - return Java8.Optional_Option().f(o); + return o.isPresent() ? Option.some(o.get()) : Option.none(); } public static F, Option> Optional_Option() { - return o -> o.isPresent() ? Option.some(o.get()) : Option.none(); + return Java8::Optional_Option; } public static Optional Option_Optional(final Option o) { - return Java8.Option_Optional().f(o); + return o.option(Optional.empty(), Optional::ofNullable); } public static F, Optional> Option_Optional() { - return o -> o.isSome() ? Optional.ofNullable(o.some()) : Optional.empty(); + return Java8::Option_Optional; } public static F, F> Consumer_F() { @@ -139,7 +140,7 @@ public static java.util.stream.Stream Iterable_JavaStream(final Iterable< } public static java.util.stream.Stream Iterator_JavaStream(final Iterator it) { - return Iterable_JavaStream(() -> it); + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false); } public static F, java.util.stream.Stream> Stream_JavaStream() { @@ -147,7 +148,7 @@ public static F, java.util.stream.Stream> Stream_JavaSt } public static Stream JavaStream_Stream(final java.util.stream.Stream s) { - return s.collect(Collectors.toStream()); + return Stream.iteratorStream(s.iterator()); } public static List JavaStream_List(final java.util.stream.Stream s) { From a8f9db4320e78f459525a96fa6e7ff3b3da7f94a Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 10:38:28 +0200 Subject: [PATCH 144/336] Java8 converter: Do not silently convert Option.some(null) to Optional.absent() Let's not try to cover for Optional mistakes. Otherwise bugs will silently happen. --- java8/src/main/java/fj/data/Java8.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/java8/src/main/java/fj/data/Java8.java b/java8/src/main/java/fj/data/Java8.java index d2d23fb2..e41f0958 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/java8/src/main/java/fj/data/Java8.java @@ -112,8 +112,11 @@ public static F, Option> Optional_Option() { return Java8::Optional_Option; } + /** + * Convert an Option to {@link Optional}. Will throw a {@link NullPointerException} if the Option is some(null). + */ public static Optional Option_Optional(final Option o) { - return o.option(Optional.empty(), Optional::ofNullable); + return o.option(Optional.empty(), Optional::of); } public static F, Optional> Option_Optional() { From 9c28f6f19cc383bf660ac0d4d1c441123313b372 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Thu, 15 Sep 2016 21:05:17 +0200 Subject: [PATCH 145/336] Fix #287: Add semigroup constraint to List.traverseValidation for now implement traverse from sequence. (but the other way around would be better) --- core/src/main/java/fj/data/List.java | 11 ++++----- core/src/main/java/fj/data/optic/PIso.java | 3 ++- core/src/main/java/fj/data/optic/PLens.java | 3 ++- .../main/java/fj/data/optic/POptional.java | 3 ++- core/src/main/java/fj/data/optic/PPrism.java | 3 ++- .../main/java/fj/data/optic/PTraversal.java | 23 ++++++++++--------- .../main/java/fj/data/optic/Traversal.java | 5 ++-- 7 files changed, 28 insertions(+), 23 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index a4fa19eb..07b21862 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -10,6 +10,7 @@ import fj.Ordering; import fj.P; import fj.P1; +import fj.Semigroup; import fj.Show; import fj.Unit; import fj.P2; @@ -676,10 +677,8 @@ public final List> traverseList(final F> f) { single(List.nil())); } - public final Validation> traverseValidation(final F> f) { - return foldRight( - (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - Validation.success(List.nil())); + public final Validation> traverseValidation(Semigroup s, final F> f) { + return Validation.sequence(s, map(f)); } public final V2> traverseV2(final F> f) { @@ -2166,8 +2165,8 @@ public F, P1>> modifyP1F(F> f) { } @Override - public F, Validation>> modifyValidationF(F> f) { - return l -> l.traverseValidation(f); + public F, Validation>> modifyValidationF(Semigroup s, F> f) { + return l -> l.traverseValidation(s, f); } @Override diff --git a/core/src/main/java/fj/data/optic/PIso.java b/core/src/main/java/fj/data/optic/PIso.java index 7dcd0888..e10b47bb 100644 --- a/core/src/main/java/fj/data/optic/PIso.java +++ b/core/src/main/java/fj/data/optic/PIso.java @@ -6,6 +6,7 @@ import fj.P; import fj.P1; import fj.P2; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.data.Either; @@ -314,7 +315,7 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { + public F> modifyValidationF(Semigroup s, final F> f) { return self.modifyValidationF(f); } diff --git a/core/src/main/java/fj/data/optic/PLens.java b/core/src/main/java/fj/data/optic/PLens.java index 68de9079..971f76ff 100644 --- a/core/src/main/java/fj/data/optic/PLens.java +++ b/core/src/main/java/fj/data/optic/PLens.java @@ -4,6 +4,7 @@ import fj.Function; import fj.Monoid; import fj.P1; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.data.Either; @@ -320,7 +321,7 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { + public F> modifyValidationF(Semigroup s, final F> f) { return self.modifyValidationF(f); } diff --git a/core/src/main/java/fj/data/optic/POptional.java b/core/src/main/java/fj/data/optic/POptional.java index 73cc6fe9..d35979d8 100644 --- a/core/src/main/java/fj/data/optic/POptional.java +++ b/core/src/main/java/fj/data/optic/POptional.java @@ -6,6 +6,7 @@ import fj.P; import fj.P1; import fj.P2; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.control.parallel.Strategy; @@ -345,7 +346,7 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { + public F> modifyValidationF(Semigroup s, final F> f) { return self.modifyValidationF(f); } diff --git a/core/src/main/java/fj/data/optic/PPrism.java b/core/src/main/java/fj/data/optic/PPrism.java index f6712989..c4a65a68 100644 --- a/core/src/main/java/fj/data/optic/PPrism.java +++ b/core/src/main/java/fj/data/optic/PPrism.java @@ -5,6 +5,7 @@ import fj.Monoid; import fj.P; import fj.P1; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.control.parallel.Strategy; @@ -310,7 +311,7 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { + public F> modifyValidationF(Semigroup s, final F> f) { return self.modifyValidationF(f); } diff --git a/core/src/main/java/fj/data/optic/PTraversal.java b/core/src/main/java/fj/data/optic/PTraversal.java index 50c1e14c..6344d4d8 100644 --- a/core/src/main/java/fj/data/optic/PTraversal.java +++ b/core/src/main/java/fj/data/optic/PTraversal.java @@ -10,6 +10,7 @@ import fj.Monoid; import fj.P; import fj.P1; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.data.Either; @@ -82,7 +83,7 @@ public abstract class PTraversal { /** * modify polymorphically the target of a {@link PTraversal} with an Applicative function */ - public abstract F> modifyValidationF(F> f); + public abstract F> modifyValidationF(Semigroup s, F> f); /** * modify polymorphically the target of a {@link PTraversal} with an Applicative function @@ -218,10 +219,10 @@ public F, V2>> modifyV2F(final F> f) { } @Override - public F, Validation>> modifyValidationF(final F> f) { + public F, Validation>> modifyValidationF(Semigroup se, final F> f) { return ss1 -> ss1.either( - s -> self.modifyValidationF(f).f(s).map(Either.left_()), - s1 -> other.modifyValidationF(f).f(s1).map(Either.right_()) + s -> self.modifyValidationF(se, f).f(s).map(Either.left_()), + s1 -> other.modifyValidationF(se, f).f(s1).map(Either.right_()) ); } @@ -307,8 +308,8 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { - return self.modifyValidationF(other.modifyValidationF(f)); + public F> modifyValidationF(Semigroup s, final F> f) { + return self.modifyValidationF(s, other.modifyValidationF(s, f)); } @Override @@ -450,7 +451,7 @@ public F, V2>> modifyV2F(final F> f) { } @Override - public F, Validation>> modifyValidationF(final F> f) { + public F, Validation>> modifyValidationF(Semigroup se, final F> f) { return s -> s.bimap(f, f).either( v -> v.map(Either.left_()), v -> v.map(Either.right_()) @@ -520,8 +521,8 @@ public F> modifyV2F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { - return s -> f.f(get2.f(s)).apply(f.f(get1.f(s)).> map(b1 -> b2 -> set.f(b1, b2, s))); + public F> modifyValidationF(Semigroup se, final F> f) { + return s -> f.f(get2.f(s)).accumapply(se, f.f(get1.f(s)).> map(b1 -> b2 -> set.f(b1, b2, s))); } @Override @@ -611,8 +612,8 @@ public F> modifyV2F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { - return s -> f.f(lastGet.f(s)).apply(curriedTraversal.modifyValidationF(f).f(s)); + public F> modifyValidationF(Semigroup se, final F> f) { + return s -> f.f(lastGet.f(s)).accumapply(se, curriedTraversal.modifyValidationF(se, f).f(s)); } @Override diff --git a/core/src/main/java/fj/data/optic/Traversal.java b/core/src/main/java/fj/data/optic/Traversal.java index 4064385e..a1a466d8 100644 --- a/core/src/main/java/fj/data/optic/Traversal.java +++ b/core/src/main/java/fj/data/optic/Traversal.java @@ -8,6 +8,7 @@ import fj.F7; import fj.Monoid; import fj.P1; +import fj.Semigroup; import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.data.Either; @@ -72,8 +73,8 @@ public F> modifyP1F(final F> f) { } @Override - public F> modifyValidationF(final F> f) { - return pTraversal.modifyValidationF(f); + public F> modifyValidationF(Semigroup s, final F> f) { + return pTraversal.modifyValidationF(s, f); } @Override From 3ceef52530e378a9b5a61222705c98c267d1254d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 25 Sep 2016 18:35:35 +0200 Subject: [PATCH 146/336] Convert to property based tests to use runner. add test for hardMemo (also, previously, they did not fails the test if a property failed. --- .../src/test/java/fj/MemoisationTest.java | 76 +++++++------------ 1 file changed, 28 insertions(+), 48 deletions(-) diff --git a/props-core/src/test/java/fj/MemoisationTest.java b/props-core/src/test/java/fj/MemoisationTest.java index b3c2853b..ac686465 100644 --- a/props-core/src/test/java/fj/MemoisationTest.java +++ b/props-core/src/test/java/fj/MemoisationTest.java @@ -1,7 +1,9 @@ package fj; import fj.test.Property; +import fj.test.runner.PropertyTestRunner; import org.junit.Test; +import org.junit.runner.RunWith; import static fj.test.Arbitrary.arbInteger; import static fj.test.CheckResult.summary; @@ -12,99 +14,77 @@ /** * Created by mperry on 14/07/2014. */ +@RunWith(PropertyTestRunner.class) public class MemoisationTest { - @Test - public void test1() { - final Property p = property(arbInteger, a -> { - P1 t = P.p(a).memo(); - return prop(t._1() == t._1()); + public Property test1() { + return property(arbInteger, a -> { + P1 t = P.lazy(() -> a).memo(); + return prop(t._1().equals(t._1())).and(prop(t._1().equals(a))); }); - summary.println(p.check()); } - @Test - public void test2() { - final Property p = property(arbInteger, arbInteger, (a, b) -> { - P2 t = P.p(a, b).memo(); - return prop(t._1() == t._1() && t._2() == t._2()); + public Property test1_hardMemo() { + return property(arbInteger, a -> { + P1 t = P.lazy(() -> new Integer(a)).hardMemo(); + return prop(t._1() == t._1()).and(prop(t._1().equals(a))); }); - summary.println(p.check()); - } - - static P2 pair = P.p(0, 0); - - static Integer count(int i) { - if (i == 1) { - pair = P.p(pair._1() + 1, pair._2()); - return pair._1(); - } else if (i == 2) { - pair = P.p(pair._1(), pair._2() + 1); - return pair._2(); - } else { - return -1; - } } @Test - public void testRecomputeP2() { - P2 t = P.lazy(u -> count(1), u -> count(2)).memo(); - System.out.println("tuple: " + t + " 1:" + t._1() + " 2: " + t._2()); - assertTrue(t._1() == t._1() && t._2() == t._2()); + public Property test2() { + return property(arbInteger, arbInteger, (a, b) -> { + P2 t = P.lazy(u -> new Integer(a), u -> new Integer(b)).memo(); + return prop(t._1().equals(t._1()) && t._1().equals(a) && t._2().equals(t._2()) && t._2().equals(b) ); + }); } @Test - public void test3() { - final Property p = property(arbInteger, arbInteger, arbInteger, (a, b, c) -> { + public Property test3() { + return property(arbInteger, arbInteger, arbInteger, (a, b, c) -> { P3 t = P.p(a, b, c).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3()); }); - summary.println(p.check()); } @Test - public void test4() { - final Property p = property(arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d) -> { + public Property test4() { + return property(arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d) -> { P4 t = P.p(a, b, c, d).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3() && t._4() == t._4()); }); - summary.println(p.check()); } @Test - public void test5() { - final Property p = property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e) -> { + public Property test5() { + return property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e) -> { P5 t = P.p(a, b, c, d, e).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3() && t._4() == t._4() && t._5() == t._5()); }); - summary.println(p.check()); } @Test - public void test6() { - final Property p = property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f) -> { + public Property test6() { + return property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f) -> { P6 t = P.p(a, b, c, d, e, f).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3() && t._4() == t._4() && t._5() == t._5() && t._6() == t._6()); }); - summary.println(p.check()); } @Test - public void test7() { - final Property p = property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f, g) -> { + public Property test7() { + return property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f, g) -> { P7 t = P.p(a, b, c, d, e, f, g).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3() && t._4() == t._4() && t._5() == t._5() && t._6() == t._6() && t._7() == t._7()); }); - summary.println(p.check()); } @Test - public void test8() { - final Property p = property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f, g, h) -> { + public Property test8() { + return property(arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, arbInteger, (a, b, c, d, e, f, g, h) -> { P8 t = P.p(a, b, c, d, e, f, g, h).memo(); return prop(t._1() == t._1() && t._2() == t._2() && t._3() == t._3() && t._4() == t._4() && t._5() == t._5() && t._6() == t._6() && t._7() == t._7() && t._8() == t._8()); }); - summary.println(p.check()); } } From ac116dfa81a15e63274adb13463e436a012ae3d1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 25 Sep 2016 18:45:58 +0200 Subject: [PATCH 147/336] Make _1() method of memoized P1s smaller so that the fast path can be inlined by the jvm. Also replaced Option by P1 in implementation, also avoid wrapping some more memoized instances. --- core/src/main/java/fj/P1.java | 84 +++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 39 deletions(-) diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 1b36e0a7..cf763f55 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -1,15 +1,17 @@ package fj; -import java.lang.ref.Reference; -import java.lang.ref.SoftReference; -import java.lang.ref.WeakReference; - import fj.data.Array; -import fj.data.List; -import fj.data.Stream; import fj.data.Either; +import fj.data.List; import fj.data.Option; +import fj.data.Stream; import fj.data.Validation; + +import java.lang.ref.Reference; +import java.lang.ref.SoftReference; +import java.lang.ref.WeakReference; + +import static fj.P.p; //import fj.data.*; @@ -138,7 +140,7 @@ public final P1 liftM2(P1 pb, F2 f) { * @return A single P1 for the given List. */ public static P1> sequence(final List> as) { - return as.foldRight(liftM2(List.cons()), P.p(List.nil())); + return as.foldRight(liftM2(List.cons()), p(List.nil())); } /** @@ -157,7 +159,7 @@ public static F>, P1>> sequenceList() { * @return A single P1 for the given stream. */ public static P1> sequence(final Stream> as) { - return as.foldRight(liftM2(Stream.cons()), P.p(Stream.nil())); + return as.foldRight(liftM2(Stream.cons()), p(Stream.nil())); } /** @@ -238,7 +240,7 @@ public final P1 map(final F f) { return P.lazy(() -> f.f(self._1())); } - public P1 memo() { + public final P1 memo() { return weakMemo(); } @@ -247,7 +249,7 @@ public P1 memo() { * * @return A P1 that calls this P1 once and remembers the value for subsequent calls. */ - public final P1 hardMemo() { return new Memo<>(this); } + public P1 hardMemo() { return new Memo<>(this); } /** * Like memo, but the memoized value is wrapped into a WeakReference @@ -267,65 +269,69 @@ public static P1 memo(F0 f) { return P.lazy(f).memo(); } - static class Memo extends P1 { + static final class Memo extends P1 { private volatile P1 self; private A value; Memo(P1 self) { this.self = self; } @Override public final A _1() { + return (self == null) ? value : computeValue(); + } + + private synchronized A computeValue() { + P1 self = this.self; if (self != null) { - synchronized (this) { - if (self != null) { - A a = self._1(); - value = a; - self = null; - return a; - } - } + value = self._1(); + this.self = null; } return value; } - @Override public final P1 memo() { return this; } + @Override public P1 hardMemo() { return this; } + @Override public P1 softMemo() { return this; } + @Override public P1 weakMemo() { return this; } } abstract static class ReferenceMemo extends P1 { private final P1 self; - private final Object latch = new Object(); - private volatile Reference> v = null; + private volatile Reference> v = null; ReferenceMemo(final P1 self) { this.self = self; } @Override public final A _1() { - Option o = v != null ? v.get() : null; - if (o == null) { - synchronized (latch) { - o = v != null ? v.get() : null; - if (o == null) { - o = Option.some(self._1()); - v = newReference(o); - } - } + Reference> v = this.v; + P1 p1 = v != null ? v.get() : null; + return p1 != null ? p1._1() : computeValue(); + } + + private synchronized A computeValue() { + Reference> v = this.v; + P1 p1 = v != null ? v.get() : null; + if (p1 == null) { + A a = self._1(); + this.v = newReference(p(a)); + return a; } - return o.some(); + return p1._1(); } - abstract Reference> newReference(Option o); + abstract Reference newReference(B ref); } - static class WeakReferenceMemo extends ReferenceMemo { + static final class WeakReferenceMemo extends ReferenceMemo { WeakReferenceMemo(P1 self) { super(self); } @Override - final Reference> newReference(final Option o) { return new WeakReference<>(o); } - @Override public final P1 weakMemo() { return this; } + Reference newReference(final B ref) { return new WeakReference<>(ref); } + @Override public P1 weakMemo() { return this; } } - static class SoftReferenceMemo extends ReferenceMemo { + static final class SoftReferenceMemo extends ReferenceMemo { SoftReferenceMemo(P1 self) { super(self); } @Override - final Reference> newReference(final Option o) { return new SoftReference<>(o); } - @Override public final P1 softMemo() { return this; } + Reference newReference(final B ref) { return new SoftReference<>(ref); } + @Override public P1 softMemo() { return this; } + @Override public P1 weakMemo() { return this; } } /** From 9394d84652156be1d1ffe359f0a7b37523fab452 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 25 Sep 2016 18:49:32 +0200 Subject: [PATCH 148/336] Use weakMemo() explicitly. --- core/src/main/java/fj/P1.java | 4 ++-- core/src/test/java/fj/P1Test.java | 2 +- props-core/src/test/java/fj/MemoisationTest.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index cf763f55..2f3fa721 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -262,11 +262,11 @@ public final P1 memo() { public P1 softMemo() { return new SoftReferenceMemo<>(this); } public static P1 memo(F f) { - return P.lazy(f).memo(); + return P.lazy(f).weakMemo(); } public static P1 memo(F0 f) { - return P.lazy(f).memo(); + return P.lazy(f).weakMemo(); } static final class Memo extends P1 { diff --git a/core/src/test/java/fj/P1Test.java b/core/src/test/java/fj/P1Test.java index a866e0c2..788c2829 100644 --- a/core/src/test/java/fj/P1Test.java +++ b/core/src/test/java/fj/P1Test.java @@ -11,7 +11,7 @@ public final class P1Test { @Test public void bug105() throws Exception { - final P1 p1 = P.p("Foo").memo(); + final P1 p1 = P.p("Foo").weakMemo(); final AtomicInteger nullCounter = new AtomicInteger(); ExecutorService executorService = Executors.newCachedThreadPool(); diff --git a/props-core/src/test/java/fj/MemoisationTest.java b/props-core/src/test/java/fj/MemoisationTest.java index ac686465..e86e2a8b 100644 --- a/props-core/src/test/java/fj/MemoisationTest.java +++ b/props-core/src/test/java/fj/MemoisationTest.java @@ -19,7 +19,7 @@ public class MemoisationTest { public Property test1() { return property(arbInteger, a -> { - P1 t = P.lazy(() -> a).memo(); + P1 t = P.lazy(() -> a).weakMemo(); return prop(t._1().equals(t._1())).and(prop(t._1().equals(a))); }); } From e723d7122c00feec41d3375f327a819f7804f454 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 25 Sep 2016 19:09:01 +0200 Subject: [PATCH 149/336] Fix wrong override in P.p(A) --- core/src/main/java/fj/P.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index 1ff82475..ebc2d9e4 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -32,7 +32,7 @@ public static P1 p(final A a) { @Override public A _1() { return a; } - @Override public P1 memo() { return this; } + @Override public P1 hardMemo() { return this; } @Override public P1 weakMemo() { return this; } @Override public P1 softMemo() { return this; } }; From f56fa238e3dd6022f8558ab5f35835123953d331 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 11:32:27 +0200 Subject: [PATCH 150/336] P1.*memo: avoid uncessary wrapping of F0 value into a P1.lazy when possible. Expose static factories in P for this. Deprecated redondant API. --- core/src/main/java/fj/P.java | 50 ++++++++++++++----- core/src/main/java/fj/P1.java | 43 ++++++++++------ core/src/main/java/fj/P2.java | 5 +- core/src/main/java/fj/P3.java | 8 +-- core/src/main/java/fj/P4.java | 10 ++-- core/src/main/java/fj/P5.java | 12 +++-- core/src/main/java/fj/P6.java | 14 +++--- core/src/main/java/fj/P7.java | 16 +++--- core/src/main/java/fj/P8.java | 18 ++++--- core/src/main/java/fj/data/Stream.java | 3 +- core/src/test/java/fj/P1Test.java | 2 +- .../src/test/java/fj/MemoisationTest.java | 4 +- 12 files changed, 119 insertions(+), 66 deletions(-) diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index ebc2d9e4..b0f3a31d 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -38,10 +38,45 @@ public static P1 p(final A a) { }; } + /** + * Convert a F0 into a P1, using call-by-need semantic: + * function f is evaluated at most once, at first to {@link P1#_1()}. + */ + public static P1 hardMemo(F0 f) { + return new P1.Memo<>(f); + } - public static P1 lazy(final P1 pa) { - return pa; - } + /** + * Convert a F0 into a P1, using weak call-by-need semantic: + * function f is evaluated at first call to {@link P1#_1()} + * and at each subsequent call if and only if the reference have been garbage collected. + */ + public static P1 weakMemo(F0 f) { + return new P1.WeakReferenceMemo<>(f); + } + + /** + * Convert a F0 into a P1, using soft call-by-need semantic: + * function f is evaluated at first call to {@link P1#_1()} + * and at each subsequent call if and only if the reference have been garbage collected + * due of shortage of memory (ie. to avoid OutOfMemoryErrors). + */ + public static P1 sofMemo(F0 f) { + return new P1.SoftReferenceMemo<>(f); + } + + /** + * Convert a F0 into a P1, using call-by-name semantic: + * function f is evaluated at each call to {@link P1#_1()}. + */ + public static P1 lazy(F0 f) { + return new P1() { + @Override + public A _1() { + return f.f(); + } + }; + } public static P2 lazy(final F0 pa, final F0 pb) { return new P2() { @@ -538,15 +573,6 @@ public H _8() { }; } - public static P1 lazy(F0 f) { - return new P1() { - @Override - public A _1() { - return f.f(); - } - }; - } - public static P1 lazy(F f) { return lazy(() -> f.f(unit())); } diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 2f3fa721..555a28ae 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -12,6 +12,7 @@ import java.lang.ref.WeakReference; import static fj.P.p; +import static fj.Unit.unit; //import fj.data.*; @@ -240,6 +241,10 @@ public final P1 map(final F f) { return P.lazy(() -> f.f(self._1())); } + /** + * @deprecated since 4.7. Use {@link P1#weakMemo()} instead. + */ + @Deprecated public final P1 memo() { return weakMemo(); } @@ -261,29 +266,37 @@ public final P1 memo() { */ public P1 softMemo() { return new SoftReferenceMemo<>(this); } + /** + * @deprecated since 4.7. Use {@link P#weakMemo(F0)} instead. + */ + @Deprecated public static P1 memo(F f) { - return P.lazy(f).weakMemo(); + return P.weakMemo(() -> f.f(unit())); } - public static P1 memo(F0 f) { - return P.lazy(f).weakMemo(); + /** + * @deprecated since 4.7. Use {@link P#weakMemo(F0)} instead. + */ + @Deprecated + public static P1 memo(F0 f) { + return P.weakMemo(f); } static final class Memo extends P1 { - private volatile P1 self; + private volatile F0 fa; private A value; - Memo(P1 self) { this.self = self; } + Memo(F0 fa) { this.fa = fa; } @Override public final A _1() { - return (self == null) ? value : computeValue(); + return (fa == null) ? value : computeValue(); } private synchronized A computeValue() { - P1 self = this.self; - if (self != null) { - value = self._1(); - this.self = null; + F0 fa = this.fa; + if (fa != null) { + value = fa.f(); + this.fa = null; } return value; } @@ -294,10 +307,10 @@ private synchronized A computeValue() { } abstract static class ReferenceMemo extends P1 { - private final P1 self; + private final F0 fa; private volatile Reference> v = null; - ReferenceMemo(final P1 self) { this.self = self; } + ReferenceMemo(final F0 fa) { this.fa = fa; } @Override public final A _1() { Reference> v = this.v; @@ -309,7 +322,7 @@ private synchronized A computeValue() { Reference> v = this.v; P1 p1 = v != null ? v.get() : null; if (p1 == null) { - A a = self._1(); + A a = fa.f(); this.v = newReference(p(a)); return a; } @@ -320,14 +333,14 @@ private synchronized A computeValue() { } static final class WeakReferenceMemo extends ReferenceMemo { - WeakReferenceMemo(P1 self) { super(self); } + WeakReferenceMemo(F0 fa) { super(fa); } @Override Reference newReference(final B ref) { return new WeakReference<>(ref); } @Override public P1 weakMemo() { return this; } } static final class SoftReferenceMemo extends ReferenceMemo { - SoftReferenceMemo(P1 self) { super(self); } + SoftReferenceMemo(F0 self) { super(self); } @Override Reference newReference(final B ref) { return new SoftReference<>(ref); } @Override public P1 softMemo() { return this; } diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index abe4d0d5..e503ff40 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -1,6 +1,7 @@ package fj; import static fj.Function.*; +import static fj.P.weakMemo; import static fj.data.optic.PLens.pLens; import fj.data.*; import fj.data.optic.Lens; @@ -185,8 +186,8 @@ public final P1 _2_() { public final P2 memo() { P2 self = this; return new P2() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index 26c51b05..ec277346 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-3. * @@ -128,9 +130,9 @@ public final P1 _3_() { public final P3 memo() { P3 self = this; return new P3() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index c2f94f8f..3f7236fe 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-4. * @@ -182,10 +184,10 @@ public final P1 _4_() { public final P4 memo() { P4 self = this; return new P4() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); - private final P1 d = P1.memo(u -> self._4()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); + private final P1 d = weakMemo(self::_4); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 902da93c..393b0632 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-5. * @@ -244,11 +246,11 @@ public final P1 _5_() { public final P5 memo() { P5 self = this; return new P5() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); - private final P1 d = P1.memo(u -> self._4()); - private final P1 e = P1.memo(u -> self._5()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); + private final P1 d = weakMemo(self::_4); + private final P1 e = weakMemo(self::_5); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index 37f5fe6c..1e8c3055 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-6. * @@ -315,12 +317,12 @@ public final P1 _6_() { public final P6 memo() { P6 self = this; return new P6() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); - private final P1 d = P1.memo(u -> self._4()); - private final P1 e = P1.memo(u -> self._5()); - private final P1 f = P1.memo(u -> self._6()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); + private final P1 d = weakMemo(self::_4); + private final P1 e = weakMemo(self::_5); + private final P1 f = weakMemo(self::_6); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index e2673183..ca24b40e 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-7. * @@ -393,13 +395,13 @@ public final P1 _7_() { public final P7 memo() { P7 self = this; return new P7() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); - private final P1 d = P1.memo(u -> self._4()); - private final P1 e = P1.memo(u -> self._5()); - private final P1 f = P1.memo(u -> self._6()); - private final P1 g = P1.memo(u -> self._7()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); + private final P1 d = weakMemo(self::_4); + private final P1 e = weakMemo(self::_5); + private final P1 f = weakMemo(self::_6); + private final P1 g = weakMemo(self::_7); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index cfa916eb..f15d63a1 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -1,5 +1,7 @@ package fj; +import static fj.P.weakMemo; + /** * A product-8. * @@ -480,14 +482,14 @@ public final P1 _8_() { public final P8 memo() { P8 self = this; return new P8() { - private final P1 a = P1.memo(u -> self._1()); - private final P1 b = P1.memo(u -> self._2()); - private final P1 c = P1.memo(u -> self._3()); - private final P1 d = P1.memo(u -> self._4()); - private final P1 e = P1.memo(u -> self._5()); - private final P1 f = P1.memo(u -> self._6()); - private final P1 g = P1.memo(u -> self._7()); - private final P1 h = P1.memo(u -> self._8()); + private final P1 a = weakMemo(self::_1); + private final P1 b = weakMemo(self::_2); + private final P1 c = weakMemo(self::_3); + private final P1 d = weakMemo(self::_4); + private final P1 e = weakMemo(self::_5); + private final P1 f = weakMemo(self::_6); + private final P1 g = weakMemo(self::_7); + private final P1 h = weakMemo(self::_8); public A _1() { return a._1(); diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index ae37d714..e4baccf5 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -25,6 +25,7 @@ import static fj.Function.*; import static fj.P.p; import static fj.P.p2; +import static fj.P.weakMemo; import static fj.Unit.unit; import static fj.control.parallel.Promise.promise; import static fj.data.Array.mkArray; @@ -1442,7 +1443,7 @@ private static final class Cons extends Stream { Cons(final A head, final F0> tail) { this.head = head; - this.tail = P1.memo(tail); + this.tail = weakMemo(tail); } public A head() { diff --git a/core/src/test/java/fj/P1Test.java b/core/src/test/java/fj/P1Test.java index 788c2829..4d3c5c35 100644 --- a/core/src/test/java/fj/P1Test.java +++ b/core/src/test/java/fj/P1Test.java @@ -11,7 +11,7 @@ public final class P1Test { @Test public void bug105() throws Exception { - final P1 p1 = P.p("Foo").weakMemo(); + final P1 p1 = P.weakMemo(() -> "Foo"); final AtomicInteger nullCounter = new AtomicInteger(); ExecutorService executorService = Executors.newCachedThreadPool(); diff --git a/props-core/src/test/java/fj/MemoisationTest.java b/props-core/src/test/java/fj/MemoisationTest.java index e86e2a8b..65fa83fc 100644 --- a/props-core/src/test/java/fj/MemoisationTest.java +++ b/props-core/src/test/java/fj/MemoisationTest.java @@ -19,14 +19,14 @@ public class MemoisationTest { public Property test1() { return property(arbInteger, a -> { - P1 t = P.lazy(() -> a).weakMemo(); + P1 t = P.weakMemo(() -> a); return prop(t._1().equals(t._1())).and(prop(t._1().equals(a))); }); } public Property test1_hardMemo() { return property(arbInteger, a -> { - P1 t = P.lazy(() -> new Integer(a)).hardMemo(); + P1 t = P.hardMemo(() -> new Integer(a)); return prop(t._1() == t._1()).and(prop(t._1().equals(a))); }); } From 0e3187feb37751669028ceb6f06e6b012d47fa8b Mon Sep 17 00:00:00 2001 From: JB Giraudeau Date: Sun, 6 Nov 2016 11:46:20 +0100 Subject: [PATCH 151/336] Add a Hash Array Mapped Trie * Copied hamt from personal repo * Created show instances. Fixed BitSet.xor * Fixing overflow on BitSet longs. Adding tests * BitSet properties test * More BitSetProperties tests * Added remaining BitSet properties required * Moved hamt to String to the Show class * Clean up hamt test print lines * Updated after Gen/Arbitrary changes * Changed BitSet method name for creation from a long value * Fixed BitSet.asString * Added javadoc for HAMT * Added javadoc for HAMT * More tests on BitSet * Added more tests and minor refactoring for BitSet * Fixed BitSet.takeUpper * Fixed HAMT issue * Deleted BitSetTest * Fixed find and set. Added folds for HAMT * Properties and ad hoc tests for HAMT properties * Added Seq insert and filter * Added count population (CTPOP) from the paper for a bit set * Minor clean-up, remove dead-code. * improve BitSet#range performance (use bitwise operations) * remove unnecessary lambda --- core/src/main/java/fj/Equal.java | 3 + core/src/main/java/fj/Show.java | 22 +- core/src/main/java/fj/data/Seq.java | 17 ++ core/src/main/java/fj/data/hamt/BitSet.java | 204 ++++++++++++++++ .../fj/data/hamt/HashArrayMappedTrie.java | 220 ++++++++++++++++++ core/src/main/java/fj/data/hamt/Node.java | 56 +++++ core/src/test/java/fj/data/SeqTest.java | 9 + core/src/test/java/fj/data/hamt/HamtTest.java | 66 ++++++ .../java/fj/data/hamt/BitSetProperties.java | 218 +++++++++++++++++ .../hamt/HashArrayMappedTrieProperties.java | 94 ++++++++ quickcheck/src/main/java/fj/test/Gen.java | 10 + quickcheck/src/main/java/fj/test/Rand.java | 3 + .../src/test/java/fj/test/TestRand.java | 2 +- 13 files changed, 921 insertions(+), 3 deletions(-) create mode 100644 core/src/main/java/fj/data/hamt/BitSet.java create mode 100644 core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java create mode 100644 core/src/main/java/fj/data/hamt/Node.java create mode 100644 core/src/test/java/fj/data/hamt/HamtTest.java create mode 100644 props-core/src/test/java/fj/data/hamt/BitSetProperties.java create mode 100644 props-core/src/test/java/fj/data/hamt/HashArrayMappedTrieProperties.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index a09dceba..b3709f4b 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -3,6 +3,7 @@ import static fj.Function.curry; import fj.data.*; +import fj.data.hamt.BitSet; import fj.data.hlist.HList; import fj.data.vector.V2; import fj.data.vector.V3; @@ -104,6 +105,8 @@ public static Equal anyEqual() { */ public static final Equal booleanEqual = anyEqual(); + public static final Equal bitSetSequal = Equal.equal(bs1 -> bs2 -> bs1.longValue() == bs2.longValue()); + /** * An equal instance for the byte type. */ diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 9e55a1d6..2d2c4707 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -1,8 +1,9 @@ package fj; import fj.data.*; +import fj.data.hamt.BitSet; +import fj.data.hamt.HashArrayMappedTrie; import fj.data.fingertrees.FingerTree; -import fj.data.fingertrees.Node; import fj.data.hlist.HList; import fj.data.vector.V2; import fj.data.vector.V3; @@ -315,7 +316,7 @@ public static Show> digitShow(final Show< }); } - public static Show> nodeShow(final Show sv, final Show sa) { + public static Show> nodeShow(final Show sv, final Show sa) { return show(n -> { final String s = n.match( n2 -> "Node2(" + n2.measure() + " -> " + v2Show(sa).showS(n2.toVector()) + ")", @@ -701,4 +702,21 @@ public static Show> unlineShow(final Show sa) { public static > Show> HListShow(final Show e, final Show l) { return show(c -> fromString("HList(").append(e.show(c.head())).append(l.show(c.tail())).append(fromString(")"))); } + + public static Show> hamtNodeShow(Show sk, Show sv) { + F, String> f = n -> n.match(p -> p2Show(sk, sv).showS(p), h -> hamtShow(sk, sv).showS(h)); + return Show.showS(f); + } + + public static Show> hamtShow(Show sk, Show sv) { + return Show.showS(hamt -> + "HashArrayMappedTrie(" + Show.bitSetShow.showS(hamt.getBitSet()) + + ", " + Show.seqShow(Show.hamtNodeShow(sk, sv)).showS(hamt.getSeq()) + ")" + ); + } + + public static final Show bitSetShow = Show.showS( + bs -> "BitSet(" + bs.asString() + ")" + ); + } diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index c6eb98be..abd20162 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -275,6 +275,18 @@ public boolean isEmpty() { return ftree.isEmpty(); } + /** + * Inserts the element at the given index. This is an O(log(n)) operation. + * + * @param index The index of the element to return. + * @return The sequence with the element inserted at the given index, + * or throws an error if the index is out of bounds. + */ + public Seq insert(int index, A a) { + final P2, Seq> p = split(index); + return p._1().append(single(a)).append(p._2()); + } + /** * Checks if this sequence is not empty. * @@ -370,6 +382,11 @@ public B foldRight(final F2 f, final B z) { return ftree.foldRight(f, z); } + + public Seq filter(F f) { + return foldLeft((acc, a) -> f.f(a) ? acc.snoc(a) : acc, empty()); + } + @Override public int hashCode() { return Hash.seqHash(Hash.anyHash()).hash(this); diff --git a/core/src/main/java/fj/data/hamt/BitSet.java b/core/src/main/java/fj/data/hamt/BitSet.java new file mode 100644 index 00000000..d164642d --- /dev/null +++ b/core/src/main/java/fj/data/hamt/BitSet.java @@ -0,0 +1,204 @@ +package fj.data.hamt; + +import fj.Equal; +import fj.F2; +import fj.Monoid; +import fj.Show; +import fj.data.List; +import fj.data.Stream; + +/** + * A sequence of bits representing a value. The most significant bit (the + * bit with the highest value) is the leftmost bit and has the highest index. + * For example, the BitSet("1011") represents the decimal number 11 and has + * indices [3, 0] inclusive where the bit with the lowest value has the lowest + * index and is the rightmost bit. + * + * Created by maperr on 31/05/2016. + */ +public final class BitSet { + + public static final int TRUE_BIT = 1; + public static final int FALSE_BIT = 0; + public static final BitSet EMPTY = new BitSet(FALSE_BIT); + + public static final long BASE_LONG = 1L; + public static final int MAX_BIT_SIZE = Long.SIZE; + public static final int MAX_BIT_INDEX = Long.SIZE - 1; + + private final long value; + + private BitSet(final long l) { + value = l; + } + + public static BitSet empty() { + return EMPTY; + } + + public static BitSet longBitSet(final long l) { + return new BitSet(l); + } + + public static BitSet listBitSet(final List list) { + final int n = list.length(); + if (n > MAX_BIT_SIZE) { + throw new IllegalArgumentException("Does not support lists greater than " + MAX_BIT_SIZE + " bits, actual size is " + n); + } + long result = 0; + for (Boolean b: list) { + result = (result << 1) | toInt(b); + } + return longBitSet(result); + } + + public static BitSet streamBitSet(final Stream s) { + return listBitSet(s.toList()); + } + + public static BitSet stringBitSet(final String s) { + return streamBitSet(Stream.fromString(s).map(BitSet::toBoolean)); + } + + public boolean isSet(final int index) { + return (value & (BASE_LONG << index)) != 0; + } + + public boolean isEmpty() { + return value == 0; + } + + public BitSet set(final int index) { + return longBitSet(value | (BASE_LONG << index)); + } + + public BitSet set(final int index, boolean b) { + return b ? set(index) : clear(index); + } + + public BitSet clear(final int index) { + return longBitSet(value & ~(BASE_LONG << index)); + } + + public long longValue() { + return value; + } + + public BitSet and(final BitSet bs) { + return longBitSet(value & bs.longValue()); + } + + public BitSet or(final BitSet bs) { + return longBitSet(value | bs.longValue()); + } + + public BitSet shiftRight(final int n) { + return longBitSet(value >> n); + } + + public BitSet shiftLeft(final int n) { + return longBitSet(value << n); + } + + public int bitsUsed() { + return toStream().length(); + } + + public int bitsOn() { + return toStream().foldLeft((acc, b) -> acc + (b ? 1 : 0), 0); + } + + /** + * Returns a stream of boolean where the head is the most significant bit + * (the bit with the largest value) + */ + public Stream toStream() { + return Stream.fromString(Long.toBinaryString(value)).map(BitSet::toBoolean).dropWhile(b -> !b); + } + + @Override + public String toString() { + return Show.bitSetShow.showS(this); + } + + @Override + public boolean equals(Object obj) { + return Equal.equals0(BitSet.class, this, obj, Equal.bitSetSequal); + } + + public int bitsToRight(final int index) { + if (index >= MAX_BIT_SIZE) { + throw new IllegalArgumentException("Does not support an index " + + "greater than or equal to " + MAX_BIT_SIZE + " bits, actual argument is " + index); + } + int pos = index - 1; + long mask = BASE_LONG << (pos); + int result = 0; + while (pos >= 0) { + if ((mask & value) != 0) { + result++; + } + mask = mask >> 1; + pos--; + } + return result; + } + + public List toList() { + return toStream().toList(); + } + + public A foldRight(final F2 f, A acc) { + return toStream().foldRight(b -> p -> f.f(b, p._1()), acc); + } + + public A foldLeft(final F2 f, A acc) { + return toStream().foldLeft(f, acc); + } + + public BitSet xor(final BitSet bs) { + return longBitSet(value ^ bs.longValue()); + } + + public BitSet not() { + return longBitSet(~value); + } + + public BitSet takeLower(final int n) { + return streamBitSet(toStream().reverse().take(n).reverse()); + } + + public BitSet takeUpper(final int n) { + String zero = Integer.toString(FALSE_BIT); + String current = asString(); + String pad = Monoid.stringMonoid.sumLeft(List.replicate(MAX_BIT_SIZE - current.length(), zero)); + return stringBitSet(pad + current.substring(0, Math.max(n - pad.length(), 0))); + } + + /** + * Returns the bit set from indices in the range from low (inclusive) + * to high(exclusive) from the least significant bit (on the right), + * e.g. "101101".range(1, 4) == "0110" + */ + public BitSet range(final int highIndex, final int lowIndex) { + int max = Math.max(lowIndex, highIndex); + int min = Math.min(lowIndex, highIndex); + return new BitSet(max == min ? 0L : (value << (64 - max)) >>> (64 - max + min)); + } + + public static boolean toBoolean(final char c) { + return c != '0'; + } + + public static boolean toBoolean(final int i) { + return i != FALSE_BIT; + } + + public static int toInt(final boolean b) { + return b ? TRUE_BIT : FALSE_BIT; + } + + public String asString() { + return Long.toBinaryString(value); + } +} diff --git a/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java b/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java new file mode 100644 index 00000000..f13ae90f --- /dev/null +++ b/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java @@ -0,0 +1,220 @@ +package fj.data.hamt; + +import fj.Equal; +import fj.F2; +import fj.Hash; +import fj.Ord; +import fj.P2; +import fj.Show; +import fj.data.List; +import fj.data.Option; +import fj.data.Seq; +import fj.data.Stream; + +import static fj.P.p; +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.data.hamt.BitSet.longBitSet; + +/** + * A hash array mapped trie (HAMT) is an implementation of an associative + * array that combines the characteristics of a hash table and an array + * mapped trie. It is a refined version of the more general notion of + * a hash tree. + * + * @author Mark Perry + * + * Based on "Ideal Hash Trees" by Phil Bagwell, available from + * http://lampwww.epfl.ch/papers/idealhashtrees.pdf + */ +public final class HashArrayMappedTrie { + + private final Seq> seq; + private final BitSet bitSet; + private final Hash hash; + private final Equal equal; + + public static final int BITS_IN_INDEX = 5; + public static final int SIZE = (int) StrictMath.pow(2, BITS_IN_INDEX); + public static final int MIN_INDEX = 0; + public static final int MAX_INDEX = SIZE - 1; + + /** + * Creates an empty trie for the bitset, sequence of nodes, equal and hash. + * + * @param bs - The set of bits to indicate which of the SIZE nodes in the sequence are used. + * @param s - The sequence of HAMT nodes - either a HAMT or a key-value pair. + * @param e - Equality instance for keys. + * @param h - Hash instance for keys. + */ + private HashArrayMappedTrie(final BitSet bs, final Seq> s, final Equal e, final Hash h) { + bitSet = bs; + seq = s; + hash = h; + equal = e; + } + + /** + * Creates an empty trie. + */ + public static HashArrayMappedTrie empty(final Equal e, final Hash h) { + return new HashArrayMappedTrie<>(BitSet.empty(), Seq.empty(), e, h); + } + + /** + * Create and empty trie keyed by integer. + */ + public static HashArrayMappedTrie emptyKeyInteger() { + return empty(Equal.intEqual, Hash.intHash); + } + + /** + * Returns if the trie is empty. + */ + public boolean isEmpty() { + return bitSet.isEmpty(); + } + + /** + * Static constructor for a HAMT instance. + */ + private static HashArrayMappedTrie hamt(final BitSet bs, final Seq> s, final Equal e, final Hash h) { + return new HashArrayMappedTrie<>(bs, s, e, h); + } + + /** + * Returns an optional value for the given key k. + */ + public Option find(final K k) { + return find(k, MIN_INDEX, MIN_INDEX + BITS_IN_INDEX); + } + + /** + * Returns an optional value for the given key k for those nodes between + * lowIndex (inclusive) and highIndex (exclusive). + */ + public Option find(final K k, final int lowIndex, final int highIndex) { + BitSet bs1 = longBitSet(hash.hash(k)).range(lowIndex, highIndex); + int i = (int) bs1.longValue(); + boolean b = bitSet.isSet(i); + final int index = bitSet.bitsToRight(i); + if (!b) { + return none(); + } else { + final Node oldNode = seq.index(index); + return oldNode.match( + n -> equal.eq(n._1(), k) ? some(n._2()) : none(), + hamt -> hamt.find(k, lowIndex + BITS_IN_INDEX, highIndex + BITS_IN_INDEX) + ); + } + } + + /** + * Adds the key-value pair (k, v) to the trie. + */ + public HashArrayMappedTrie set(final K k, final V v) { + return set(k, v, MIN_INDEX, MIN_INDEX + BITS_IN_INDEX); + } + + /** + * Adds the product of key-value (k, v) pairs to the trie. + */ + public HashArrayMappedTrie set(final List> list) { + return list.foldLeft(h -> p -> h.set(p._1(), p._2()), this); + } + + /** + * Sets the key-value pair (k, v) for the bit range lowIndex (inclusive) to highIndex (exclusive). + */ + private HashArrayMappedTrie set(final K k, final V v, final int lowIndex, final int highIndex) { + final BitSet bs1 = longBitSet(hash.hash(k)).range(lowIndex, highIndex); + final int i = (int) bs1.longValue(); + final boolean b = bitSet.isSet(i); + final int index = bitSet.bitsToRight(i); + + if (!b) { + // append new node + final Node sn1 = Node.p2Node(p(k, v)); + return hamt(bitSet.set(i), seq.insert(index, sn1), equal, hash); + } else { + final Node oldNode = seq.index(index); + final Node newNode = oldNode.match(n -> { + if (equal.eq(n._1(), k)) { + return Node.p2Node(p(k, v)); + } else { + final HashArrayMappedTrie e = HashArrayMappedTrie.empty(equal, hash); + final HashArrayMappedTrie h1 = e.set(n._1(), n._2(), lowIndex + BITS_IN_INDEX, highIndex + BITS_IN_INDEX); + final HashArrayMappedTrie h2 = h1.set(k, v, lowIndex + BITS_IN_INDEX, highIndex + BITS_IN_INDEX); + return Node.hamtNode(h2); + } + }, hamt -> Node.hamtNode(hamt.set(k, v, lowIndex + BITS_IN_INDEX, highIndex + BITS_IN_INDEX)) + ); + return hamt(bitSet, seq.update(index, newNode), equal, hash); + } + } + + /** + * Returns a stream of key-value pairs. + */ + public Stream> toStream() { + return seq.toStream().bind(Node::toStream); + } + + /** + * Returns the list of key-value pairs, ordered by key. + */ + public List> toList(Ord o) { + return toStream().sort(Ord.p2Ord1(o)).toList(); + } + + /** + * Returns a list of key-value pairs. + */ + public List> toList() { + return toStream().toList(); + } + + @Override + public String toString() { + return Show.hamtShow(Show.anyShow(), Show.anyShow()).showS(this); + } + + /** + * Performs a left-fold reduction across this trie. + */ + public B foldLeftOnNode(F2, B> f, B b) { + return seq.foldLeft(f, b); + } + + /** + * Performs a left-fold reduction across this trie. + */ + public B foldLeft(F2, B> f, F2, B> g, B b) { + return foldLeftOnNode((acc, n) -> n.match(p -> f.f(acc, p), h -> g.f(acc, h)), b); + } + + /** + * Performs a left-fold reduction across this trie. + */ + public B foldLeft(F2, B> f, B b) { + return foldLeftOnNode((acc, n) -> n.match(p -> f.f(acc, p), h -> h.foldLeft(f, acc)), b); + } + + public BitSet getBitSet() { + return bitSet; + } + + public Seq> getSeq() { + return seq; + } + + /** + * Returns the number of elements in the trie. + */ + public int length() { + return seq.foldLeft( + (acc, node) -> node.match(p2 -> acc + 1, hamt -> acc + hamt.length()), 0 + ); + } + +} diff --git a/core/src/main/java/fj/data/hamt/Node.java b/core/src/main/java/fj/data/hamt/Node.java new file mode 100644 index 00000000..f8a1ff40 --- /dev/null +++ b/core/src/main/java/fj/data/hamt/Node.java @@ -0,0 +1,56 @@ +package fj.data.hamt; + +import fj.F; +import fj.P2; +import fj.Show; +import fj.data.Either; +import fj.data.Option; +import fj.data.Stream; + +/** + * A Hash Array Mapped Trie node that is either a key-value pair or a + * Hash Array Mapped Trie. + * + * Created by maperr on 31/05/2016. + */ +public final class Node { + + private final Either, HashArrayMappedTrie> either; + + public Node(final Either, HashArrayMappedTrie> e) { + either = e; + } + + public Node(final P2 simpleNode) { + this(Either.left(simpleNode)); + } + + public Node(final HashArrayMappedTrie hamt) { + this(Either.right(hamt)); + } + + public static Node p2Node(final P2 p) { + return new Node<>(p); + } + + public static Node hamtNode(final HashArrayMappedTrie hamt) { + return new Node<>(hamt); + } + + /** + * Performs a reduction on this Node using the given arguments. + */ + public B match(final F, B> f, final F, B> g) { + return either.either(f, g); + } + + public Stream> toStream() { + return match(Stream::single, HashArrayMappedTrie::toStream); + } + + @Override + public String toString() { + return Show.hamtNodeShow(Show.anyShow(), Show.anyShow()).showS(this); + } + +} diff --git a/core/src/test/java/fj/data/SeqTest.java b/core/src/test/java/fj/data/SeqTest.java index 633ae321..27ec26e2 100644 --- a/core/src/test/java/fj/data/SeqTest.java +++ b/core/src/test/java/fj/data/SeqTest.java @@ -1,5 +1,6 @@ package fj.data; +import fj.P2; import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -34,4 +35,12 @@ public void convertToString() { expected.append(')'); assertEquals(expected.toString(), Seq.seq(Array.range(0, 10000).array()).toString()); } + + + @Test + public void test() { + P2, Seq> p2 = Seq.single(1).split(5); + System.out.println(p2); + } + } diff --git a/core/src/test/java/fj/data/hamt/HamtTest.java b/core/src/test/java/fj/data/hamt/HamtTest.java new file mode 100644 index 00000000..1e601f24 --- /dev/null +++ b/core/src/test/java/fj/data/hamt/HamtTest.java @@ -0,0 +1,66 @@ +package fj.data.hamt; + +import fj.Ord; +import fj.P2; +import fj.data.List; +import fj.data.Option; +import org.junit.Test; + +import static fj.Equal.intEqual; +import static fj.Equal.optionEqual; +import static fj.Hash.intHash; +import static fj.P.p; +import static fj.data.List.list; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * @author Mark Perry + */ +public class HamtTest { + + public static final HashArrayMappedTrie empty = HashArrayMappedTrie.emptyKeyInteger(); + + @Test + public void empty() { + assertThat(empty.length(), equalTo(0)); + } + + @Test + public void lengthOne() { + assertThat(empty.set(3, 6).length(), equalTo(1)); + } + + @Test + public void updateLength() { + HashArrayMappedTrie h1 = empty.set(3, 3).set(3, 5); + assertThat(h1.length(), equalTo(1)); + } + + @Test + public void streamLength() { + List> list = list(p(0, 1), p(31, 1), p(32, 1), p(33, 1)); + HashArrayMappedTrie h2 = empty.set(list); + assertThat(h2.toStream().length(), equalTo(list.length())); + } + + @Test + public void allIn() { + List> list = List.list(p(-5, 0), p(-1, -5), p(2, 4), p(4, -2)); + HashArrayMappedTrie h = empty.set(list); + Boolean b = list.foldLeft((acc, p) -> h.find(p._1()).option(false, i -> true && acc), true); + assertThat(b, equalTo(true)); + } + + @Test + public void sampleInts() { + List> ps = List.list(p(-3, 0), p(1, 2)); + int key = -3; + HashArrayMappedTrie h = empty.set(ps); + Option o1 = ps.find(p -> intEqual.eq(p._1(), key)).map(p -> p._2()); + Option o2 = h.find(key); + boolean b = optionEqual(intEqual).eq(o1, o2); + assertThat(b, equalTo(true)); + } + +} diff --git a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java new file mode 100644 index 00000000..0ae976ef --- /dev/null +++ b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java @@ -0,0 +1,218 @@ +package fj.data.hamt; + +import fj.Equal; +import fj.Ord; +import fj.P; +import fj.P3; +import fj.data.List; +import fj.data.Seq; +import fj.data.test.PropertyAssert; +import fj.function.Booleans; +import fj.test.Gen; +import fj.test.Property; +import fj.test.reflect.CheckParams; +import fj.test.runner.PropertyTestRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.math.BigInteger; + +import static fj.Equal.bitSetSequal; +import static fj.Equal.booleanEqual; +import static fj.Equal.listEqual; +import static fj.Equal.stringEqual; +import static fj.Function.identity; +import static fj.data.hamt.BitSet.MAX_BIT_SIZE; +import static fj.data.hamt.BitSet.listBitSet; +import static fj.data.hamt.BitSet.longBitSet; +import static fj.test.Arbitrary.arbBoolean; +import static fj.test.Arbitrary.arbLong; +import static fj.test.Property.impliesBoolean; +import static fj.test.Property.prop; +import static fj.test.Property.property; + +/** + * Created by maperr on 31/05/2016. + */ + +@RunWith(PropertyTestRunner.class) +@CheckParams(maxSize = 10000) +public class BitSetProperties { + + Property andTest() { + return property(arbLong, arbLong, (a, b) -> prop(longBitSet(a).and(longBitSet(b)).longValue() == (a & b))); + } + + Property asStringTest() { + return property(arbLong, a -> prop(longBitSet(a).asString().equals(Long.toBinaryString(a)))); + } + + Property bitsToRightTest() { + return property(arbLong, arbBitSetSize, (a, i) -> + prop( + longBitSet(a).bitsToRight(i) == + longBitSet(a).toList().reverse().take(i).filter(identity()).length() + )); + } + + Property longRoundTripTest() { + return property(arbNaturalLong, l -> prop(longBitSet(l).longValue() == l)); + } + + Property empty() { + return prop(BitSet.empty().isEmpty() && BitSet.empty().longValue() == 0); + } + + Property generalEmptinessTest() { + return property(arbListBoolean, list -> + prop(list.dropWhile(Booleans.not).isEmpty() == listBitSet(list).isEmpty()) + ); + } + + Property foldLeftTest() { + return property(arbLong, l -> prop( + BitSet.longBitSet(l).toList().dropWhile(b -> !b).foldLeft( + (acc, b) -> acc + 1, 0 + ) == BitSet.longBitSet(l).bitsUsed() + )); + } + + Property fromListTest() { + return property(arbListBoolean, l -> prop(listBitSet(l).toList().equals(l.dropWhile(b -> !b)))); + } + + Property fromStreamTest() { + return property(arbListBoolean, l -> prop(listBitSet(l).toStream().toList().equals(l.dropWhile(b -> !b)))); + } + + Property fromLongTest() { + return property(arbLong, l -> prop(BitSet.longBitSet(l).longValue() == l)); + } + + Property fromStringTest() { + Gen g = arbListBoolean.map(l -> l.map(b -> Integer.toString(BitSet.toInt(b))).foldLeft((acc, s) -> acc + s, "")); + return property(g, (s) -> { + boolean zeroLength = s.isEmpty(); + return Property.implies(!zeroLength, () -> { + long x = new BigInteger(s, 2).longValue(); + long y = BitSet.stringBitSet(s).longValue(); + return prop(x == y); + }); + }); + } + + Gen> arbListBoolean = Gen.choose(0, MAX_BIT_SIZE).bind(i -> Gen.sequenceN(i, arbBoolean)); + + Property toListTest() { + return property(arbListBoolean, list -> { + List expected = list.dropWhile(Booleans.not); + List actual = listBitSet(list).toList(); + return prop(Equal.listEqual(Equal.booleanEqual).eq(expected, actual)); + }); + } + + Property clearTest() { + return property(arbLong, arbBitSetSize, (l, i) -> + prop(BitSet.longBitSet(l).clear(i).isSet(i) == false) + ); + } + + Property bitsUsedTest() { + return property(arbListBoolean, list -> prop( + list.dropWhile(b -> !b).length() == + listBitSet(list).bitsUsed() + )); + } + + Property isSetTest() { + return property(arbNaturalLong, Gen.choose(0, MAX_BIT_SIZE), + (Long l, Integer i) -> prop(longBitSet(l).isSet(i) == ((l & (1L << i)) != 0)) + ); + } + + Property stringBitSet() { + return property(arbNaturalLong, l -> + prop(BitSet.stringBitSet(BitSet.longBitSet(l).asString()).longValue() == l) + ); + } + + Property notTest() { + return property(arbLong, l -> prop(longBitSet(l).not().longValue() == ~l)); + } + + Property orTest() { + return property(arbLong, arbLong, (x, y) -> prop( + longBitSet(x).or(longBitSet(y)).longValue() == (x | y) + )); + } + + Gen> bitSetIndices(int n) { + return Gen.listOfSorted(Gen.choose(0, MAX_BIT_SIZE - 1), n, Ord.intOrd); + } + + Property rangeTest() { + return property(arbNaturalLong, bitSetIndices(4), (x, list) -> { + int l = list.index(0); + int m = list.index(1); + int h = list.index(2); + int vh = list.index(3); + + BitSet bs1 = longBitSet(x); + BitSet bs2 = bs1.range(l, h); + boolean b = + bs1.isSet(m) == bs2.isSet(m - l) && + bs2.isSet(vh - l) == false; + return prop(b); + }); + } + + Property setTest() { + return property(arbNaturalLong, arbBitSetSize, (l, i) -> prop(longBitSet(l).set(i).isSet(i))); + } + + Property setBooleanTest() { + return property(arbNaturalLong, arbBitSetSize, arbBoolean, (l, i, b) -> prop(longBitSet(l).set(i, b).isSet(i) == b)); + } + + Property shiftLeftTest() { + return property(arbNaturalLong, arbBitSetSize, (l, i) -> { + BitSet bs = longBitSet(l); + boolean b = bs.shiftLeft(i).longValue() == (l << i); + return impliesBoolean(bs.bitsUsed() + i < MAX_BIT_SIZE, b); + }); + } + + Property shiftRightTest() { + return property(arbNaturalLong, arbBitSetSize, (l, i) -> { + return prop(longBitSet(l).shiftRight(i).longValue() == (l >> i)); + }); + } + + Property takeLowerTest() { + return property(arbNaturalLong, arbBitSetSize, (l, i) -> { + return prop(bitSetSequal.eq(longBitSet(l).takeLower(i), longBitSet(l).range(0, i))); + }); + } + + Property takeUpperTest() { + return property(arbNaturalLong, arbBitSetSize, (l, i) -> { + return prop(bitSetSequal.eq(longBitSet(l).takeUpper(i), longBitSet(l).range(MAX_BIT_SIZE, MAX_BIT_SIZE - i))); + }); + } + + Property toStreamTest() { + return property(arbNaturalLong, l -> { + return prop(listEqual(booleanEqual).eq(longBitSet(l).toList(), longBitSet(l).toStream().toList())); + }); + } + + Property xorTest() { + return property(arbNaturalLong, arbNaturalLong, (a, b) -> { + return prop(longBitSet(a).xor(longBitSet(b)).longValue() == (a ^ b)); + }); + } + static final Gen arbNaturalLong = Gen.choose(0, Long.MAX_VALUE); + + static final Gen arbBitSetSize = Gen.choose(0, MAX_BIT_SIZE - 1); + +} diff --git a/props-core/src/test/java/fj/data/hamt/HashArrayMappedTrieProperties.java b/props-core/src/test/java/fj/data/hamt/HashArrayMappedTrieProperties.java new file mode 100644 index 00000000..05001a1a --- /dev/null +++ b/props-core/src/test/java/fj/data/hamt/HashArrayMappedTrieProperties.java @@ -0,0 +1,94 @@ +package fj.data.hamt; + +import fj.Equal; +import fj.Hash; +import fj.Ord; +import fj.P2; +import fj.data.List; +import fj.data.Option; +import fj.data.Set; +import fj.test.Gen; +import fj.test.Property; +import fj.test.reflect.CheckParams; +import fj.test.runner.PropertyTestRunner; +import org.junit.runner.RunWith; + +import static fj.Equal.intEqual; +import static fj.Equal.optionEqual; +import static fj.Ord.intOrd; +import static fj.Ord.p2Ord; +import static fj.Ord.p2Ord2; +import static fj.data.Option.some; +import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbList; +import static fj.test.Arbitrary.arbListInteger; +import static fj.test.Arbitrary.arbP2; +import static fj.test.Arbitrary.arbSet; +import static fj.test.Property.prop; +import static fj.test.Property.property; + +/** + * @author Mark Perry + */ +@RunWith(PropertyTestRunner.class) +@CheckParams(maxSize = 100) +public class HashArrayMappedTrieProperties { + + private static final HashArrayMappedTrie empty = HashArrayMappedTrie.emptyKeyInteger(); + private static final Gen>> arbListProducts = arbSet(intOrd, arbInteger).bind(s -> Gen.listOf(arbInteger, s.size()).map(list -> s.toList().zip(list))); + private static final Gen> arbHamt = arbListProducts.map(l -> empty.set(l)); + + Property empty() { + return prop(empty.isEmpty()); + } + + Property setFromList() { + return property(arbListProducts, list -> { + List> actual = empty.set(list).toList(intOrd); + List> expected = list.sort(p2Ord(intOrd, intOrd)); + boolean b = actual.equals(expected); + return prop(b); + }); + } + + Property overwriteKey() { + return property(arbHamt, arbInteger, arbInteger, arbInteger, (h, k, v1, v2) -> { + Option actual = h.set(k, v1).set(k, v2).find(k); + return prop(optionEqual(intEqual).eq(actual, some(v2))); + }); + } + + Property allIn() { + return property(arbListProducts, list -> { + HashArrayMappedTrie h = empty.set(list); + Boolean b = list.foldLeft((acc, p) -> h.find(p._1()).option(false, i -> true && acc), true); + return prop(b); + }); + } + + Property sampleInts() { + return property(arbListProducts, arbInteger, (ps, i) -> { + HashArrayMappedTrie h = empty.set(ps); + Option o1 = ps.find(p -> intEqual.eq(p._1(), i)).map(p -> p._2()); + Option o2 = h.find(i); + return prop(optionEqual(intEqual).eq(o1, o2)); + }); + } + + Property fold() { + return property(arbListProducts, list -> { + Integer actual = empty.set(list).foldLeft((acc, p) -> acc + p._2(), 0); + Integer expected = list.foldLeft((acc, p) -> acc + p._2(), 0); + return prop(intEqual.eq(actual, expected)); + }); + } + + Property length() { + return property(arbListProducts, list -> { + Integer actual = empty.set(list).length(); + Integer expected = list.length(); + return prop(intEqual.eq(actual, expected)); + }); + } + +} diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 1e4a4c5e..5b0a98bc 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -363,6 +363,12 @@ public static Gen choose(final int from, final int to) { return parameterised(curry((i, r) -> value(r.choose(f, t)))); } + public static Gen choose(final long from, final long to) { + final long f = min(from, to); + final long t = max(from, to); + return parameterised(i -> r -> value(r.choose(f, t))); + } + /** * Returns a generator that produces values between the given range (inclusive). * @@ -468,6 +474,10 @@ public static Gen> listOf(final Gen g, final int x) { return sized(size -> choose(x, max(x, size)).bind(n -> sequenceN(n, g))); } + public static Gen> listOfSorted(final Gen g, final int x, Ord ord) { + return listOf(g, x).map(l -> l.sort(ord)); + } + /** * Returns a generator of lists whose values come from the given generator. * diff --git a/quickcheck/src/main/java/fj/test/Rand.java b/quickcheck/src/main/java/fj/test/Rand.java index f1849bb3..b622dfe7 100644 --- a/quickcheck/src/main/java/fj/test/Rand.java +++ b/quickcheck/src/main/java/fj/test/Rand.java @@ -55,6 +55,9 @@ public int choose(final int from, final int to) { return f.f(Option.none()).f(from).f(to); } + public long choose(final long from, final long to) { + return g.f(Option.none()).f((double) from).f((double) to).longValue(); + } /** * Randomly chooses a value between the given range (inclusive). * diff --git a/quickcheck/src/test/java/fj/test/TestRand.java b/quickcheck/src/test/java/fj/test/TestRand.java index 6c72b3b1..1ca7c749 100644 --- a/quickcheck/src/test/java/fj/test/TestRand.java +++ b/quickcheck/src/test/java/fj/test/TestRand.java @@ -20,7 +20,7 @@ public void testRandLowHighInclusive() { int max = 10; int n = 100; Stream s = Stream.range(0, n).map(i -> Rand.standard.choose(min, max)).sort(Ord.intOrd); -// System.out.println(s); +// System.out.println(s.toList()); assertTrue(s.head() == min && s.last() == max); } From 732a15176efbee751abfbeb97d82f3029d8cc9a1 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Nov 2016 17:35:16 +0100 Subject: [PATCH 152/336] rename Ord/Equal.AltDef --- core/src/main/java/fj/Equal.java | 6 +++--- core/src/main/java/fj/Ord.java | 9 ++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index ae20c4df..35232412 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -53,7 +53,7 @@ default boolean equal(A a1, A a2) { /** * Primitives functions of Equal: alternative minimal definition and overridable methods. */ - public interface AlternateDefinition extends Definition { + public interface AltDefinition extends Definition { @Override boolean equal(A a1, A a2); @@ -158,7 +158,7 @@ public static Equal equalDef(final Definition definition) { * @param definition a definition of the equal instance. * @return An equal instance from the given function. */ - public static Equal equalDef(final AlternateDefinition definition) { + public static Equal equalDef(final AltDefinition definition) { return new Equal<>(definition); } @@ -407,7 +407,7 @@ public static Equal> arrayEqual(final Equal ea) { */ public static Equal> treeEqual(final Equal ea) { Definition eaDef = ea.def; - return equalDef(new AlternateDefinition>() { + return equalDef(new AltDefinition>() { final Definition>>> subForestEqDef = p1Equal(streamEqual(equalDef(this))).def; diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 1764ea74..5fdb6046 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -16,7 +16,6 @@ import static fj.Function.apply; import static fj.Function.compose; -import static fj.Function.compose2; import static fj.Function.curry; import static fj.Semigroup.semigroup; import static fj.Semigroup.semigroupDef; @@ -90,7 +89,7 @@ public Definition dual() { /** * Primitives functions of Ord: alternative minimal definition and overridable methods. */ - public interface AlternateDefinition extends Definition { + public interface AltDefinition extends Definition { Ordering compare(A a1, A a2); @@ -301,7 +300,7 @@ public static Ord ord(final F> f) { } /** - * Returns an order instance that uses the given minimal equality test and ordering definiion. + * Returns an order instance that uses the given minimal equality test and ordering definition. * * @param def The order definition. * @return An order instance. @@ -311,12 +310,12 @@ public static Ord ordDef(final Definition def) { } /** - * Returns an order instance that uses the given minimal equality test and ordering definiion. + * Returns an order instance that uses the given minimal equality test and ordering definition. * * @param def The order definition. * @return An order instance. */ - public static Ord ordDef(final AlternateDefinition def) { + public static Ord ordDef(final AltDefinition def) { return new Ord<>(def); } From 5f73cac759e57aba717420fa3d86d380ca783e45 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Nov 2016 17:50:38 +0100 Subject: [PATCH 153/336] List.minimum/maximum: use uncurried Ord.max/min for better perf. --- core/src/main/java/fj/data/List.java | 4 ++-- demo/src/main/java/fj/demo/euler/Problem4.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 8bc31a37..fa82359f 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -1462,7 +1462,7 @@ public static F, Integer> length_() { * @return The maximum element in this list according to the given ordering. */ public final A maximum(final Ord o) { - return foldLeft1(o.max); + return foldLeft1(o::max); } /** @@ -1472,7 +1472,7 @@ public final A maximum(final Ord o) { * @return The minimum element in this list according to the given ordering. */ public final A minimum(final Ord o) { - return foldLeft1(o.min); + return foldLeft1(o::min); } public final java.util.List toJavaList() { diff --git a/demo/src/main/java/fj/demo/euler/Problem4.java b/demo/src/main/java/fj/demo/euler/Problem4.java index 60c04d85..c768ed78 100644 --- a/demo/src/main/java/fj/demo/euler/Problem4.java +++ b/demo/src/main/java/fj/demo/euler/Problem4.java @@ -19,6 +19,6 @@ public static void main(final String[] a) { intShow.println(tdl.tails().bind(tdl.zipWith(multiply)).filter(i -> { final Stream s = intShow.show(i); return streamEqual(charEqual).eq(s.reverse().take(3), s.take(3)); - }).foldLeft1(intOrd.max)); + }).foldLeft1(intOrd::max)); } } From 05275dbf41969b88b6f46426350e1d0662b2a78d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Nov 2016 18:27:54 +0100 Subject: [PATCH 154/336] Do not deprecate monoid/ord/semigroup constructors for non java 8 users. --- core/src/main/java/fj/Equal.java | 15 ++++ core/src/main/java/fj/Monoid.java | 14 +++- core/src/main/java/fj/Ord.java | 16 +++- core/src/main/java/fj/Semigroup.java | 12 ++- .../java/fj/demo/concurrent/WordCount.java | 74 +++++++++---------- 5 files changed, 83 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 35232412..b64c758d 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -135,6 +135,8 @@ public boolean equal(B b1, B b2) { /** * Constructs an equal instance from the given function. * + * Java 8+ users: use {@link #equalDef(Definition)} instead. + * * @param f The function to construct the equal with. * @return An equal instance from the given function. */ @@ -142,6 +144,19 @@ public static Equal equal(final F> f) { return new Equal<>(f::f); } + + /** + * Constructs an equal instance from the given function. + * + * Java 8+ users: use {@link #equalDef(AltDefinition)} instead. + * + * @param f The function to construct the equal with. + * @return An equal instance from the given function. + */ + public static Equal equal(final F2 f) { + return equalDef(f::f); + } + /** * Constructs an equal instance from the given definition. * diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index a342b8c7..3fcf1775 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -38,6 +38,9 @@ public final class Monoid { private final Definition def; + /** + * Primitives functions of Monoid: minimal definition and overridable methods. + */ public interface Definition extends Semigroup.Definition { A empty(); @@ -91,6 +94,10 @@ public Definition dual() { } } + + /** + * Primitives functions of Monoid: alternative minimal definition and overridable methods. + */ public interface AltDefinition extends Definition { @Override @@ -423,13 +430,12 @@ public static Monoid monoidDef(final Semigroup.AltDefinition s, final /** * Constructs a monoid from the given sum function and zero value, which must follow the monoidal * laws. - * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} instead. + * Java 8+ users: use {@link #monoidDef(Semigroup.Definition, Object)} instead. * * @param sum The sum function for the monoid. * @param zero The zero for the monoid. * @return A monoid instance that uses the given sun function and zero value. */ - @Deprecated public static Monoid monoid(final F> sum, final A zero) { return new Monoid<>(new AltDefinition() { @Override @@ -447,13 +453,13 @@ public A empty() { /** * Constructs a monoid from the given sum function and zero value, which must follow the monoidal * laws. - * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} instead. + * + * Java 8+ users: use {@link #monoidDef(Semigroup.Definition, Object)} instead. * * @param sum The sum function for the monoid. * @param zero The zero for the monoid. * @return A monoid instance that uses the given sun function and zero value. */ - @Deprecated public static Monoid monoid(final F2 sum, final A zero) { return new Monoid<>(new Definition() { @Override diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 5fdb6046..a3e55edc 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -290,15 +290,27 @@ public final Ord reverse() { /** * Returns an order instance that uses the given equality test and ordering function. * - * @deprecated since 4.7. Use {@link #ordDef(Definition)}. + * Java 8+ users: use {@link #ordDef(Definition)} instead. + * * @param f The order function. * @return An order instance. */ - @Deprecated public static Ord ord(final F> f) { return new Ord<>(f::f); } + /** + * Returns an order instance that uses the given equality test and ordering function. + * + * Java 8+ users: use {@link #ordDef(AltDefinition)} instead. + * + * @param f The order function. + * @return An order instance. + */ + public static Ord ord(final F2 f) { + return ordDef(f::f); + } + /** * Returns an order instance that uses the given minimal equality test and ordering definition. * diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index cba1f04b..74d7de9b 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -31,6 +31,9 @@ */ public final class Semigroup { + /** + * Primitives functions of Semigroup: minimal definition and overridable methods. + */ public interface Definition { A append(A a1, A a2); @@ -79,6 +82,9 @@ public A multiply1p(int n, A a) { } } + /** + * Primitives functions of Semigroup: alternative minimal definition and overridable methods. + */ public interface AltDefinition extends Definition { @Override F prepend(A a); @@ -285,24 +291,22 @@ public static Semigroup semigroupDef(final AltDefinition def) { /** * Constructs a semigroup from the given function. - * @deprecated since 4.7. Use {@link #semigroupDef(Definition)}. + * Java 8+ users: use {@link #semigroupDef(AltDefinition)} instead. * * @param sum The function to construct this semigroup with. * @return A semigroup from the given function. */ - @Deprecated public static Semigroup semigroup(final F> sum) { return semigroupDef(sum::f); } /** * Constructs a semigroup from the given function. - * @deprecated since 4.7. Use {@link #semigroupDef(Definition)}. + * Java 8+ users: use {@link #semigroupDef(Definition)} instead. * * @param sum The function to construct this semigroup with. * @return A semigroup from the given function. */ - @Deprecated public static Semigroup semigroup(final F2 sum) { return new Semigroup<>(sum::f); } diff --git a/demo/src/main/java/fj/demo/concurrent/WordCount.java b/demo/src/main/java/fj/demo/concurrent/WordCount.java index c90a0b2d..175d2d09 100644 --- a/demo/src/main/java/fj/demo/concurrent/WordCount.java +++ b/demo/src/main/java/fj/demo/concurrent/WordCount.java @@ -1,10 +1,18 @@ package fj.demo.concurrent; -import static fj.Monoid.monoid; -import static fj.Monoid.monoidDef; -import static fj.control.parallel.ParModule.parModule; -import static fj.data.List.nil; -import static java.util.concurrent.Executors.newFixedThreadPool; +import fj.F; +import fj.Monoid; +import fj.P; +import fj.P1; +import fj.P2; +import fj.control.parallel.ParModule; +import fj.control.parallel.Promise; +import fj.control.parallel.Strategy; +import fj.data.IOFunctions; +import fj.data.Iteratee.Input; +import fj.data.Iteratee.IterV; +import fj.data.List; +import fj.data.Option; import java.io.BufferedWriter; import java.io.File; @@ -14,35 +22,25 @@ import java.io.Reader; import java.io.StringWriter; import java.io.Writer; -import java.nio.charset.Charset; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.ExecutorService; -import fj.F; -import fj.Monoid; -import fj.P; -import fj.P1; -import fj.P2; -import fj.Unit; -import fj.control.parallel.ParModule; -import fj.control.parallel.Promise; -import fj.control.parallel.Strategy; -import fj.data.*; -import fj.data.Iteratee.Input; -import fj.data.Iteratee.IterV; -import fj.function.Effect1; +import static fj.Monoid.monoid; +import static fj.control.parallel.ParModule.parModule; +import static fj.data.List.nil; +import static java.util.concurrent.Executors.newFixedThreadPool; /** * Reads words and their counts from files ({@link #getWordsAndCountsFromFiles} in a single thread * and {@link #getWordsAndCountsFromFilesInParallel} in multiple threads). The files are created * initially and populated with some sample content. - * + * * @author Martin Grotzke */ public class WordCount { - + // Integers.add.f(1) caused an SOE... private static final F addOne = a -> a.intValue() + 1; @@ -55,7 +53,7 @@ private static Map update(Map map, K key, F valueFuncti map.put(key, valueFunction.f(value)); return map; } - + private static final F> fileNameToWordsAndCountsWithCharChunkIteratee = fileName -> { try { return IOFunctions.enumFileCharChunks(new File(fileName), Option.none(), wordCountsFromCharChunks()).run().run(); @@ -63,7 +61,7 @@ private static Map update(Map map, K key, F valueFuncti throw new RuntimeException(e); } }; - + private static final F> fileNameToWordsAndCountsWithCharChunk2Iteratee = fileName -> { try { return IOFunctions.enumFileChars(new File(fileName), Option.none(), wordCountsFromChars()).run().run(); @@ -71,7 +69,7 @@ private static Map update(Map map, K key, F valueFuncti throw new RuntimeException(e); } }; - + private static final F> fileNameToWordsAndCountsWithCharIteratee = fileName -> { try { return IOFunctions.enumFileChars(new File(fileName), Option.none(), wordCountsFromChars()).run().run(); @@ -181,7 +179,7 @@ public static void main(String[] args) throws IOException { final Map expectedWordsAndCounts = result._2(); long avgSize = fileNames.foldLeft((a, file) -> a.longValue() + new File(file).length(), 0l) / fileNames.length(); System.out.println("Processing " + numFiles + " files with ~"+numSharedWords+" words and an avg size of " + avgSize + " bytes."); - + // warmup for(int i = 0; i < 1; i++) { // getWordsAndCountsFromFiles(fileNames.take(1)).size(); @@ -211,7 +209,7 @@ public static void main(String[] args) throws IOException { assertTrue(wordsAndCountsFromFiles != null); assertEquals(wordsAndCountsFromFiles.size(), numFiles + numSharedWords); assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); - + System.gc(); // get word counts sequentially / single threaded \w iteratee @@ -223,7 +221,7 @@ public static void main(String[] args) throws IOException { assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); System.gc(); - + // get word counts sequentially / single threaded \w iteratee start = System.currentTimeMillis(); wordsAndCountsFromFiles = getWordsAndCountsFromFilesWithIteratee(fileNames, fileNameToWordsAndCountsWithCharChunk2Iteratee); @@ -233,7 +231,7 @@ public static void main(String[] args) throws IOException { assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); System.gc(); - + // start = System.currentTimeMillis(); // wordsAndCountsFromFiles = getWordsAndCountsFromFilesInParallel(fileNames, fileNameToWordsAndCounts, 8); // System.out.println("Getting word counts in 8 threads took " + (System.currentTimeMillis() - start) + " ms."); @@ -249,14 +247,14 @@ public static void main(String[] args) throws IOException { assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); System.gc(); - + start = System.currentTimeMillis(); wordsAndCountsFromFiles = getWordsAndCountsFromFilesInParallel(fileNames, fileNameToWordsAndCountsWithCharChunkIteratee, 32); System.out.println("Getting word counts in 32 threads with char chunk iteratee took " + (System.currentTimeMillis() - start) + " ms."); assertTrue(wordsAndCountsFromFiles != null); assertEquals(wordsAndCountsFromFiles.size(), numFiles + numSharedWords); assertEquals(wordsAndCountsFromFiles, expectedWordsAndCounts); - + // we have tmpfiles, but still want to be sure not to leave rubbish fileNames.foreachDoEffect(a -> new File(a).delete()); } @@ -286,13 +284,13 @@ private static P2, Map> writeSampleFiles( } return P.p(fileNames, expectedWordsAndCounts); } - + public static Map getWordsAndCountsFromFilesWithIteratee(final List fileNames, final F> fileNameToWordsAndCountsWithIteratee) { final List> maps = fileNames.map(fileNameToWordsAndCountsWithIteratee); return maps.foldLeft(WordCount::plus, new HashMap()); } - + public static Map getWordsAndCountsFromFilesInParallel( final List fileNames, final F> fileNameToWordsAndCounts, int numThreads) { final ExecutorService pool = newFixedThreadPool(numThreads); @@ -305,14 +303,14 @@ public static Map getWordsAndCountsFromFilesInParallel( return result; } - + // Read documents and extract words and word counts of documents public static Promise> getWordsAndCountsFromFiles( final List fileNames, final F> fileNameToWordsAndCounts, final ParModule m) { - final Monoid> monoid = monoidDef(WordCount::plus, Collections.emptyMap()); + final Monoid> monoid = monoid(WordCount::plus, Collections.emptyMap()); return m.parFoldMap(fileNames, fileNameToWordsAndCounts, monoid); } - + private static Map plus(Map a, Map b) { final Map result = new HashMap<>(a); for(Map.Entry entry : b.entrySet()) { @@ -321,7 +319,7 @@ private static Map plus(Map a, Map Date: Sun, 6 Nov 2016 18:48:05 +0100 Subject: [PATCH 155/336] retrolambda: enable backport of default methods. --- lib.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/lib.gradle b/lib.gradle index 5b84e98b..28be5e34 100644 --- a/lib.gradle +++ b/lib.gradle @@ -89,6 +89,7 @@ void configureRetroLambda(boolean useRetroLambda, String newJdkEnvVar, String ol jdk System.getenv(newJdkEnvVar) oldJdk System.getenv(oldJdkEnvVar) javaVersion retroLambdaTarget + defaultMethods true } dependencies { retrolambdaConfig "net.orfjackal.retrolambda:retrolambda:$retrolambdaVersion" From f583adb8f6fad8f2fcb46bcbd6707e4e0590cc69 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 6 Nov 2016 20:32:34 +0100 Subject: [PATCH 156/336] Fix BitSet.range property checking. --- props-core/src/test/java/fj/data/hamt/BitSetProperties.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java index 0ae976ef..f3527972 100644 --- a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java +++ b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java @@ -153,8 +153,8 @@ Gen> bitSetIndices(int n) { Property rangeTest() { return property(arbNaturalLong, bitSetIndices(4), (x, list) -> { int l = list.index(0); - int m = list.index(1); int h = list.index(2); + int m = Math.max(l, Math.min(list.index(1), h - 1)); int vh = list.index(3); BitSet bs1 = longBitSet(x); From b897b745636d51218bcd8d8ffaa7275fa4bb2423 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Tue, 6 Dec 2016 21:42:53 -0500 Subject: [PATCH 157/336] Upgrade Gradle to 2.14.1 --- gradle/wrapper/gradle-wrapper.jar | Bin 51106 -> 53637 bytes gradle/wrapper/gradle-wrapper.properties | 4 ++-- gradlew | 10 +++------- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 3c7abdf12790879c06b07176de29647f77aa4129..05ef575b0cd0173fc735f2857ce4bd594ce4f6bd 100644 GIT binary patch delta 40807 zcmZ6SQ;;UmlC8_OZQDkdZQHh8f7!Ne+v>7yqsz9dZ_k;B8)u#}BX&Nni2dct%%XVE z&|**oMHx^q7$6`hC?Hq{Rf$9da`^v=E~6A=f?vKzXJ1_A`+2nGZs3Y47Rjh@T|A`gg-gl3kj zl9Ls*GXk}!^DuQte5iklwqv`8d@GJ={*_7ujCwmXd&T!S&BxpQdUU#W3pD9zO%fXf z4GRuxL%q$>7#EAip`y8ZgO94yVMBs2HqaL612=)Gzh9{r)}g{@D!DvZW~f=^6X?0b z&yDdwFZe=jyfy^!irD$||<4t=`4ao<=ru&nwBzULL98KjnK#=Pyn2O&{$DpuxOUx zxR^52wWVI9@O+Hlk`Tl5H7Ewjc-%pD>|2|T{n{85;akKf!1Ww#_yi1@jeo0i1J}&v z0ExK&dh(ig4)?=a{KyO2`GC`r_oEY&Vzg9?0)%7b$w_@lSi7@`lc;LixM-y&B}as) z@KrJYDR1GbI=|G9onlY@!I%(QEb zKx}nMvwtDHBX>$G#UA$)|Ln@=nEaOC9OYIva6E@QDUWnEuF>_^j2nQnkD27B#KpBT zT5A0h22D!8sq=dV*v>5h0IM;v`KMHA7(Jsy9%Eyf@jv=O{g2%KM<1tGnl4rUWVQvA zJTH!uTnRS#AN@2tfER-x{7(Viq2AUAI1tbWOfnG^KLFJX@2_1Jg;kdw@h@UUTcFSu z#ULt-rJ%HRV@vG<_)>86_6ZKXuASIyIT=49fs0SKyR+P47E*dm$Wd$wiLqdwqrm&Y z5p2dhEJlLiz4q+1K753Cg1@J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KA^bGRY+eHX`%oM^i-EDlkqt4Hes6Y>D76^uU zio#Txj39UeePA&v1i>(`N*K&(0>az?MK2Qs{%f@bLhuF!oCQ8O90hE9k$eZwPyg$m z1zrZBVTwXlKuoVNG^Guw>BW!>S_4mdxuHZb7b;jHb8A3)hyygG!T`8FSLfM3LEh5 z$&X?z3({@sf<-U@+Z`4r7u%V+t7f$r-rksRle6K=K}h22EuJ)n0(D zSP=%Y03Z5=fbhoxkl?{wzn(qHKFi#Rl{K5W`zJi`-JI7Rq#K- zkdq>SnRwhm^*|v(lO(|S4}oFnz;d}B1;yX@1Pg(`p0xix7v&fb6abV5nII50ybDuY z$%GV>2YDb6Hev7VB6FGQP9vK4EaC-Sa_*_4=3za zAS~h2A}}|o=Ap2D-E9Gfs9|7tDO5={wG96rzJnVGt6&9%f@el}3)U-#3OhM00;&G$ zYakFxFxA8=fM-M(f?%Bw801g`sY!v>;{P-z=mHeX`Z3M#N20d&=W(V4=$`UJ%JARS cU()pvI`_d}*<&- +cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" -cd "$SAVED" >&- +cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar @@ -114,6 +109,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` From bb1663394fd8f15e25041b745184bc970fc44c22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Wed, 7 Dec 2016 18:21:47 -0500 Subject: [PATCH 158/336] Switch coverage to cover.io --- .travis.yml | 2 +- README.adoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index bf8f8d78..4a7c9290 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,4 +30,4 @@ script: - ./gradlew build coverage -s -i after_success: - - ./gradlew jacocoRootReport coveralls + - bash <(curl -s https://codecov.io/bash) diff --git a/README.adoc b/README.adoc index 9addaff8..418605de 100644 --- a/README.adoc +++ b/README.adoc @@ -1,7 +1,7 @@ = Functional Java image:https://travis-ci.org/functionaljava/functionaljava.svg?branch=master["Build Status", link="https://travis-ci.org/functionaljava/functionaljava"] -image:https://coveralls.io/repos/github/functionaljava/functionaljava/badge.svg?branch=master["Coverage Status", link="https://coveralls.io/github/functionaljava/functionaljava?branch=master"] +image:https://codecov.io/gh/functionaljava/functionaljava/branch/master/graph/badge.svg["Code Coverage", link="https://codecov.io/gh/functionaljava/functionaljava"] image:https://badges.gitter.im/functionaljava/functionaljava.svg[link="https://gitter.im/functionaljava/functionaljava?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"] image::http://www.functionaljava.org/img/logo-600x144.png[] From e95182ad090ff8c1bbdc9d4bd7bf37ba7ae5c4be Mon Sep 17 00:00:00 2001 From: JB Giraudeau Date: Fri, 16 Dec 2016 08:54:46 +0100 Subject: [PATCH 159/336] Change coverage executionData on root project to use wildcard path (#310) otherwise it is skipped because some sub-projects do not have execution Data. Also only aggregate results for published artefacts. Also removed unsused gradle task, --- build.gradle | 41 ++++++++--------------------------------- 1 file changed, 8 insertions(+), 33 deletions(-) diff --git a/build.gradle b/build.gradle index 7d9efae1..1ccd524a 100644 --- a/build.gradle +++ b/build.gradle @@ -20,12 +20,10 @@ buildscript { dependencies { classpath "com.ofg:uptodate-gradle-plugin:$uptodateVersion" classpath "me.tatarka:gradle-retrolambda:$retrolambdaPluginVersion" - classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.6.3' } } apply plugin: "jacoco" -apply plugin: 'com.github.kt3k.coveralls' if (JavaVersion.current().isJava8Compatible()) { allprojects { @@ -129,27 +127,24 @@ subprojects { reports { html.enabled = true xml.enabled = true - csv.enabled = false -// html.destination "${buildDir}/jacocoHtml" } } - - task coverage(dependsOn: ["test", "jacocoTestReport"]) << { - - } + task coverage(dependsOn: ["test", "jacocoTestReport"]) << {} } task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { - dependsOn = subprojects.test - sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories = files(subprojects.sourceSets.main.output) - executionData = files(subprojects.jacocoTestReport.executionData) + dependsOn = subprojects.coverage + executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") + // We only care about coverage of: + def projectForFoverage = ["core", "java8", "quickcheck", "java-core"] + classDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.output) + sourceDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.allSource.srcDirs) + reports { html.enabled = true xml.enabled = true - csv.enabled = false } } @@ -210,23 +205,3 @@ configure(subprojects.findAll { it.name != "props-core" }) { task env << { println System.getenv() } - -task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) { - dependsOn = subprojects.jacocoTestReport - sourceDirectories = files(subprojects.sourceSets.main.allSource.srcDirs) - classDirectories = files(subprojects.sourceSets.main.output) - executionData = files(subprojects.jacocoTestReport.executionData) - reports { - xml.enabled true - xml.destination ="${buildDir}/reports/jacoco/test/jacocoTestReport.xml" - } - // We could remove the following setOnlyIf line, but then - // jacocoRootReport would silently be SKIPPED if something with - // the projectsWithUnitTests is wrong (e.g. a project is missing - // in there). - setOnlyIf { true } -} - -coveralls { - sourceDirs = files(subprojects.sourceSets.main.allSource.srcDirs).files.absolutePath -} From 6ac5f9547dbb1f0ca3777be6b366f256e9943194 Mon Sep 17 00:00:00 2001 From: Shimi Bandiel Date: Mon, 23 Jan 2017 21:22:20 +0200 Subject: [PATCH 160/336] Add NEL.minimum/maximum and safe versions of minimum/maximum for List * added minimum/maximum on NEL && changed impl of minimumOption/maximumOption in List to use it * spaces for tabs --- core/src/main/java/fj/data/List.java | 20 ++++++++++++++++++ core/src/main/java/fj/data/NonEmptyList.java | 22 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index fa82359f..f58fd73f 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -1465,6 +1465,16 @@ public final A maximum(final Ord o) { return foldLeft1(o::max); } + /** + * Returns the maximum element in this list according to the given ordering. + * + * @param o An ordering for the elements of the list. + * @return The optional maximum element in this list according to the given ordering. + */ + public final Option maximumOption(final Ord o) { + return NonEmptyList.fromList(this).map(nel -> nel.maximum(o)); + } + /** * Returns the minimum element in this list according to the given ordering. * @@ -1474,6 +1484,16 @@ public final A maximum(final Ord o) { public final A minimum(final Ord o) { return foldLeft1(o::min); } + + /** + * Returns the minimum element in this list according to the given ordering. + * + * @param o An ordering for the elements of the list. + * @return The optional minimum element in this list according to the given ordering. + */ + public final Option minimumOption(final Ord o) { + return NonEmptyList.fromList(this).map(nel -> nel.minimum(o)); + } public final java.util.List toJavaList() { return new java.util.LinkedList<>(toCollection()); diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index da06e0f4..4073476d 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -226,6 +226,28 @@ public NonEmptyList sort(final Ord o) { return nel(list.head(), list.tail()); } + + /** + * Returns the minimum element in this non empty list according to the given ordering. + * + * @param o An ordering for the elements of this non empty list. + * @return The minimum element in this list according to the given ordering. + */ + public final A minimum(final Ord o) { + return foldLeft1(o::min); + } + + /** + * Returns the maximum element in this non empty list according to the given ordering. + * + * @param o An ordering for the elements of this non empty list. + * @return The maximum element in this list according to the given ordering. + */ + public final A maximum(final Ord o) { + return foldLeft1(o::max); + } + + /** * Zips this non empty list with the given non empty list to produce a list of pairs. If this list and the given list * have different lengths, then the longer list is normalised so this function never fails. From 7417c434e29c0f62b15c93f9cfc6dd06c06764d0 Mon Sep 17 00:00:00 2001 From: siro-mateos Date: Tue, 6 Dec 2016 17:45:08 +0100 Subject: [PATCH 161/336] + Added 'Set.lookup', and 'Set.lookupLT', 'Set.lookupGT','Set.lookupLE' and 'Set.lookupGE' from Haskell. + Added some test cases for new Set.lookup* functionality. * Changed 'get(K)' to use 'Set.lookup' instead of 'Set.split', so it can run much faster. --- core/src/main/java/fj/data/Set.java | 123 ++++++++++++++++++++++++ core/src/main/java/fj/data/TreeMap.java | 3 +- core/src/test/java/fj/data/SetTest.java | 16 +++ 3 files changed, 140 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 35b3c683..15207d83 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -515,6 +515,129 @@ public final P3, Option, Set> split(final A a) { } } + /** + * Find element equal to the given one. + * + * @param a An element to compare with. + * @return Some element in this set equal to the given one, or None. + */ + public final Option lookup(final A a) { + Set s = this; + while (true) + if (s.isEmpty()) + return none(); + else { + final A h = s.head(); + final Ordering i = ord.compare(a, h); + if (i == LT) + s = s.l(); + else if (i == GT) + s = s.r(); + else + return some(h); + } + } + + /** + * Find largest element smaller than the given one. + * + * @param a An element to compare with. + * @return Some largest element in this set smaller than the given one, or None. + */ + public final Option lookupLT(final A a) { + Set s = this; + Option r = none(); + while (true) + if (s.isEmpty()) + return r; + else { + final A h = s.head(); + final Ordering i = ord.compare(a, h); + if (i == GT) { + r = some(h); + s = s.r(); + } + else + s = s.l(); + } + } + + /** + * Find smallest element greater than the given one. + * + * @param a An element to compare with. + * @return Some smallest element in this set greater than the given one, or None. + */ + public final Option lookupGT(final A a) { + Set s = this; + Option r = none(); + while (true) + if (s.isEmpty()) + return r; + else { + final A h = s.head(); + final Ordering i = ord.compare(a, h); + if (i == LT) { + r = some(h); + s = s.l(); + } + else + s = s.r(); + } + } + + /** + * Find largest element smaller or equal to the given one. + * + * @param a An element to compare with. + * @return Some largest element in this set smaller or equal to the given one, or None. + */ + public final Option lookupLE(final A a) { + Set s = this; + Option r = none(); + while (true) + if (s.isEmpty()) + return r; + else { + final A h = s.head(); + final Ordering i = ord.compare(a, h); + if (i == LT) + s = s.l(); + else if (i == GT) { + r = some(h); + s = s.r(); + } + else + return some(h); + } + } + + /** + * Find smallest element greater or equal to the given one. + * + * @param a An element to compare with. + * @return Some smallest element in this set greater or equal to the given one, or None. + */ + public final Option lookupGE(final A a) { + Set s = this; + Option r = none(); + while (true) + if (s.isEmpty()) + return r; + else { + final A h = s.head(); + final Ordering i = ord.compare(a, h); + if (i == LT) { + r = some(h); + s = s.l(); + } + else if (i == GT) + s = s.r(); + else + return some(h); + } + } + /** * Returns true if this set is a subset of the given set. * diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index f663ab09..e5a3f06f 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -129,8 +129,7 @@ public static TreeMap arrayTreeMap(final Ord keyOrd, final P2 get(final K k) { - final Option>> x = tree.split(p(k, Option.none()))._2(); - return x.bind(P2.__2()); + return tree.lookup(p(k, Option.none())).bind(P2::_2); } /** diff --git a/core/src/test/java/fj/data/SetTest.java b/core/src/test/java/fj/data/SetTest.java index 78084bb4..cdf2519c 100644 --- a/core/src/test/java/fj/data/SetTest.java +++ b/core/src/test/java/fj/data/SetTest.java @@ -2,6 +2,8 @@ import org.junit.Test; +import static fj.data.Option.none; +import static fj.data.Option.some; import static fj.Ord.intOrd; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; @@ -23,4 +25,18 @@ public void testString() { assertThat(s.toString(), equalTo("Set(1,2,3)")); } + @Test + public void testLookups() { + Set s = Set.set(intOrd, 5, 1, 7, 8); + assertThat(s.lookup(7), equalTo(some(7))); + assertThat(s.lookup(4), equalTo(none())); + assertThat(s.lookupLT(6), equalTo(some(5))); + assertThat(s.lookupLT(1), equalTo(none())); + assertThat(s.lookupGT(5), equalTo(some(7))); + assertThat(s.lookupGT(9), equalTo(none())); + assertThat(s.lookupLE(8), equalTo(some(8))); + assertThat(s.lookupLE(0), equalTo(none())); + assertThat(s.lookupGE(8), equalTo(some(8))); + assertThat(s.lookupGE(9), equalTo(none())); + } } From 443e01a12f2732e94f4b19d485dfb95cebd70075 Mon Sep 17 00:00:00 2001 From: siro-mateos Date: Mon, 12 Dec 2016 23:27:18 +0100 Subject: [PATCH 162/336] Force strict evaluation in 'TreeMap.map'. --- core/src/main/java/fj/data/TreeMap.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index e5a3f06f..cd111d06 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -359,7 +359,7 @@ public P3, Option, TreeMap> splitLookup(final K k) { */ @SuppressWarnings("unchecked") public TreeMap map(final F f) { - final F>, P2>> g = P2.map2_(F1Functions.mapOption(f)); + final F>, P2>> g = compose(p2 -> p(p2._1(), p2._2()), P2.map2_(F1Functions.mapOption(f))); final F>> coord = flip(P.>p2()).f(Option.none()); final Ord o = tree.ord().contramap(coord); return new TreeMap<>(tree.map(TreeMap.ord(o), g)); From dd8451dd26d5ca9406e173b1ebaae02a74ae03e6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Feb 2017 21:05:56 +0100 Subject: [PATCH 163/336] Fix typo. sofMemo -> softMemo --- core/src/main/java/fj/P.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index b0f3a31d..6d174ed7 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -61,7 +61,7 @@ public static P1 weakMemo(F0 f) { * and at each subsequent call if and only if the reference have been garbage collected * due of shortage of memory (ie. to avoid OutOfMemoryErrors). */ - public static P1 sofMemo(F0 f) { + public static P1 softMemo(F0 f) { return new P1.SoftReferenceMemo<>(f); } From 9ca5ce35e7f83bbedfd707e8d67f1c7fc477ffdf Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 12:47:20 +0200 Subject: [PATCH 164/336] Update to gradle 3.4 --- gradle/wrapper/gradle-wrapper.jar | Bin 53637 -> 54208 bytes gradle/wrapper/gradle-wrapper.properties | 4 +- gradlew | 68 +++++++++++++---------- gradlew.bat | 14 ++--- props-core-scalacheck/build.gradle | 10 +--- 5 files changed, 48 insertions(+), 48 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 05ef575b0cd0173fc735f2857ce4bd594ce4f6bd..7f9251933fd4846b7f2c971bb2c5f6a575ad3e3a 100644 GIT binary patch delta 24962 zcmZ6SV~{05x2~Jhwr$(Sv~AnAy{B#4wr%(Bp7ykDThrE^bMJ{b=errTDk3W~^G{V| zzVEYEg%*Pkl!GHG$$~?mgMdIogTVTc$s{5YA^uNq`6KW#kx!HN0_VZy&IJ_Yf5v|L zlF5MlYheF%`_~};g`TLYn(WJw5FEvg_;ZMdZ3eGz#SOLVe_X6%=AqIh?EhAfCSYPt4nw(;e}{Bi_qbtJmyjkLZGeKdXTqrPE4 zQ}hLQ)(~L%#75FXY>IT8;V(VPbu0g)m;M0u*gVCVBgRqMif1#MknsEp7w4J)ADam0 z98VDeq0A>NOp-$EO`)oMX(lHt|6ESDEH9sz*jTzfkx9p9o44#(CM#r__E(+g86lDg z2b;UqOGS8RS5&5;kCorpwZOqyVgO9_sE_Kw*&bl9Fi%Gesr-imV}`^}HU@n<87=E< zgQmZFmJ?f44|sGcl7I2ncC2L2C8!q2mGfEdliyN882rO{mUzso)^e7;N7dlm>K-}- zJmE5vDs{RN%SGjr!=!x_Y;Z0b9OkVuno&J~Rf9JntF9W8DW}+hkX^C#+HEb0v$o)+ znJ|E9d=0AAWvTo`W!Et^Rm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}?-rDr@IMwJ!X7n5?x)BcxH|Uy* zm~b^04}}bGq+Fn92>tD`UM-WFrN+)XdoppaN8<;=OYN5phGbi_Qvv_L0V<=H#l-%j zRB1qSO9zlz6o6<2&_d29Xlr{r{zCg#oAC;B-D?e@SbMMR1hKkyr)~|YJk%VAifF%? zOpSwBwrr(FM=YO*2%}T{iitI7z&II*C!G)yUO)-)sKl=wam>d=h&s!~bgUTYu_AO7 z6miIb9|MF0f?ccN-HqhdzhD#_(G7|3AX0sx`%9#-r5@ywA=+2jZ6nnWThAet6#}X- z5bZs4&yeb88$KbGH~jRG{A*Q8BH?i|2axJhYSfYN3t4gK*0TsuKmZ51m#>V1NeF=WUHzAi~Dy3{(rtn0gh+%eocfEYE*u-@%HD&FndkSMB1`Wff*6RdK!6Y*B+i2T4 zIBI6V0SMT0#e(qn<0E2_UqScp0|e(eDH>2O6xI(kW#;&SCqbCd;UROKxCXq^YAh>q;>X} zJ&@_$2Y>^~KL92HZfVZ|*||Q_-#u(cK)|`I|I5I-^b;#5;t~R+3?CTBl1P5KpFkLW zr7wFFu_1yk2K6dHRxp6Ogv%xHzoRZZHSVh6rS9y1c3Rt2Y7`Ox3s%VABR{VQml2o~ z%T5#kj9ftQLjTbLpLOB;c~^|@?a2OUt0>VHBt-l07T#)O7q=;b$aIEQC z0B=6g0?U>Zk`rh#FmP!g^dmp7^H(E7ZS1l$!R0{eZvNrDzO&jp4e(wH3=J71wy3Hr z@5GIuKa-F+d`THlb2So){E2^0t^7D>a~tS}5Fke6`7m31m52fuGtz(yxf;FnjgYj_ zzmO_MVV9ovo32oV<499ju^#7G2JkWn+*BZELb3JA{=FS00t`I!&db{W0XJy*x&QzG diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 23175860..aa8a01af 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Tue Dec 06 21:53:19 EST 2016 +#Mon Feb 27 21:23:04 CET 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.4-bin.zip diff --git a/gradlew b/gradlew index 9d82f789..4453ccea 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,26 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -85,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -150,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec99730..e95643d6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index 4d1a04e9..02f3652a 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -4,16 +4,12 @@ archivesBaseName = "${project.projectName}-${project.name}" apply plugin: 'scala' ext { - scalaVersion = "2.11.7" + scalaVersion = "2.11.8" scalacheckScalaVersion = "2.11" - scalacheckVersion = "1.12.4" + scalacheckVersion = "1.12.5" signModule = true } -tasks.withType(ScalaCompile) { - scalaCompileOptions.useAnt = false -} - dependencies { compile project(":core") compile "org.scala-lang:scala-library:$scalaVersion" @@ -22,8 +18,6 @@ dependencies { testCompile dependencyJunit } -sourceCompatibility = "1.7" - performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) From 6fa8bce2008c73d5995af20f6f41f60908e2ca6d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 23 Oct 2016 12:49:34 +0200 Subject: [PATCH 165/336] add "_1.8" suffix to artifact cross-built for java 8. Use JDK7 as retrolambda target --- .travis.yml | 1 - build.gradle | 8 ++++---- java-core/build.gradle | 2 ++ java8/build.gradle | 4 +++- lib.gradle | 2 ++ quickcheck/build.gradle | 4 ++-- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a7c9290..8f3091d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,6 @@ before_script: - sudo service x11-common stop || true script: - - jdk_switcher use openjdk6 && export JAVA6_HOME=$JAVA_HOME - jdk_switcher use oraclejdk7 && export JAVA7_HOME=$JAVA_HOME - jdk_switcher use oraclejdk8 && export JAVA8_HOME=$JAVA_HOME - ./gradlew build coverage -s -i diff --git a/build.gradle b/build.gradle index 1ccd524a..5bedc102 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ ext { buildscript { ext { - uptodateVersion = "1.6.0" - retrolambdaPluginVersion = "3.2.5" + uptodateVersion = "1.6.2" + retrolambdaPluginVersion = "3.3.1" retrolambdaVersion = "2.3.0" } @@ -77,8 +77,8 @@ allprojects { displayCompilerWarnings = true newJdkEnvVar = "JAVA8_HOME" - oldJdkEnvVar = "JAVA6_HOME" - retroLambdaTarget = JavaVersion.VERSION_1_6 + oldJdkEnvVar = "JAVA7_HOME" + retroLambdaTarget = JavaVersion.VERSION_1_7 } repositories { diff --git a/java-core/build.gradle b/java-core/build.gradle index 88e9a25f..6a92cc28 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -1,5 +1,6 @@ archivesBaseName = "${project.projectName}-${project.name}" +configureAllRetroLambda() ext { signModule = true @@ -13,4 +14,5 @@ dependencies { performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) + uploadArchives.enabled = true diff --git a/java8/build.gradle b/java8/build.gradle index 88e9a25f..d6d4c485 100644 --- a/java8/build.gradle +++ b/java8/build.gradle @@ -13,4 +13,6 @@ dependencies { performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) -uploadArchives.enabled = true +if (!useRetroLambda) { + uploadArchives.enabled = true +} diff --git a/lib.gradle b/lib.gradle index 28be5e34..253ed251 100644 --- a/lib.gradle +++ b/lib.gradle @@ -94,6 +94,8 @@ void configureRetroLambda(boolean useRetroLambda, String newJdkEnvVar, String ol dependencies { retrolambdaConfig "net.orfjackal.retrolambda:retrolambda:$retrolambdaVersion" } + } else { + project.archivesBaseName = "${project.archivesBaseName}_1.8" } } diff --git a/quickcheck/build.gradle b/quickcheck/build.gradle index 4d3a25be..45e379da 100644 --- a/quickcheck/build.gradle +++ b/quickcheck/build.gradle @@ -3,10 +3,10 @@ ext { signModule = true } -configureAllRetroLambda() - archivesBaseName = "${project.projectName}-${project.name}" +configureAllRetroLambda() + dependencies { compile project(":core") compile dependencyJunit From 3dcdf401182899611608537dd9862f06eed18062 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Feb 2017 21:18:51 +0100 Subject: [PATCH 166/336] java-core module should be publish with retrolambda processing. --- java-core/build.gradle | 2 ++ 1 file changed, 2 insertions(+) diff --git a/java-core/build.gradle b/java-core/build.gradle index 6a92cc28..032c2ca5 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -16,3 +16,5 @@ configureUpload(signingEnabled, signModule) uploadArchives.enabled = true + +configureAllRetroLambda() \ No newline at end of file From d1b15e16f8287b1265efc6516801aba29abdd290 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Feb 2017 21:25:41 +0100 Subject: [PATCH 167/336] upgrade to latest retrolambda version. --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 5bedc102..b9597063 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,8 @@ ext { buildscript { ext { uptodateVersion = "1.6.2" - retrolambdaPluginVersion = "3.3.1" - retrolambdaVersion = "2.3.0" + retrolambdaPluginVersion = "3.5.0" + retrolambdaVersion = "2.5.1" } repositories { From 0759750518cfbd920170d75c73c199d80b5bb49e Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 17 Mar 2017 00:43:54 +1000 Subject: [PATCH 168/336] Added release notes for 4.7 --- etc/release-notes/release-notes-4.7.adoc | 44 ++++++++++++++++++++---- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/etc/release-notes/release-notes-4.7.adoc b/etc/release-notes/release-notes-4.7.adoc index 3c1b265f..6f5958de 100644 --- a/etc/release-notes/release-notes-4.7.adoc +++ b/etc/release-notes/release-notes-4.7.adoc @@ -1,28 +1,58 @@ = Release 4.7 -Proposed release: September 2016 +Released: unknown, potentially 25 March 2017 == Enhancements -* TODO. +* Added Hash Array Mapped Trie (#284). +* Improve performance of List#groupBy via a mutable buffer (#288). +* Avoid unnecessary wrapping of F0 into P1.lazy where applicable. Use static P factories for this (#284). +* Added semigroup constraint to List.traverseValidation (#287). +* Added first class fold for either (catamorphism) (#284). +* Added first class fold for Option (catamorphism) (#284). +* Added optimisable definitions for Equal (#284). +* Added uncurried version of foldRight, foldLeft and append to NonEmptyList (#284). +* Added optimisable definitions for Monoid and Semigroup (#284). +* Improved performance of List.minimum and maximum by using uncurried Ord.max and Ord.min (#284). +* Removed deprecation of Monoid, Ord and Semigroup constructors for non Java 8 versions (#284). +* Added safe List minimumOption and maximumOption and NonEmptyList minimum and maximum. +* Added Set.lookup, Set.lookupLT, Set.lookupGT, Set.lookupLE and Set.lookupGE from Haskell (#305). == Fixes -* TODO. +* Make Stream conversions respect laziness (#284). +* Fixed Ord#isGreaterThan(A)/isLesserThan(A) not using strict inequality (#293). +* Correctly convert Option.some(null) to Optional (#284). +* Fixed override in P.p(A) (#284). +* Avoid unnecessary currying in uncurried version of foldRight (#284). == Internal -* TODO. +* Deprecated unsafe Ord instance and List#groupBy without an Ord parameter (#290). +* Added tests for Strings class (#295). +* Use more method references (#284). +* Converted memoisation tests from JUnit to PropertyTestRunner (#284) for hard memoisation. +* Improved implementation of P1#_1 method (#284). +* Make use of weak memoisation explicit (#284). +* Enable backport of default methods using Retro Lambda (#284). +* Upgrade to Gradle 2.14.1 (#310). +* Switch from Coveralls to cover.io (#308). +* Force strict evaluation in TreeMap.map (#309). == Breaking Changes -* TODO. +* none. == Documentation -* TODO. +* none. == Contributors -* TODO. +* Jean-Baptiste Giradeau +* Mark Perry +* Gabor Liptak +* Shimi Bandiel +* Siro Mateos + From 1faf5b9184d82cca5929747f5cfb4e67100752ab Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 25 Mar 2017 18:12:58 +0100 Subject: [PATCH 169/336] Make retrolambda target java 6. --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b9597063..6c417b5c 100644 --- a/build.gradle +++ b/build.gradle @@ -78,7 +78,7 @@ allprojects { newJdkEnvVar = "JAVA8_HOME" oldJdkEnvVar = "JAVA7_HOME" - retroLambdaTarget = JavaVersion.VERSION_1_7 + retroLambdaTarget = JavaVersion.VERSION_1_6 } repositories { From 4d36fcddcf9899191899d83ec80546e41c528bac Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Mar 2017 20:58:13 +0200 Subject: [PATCH 170/336] Update gradle wrapper to 3.4.1 --- gradle/wrapper/gradle-wrapper.jar | Bin 54208 -> 54208 bytes gradle/wrapper/gradle-wrapper.properties | 4 ++-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f9251933fd4846b7f2c971bb2c5f6a575ad3e3a..2dcd00d1ccd90b5b3d39e0da139893d5e7651ae4 100644 GIT binary patch delta 957 zcmYL{YeR2CHVzW+1q!^`jYJm-H7=RM~PJGfy7Cok7> zNeV)wQqo{Ew8@oH9vWZXgMDqKMn%VL(_E8?{Lh&9j3b{D5MBlRSSP@x63G?|LQ7=R zXym1+B#^RI@V5MX4V^6my6OdBhR2kT7)&kk9S8Qi$YUoQ2bx0 zV6pcgc*9!(zV=$cO(RyYd!z~!`6|IGAIm@X8BxppIw11RKJ7@MYKvt{go9-WoN4UqYjOBjCPNKHP86$Bs>NR6*{@nz*arSU)$7?a}Pt?i@jg-GC Ljc`HKKC%BF8^&kK delta 957 zcmYL{T}YEr7{|}{s#}wpQ-d_jR9Fd>C1N%Epig46HJg#8PIG48WDCbiFA}1gE>cfK z(WF3YBVkdCA`!H0x^Fj?KB-8hM7l}JEKurw|7Y06%kTF*=YJ08J?He>xPBWa*J-%8 zG(x0OB5TfVlPje>)UW4SX4;C&)6##KrcEO9KQrHy+h)t=1O!(Bzt#zG=80sB1ffN; zNiuISagU*j+I6ZxPFoDWlT5kMd z1vR)-*$Mn5OQaJY9$!r*gedq=rxA(M$ima0FI7N*TISV)6<#%H_m+UOUJbb0cM$CG zvHb5C^?t2zfV9i60>}IYa7Tc#Gf;|pHgFz19n^y_gGO*==oolCR0e(x)r0%Pr@-DY zo1Z*%0(H|+9XLM3a+=5?)b}GS_a|~3wK2*Vj#i;wGtB1Sijf;(54U!t7USMntsGTL O`KwY37ep Date: Mon, 27 Mar 2017 20:58:59 +0200 Subject: [PATCH 171/336] java-core build: remove duplicate call of configureAllRetroLambda() --- java-core/build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/java-core/build.gradle b/java-core/build.gradle index 032c2ca5..3b636072 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -1,6 +1,5 @@ archivesBaseName = "${project.projectName}-${project.name}" -configureAllRetroLambda() ext { signModule = true From 8fb59b9f1ed3771296c4a164e5cde4439a4e82c4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Mar 2017 21:17:53 +0200 Subject: [PATCH 172/336] 4.7 release. --- README.adoc | 22 +++++++++++----------- build.gradle | 2 +- etc/release-notes/release-notes-4.7.adoc | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.adoc b/README.adoc index 418605de..6c5d3c1e 100644 --- a/README.adoc +++ b/README.adoc @@ -31,16 +31,16 @@ The recommended way to download and use the project is through your build tool. The Functional Java artifact is published to Maven Central using the group `org.functionaljava` with three published artifacts: -* the core library (`functionaljava`) +* the core library (`functionaljava` or `functionaljava_1.8` if you use Java 8+) * Java 8 specific support (`functionaljava-java8`) -* property based testing (`functionaljava-quickcheck`) +* property based testing (`functionaljava-quickcheck` or `functionaljava-quickcheck_1.8` if you use Java 8+) -The latest stable version is `4.6`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `4.7`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.6" -compile "org.functionaljava:functionaljava-java8:4.6" -compile "org.functionaljava:functionaljava-quickcheck:4.6" -compile "org.functionaljava:functionaljava-java-core:4.6" +compile "org.functionaljava:functionaljava:4.7" +compile "org.functionaljava:functionaljava-java8:4.7" +compile "org.functionaljava:functionaljava-quickcheck:4.7" +compile "org.functionaljava:functionaljava-java-core:4.7" ---- and in Maven: @@ -48,22 +48,22 @@ and in Maven: org.functionaljava functionaljava - 4.6 + 4.7 org.functionaljava functionaljava-java8 - 4.6 + 4.7 org.functionaljava functionaljava-quickcheck - 4.6 + 4.7 org.functionaljava functionaljava-java-core - 4.6 + 4.7 ---- diff --git a/build.gradle b/build.gradle index 6c417b5c..c0152d08 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true + isSnapshot = false fjBaseVersion = "4.7" snapshotAppendix = "-SNAPSHOT" diff --git a/etc/release-notes/release-notes-4.7.adoc b/etc/release-notes/release-notes-4.7.adoc index 6f5958de..428a0726 100644 --- a/etc/release-notes/release-notes-4.7.adoc +++ b/etc/release-notes/release-notes-4.7.adoc @@ -1,7 +1,7 @@ = Release 4.7 -Released: unknown, potentially 25 March 2017 +Released: 27 March 2017 == Enhancements From 0ff3a9c27425736994f6f336aec68e40b6183884 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 27 Mar 2017 21:46:59 +0200 Subject: [PATCH 173/336] Prepare next iteration. --- build.gradle | 6 ++--- etc/release-notes/release-notes-4.8.adoc | 28 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 etc/release-notes/release-notes-4.8.adoc diff --git a/build.gradle b/build.gradle index c0152d08..04209664 100644 --- a/build.gradle +++ b/build.gradle @@ -46,12 +46,12 @@ allprojects { defaultTasks "build" ext { - isSnapshot = false - fjBaseVersion = "4.7" + isSnapshot = true + fjBaseVersion = "4.8" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.6" + fjConsumeVersion = "4.7" signModule = false useRetroLambda = false diff --git a/etc/release-notes/release-notes-4.8.adoc b/etc/release-notes/release-notes-4.8.adoc new file mode 100644 index 00000000..22dbc552 --- /dev/null +++ b/etc/release-notes/release-notes-4.8.adoc @@ -0,0 +1,28 @@ + += Release + +Proposed release: + +== Enhancements + +* TODO. + +== Fixes + +* TODO. + +== Internal + +* TODO. + +== Breaking Changes + +* TODO. + +== Documentation + +* TODO. + +== Contributors + +* TODO. From 07f94fa172d9465de69abea188ecbdbc73c09078 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 1 May 2017 21:44:09 -0500 Subject: [PATCH 174/336] Fixed a bug in the NonEmptyList Semigroup implementation that resulted in the same NonEmptyList appended to itself. --- core/src/main/java/fj/Semigroup.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 74d7de9b..16b0d130 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -534,7 +534,7 @@ public static Semigroup> nonEmptyListSemigroup() { return semigroupDef(new Definition>() { @Override public NonEmptyList append(NonEmptyList a1, NonEmptyList a2) { - return a1.append(a1); + return a1.append(a2); } @Override From 405c3ec31351bf8518bfec8b91bf8be66056991b Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Mon, 1 May 2017 21:44:46 -0500 Subject: [PATCH 175/336] Added Scalacheck Arbitrary implementations for Natural and NonEmptyList. --- .../main/scala/fj/data/ArbitraryNatural.scala | 13 +++++++++++++ .../scala/fj/data/ArbitraryNonEmptyList.scala | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 props-core-scalacheck/src/main/scala/fj/data/ArbitraryNatural.scala create mode 100644 props-core-scalacheck/src/main/scala/fj/data/ArbitraryNonEmptyList.scala diff --git a/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNatural.scala b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNatural.scala new file mode 100644 index 00000000..4210eef7 --- /dev/null +++ b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNatural.scala @@ -0,0 +1,13 @@ +package fj.data + +import org.scalacheck.Arbitrary + +/** + * A Scalacheck [[Arbitrary]] for [[Natural]]. + */ +object ArbitraryNatural { + + implicit def arbitraryNatural: Arbitrary[Natural] = + Arbitrary(Arbitrary.arbBigInt.arbitrary.map(_.abs).map(bi => Natural.natural(bi.bigInteger).some())) + +} diff --git a/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNonEmptyList.scala b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNonEmptyList.scala new file mode 100644 index 00000000..2258ba9b --- /dev/null +++ b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryNonEmptyList.scala @@ -0,0 +1,16 @@ +package fj.data + +import fj.data.NonEmptyList.nel +import org.scalacheck.Arbitrary.arbitrary +import org.scalacheck.{Arbitrary, Gen} + +/** + * A Scalacheck [[Arbitrary]] for [[NonEmptyList]]. + */ +object ArbitraryNonEmptyList { + implicit def arbitraryNonEmptyList[A](implicit a: Arbitrary[A]): Arbitrary[NonEmptyList[A]] = + Arbitrary(nelOf(arbitrary[A])) + + def nelOf[A](g: => Gen[A]): Gen[NonEmptyList[A]] = + Gen.nonEmptyListOf(g).map(l => l.tail.foldRight(nel(l.head))((x, n) => n.cons(x))) +} From ef811305b0e60e8b4dd5e42c601c8b3cbfed1fe7 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 2 May 2017 00:15:25 -0500 Subject: [PATCH 176/336] Added unit test coverage for Semigroup implementations. The StringBuffer and StringBuilder tests fail because both of those types are mutable. The IO test fails because the ArbitraryIO implementation does not implement equals. --- .../src/main/scala/fj/data/ArbitraryIO.scala | 22 +++ .../src/test/scala/fj/CheckSemigroup.scala | 152 ++++++++++++++++++ 2 files changed, 174 insertions(+) create mode 100644 props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala create mode 100644 props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala diff --git a/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala new file mode 100644 index 00000000..7667840b --- /dev/null +++ b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala @@ -0,0 +1,22 @@ +package fj.data + +import org.scalacheck.Arbitrary + +/** + * + */ +object ArbitraryIO { + + implicit def arbitraryIO[T](implicit arbT: Arbitrary[T]): Arbitrary[IO[T]] = + Arbitrary(arbT.arbitrary.map(t => new IO[T]() { + + override def run(): T = t + + override def toString: String = t.toString + + override def hashCode(): Int = t.hashCode() + + override def equals(obj: scala.Any): Boolean = ??? + })) + +} diff --git a/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala new file mode 100644 index 00000000..933bedc6 --- /dev/null +++ b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala @@ -0,0 +1,152 @@ +package fj + +import fj.ArbitraryP._ +import fj.ArbitraryUnit.arbitraryUnit +import fj.Ord.intOrd +import fj.data.ArbitraryArray.arbitraryArray +import fj.data.ArbitraryIO.arbitraryIO +import fj.data.ArbitraryList.arbitraryList +import fj.data.ArbitraryNatural.arbitraryNatural +import fj.data.ArbitraryNonEmptyList.arbitraryNonEmptyList +import fj.data.ArbitraryOption.arbitraryOption +import fj.data.ArbitrarySet.arbitrarySet +import fj.data.ArbitraryStream.arbitraryStream +import org.scalacheck.Arbitrary._ +import org.scalacheck.Prop._ +import org.scalacheck.{Arbitrary, Properties} + +/** + * Scalacheck [[Properties]] for [[Semigroup]] implementations. + * + * @param s a Semigroup implementation. + * @param desc a description of the Semigroup implementation. + * @param arbitrary a Scalacheck [[Arbitrary]] implementation for the Semigroup's type. + * @tparam T the type to which the Semigroup applies. + */ +case class SemigroupProperties[T](s: Semigroup[T], desc: String)(implicit val arbitrary: Arbitrary[T]) extends Properties(desc) { + + + property("sum(x,y)") = forAll((x: T, y: T, z: T) => + s.sum(s.sum(x, y), z) == s.sum(x, s.sum(y, z))) + + property("sum()") = forAll((x: T, y: T, z: T) => { + val sf = s.sum() + sf.f(sf.f(x).f(y)).f(z) == sf.f(x).f(sf.f(y).f(z)) + }) + + property("dual()") = forAll((x: T, y: T, z: T) => { + val sd = s.dual() + sd.sum(sd.sum(x, y), z) == sd.sum(x, sd.sum(y, z)) + }) + + property("sum(x)") = forAll((x: T, y: T) => + s.sum(x).f(y) == s.sum(x, y)) + +} + + +/** + * + */ +object CheckSemigroup extends Properties("Semigroup") { + + + def idInt(n: Int): java.lang.Integer = n + + implicit def oi: Ord[Int] = intOrd.contramap(idInt _) + + implicit lazy val arbJavaBigDecimal: Arbitrary[java.math.BigDecimal] = Arbitrary( + Arbitrary.arbLong.arbitrary.map(l => new java.math.BigDecimal(l)) + ) + + implicit lazy val arbJavaBigInteger: Arbitrary[java.math.BigInteger] = Arbitrary( + Arbitrary.arbBigInt.arbitrary.map(_.bigInteger) + ) + + implicit lazy val arbJavaInteger: Arbitrary[Integer] = Arbitrary( + Arbitrary.arbInt.arbitrary.map(i => i) + ) + + implicit lazy val arbJavaLong: Arbitrary[java.lang.Long] = Arbitrary( + Arbitrary.arbLong.arbitrary.map(i => i) + ) + + implicit lazy val arbJavaBoolean: Arbitrary[java.lang.Boolean] = Arbitrary( + Arbitrary.arbBool.arbitrary.map(b => b) + ) + + implicit lazy val arbStringBuilder: Arbitrary[java.lang.StringBuilder] = Arbitrary( + Arbitrary.arbString.arbitrary.map(new java.lang.StringBuilder(_)) + ) + + implicit lazy val arbStringBuffer: Arbitrary[StringBuffer] = Arbitrary( + Arbitrary.arbString.arbitrary.map(new StringBuffer(_)) + ) + + include(SemigroupProperties(Semigroup.arraySemigroup[Int](), "arraySemigroup()")) + + include(SemigroupProperties(Semigroup.bigdecimalAdditionSemigroup, "bigdecimalAdditionSemigroup")) + include(SemigroupProperties(Semigroup.bigdecimalMultiplicationSemigroup, "bigdecimalMultiplicationSemigroup")) + include(SemigroupProperties(Semigroup.bigDecimalMaximumSemigroup, "bigDecimalMaximumSemigroup")) + include(SemigroupProperties(Semigroup.bigDecimalMinimumSemigroup, "bigDecimalMinimumSemigroup")) + + include(SemigroupProperties(Semigroup.bigintAdditionSemigroup, "bigintAdditionSemigroup")) + include(SemigroupProperties(Semigroup.bigintMultiplicationSemigroup, "bigintMultiplicationSemigroup")) + include(SemigroupProperties(Semigroup.bigintMaximumSemigroup, "bigintMaximumSemigroup")) + include(SemigroupProperties(Semigroup.bigintMinimumSemigroup, "bigintMinimumSemigroup")) + + include(SemigroupProperties(Semigroup.conjunctionSemigroup, "conjunctionSemigroup")) + include(SemigroupProperties(Semigroup.disjunctionSemigroup, "disjunctionSemigroup")) + include(SemigroupProperties(Semigroup.exclusiveDisjunctionSemiGroup, "exclusiveDisjunctionSemiGroup")) + + include(SemigroupProperties(Semigroup.firstOptionSemigroup[Int](), "firstOptionSemigroup()")) + include(SemigroupProperties(Semigroup.firstSemigroup[Int](), "firstSemigroup()")) + + include(SemigroupProperties(Semigroup.intAdditionSemigroup, "intAdditionSemigroup")) + include(SemigroupProperties(Semigroup.intMultiplicationSemigroup, "intMultiplicationSemigroup")) + include(SemigroupProperties(Semigroup.intMaximumSemigroup, "intMaximumSemigroup")) + include(SemigroupProperties(Semigroup.intMinimumSemigroup, "intMinimumSemigroup")) + + include(SemigroupProperties(Semigroup.ioSemigroup[String](Semigroup.stringSemigroup), "ioSemigroup(Semigroup)")) + + include(SemigroupProperties(Semigroup.lastOptionSemigroup[Int](), "lastOptionSemigroup()")) + include(SemigroupProperties(Semigroup.lastSemigroup[Int](), "lastSemigroup()")) + + include(SemigroupProperties(Semigroup.longAdditionSemigroup, "longAdditionSemigroup")) + include(SemigroupProperties(Semigroup.longMultiplicationSemigroup, "longMultiplicationSemigroup")) + include(SemigroupProperties(Semigroup.longMaximumSemigroup, "longMaximumSemigroup")) + include(SemigroupProperties(Semigroup.longMinimumSemigroup, "longMinimumSemigroup")) + + + include(SemigroupProperties(Semigroup.listSemigroup[Int], "listSemigroup")) + + include(SemigroupProperties(Semigroup.naturalAdditionSemigroup, "naturalAdditionSemigroup")) + include(SemigroupProperties(Semigroup.naturalMaximumSemigroup, "naturalMaximumSemigroup")) + include(SemigroupProperties(Semigroup.naturalMinimumSemigroup, "naturalMinimumSemigroup")) + include(SemigroupProperties(Semigroup.naturalMultiplicationSemigroup, "naturalMultiplicationSemigroup")) + + include(SemigroupProperties(Semigroup.nonEmptyListSemigroup[Int], "nonEmptyListSemigroup")) + + include(SemigroupProperties(Semigroup.p1Semigroup(Semigroup.intAdditionSemigroup), "p1Semigroup(Semigroup)")) + include(SemigroupProperties(Semigroup.p2Semigroup(Semigroup.intAdditionSemigroup, Semigroup.stringSemigroup), "p2Semigroup(Semigroup,Semigroup)")) + + include(SemigroupProperties(Semigroup.semigroup[Int](new F2[Int, Int, Int] { + def f(x: Int, y: Int): Int = x + y + }), "semigroup(F)")) + + include(SemigroupProperties(Semigroup.semigroup[Int](new F[Int, F[Int, Int]] { + def f(x: Int): F[Int, Int] = (y: Int) => x + y + }), "semigroup(F>)")) + + include(SemigroupProperties(Semigroup.setSemigroup[Int](), "setSemigroup()")) + include(SemigroupProperties(Semigroup.streamSemigroup[Int](), "streamSemigroup")) + + include(SemigroupProperties(Semigroup.stringSemigroup, "stringSemigroup")) + include(SemigroupProperties(Semigroup.stringBufferSemigroup, "stringBufferSemigroup")) + include(SemigroupProperties(Semigroup.stringBuilderSemigroup, "stringBuilderSemigroup")) + + + include(SemigroupProperties(Semigroup.unitSemigroup, "unitSemigroup")) + + +} From a8e979fc78e0cdd4e33e86d32b0394edcc065e47 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 2 May 2017 22:51:29 -0500 Subject: [PATCH 177/336] Fixed the ArbitraryIO implementation and created a Properties object for testing the IO semigroup. --- .../src/main/scala/fj/data/ArbitraryIO.scala | 14 ++--- .../src/test/scala/fj/CheckSemigroup.scala | 57 ++++++++++++++++++- 2 files changed, 59 insertions(+), 12 deletions(-) diff --git a/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala index 7667840b..aca5cbd1 100644 --- a/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala +++ b/props-core-scalacheck/src/main/scala/fj/data/ArbitraryIO.scala @@ -7,16 +7,12 @@ import org.scalacheck.Arbitrary */ object ArbitraryIO { - implicit def arbitraryIO[T](implicit arbT: Arbitrary[T]): Arbitrary[IO[T]] = - Arbitrary(arbT.arbitrary.map(t => new IO[T]() { - - override def run(): T = t - override def toString: String = t.toString + private case class ArbIO[T](value: T) extends IO[T] { + override def run(): T = value + } - override def hashCode(): Int = t.hashCode() - - override def equals(obj: scala.Any): Boolean = ??? - })) + implicit def arbitraryIO[T](implicit arbT: Arbitrary[T]): Arbitrary[IO[T]] = + Arbitrary(arbT.arbitrary.map(ArbIO(_))) } diff --git a/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala index 933bedc6..1305efe9 100644 --- a/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala +++ b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala @@ -11,12 +11,13 @@ import fj.data.ArbitraryNonEmptyList.arbitraryNonEmptyList import fj.data.ArbitraryOption.arbitraryOption import fj.data.ArbitrarySet.arbitrarySet import fj.data.ArbitraryStream.arbitraryStream +import fj.data.IO import org.scalacheck.Arbitrary._ import org.scalacheck.Prop._ import org.scalacheck.{Arbitrary, Properties} /** - * Scalacheck [[Properties]] for [[Semigroup]] implementations. + * Scalacheck [[Properties]] parameterized for [[Semigroup]] implementations. * * @param s a Semigroup implementation. * @param desc a description of the Semigroup implementation. @@ -44,9 +45,59 @@ case class SemigroupProperties[T](s: Semigroup[T], desc: String)(implicit val ar } +/** + * A specialized Scalacheck [[Properties]] object for testing the [[Semigroup.ioSemigroup()]] method. + */ +object CheckIOSemigroup extends Properties("ioSemigroup") { + + val s = Semigroup.ioSemigroup(Semigroup.stringSemigroup) + + property("sum(x,y)") = forAll((x: IO[String], y: IO[String], z: IO[String]) => + s.sum(s.sum(x, y), z).run() == s.sum(x, s.sum(y, z)).run()) + + property("sum()") = forAll((x: IO[String], y: IO[String], z: IO[String]) => { + val sf = s.sum() + sf.f(sf.f(x).f(y)).f(z).run() == sf.f(x).f(sf.f(y).f(z)).run() + }) + + property("dual()") = forAll((x: IO[String], y: IO[String], z: IO[String]) => { + val sd = s.dual() + sd.sum(sd.sum(x, y), z).run() == sd.sum(x, sd.sum(y, z)).run() + }) + + property("sum(x)") = forAll((x: IO[String], y: IO[String]) => + s.sum(x).f(y).run() == s.sum(x, y).run()) + +} + +object CheckStringBuilder extends Properties("stringBuilderSemigroup") { + + val s: Semigroup[java.lang.StringBuilder] = Semigroup.stringBuilderSemigroup + + implicit def toStringBuilder(str: String): java.lang.StringBuilder = new java.lang.StringBuilder(str) + + property("sum(x,y)") = forAll((x: String, y: String, z: String) => + s.sum(s.sum(x, y), z).toString == s.sum(x, s.sum(y, z)).toString + ) + + property("sum()") = forAll((x: String, y: String, z: String) => { + val sf = s.sum() + sf.f(sf.f(x).f(y)).f(z).toString == sf.f(x).f(sf.f(y).f(z.toString)) + }) + + property("dual()") = forAll((x: String, y: String, z: String) => { + val sd = s.dual() + sd.sum(sd.sum(x, y), z).toString == sd.sum(x, sd.sum(y, z).toString) + }) + + property("sum(x)") = forAll((x: String, y: String) => + s.sum(x).f(y).toString == s.sum(x, y).toString) + +} + /** - * + * A Scalacheck [[Properties]] object that aggregates the tests for all [[Semigroup]] implementations. */ object CheckSemigroup extends Properties("Semigroup") { @@ -107,7 +158,7 @@ object CheckSemigroup extends Properties("Semigroup") { include(SemigroupProperties(Semigroup.intMaximumSemigroup, "intMaximumSemigroup")) include(SemigroupProperties(Semigroup.intMinimumSemigroup, "intMinimumSemigroup")) - include(SemigroupProperties(Semigroup.ioSemigroup[String](Semigroup.stringSemigroup), "ioSemigroup(Semigroup)")) + include(CheckIOSemigroup) include(SemigroupProperties(Semigroup.lastOptionSemigroup[Int](), "lastOptionSemigroup()")) include(SemigroupProperties(Semigroup.lastSemigroup[Int](), "lastSemigroup()")) From aa4de33faacb59c7dd24092fe3d3a65ca3a4c4d9 Mon Sep 17 00:00:00 2001 From: Ryan Johnson Date: Tue, 9 May 2017 22:47:43 -0500 Subject: [PATCH 178/336] Added working tests coverage for the StringBuffer and StringBuilder semigroup implementations. Added the Semigroup tests to the list of Scalacheck test suite. --- .../src/test/scala/fj/CheckSemigroup.scala | 33 ++++++++++++------- .../src/test/scala/fj/Tests.scala | 30 +++++++++-------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala index 1305efe9..8c9fe547 100644 --- a/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala +++ b/props-core-scalacheck/src/test/scala/fj/CheckSemigroup.scala @@ -70,27 +70,36 @@ object CheckIOSemigroup extends Properties("ioSemigroup") { } -object CheckStringBuilder extends Properties("stringBuilderSemigroup") { - - val s: Semigroup[java.lang.StringBuilder] = Semigroup.stringBuilderSemigroup +/** + * A [[Properties]] implementation for testing [[Semigroup]] implementations that + * apply to mutable builder style classes such as [[java.lang.StringBuilder]] and + * [[java.lang.StringBuffer]]. + * + * @param s a Semigroup implementation to test. + * @param desc a description of the Semigroup implementation under test. + * @param conversion a function that converts a value of type T to a new instance of type S. + * @tparam T the type that the builder constructs. + * @tparam S the type to which the Semigroup applies. + */ +case class CheckMutableBuilder[S, T](s: Semigroup[S], desc: String, conversion: T => S)(implicit val arbitrary: Arbitrary[T]) extends Properties(desc) { - implicit def toStringBuilder(str: String): java.lang.StringBuilder = new java.lang.StringBuilder(str) + implicit def toBuilder(t: T): S = conversion(t) - property("sum(x,y)") = forAll((x: String, y: String, z: String) => + property("sum(x,y)") = forAll((x: T, y: T, z: T) => s.sum(s.sum(x, y), z).toString == s.sum(x, s.sum(y, z)).toString ) - property("sum()") = forAll((x: String, y: String, z: String) => { + property("sum()") = forAll((x: T, y: T, z: T) => { val sf = s.sum() - sf.f(sf.f(x).f(y)).f(z).toString == sf.f(x).f(sf.f(y).f(z.toString)) + sf.f(sf.f(x).f(y)).f(z).toString == sf.f(x).f(sf.f(y).f(z)).toString }) - property("dual()") = forAll((x: String, y: String, z: String) => { + property("dual()") = forAll((x: T, y: T, z: T) => { val sd = s.dual() - sd.sum(sd.sum(x, y), z).toString == sd.sum(x, sd.sum(y, z).toString) + sd.sum(sd.sum(x, y), z).toString == sd.sum(x, sd.sum(y, z)).toString }) - property("sum(x)") = forAll((x: String, y: String) => + property("sum(x)") = forAll((x: T, y: T) => s.sum(x).f(y).toString == s.sum(x, y).toString) } @@ -193,8 +202,8 @@ object CheckSemigroup extends Properties("Semigroup") { include(SemigroupProperties(Semigroup.streamSemigroup[Int](), "streamSemigroup")) include(SemigroupProperties(Semigroup.stringSemigroup, "stringSemigroup")) - include(SemigroupProperties(Semigroup.stringBufferSemigroup, "stringBufferSemigroup")) - include(SemigroupProperties(Semigroup.stringBuilderSemigroup, "stringBuilderSemigroup")) + include(CheckMutableBuilder(Semigroup.stringBufferSemigroup, "stringBufferSemigroup", (s: String) => new java.lang.StringBuffer(s))) + include(CheckMutableBuilder(Semigroup.stringBuilderSemigroup, "stringBuilderSemigroup", (s: String) => new java.lang.StringBuilder(s))) include(SemigroupProperties(Semigroup.unitSemigroup, "unitSemigroup")) diff --git a/props-core-scalacheck/src/test/scala/fj/Tests.scala b/props-core-scalacheck/src/test/scala/fj/Tests.scala index 60c2f009..d94661f9 100644 --- a/props-core-scalacheck/src/test/scala/fj/Tests.scala +++ b/props-core-scalacheck/src/test/scala/fj/Tests.scala @@ -1,8 +1,9 @@ package fj object Tests { - def tests = List ( + def tests = List( CheckP2.properties, + CheckSemigroup.properties, fj.data.CheckArray.properties, fj.data.CheckIO.properties, fj.data.CheckIteratee.properties, @@ -19,26 +20,27 @@ object Tests { def main(args: Array[String]) { run(tests) -// System.exit(0) + // System.exit(0) } - import org.scalacheck.Prop - import org.scalacheck.Test import org.scalacheck.Test.check + import org.scalacheck.{Prop, Test} def run(tests: List[(String, Prop)]) = tests foreach { case (name, p) => { - val c = check(new Test.Parameters.Default { override val maxSize = 20 }, p) - c.status match { - case Test.Passed => println("Passed " + name) - case Test.Proved(_) => println("Proved " + name) - case f @ Test.Failed(_, _) => sys.error(name + ": " + f) - case Test.Exhausted => println("Exhausted " + name) - case f @ Test.PropException(_, e, _) => { - e.printStackTrace - sys.error(name + ": " + f) - } + val c = check(new Test.Parameters.Default { + override val maxSize = 20 + }, p) + c.status match { + case Test.Passed => println("Passed " + name) + case Test.Proved(_) => println("Proved " + name) + case f@Test.Failed(_, _) => sys.error(name + ": " + f) + case Test.Exhausted => println("Exhausted " + name) + case f@Test.PropException(_, e, _) => { + e.printStackTrace + sys.error(name + ": " + f) } } } + } } From e834e8bfb87c394b0071e478a84445a1ca88834e Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Wed, 9 Aug 2017 13:34:53 +0200 Subject: [PATCH 179/336] Enable upload of snapshot artifacts. --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8f3091d1..4a9f2d24 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,3 +30,10 @@ script: after_success: - bash <(curl -s https://codecov.io/bash) + - '[ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] + && ./gradlew uploadArchives' + +env: + global: + - secure: Bun+1FZ29Q3dR9gZ/5brxcSf+zcY5tWrsqOA4GUb5bYCMyORuXQB0FYXuhKR4wB1pFrk1a9EYwRwSu3GwRJVWb+UzF0CNOWF/QG5tGPx32IOXScwlL/KonI4Vhs7Oc0fF4Wdb7euNrT27BU61jbUugjJ642b3n0VBYFYDdquprU= + - secure: QAxhjqLRa+WHKIzgIJPZ/rM5a5uzqG7E5rsC0YvB25cO712oYXmzsYPia/oSp0chXlYLYMfk2UnLeQCSx2e6ogXRRRa977Q+B33Nt0Hd9SGLtduv6DBrbA2ehLU12Ib4DWe5VhF5eueAunycYcllTvqA5h+pzTtEVbd68ZHncM4= From 8330696120a4bcb744b1601600cb573dc176d0fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 9 Sep 2017 16:29:09 -0400 Subject: [PATCH 180/336] Upgrade Gradle version to 4.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- gradle/wrapper/gradle-wrapper.jar | Bin 54208 -> 54708 bytes gradle/wrapper/gradle-wrapper.properties | 3 +-- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2dcd00d1ccd90b5b3d39e0da139893d5e7651ae4..7a3265ee94c0ab25cf079ac8ccdf87f41d455d42 100644 GIT binary patch delta 19176 zcmZ6yV{m3&w>2Ew?6_mwwr$(Cadpzk6(=3rwylnB+qRv&_j&H~)mP8?v1`rRHP^0M zRb!8-vHq5TH&%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uvSbOtk7TXM#VjIC7uwcFtEUh0H?J>hD{M) vwUyIkHpb9Y2WsfFKoMgC5j)eYo?PHz_^J}xf%3=1x=t)7Og%R{*mM5_tD>+w diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7a57ac51..f16d2666 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Mar 27 13:51:02 CEST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip From 95c0d0d659a2dfa354aa549aa6197be7d12aba15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 9 Sep 2017 17:38:22 -0400 Subject: [PATCH 181/336] Bring dependencies current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 2 +- core/build.gradle | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 04209664..6f8ecc5d 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,7 @@ ext { buildscript { ext { - uptodateVersion = "1.6.2" + uptodateVersion = "1.6.3" retrolambdaPluginVersion = "3.5.0" retrolambdaVersion = "2.5.1" } diff --git a/core/build.gradle b/core/build.gradle index b3e1756e..e0c86f0c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -7,8 +7,8 @@ archivesBaseName = project.projectName dependencies { testCompile dependencyJunit - testCompile 'com.h2database:h2:1.4.191' - testCompile 'commons-dbutils:commons-dbutils:1.6' + testCompile 'com.h2database:h2:1.4.196' + testCompile 'commons-dbutils:commons-dbutils:1.7' } performSigning(signingEnabled, signModule) From 6c6dabdb26b050c5d0e3a712fe4f28edd0e1ad57 Mon Sep 17 00:00:00 2001 From: l1cache Date: Mon, 11 Sep 2017 14:19:59 +0300 Subject: [PATCH 182/336] Equal: remove reference to static field of LazyString. Fix #321 Cause it could cause deadlock on parallel static initialization. --- core/src/main/java/fj/Equal.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index b64c758d..5e407a00 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -674,7 +674,7 @@ public static Equal> v8Equal(final Equal ea) { /** * An equal instance for lazy strings. */ - public static final Equal eq = streamEqual(charEqual).contramap(LazyString.toStream); + public static final Equal eq = streamEqual(charEqual).contramap(LazyString::toStream); /** * An equal instance for the empty heterogeneous list. From 065ed439303eacf90e3ac49c5403b1d62979b8f4 Mon Sep 17 00:00:00 2001 From: janbols Date: Mon, 6 Nov 2017 20:09:10 +0100 Subject: [PATCH 183/336] Add append methods to all Px classes. Fix #326 --- core/src/main/java/fj/P2.java | 63 ++++++++++++++++++++++++++++++++++- core/src/main/java/fj/P3.java | 52 +++++++++++++++++++++++++++++ core/src/main/java/fj/P4.java | 44 ++++++++++++++++++++++++ core/src/main/java/fj/P5.java | 30 +++++++++++++++++ core/src/main/java/fj/P6.java | 20 +++++++++++ core/src/main/java/fj/P7.java | 10 ++++++ 6 files changed, 218 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index e503ff40..b434a0da 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -178,7 +178,68 @@ public final P1 _2_() { return F1Functions.lazy(P2.__2()).f(this); } - /** + /** + * Creates a {@link P3} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P3} containing the original {@link P2} with the extra element added at the end + */ + public final P3 append(C el) { + return P.p(_1(), _2(), el); + } + + /** + * Creates a {@link P4} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P4} containing the original {@link P2} with the extra element added at the end + */ + public final P4 append(P2 el) { + return P.p(_1(), _2(), el._1(), el._2()); + } + + /** + * Creates a {@link P5} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P5} containing the original {@link P2} with the extra element added at the end + */ + public final P5 append(P3 el) { + return P.p(_1(), _2(), el._1(), el._2(), el._3()); + } + + /** + * Creates a {@link P6} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P6} containing the original {@link P2} with the extra element added at the end + */ + public final P6 append(P4 el) { + return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4()); + } + + /** + * Creates a {@link P7} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P7} containing the original {@link P2} with the extra element added at the end + */ + public final P7 append(P5 el) { + return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4(), el._5()); + } + + /** + * Creates a {@link P8} by adding the given element to the current {@link P2} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P2} with the extra element added at the end + */ + public final P8 append(P6 el) { + return P.p(_1(), _2(), el._1(), el._2(), el._3(), el._4(), el._5(), el._6()); + } + + + /** * Provides a memoising P2 that remembers its values. * * @return A P2 that calls this P2 once for any given element and remembers the value for subsequent calls. diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index ec277346..fe980059 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -122,6 +122,58 @@ public final P1 _3_() { return F1Functions.lazy(P3.__3()).f(this); } + + /** + * Creates a {@link P4} by adding the given element to the current {@link P3} + * + * @param el the element to append + * @return A {@link P4} containing the original {@link P3} with the extra element added at the end + */ + public final P4 append(D el) { + return P.p(_1(), _2(), _3(), el); + } + + /** + * Creates a {@link P5} by adding the given element to the current {@link P3} + * + * @param el the element to append + * @return A {@link P5} containing the original {@link P3} with the extra element added at the end + */ + public final P5 append(P2 el) { + return P.p(_1(), _2(), _3(), el._1(), el._2()); + } + + /** + * Creates a {@link P6} by adding the given element to the current {@link P3} + * + * @param el the element to append + * @return A {@link P6} containing the original {@link P3} with the extra element added at the end + */ + public final P6 append(P3 el) { + return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3()); + } + + /** + * Creates a {@link P7} by adding the given element to the current {@link P3} + * + * @param el the element to append + * @return A {@link P7} containing the original {@link P3} with the extra element added at the end + */ + public final P7 append(P4 el) { + return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4()); + } + + /** + * Creates a {@link P8} by adding the given element to the current {@link P3} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P3} with the extra element added at the end + */ + public final P8 append(P5 el) { + return P.p(_1(), _2(), _3(), el._1(), el._2(), el._3(), el._4(), el._5()); + } + + /** * Provides a memoising P3 that remembers its values. * diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index 3f7236fe..a7bf8167 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -176,6 +176,50 @@ public final P1 _4_() { return F1Functions.lazy(P4.__4()).f(this); } + + /** + * Creates a {@link P5} by adding the given element to the current {@link P4} + * + * @param el the element to append + * @return A {@link P5} containing the original {@link P4} with the extra element added at the end + */ + public final P5 append(E el) { + return P.p(_1(), _2(), _3(), _4(), el); + } + + /** + * Creates a {@link P6} by adding the given element to the current {@link P4} + * + * @param el the element to append + * @return A {@link P6} containing the original {@link P4} with the extra element added at the end + */ + public final P6 append(P2 el) { + return P.p(_1(), _2(), _3(), _4(), el._1(), el._2()); + } + + /** + * Creates a {@link P7} by adding the given element to the current {@link P4} + * + * @param el the element to append + * @return A {@link P7} containing the original {@link P4} with the extra element added at the end + */ + public final P7 append(P3 el) { + return P.p(_1(), _2(), _3(), _4(), el._1(), el._2(), el._3()); + } + + /** + * Creates a {@link P8} by adding the given element to the current {@link P4} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P4} with the extra element added at the end + */ + public final P8 append(P4 el) { + return P.p(_1(), _2(), _3(), _4(), el._1(), el._2(), el._3(), el._4()); + } + + + + /** * Provides a memoising P4 that remembers its values. * diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 393b0632..69262327 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -238,6 +238,36 @@ public final P1 _5_() { return F1Functions.lazy(P5.__5()).f(this); } + /** + * Creates a {@link P6} by adding the given element to the current {@link P5} + * + * @param el the element to append + * @return A {@link P6} containing the original {@link P5} with the extra element added at the end + */ + public final P6 append(F el) { + return P.p(_1(), _2(), _3(), _4(), _5(), el); + } + + /** + * Creates a {@link P7} by adding the given element to the current {@link P5} + * + * @param el the element to append + * @return A {@link P7} containing the original {@link P5} with the extra element added at the end + */ + public final P7 append(P2 el) { + return P.p(_1(), _2(), _3(), _4(), _5(), el._1(), el._2()); + } + + /** + * Creates a {@link P8} by adding the given element to the current {@link P5} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P5} with the extra element added at the end + */ + public final P8 append(P3 el) { + return P.p(_1(), _2(), _3(), _4(), _5(), el._1(), el._2(), el._3()); + } + /** * Provides a memoising P5 that remembers its values. * diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index 1e8c3055..fbf91948 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -309,6 +309,26 @@ public final P1 _6_() { return F1Functions.lazy(P6.__6()).f(this); } + /** + * Creates a {@link P7} by adding the given element to the current {@link P6} + * + * @param el the element to append + * @return A {@link P7} containing the original {@link P6} with the extra element added at the end + */ + public final P7 append(G el) { + return P.p(_1(), _2(), _3(), _4(), _5(), _6(), el); + } + + /** + * Creates a {@link P8} by adding the given element to the current {@link P6} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P6} with the extra element added at the end + */ + public final P8 append(P2 el) { + return P.p(_1(), _2(), _3(), _4(), _5(), _6(), el._1(), el._2()); + } + /** * Provides a memoising P6 that remembers its values. * diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index ca24b40e..b1c67b30 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -387,6 +387,16 @@ public final P1 _7_() { return F1Functions.lazy(P7.__7()).f(this); } + /** + * Creates a {@link P8} by adding the given element to the current {@link P7} + * + * @param el the element to append + * @return A {@link P8} containing the original {@link P7} with the extra element added at the end + */ + public final P8 append(H el) { + return P.p(_1(), _2(), _3(), _4(), _5(), _6(), _7(), el); + } + /** * Provides a memoising P7 that remembers its values. * From 34f2c176ac462596f22de81a70fd0bfdda8f6ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 9 Sep 2017 17:44:31 -0400 Subject: [PATCH 184/336] Bring ScalaCheck current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- props-core-scalacheck/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index 02f3652a..a395a586 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -4,9 +4,9 @@ archivesBaseName = "${project.projectName}-${project.name}" apply plugin: 'scala' ext { - scalaVersion = "2.11.8" + scalaVersion = "2.11.11" scalacheckScalaVersion = "2.11" - scalacheckVersion = "1.12.5" + scalacheckVersion = "1.12.6" signModule = true } From 98294fc3bdffe6c290818a6ffc04227e44ea3719 Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Wed, 17 Jan 2018 08:51:51 -0500 Subject: [PATCH 185/336] Introduce the Eval monad a convenient wrapper around Trampoline and P1.hardMemo for stack-safe computation. --- core/src/main/java/fj/data/Eval.java | 238 +++++++++++++++++++++++ core/src/test/java/fj/data/EvalTest.java | 76 ++++++++ 2 files changed, 314 insertions(+) create mode 100644 core/src/main/java/fj/data/Eval.java create mode 100644 core/src/test/java/fj/data/EvalTest.java diff --git a/core/src/main/java/fj/data/Eval.java b/core/src/main/java/fj/data/Eval.java new file mode 100644 index 00000000..519070a1 --- /dev/null +++ b/core/src/main/java/fj/data/Eval.java @@ -0,0 +1,238 @@ +package fj.data; + +import fj.F; +import fj.F0; +import fj.P; +import fj.P1; +import fj.control.Trampoline; + +/** + * Eval is an abstraction over different models of evaluation. + * The data constructors: + *
        + *
      • Now - the value is evaluated immediately.
      • + *
      • Later - the value is evaluated only once when it's requested (lazy evaluation).
      • + *
      • Always - the value is evaluated every time when it's requested.
      • + *
      + * + * Both Later and Always are lazy computations, while Now is eager. + * + * + * @version %build.number% + */ +public abstract class Eval
      { + + /** + * Constructs an eager evaluation by wrapping the given value. + * + * @param a the evaluated value. + * @return an eval with computed value. + */ + public static Eval now(A a) { + return new Now<>(a); + } + + /** + * Constructs a lazy evaluation with caching. + * + * @param a the supplier that evaluates a value. + * @return a lazy evaluation. + */ + public static Eval later(F0 a) { + return new Later<>(a); + } + + /** + * Constructs a lazy evaluation without caching. + * + * @param a the supplier that evaluates a value. + * @return a lazy evaluation. + */ + public static Eval always(F0 a) { + return new Always<>(a); + } + + /** + * Constructs a lazy evaluation of an expression that produces Eval. + * This operation is stack-safe and can be used for recursive computations. + * + * @param a the supplier that produces an Eval. + * @return a lazily evaluated nested evaluation. + */ + public static Eval defer(F0> a) { + return new DeferEval<>(a); + } + + /** + * Evaluates the computation and return its result. + * Depending on whether the current instance is lazy or eager the + * computation may or may not happen at this point. + * + * @return a result of this computation. + */ + public abstract A value(); + + /** + * Transforms Eval into a Eval using + * the given function. + * + * Note: the computation of the given transformation is always lazy, + * even if it invoked for an eager Now instance. This computation + * is performed in O(1) stack space. + * + * @param f the transformation function. + * @return a transformed evaluation. + */ + public final Eval map(final F f) { + return bind(a -> now(f.f(a))); + } + + /** + * Alias for {@link #bind(F)}. + */ + public final Eval flatMap(final F> f) { + return bind(f); + } + + /** + * Transforms Eval into a Eval using + * the given function that directly produces Eval. + * + * Note: the computation of the given transformation is always lazy, + * even if it invoked for an eager Now instance. This computation + * is performed in O(1) stack space. + * + * @param f the transformation function. + * @return a transformed evaluation. + */ + public final Eval bind(final F> f) { + return new BindTrampolineEval<>(f, asTrampoline()); + } + + /** + * Transforms the current instance into a trampoline instance. + */ + abstract TrampolineEval asTrampoline(); + + /** + * Represents an eager computation. + */ + private static final class Now extends Eval { + private final A a; + + Now(A a) { + this.a = a; + } + + @Override + public final A value() { + return a; + } + + @Override + final TrampolineEval asTrampoline() { + return new PureTrampolineEval<>(this); + } + } + + /** + * Represents a lazy computation that is evaluated only once. + */ + private static final class Later extends Eval { + private final P1 memo; + + Later(F0 producer) { + this.memo = P.hardMemo(producer); + } + + @Override + public final A value() { + return memo._1(); + } + + @Override + final TrampolineEval asTrampoline() { + return new PureTrampolineEval<>(this); + } + } + + /** + * Represents a lazy computation that is evaluated every time when it's requested. + */ + private static final class Always extends Eval { + private final F0 supplier; + + Always(F0 supplier) { + this.supplier = supplier; + } + + @Override + public final A value() { + return supplier.f(); + } + + @Override + final TrampolineEval asTrampoline() { + return new PureTrampolineEval<>(this); + } + } + + /** + * A helper abstraction that allows to perform recursive lazy transformations in O(1) stack space. + */ + private static abstract class TrampolineEval extends Eval { + + protected abstract Trampoline trampoline(); + + @Override + public final A value() { + return trampoline().run(); + } + + @Override + final TrampolineEval asTrampoline() { + return this; + } + } + + private static final class PureTrampolineEval extends TrampolineEval { + private final Eval start; + + PureTrampolineEval(Eval start) { + this.start = start; + } + + @Override + protected final Trampoline trampoline() { + return Trampoline.suspend(P.lazy(() -> Trampoline.pure(start.value()))); + } + } + + private static final class BindTrampolineEval extends TrampolineEval { + private final TrampolineEval next; + private final F> f; + + BindTrampolineEval(F> f, TrampolineEval next) { + this.next = next; + this.f = f; + } + + @Override + protected final Trampoline trampoline() { + return Trampoline.suspend(P.lazy(() -> next.trampoline().bind(v -> f.f(v).asTrampoline().trampoline()))); + } + } + + private static final class DeferEval extends TrampolineEval { + private final P1> memo; + + DeferEval(F0> producer) { + this.memo = P.hardMemo(producer); + } + + @Override + protected final Trampoline trampoline() { + return memo._1().asTrampoline().trampoline(); + } + } +} diff --git a/core/src/test/java/fj/data/EvalTest.java b/core/src/test/java/fj/data/EvalTest.java new file mode 100644 index 00000000..a604c873 --- /dev/null +++ b/core/src/test/java/fj/data/EvalTest.java @@ -0,0 +1,76 @@ +package fj.data; + +import fj.F0; +import org.junit.Assert; +import org.junit.Test; + +public class EvalTest { + + @Test + public void testNow() { + Eval eval = Eval.now(1); + Assert.assertEquals(eval.value().intValue(), 1); + Assert.assertEquals(eval.map(a -> a.toString()).value(), "1"); + Assert.assertEquals(eval.bind(a -> Eval.now(a * 3)).value().intValue(), 3); + } + + @Test + public void testLater() { + InvocationTrackingF tracker = new InvocationTrackingF<>(1); + Eval eval = Eval.later(tracker); + + Assert.assertEquals(tracker.getInvocationCounter(), 0); + Assert.assertEquals(eval.value().intValue(), 1); + Assert.assertEquals(tracker.getInvocationCounter(), 1); + eval.value(); + Assert.assertEquals(tracker.getInvocationCounter(), 1); + } + + @Test + public void testAlways() { + InvocationTrackingF tracker = new InvocationTrackingF<>(1); + Eval eval = Eval.always(tracker); + + Assert.assertEquals(tracker.getInvocationCounter(), 0); + Assert.assertEquals(eval.value().intValue(), 1); + Assert.assertEquals(tracker.getInvocationCounter(), 1); + eval.value(); + eval.value(); + Assert.assertEquals(tracker.getInvocationCounter(), 3); + } + + @Test + public void testDefer() { + // Make sure that a recursive computation is actually stack-safe. + Assert.assertEquals(even(200000).value(), "done"); + } + + private static Eval even(int n) { + return Eval.now(n <= 0).flatMap(b -> b ? Eval.now("done") : Eval.defer(() -> odd(n - 1))); + } + + private static Eval odd(int n) { + return Eval.defer(() -> even(n - 1)); + } + + private static class InvocationTrackingF implements F0 { + + private final A value; + private int invocationCounter; + + public InvocationTrackingF(A value) { + this.value = value; + this.invocationCounter = 0; + } + + @Override + public A f() { + invocationCounter++; + return value; + } + + public int getInvocationCounter() { + return invocationCounter; + } + } +} From e0f69dc368fe0df52531dc48c490a27ae143de2c Mon Sep 17 00:00:00 2001 From: Iaroslav Zeigerman Date: Thu, 18 Jan 2018 10:25:18 -0500 Subject: [PATCH 186/336] Fix a recursive trampoline call in the Eval Defer implementation (#329) --- core/src/main/java/fj/data/Eval.java | 2 +- core/src/test/java/fj/data/EvalTest.java | 21 ++++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/data/Eval.java b/core/src/main/java/fj/data/Eval.java index 519070a1..3e513075 100644 --- a/core/src/main/java/fj/data/Eval.java +++ b/core/src/main/java/fj/data/Eval.java @@ -232,7 +232,7 @@ private static final class DeferEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return memo._1().asTrampoline().trampoline(); + return Trampoline.suspend(P.lazy(() -> memo._1().asTrampoline().trampoline())); } } } diff --git a/core/src/test/java/fj/data/EvalTest.java b/core/src/test/java/fj/data/EvalTest.java index a604c873..a3302e55 100644 --- a/core/src/test/java/fj/data/EvalTest.java +++ b/core/src/test/java/fj/data/EvalTest.java @@ -1,9 +1,12 @@ package fj.data; import fj.F0; +import fj.F2; import org.junit.Assert; import org.junit.Test; +import java.util.Iterator; + public class EvalTest { @Test @@ -42,15 +45,19 @@ public void testAlways() { @Test public void testDefer() { // Make sure that a recursive computation is actually stack-safe. - Assert.assertEquals(even(200000).value(), "done"); - } - - private static Eval even(int n) { - return Eval.now(n <= 0).flatMap(b -> b ? Eval.now("done") : Eval.defer(() -> odd(n - 1))); + int targetValue = 200000; + Iterator it = Enumerator.intEnumerator.toStream(0).iterator(); + Eval result = foldRight(it, (v, acc) -> v == targetValue ? Eval.now(true) : acc, false); + Assert.assertTrue(result.value()); } - private static Eval odd(int n) { - return Eval.defer(() -> even(n - 1)); + private static Eval foldRight(Iterator iterator, + F2, Eval> f, + A zero) { + if (!iterator.hasNext()) { + return Eval.now(zero); + } + return f.f(iterator.next(), Eval.defer(() -> foldRight(iterator, f, zero))); } private static class InvocationTrackingF implements F0 { From 7a30ac7323670bb134b78e6ddbba4452b881af4f Mon Sep 17 00:00:00 2001 From: l1cache Date: Fri, 2 Feb 2018 11:46:12 -0800 Subject: [PATCH 187/336] Added some useful functions to Equal --- core/src/main/java/fj/Equal.java | 68 ++++++++++++++++++++++++++++ core/src/test/java/fj/EqualTest.java | 48 ++++++++++++++++++++ 2 files changed, 116 insertions(+) create mode 100644 core/src/test/java/fj/EqualTest.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 5e407a00..07863acf 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -132,6 +132,74 @@ public boolean equal(B b1, B b2) { }); } + /** + * Constructs an equal instance, which tests equality of self and the mapped object in "and" manner + * + * @param f The function to map the original object + * @param eq Equality for the mapped object + * @return A new equal instance + */ + public final Equal andThen(final F f, final Equal eq) { + return and(eq.contramap(f)); + } + + /** + * An equal instance, which executes two Equality of self in "and" manner + * + * @param eq Another equality for self + * @return A new equal instance + */ + public final Equal and(final Equal eq) { + return equalDef((a1, a2) -> def.equal(a1, a2) && eq.def.equal(a1, a2)); + } + + /** + * An equal instance, which executes two Equality of self in "or" manner + * + * @param eq Another equality for self + * @return A new equal instance + */ + public final Equal or(final Equal eq) { + return equalDef((a1, a2) -> def.equal(a1, a2) || eq.def.equal(a1, a2)); + } + + /** + * An equal instance, which reverts equality for self + * + * @return A new equal instance + */ + public final Equal not() { + return equalDef((a1, a2) -> !def.equal(a1, a2)); + } + + /** + * Static version of {@link #contramap(F)} + */ + public static Equal contramap(final F f, final Equal eq) { + return eq.contramap(f); + } + + /** + * Static version of {@link #and(Equal)} + */ + public static Equal and(final Equal eq1, final Equal eq2) { + return eq1.and(eq2); + } + + /** + * Static version of {@link #or(Equal)} + */ + public static Equal or(final Equal eq1, final Equal eq2) { + return eq1.or(eq2); + } + + /** + * Static version of {@link #not()} + */ + public static Equal not(final Equal eq) { + return eq.not(); + } + /** * Constructs an equal instance from the given function. * diff --git a/core/src/test/java/fj/EqualTest.java b/core/src/test/java/fj/EqualTest.java new file mode 100644 index 00000000..776ccc57 --- /dev/null +++ b/core/src/test/java/fj/EqualTest.java @@ -0,0 +1,48 @@ +package fj; + +import org.junit.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; + +public class EqualTest { + @Test + public void contramapShouldWork() { + Equal equalByLength = Equal.contramap(String::length, Equal.intEqual); + + assertThat(equalByLength.eq("str1", "str2"), is(true)); + assertThat(equalByLength.eq("str1", "str11"), is(false)); + } + + @Test + public void andShouldWork() { + Equal equalByLengthAndLastDigit = Equal.and(Equal.contramap(String::length, Equal.intEqual), + Equal.contramap(s -> s.charAt(s.length() - 1), + Equal.charEqual)); + + assertThat(equalByLengthAndLastDigit.eq("str1", "spr1"), is(true)); + assertThat(equalByLengthAndLastDigit.eq("str1", "str2"), is(false)); + assertThat(equalByLengthAndLastDigit.eq("str1", "strr1"), is(false)); + } + + @Test + public void orShouldWork() { + Equal equalByLengthOrLastDigit = Equal.or(Equal.contramap(String::length, Equal.intEqual), + Equal.contramap(s -> s.charAt(s.length() - 1), + Equal.charEqual)); + + assertThat(equalByLengthOrLastDigit.eq("str1", "str2"), is(true)); + assertThat(equalByLengthOrLastDigit.eq("str1", "strr1"), is(true)); + assertThat(equalByLengthOrLastDigit.eq("str1", "strr2"), is(false)); + } + + @Test + public void thenShouldWork() { + Equal equalByLengthThenLastDigit = Equal.contramap(String::length, Equal.intEqual) + .andThen(s -> s.charAt(s.length() - 1), Equal.charEqual); + + assertThat(equalByLengthThenLastDigit.eq("str1", "spr1"), is(true)); + assertThat(equalByLengthThenLastDigit.eq("str1", "str2"), is(false)); + assertThat(equalByLengthThenLastDigit.eq("str1", "strr1"), is(false)); + } +} From dc0f405dc9ab62c97400ce0c88853027218fb211 Mon Sep 17 00:00:00 2001 From: l1cache Date: Fri, 2 Feb 2018 13:17:49 -0800 Subject: [PATCH 188/336] few useful function added to Ord class as well --- core/src/main/java/fj/Ord.java | 33 ++++++++++++++++++++++++++++++ core/src/test/java/fj/OrdTest.java | 18 ++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index a3e55edc..0b532ed1 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -287,6 +287,39 @@ public final Ord reverse() { return ordDef(def.dual()); } + /** + * Constructs an ord instance, which compares using self and if objects are equal compares using ord + * + * @param ord Ord for subsequent comparison + * @return A new equal instance + */ + public final Ord andThen(final Ord ord) { + return ordDef((a1, a2) -> { + final Ordering compareResult = compare(a1, a2); + if(compareResult == Ordering.EQ) + return ord.compare(a1, a2); + return compareResult; + }); + } + + /** + * Constructs an ord instance, which compares using self and if objects are equal compares the mapped objects + * + * @param f The function to map the original object + * @param ord Ord for the mapped object + * @return A new equal instance + */ + public final Ord andThen(final F f, final Ord ord) { + return andThen(ord.contramap(f)); + } + + /** + * Static version of {@link #contramap(F)} + */ + public static Ord contramap(final F f, final Ord ord) { + return ord.contramap(f); + } + /** * Returns an order instance that uses the given equality test and ordering function. * diff --git a/core/src/test/java/fj/OrdTest.java b/core/src/test/java/fj/OrdTest.java index d218387a..1dfa6223 100644 --- a/core/src/test/java/fj/OrdTest.java +++ b/core/src/test/java/fj/OrdTest.java @@ -24,4 +24,22 @@ public void isLessThan() { assertThat(pred.f(1L), is(false)); assertThat(pred.f(2L), is(false)); } + + @Test + public void contramapShouldWork() { + Ord lengthOrd = Ord.contramap(String::length, Ord.intOrd); + + assertThat(lengthOrd.compare("str", "rts"), is(Ordering.EQ)); + assertThat(lengthOrd.compare("strlong", "str"), is(Ordering.GT)); + } + + @Test + public void andThenShouldWork() { + Ord lengthThenLastDigitOrd = Ord.contramap(String::length, Ord.intOrd) + .andThen(s -> s.charAt(s.length() - 1), Ord.charOrd); + + assertThat(lengthThenLastDigitOrd.compare("str", "dyr"), is(Ordering.EQ)); + assertThat(lengthThenLastDigitOrd.compare("stt", "str"), is(Ordering.GT)); + assertThat(lengthThenLastDigitOrd.compare("str", "strr"), is(Ordering.LT)); + } } From c4f1f6830a7f6cf66efdffb9436676361af2ff25 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Tue, 20 Mar 2018 13:55:23 +0100 Subject: [PATCH 189/336] Move fluent Equal/Ord construction api to the Definition interfaces. Also remove Equal.or and Equal.and as there is no precise use case. --- core/src/main/java/fj/Equal.java | 111 +++++++++++++-------------- core/src/main/java/fj/Ord.java | 101 ++++++++++++++---------- core/src/test/java/fj/EqualTest.java | 26 +------ core/src/test/java/fj/OrdTest.java | 6 +- 4 files changed, 117 insertions(+), 127 deletions(-) diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 07863acf..f427849a 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -48,6 +48,39 @@ public interface Definition { default boolean equal(A a1, A a2) { return equal(a1).f(a2); } + + /** + * Refine this equal definition, to tests equality of self and the mapped object in "and" manner. + * @see #equal() + * + * @param f The function to map the original object + * @param eq Equality for the mapped object + * @return A new equal definition + */ + default Definition then(final F f, final Equal eq) { + Definition bEqDef = eq.def; + return new Definition() { + @Override + public F equal(A a1) { + F fa = Definition.this.equal(a1); + F fb = bEqDef.equal(f.f(a1)); + return a2 -> fa.f(a2) && fb.f(f.f(a2)); + } + + @Override + public boolean equal(A a1, A a2) { + return Definition.this.equal(a1, a2) && bEqDef.equal(f.f(a1), f.f(a2)); + } + }; + } + + /** + * Build an equal instance from this definition. + * to be called after some successive {@link #then(F, Equal)} calls. + */ + default Equal equal() { + return equalDef(this); + } } /** @@ -118,58 +151,31 @@ public F eq(final A a) { * @return A new equal. */ public Equal contramap(final F f) { - Definition eaDef = def; - return equalDef(new Definition(){ - @Override - public F equal(B b) { - return compose(eaDef.equal(f.f(b)), f); - } - - @Override - public boolean equal(B b1, B b2) { - return eaDef.equal(f.f(b1), f.f(b2)); - } - }); + return equalDef(contramapDef(f, def)); } /** - * Constructs an equal instance, which tests equality of self and the mapped object in "and" manner + * An equal instance, which reverts equality for self * - * @param f The function to map the original object - * @param eq Equality for the mapped object * @return A new equal instance */ - public final Equal andThen(final F f, final Equal eq) { - return and(eq.contramap(f)); + public final Equal not() { + return equalDef((a1, a2) -> !def.equal(a1, a2)); } - /** - * An equal instance, which executes two Equality of self in "and" manner - * - * @param eq Another equality for self - * @return A new equal instance - */ - public final Equal and(final Equal eq) { - return equalDef((a1, a2) -> def.equal(a1, a2) && eq.def.equal(a1, a2)); - } - /** - * An equal instance, which executes two Equality of self in "or" manner - * - * @param eq Another equality for self - * @return A new equal instance - */ - public final Equal or(final Equal eq) { - return equalDef((a1, a2) -> def.equal(a1, a2) || eq.def.equal(a1, a2)); - } + private static Definition contramapDef(F f, Definition aEqDef) { + return new Definition(){ + @Override + public F equal(B b) { + return compose(aEqDef.equal(f.f(b)), f); + } - /** - * An equal instance, which reverts equality for self - * - * @return A new equal instance - */ - public final Equal not() { - return equalDef((a1, a2) -> !def.equal(a1, a2)); + @Override + public boolean equal(B b1, B b2) { + return aEqDef.equal(f.f(b1), f.f(b2)); + } + }; } /** @@ -180,24 +186,11 @@ public static Equal contramap(final F f, final Equal eq) { } /** - * Static version of {@link #and(Equal)} - */ - public static Equal and(final Equal eq1, final Equal eq2) { - return eq1.and(eq2); - } - - /** - * Static version of {@link #or(Equal)} - */ - public static Equal or(final Equal eq1, final Equal eq2) { - return eq1.or(eq2); - } - - /** - * Static version of {@link #not()} + * Begin definition of an equal instance. + * @see Definition#then(F, Equal) */ - public static Equal not(final Equal eq) { - return eq.not(); + public static Definition on(final F f, final Equal eq) { + return contramapDef(f, eq.def); } /** diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 0b532ed1..0a778f4d 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -84,6 +84,42 @@ public Definition dual() { } }; } + + /** + * Refine this ord definition: compares using self and if objects are equal compares using given Ord. + * @see #ord() + * + * @param bOrd Ord for subsequent comparison + * @return A new ord definition. + */ + default Definition then(final F f, final Ord bOrd) { + Definition bOrdDef = bOrd.def; + return new Definition() { + @Override + public F compare(A a1) { + F fa = Definition.this.compare(a1); + F fb = bOrdDef.compare(f.f(a1)); + return a2 -> { + Ordering aOrdering = fa.f(a2); + return aOrdering != Ordering.EQ ? aOrdering : fb.f(f.f(a2)); + }; + } + + @Override + public Ordering compare(A a1, A a2) { + Ordering aOrdering = Definition.this.compare(a1, a2); + return aOrdering != Ordering.EQ ? aOrdering : bOrdDef.compare(f.f(a1), f.f(a2)); + } + }; + } + + /** + * Build an ord instance from this definition. + * to be called after some successive {@link #then(F, Ord)} calls. + */ + default Ord ord() { + return ordDef(this); + } } /** @@ -160,18 +196,7 @@ public Equal equal() { * @return A new ord. */ public Ord contramap(final F f) { - Definition selfDef = def; - return ordDef(new Definition() { - @Override - public F compare(B b) { - return compose(selfDef.compare(f.f(b)), f); - } - - @Override - public Ordering compare(B b1, B b2) { - return selfDef.compare(f.f(b1), f.f(b2)); - } - }); + return ordDef(contramapDef(f, def)); } /** @@ -288,36 +313,32 @@ public final Ord reverse() { } /** - * Constructs an ord instance, which compares using self and if objects are equal compares using ord - * - * @param ord Ord for subsequent comparison - * @return A new equal instance + * Begin definition of an ord instance. + * @see Definition#then(F, Equal) */ - public final Ord andThen(final Ord ord) { - return ordDef((a1, a2) -> { - final Ordering compareResult = compare(a1, a2); - if(compareResult == Ordering.EQ) - return ord.compare(a1, a2); - return compareResult; - }); - } - - /** - * Constructs an ord instance, which compares using self and if objects are equal compares the mapped objects - * - * @param f The function to map the original object - * @param ord Ord for the mapped object - * @return A new equal instance - */ - public final Ord andThen(final F f, final Ord ord) { - return andThen(ord.contramap(f)); + public static Definition on(final F f, final Ord ord) { + return contramapDef(f, ord.def); } /** * Static version of {@link #contramap(F)} */ public static Ord contramap(final F f, final Ord ord) { - return ord.contramap(f); + return ordDef(contramapDef(f, ord.def)); + } + + private static Definition contramapDef(F f, Definition def) { + return new Definition() { + @Override + public F compare(B b) { + return compose(def.compare(f.f(b)), f); + } + + @Override + public Ordering compare(B b1, B b2) { + return def.compare(f.f(b1), f.f(b2)); + } + }; } /** @@ -609,15 +630,15 @@ public static Ord> p1Ord(final Ord oa) { * @return An order instance for a product-2, with the first factor considered most significant. */ public static Ord> p2Ord(final Ord oa, final Ord ob) { - return ordDef((a, b) -> oa.eq(a._1(), b._1()) ? ob.compare(a._2(), b._2()) : oa.compare(a._1(), b._1())); + return on(P2.__1(), oa).then(P2.__2(), ob).ord(); } public static Ord> p2Ord1(Ord oa) { - return ordDef((p1, p2) -> oa.compare(p1._1(), p2._1())); + return on(P2.__1(), oa).ord(); } public static Ord> p2Ord2(Ord ob) { - return ordDef((p1, p2) -> ob.compare(p1._2(), p2._2())); + return on(P2.__2(), ob).ord(); } /** @@ -629,9 +650,7 @@ public static Ord> p2Ord2(Ord ob) { * @return An order instance for a product-3, with the first factor considered most significant. */ public static Ord> p3Ord(final Ord oa, final Ord ob, final Ord oc) { - return ordDef((a, b) -> oa.eq(a._1(), b._1()) ? - p2Ord(ob, oc).compare(P.p(a._2(), a._3()), P.p(b._2(), b._3())) - : oa.compare(a._1(), b._1())); + return on(P3.__1(), oa).then(P3.__2(), ob).then(P3.__3(), oc).ord(); } /** diff --git a/core/src/test/java/fj/EqualTest.java b/core/src/test/java/fj/EqualTest.java index 776ccc57..bacecc46 100644 --- a/core/src/test/java/fj/EqualTest.java +++ b/core/src/test/java/fj/EqualTest.java @@ -14,32 +14,10 @@ public void contramapShouldWork() { assertThat(equalByLength.eq("str1", "str11"), is(false)); } - @Test - public void andShouldWork() { - Equal equalByLengthAndLastDigit = Equal.and(Equal.contramap(String::length, Equal.intEqual), - Equal.contramap(s -> s.charAt(s.length() - 1), - Equal.charEqual)); - - assertThat(equalByLengthAndLastDigit.eq("str1", "spr1"), is(true)); - assertThat(equalByLengthAndLastDigit.eq("str1", "str2"), is(false)); - assertThat(equalByLengthAndLastDigit.eq("str1", "strr1"), is(false)); - } - - @Test - public void orShouldWork() { - Equal equalByLengthOrLastDigit = Equal.or(Equal.contramap(String::length, Equal.intEqual), - Equal.contramap(s -> s.charAt(s.length() - 1), - Equal.charEqual)); - - assertThat(equalByLengthOrLastDigit.eq("str1", "str2"), is(true)); - assertThat(equalByLengthOrLastDigit.eq("str1", "strr1"), is(true)); - assertThat(equalByLengthOrLastDigit.eq("str1", "strr2"), is(false)); - } - @Test public void thenShouldWork() { - Equal equalByLengthThenLastDigit = Equal.contramap(String::length, Equal.intEqual) - .andThen(s -> s.charAt(s.length() - 1), Equal.charEqual); + Equal equalByLengthThenLastDigit = Equal.on(String::length, Equal.intEqual) + .then(s -> s.charAt(s.length() - 1), Equal.charEqual).equal(); assertThat(equalByLengthThenLastDigit.eq("str1", "spr1"), is(true)); assertThat(equalByLengthThenLastDigit.eq("str1", "str2"), is(false)); diff --git a/core/src/test/java/fj/OrdTest.java b/core/src/test/java/fj/OrdTest.java index 1dfa6223..4addec65 100644 --- a/core/src/test/java/fj/OrdTest.java +++ b/core/src/test/java/fj/OrdTest.java @@ -34,9 +34,9 @@ public void contramapShouldWork() { } @Test - public void andThenShouldWork() { - Ord lengthThenLastDigitOrd = Ord.contramap(String::length, Ord.intOrd) - .andThen(s -> s.charAt(s.length() - 1), Ord.charOrd); + public void thenShouldWork() { + Ord lengthThenLastDigitOrd = Ord.on(String::length, Ord.intOrd) + .then(s -> s.charAt(s.length() - 1), Ord.charOrd).ord(); assertThat(lengthThenLastDigitOrd.compare("str", "dyr"), is(Ordering.EQ)); assertThat(lengthThenLastDigitOrd.compare("stt", "str"), is(Ordering.GT)); From bbc28c47a29d04724007192100edef79499078cc Mon Sep 17 00:00:00 2001 From: Sidney Quitorio Date: Tue, 3 Jul 2018 16:16:17 -0700 Subject: [PATCH 190/336] Fixes exception in Either.LeftProjection.traverseIO --- core/src/main/java/fj/data/Either.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index 7d8e0bb7..a9a746a9 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -316,7 +316,7 @@ public List> traverseList(final F> f) { * @return An either after traversing through this projection. */ public IO> traverseIO(final F> f) { - return e.isRight() ? + return e.isLeft() ? IOFunctions.map(f.f(value()), Either::left) : IOFunctions.unit(Either.right(e.right().value())); } From 8ff163c6bbcaf4888bde7dcef21a16137b4db5c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Wed, 11 Jul 2018 21:24:12 -0400 Subject: [PATCH 191/336] Bring Gradle to 4.8.1 --- gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f16d2666..717f0389 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip diff --git a/gradlew b/gradlew index 4453ccea..cccdd3d5 100755 --- a/gradlew +++ b/gradlew @@ -33,11 +33,11 @@ DEFAULT_JVM_OPTS="" # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -155,7 +155,7 @@ if $cygwin ; then fi # Escape application args -save ( ) { +save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } From 4b6536110719689dad7e784ac389db05a0959af0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Wed, 11 Jul 2018 21:43:15 -0400 Subject: [PATCH 192/336] Bring dependencies current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 2 +- core/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 6f8ecc5d..e1fed096 100644 --- a/build.gradle +++ b/build.gradle @@ -72,7 +72,7 @@ allprojects { sonatypeUploadUrl = isSnapshot ? sonatypeSnapshotUrl : sonatypeReleaseUrl primaryEmail = "functionaljava@googlegroups.com" - dependencyJunit = "junit:junit:4.12" + dependencyJunit = "org.junit.vintage:junit-vintage-engine:5.2.0" displayCompilerWarnings = true diff --git a/core/build.gradle b/core/build.gradle index e0c86f0c..71dae913 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -7,7 +7,7 @@ archivesBaseName = project.projectName dependencies { testCompile dependencyJunit - testCompile 'com.h2database:h2:1.4.196' + testCompile 'com.h2database:h2:1.4.197' testCompile 'commons-dbutils:commons-dbutils:1.7' } From 7576f6f65537cbb7f059d683d96425860b306213 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 21 Jul 2018 09:21:05 +0200 Subject: [PATCH 193/336] use openjdk7, remove oracle installer, try sudo false --- .travis.yml | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a9f2d24..539e7a45 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,30 +1,13 @@ -language: java +# Use faster, Docker-based container (instead of OpenVZ) +sudo: false -sudo: required +language: java jdk: - oraclejdk8 -addons: - apt: - packages: - - oracle-java8-installer - -before_script: - - sudo service postgresql stop || true - - sudo service mysql stop || true - - sudo service memcached stop || true - - sudo service bootlogd stop || true - - sudo service elasticsearch stop || true - - sudo service mongodb stop || true - - sudo service neo4j stop || true - - sudo service cassandra stop || true - - sudo service riak stop || true - - sudo service rsync stop || true - - sudo service x11-common stop || true - script: - - jdk_switcher use oraclejdk7 && export JAVA7_HOME=$JAVA_HOME + - jdk_switcher use openjdk7 && export JAVA7_HOME=$JAVA_HOME - jdk_switcher use oraclejdk8 && export JAVA8_HOME=$JAVA_HOME - ./gradlew build coverage -s -i From b280c531debd92885ca6b7998cb2aa485a0fd955 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Thu, 26 Jul 2018 18:48:45 -0400 Subject: [PATCH 194/336] Add IOFunctions tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/IOTest.java | 30 -------- .../test/java/fj/data/IOFunctionsTest.java | 69 +++++++++++++++++-- 2 files changed, 63 insertions(+), 36 deletions(-) delete mode 100644 core/src/test/java/fj/IOTest.java diff --git a/core/src/test/java/fj/IOTest.java b/core/src/test/java/fj/IOTest.java deleted file mode 100644 index f965204c..00000000 --- a/core/src/test/java/fj/IOTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package fj; - -import fj.data.IO; -import fj.data.IOFunctions; -import org.junit.Test; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.StringReader; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - - -public class IOTest { - - @Test - public void testLift() throws IOException { - final IO readName = () -> new BufferedReader(new StringReader("foo")).readLine(); - final F> upperCaseAndPrint = F1Functions., String>o(this::println).f(String::toUpperCase); - final IO readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint); - assertThat(readAndPrintUpperCasedName.run(), is("FOO")); - } - - public IO println(final String s) { - return () -> { - return s; - }; - } -} diff --git a/core/src/test/java/fj/data/IOFunctionsTest.java b/core/src/test/java/fj/data/IOFunctionsTest.java index dcafc221..b943db36 100644 --- a/core/src/test/java/fj/data/IOFunctionsTest.java +++ b/core/src/test/java/fj/data/IOFunctionsTest.java @@ -1,7 +1,6 @@ package fj.data; -import fj.Unit; -import org.hamcrest.core.Is; +import fj.*; import org.junit.Assert; import org.junit.Test; @@ -9,6 +8,10 @@ import java.io.Reader; import java.util.concurrent.atomic.AtomicBoolean; +import static fj.data.IOFunctions.*; +import static fj.data.Stream.cons; +import static fj.data.Stream.nil_; +import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.*; public class IOFunctionsTest { @@ -30,8 +33,8 @@ public void close() { r -> () -> new BufferedReader(r).readLine() ); - Assert.assertThat(bracketed.run(), Is.is("Read OK")); - Assert.assertThat(closed.get(), Is.is(true)); + Assert.assertThat(bracketed.run(), is("Read OK")); + Assert.assertThat(closed.get(), is(true)); } @Test @@ -56,9 +59,63 @@ public void close() { bracketed.run(); fail("Exception expected"); } catch (IllegalArgumentException e) { - Assert.assertThat(e.getMessage(), Is.is("OoO")); + Assert.assertThat(e.getMessage(), is("OoO")); } - Assert.assertThat(closed.get(), Is.is(true)); + Assert.assertThat(closed.get(), is(true)); + } + + @Test + public void testTraverseIO() throws IOException { + String[] as = {"foo1", "bar2", "foobar3"}; + Stream stream = Stream.arrayStream(as); + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + PrintStream originalOut = System.out; + System.setOut(new PrintStream(outContent)); + stream.traverseIO(IOFunctions::stdoutPrint).run(); + System.setOut(originalOut); + assertThat(outContent.toString(), is("foobar3bar2foo1")); + } + + @Test + public void testSequenceWhile() throws IOException { + BufferedReader r = new BufferedReader(new StringReader("foo1\nbar2\nfoobar3")); + Stream> s1 = Stream.repeat(() -> r.readLine()); + IO> io = sequenceWhile(s1, s -> !s.equals("foobar3")); + assertThat(io.run(), is(cons("foo1", () -> cons("bar2", () -> Stream.nil())))); + } + + @Test + public void testForeach() throws IOException { + Stream> s1 = Stream.repeat(() -> "foo1"); + IO> io = sequence(s1.take(2)); + ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + PrintStream originalOut = System.out; + System.setOut(new PrintStream(outContent)); + runSafe(io).foreach(s -> runSafe(stdoutPrint(s))); + System.setOut(originalOut); + assertThat(outContent.toString(), is("foo1foo1")); + } + + + @Test + public void testReplicateM() throws IOException { + final IO is = () -> new BufferedReader(new StringReader("foo")).readLine(); + assertThat(replicateM(is, 3).run(), is(List.list("foo", "foo", "foo"))); + } + + + @Test + public void testLift() throws IOException { + final IO readName = () -> new BufferedReader(new StringReader("foo")).readLine(); + final F> upperCaseAndPrint = F1Functions., String>o(this::println).f(String::toUpperCase); + final IO readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint); + assertThat(readAndPrintUpperCasedName.run(), is("FOO")); + } + + private IO println(final String s) { + return () -> { + return s; + }; } } \ No newline at end of file From be646621a7be6dc7dfe5a10bb9fd26fd3d04c6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 29 Jul 2018 08:47:35 -0400 Subject: [PATCH 195/336] Add Stream tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/data/StreamTest.java | 75 ++++++++++++++++++++-- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index a37764c2..49840b78 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -1,16 +1,16 @@ package fj.data; +import fj.Equal; +import fj.Ord; +import fj.P2; +import fj.control.parallel.Strategy; import org.junit.Test; -import java.io.IOException; -import java.util.ArrayList; import java.util.ConcurrentModificationException; -import static fj.data.IOFunctions.stdinReadLine; -import static java.lang.System.out; +import static fj.data.Stream.*; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; /** @@ -21,7 +21,7 @@ public class StreamTest { @Test public void infiniteStream() { Stream s = Stream.forever(Enumerator.intEnumerator, 0).bind(Stream::single); - assertEquals(List.range(0, 5), s.take(5).toList()); + assertThat(List.range(0, 5), is(s.take(5).toList())); } @Test @@ -48,5 +48,68 @@ public void iterableStreamWithStructureUpdate() { x = s2.head(); } + @Test(expected=Error.class) + public void testCycleNil(){ + cycle(Stream.nil()); + } + + @Test + public void testCycle() { + Stream s = stream(new Character[]{'a', 'b'}); + assertThat(cycle(s).take(5), + is(stream(new Character[]{'a', 'b', 'a', 'b', 'a'}))); + } + + @Test + public void testIterate() { + assertThat(iterate(a -> 2 * a + 1, 1).take(5), + is(stream(new Integer[]{1, 3, 7, 15, 31}))); + } + + @Test + public void testArrayStreamEmpty() { + assertThat(arrayStream(new Integer[]{}), is(Stream.nil())); + } + + @Test(expected=Error.class) + public void testNilHead() { + Stream.nil().head(); + } + @Test(expected=Error.class) + public void testNilTail() { + Stream.nil().tail(); + } + + @Test + public void testArray() { + Character[] a = new Character[]{'a', 'b', 'c'}; + Stream s = stream(a); + assertThat(s.array(Character[].class), is(a)); + } + + @Test + public void testZipIndex() { + Character[] a = new Character[]{'a', 'b', 'c'}; + P2, Stream> p = unzip(stream(a).zipIndex().drop(1)); + assertThat(p._1(), is(stream(new Character[]{'b', 'c'}))); + assertThat(p._2(), is(stream(new Integer[]{1, 2}))); + } + + @Test + public void testMinus() { + Character[] a1 = new Character[]{'a', 'b', 'c', 'd', 'e'}; + Stream s1 = stream(a1); + Character[] a2 = new Character[]{'b', 'e'}; + Stream s2 = stream(a2); + assertThat(s1.minus(Equal.charEqual, s2), + is(stream(new Character[]{'a', 'c', 'd'}))); + } + + @Test + public void testSort() { + Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, Strategy.seqStrategy()), + is(s.sort(Ord.intOrd))); + } } From 99a7642a5fbae7e90e5ce80bbe44842acc8f524b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 29 Jul 2018 21:20:43 +0200 Subject: [PATCH 196/336] Update to latest retrolambda --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index e1fed096..08d3e946 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,8 @@ ext { buildscript { ext { uptodateVersion = "1.6.3" - retrolambdaPluginVersion = "3.5.0" - retrolambdaVersion = "2.5.1" + retrolambdaPluginVersion = "3.7.0" + retrolambdaVersion = "2.5.4" } repositories { From 3fc4ab2994d942c121d79be37bda672e9a2a8262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 29 Jul 2018 17:01:47 -0400 Subject: [PATCH 197/336] Exclude paths in codecov.io MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- codecov.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 codecov.yml diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..8c7fd5e4 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,3 @@ +ignore: + - "demo/.*" + - "performance/.*" \ No newline at end of file From fa322e27df3c491d2e771a540894f9073d95f6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 30 Jul 2018 15:45:03 -0400 Subject: [PATCH 198/336] Bring Gradle Jacoco current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index e1fed096..1cc8078e 100644 --- a/build.gradle +++ b/build.gradle @@ -38,8 +38,7 @@ allprojects { jacoco { -// toolVersion = "0.7.1.201405082137" - toolVersion = "0.7.6.201602180812" + toolVersion = "0.8.1" } From e9fd4eca665bf392c6b1a72176e476ff6bae1289 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 30 Jul 2018 15:22:45 -0400 Subject: [PATCH 199/336] Add tests for Try, F, FW, Digit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/F8Functions.java | 1 - core/src/test/java/fj/DigitTest.java | 30 ++++++++ core/src/test/java/fj/FFunctionsTest.java | 25 +++++++ core/src/test/java/fj/FWFunctionsTest.java | 24 ++++++ core/src/test/java/fj/ShowTest.java | 6 -- core/src/test/java/fj/TryEffectTest.java | 82 +++++++++++++++++++++ core/src/test/java/fj/TryTest.java | 50 +++++++++++++ core/src/test/java/fj/data/JavaTest.java | 4 +- core/src/test/java/fj/data/OptionTest.java | 1 - core/src/test/java/fj/data/SeqTest.java | 5 +- core/src/test/java/fj/data/StreamTest.java | 9 ++- core/src/test/java/fj/data/TreeMapTest.java | 11 --- 12 files changed, 226 insertions(+), 22 deletions(-) create mode 100644 core/src/test/java/fj/DigitTest.java create mode 100644 core/src/test/java/fj/FFunctionsTest.java create mode 100644 core/src/test/java/fj/FWFunctionsTest.java create mode 100644 core/src/test/java/fj/TryEffectTest.java create mode 100644 core/src/test/java/fj/TryTest.java diff --git a/core/src/main/java/fj/F8Functions.java b/core/src/main/java/fj/F8Functions.java index 071cb6bc..8b9883a3 100644 --- a/core/src/main/java/fj/F8Functions.java +++ b/core/src/main/java/fj/F8Functions.java @@ -11,7 +11,6 @@ private F8Functions() { /** * Partial application. * - * @param a The A to which to apply this function. * @return The function partially applied to the given argument. */ public static F7 f(final F8 func, final A a) { diff --git a/core/src/test/java/fj/DigitTest.java b/core/src/test/java/fj/DigitTest.java new file mode 100644 index 00000000..9fc98d4c --- /dev/null +++ b/core/src/test/java/fj/DigitTest.java @@ -0,0 +1,30 @@ +package fj; + +import fj.data.Option; +import org.junit.Test; + +import static fj.data.Array.range; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class DigitTest { + @Test + public void testInteger() { + for (Integer i: range(0, 10)) { + assertThat(Digit.fromLong(i).toLong(), is(i.longValue())); + } + } + + @Test + public void testChar() { + for (Integer i: range(0, 10)) { + Character c = Character.forDigit(i, 10); + assertThat(Digit.fromChar(c).some().toChar(), is(c)); + } + } + + @Test + public void testCharNone() { + assertThat(Digit.fromChar('x'), is(Option.none())); + } +} diff --git a/core/src/test/java/fj/FFunctionsTest.java b/core/src/test/java/fj/FFunctionsTest.java new file mode 100644 index 00000000..9d38e1f5 --- /dev/null +++ b/core/src/test/java/fj/FFunctionsTest.java @@ -0,0 +1,25 @@ +package fj; + +import org.junit.Test; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class FFunctionsTest { + @Test + public void testApply() { + F8 f8 = + (i1, i2, i3, i4, i5, i6, i7, i8) -> + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8; + F7 f7 = F8Functions.f(f8, 8); + F6 f6 = + F7Functions.f(f7, 7); + F5 f5 = F6Functions.f(f6, 6); + F4 f4 = F5Functions.f(f5, 5); + F3 f3 = F4Functions.f(f4, 4); + F2 f2 = F3Functions.f(f3, 3); + F f1 = F2Functions.f(f2, 2); + assertThat(F1Functions.f(f1, 1).f(), is(36)); + } +} diff --git a/core/src/test/java/fj/FWFunctionsTest.java b/core/src/test/java/fj/FWFunctionsTest.java new file mode 100644 index 00000000..b9ce65d5 --- /dev/null +++ b/core/src/test/java/fj/FWFunctionsTest.java @@ -0,0 +1,24 @@ +package fj; + +import org.junit.Test; + +import fj.F1W; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class FWFunctionsTest { + @Test + public void testLift1() { + F f = i -> i + 1; + F1W f1w = F1W.lift(f); + assertThat(f1w.f(1), is(2)); + } + + @Test + public void testLift2() { + F2 f2 = (i, j) -> i + j; + F2W f2w = F2W.lift(f2); + assertThat(f2w.f(1, 2), is(3)); + } + +} diff --git a/core/src/test/java/fj/ShowTest.java b/core/src/test/java/fj/ShowTest.java index e271f5a1..c516c0df 100644 --- a/core/src/test/java/fj/ShowTest.java +++ b/core/src/test/java/fj/ShowTest.java @@ -10,16 +10,10 @@ * Created by MarkPerry on 4/06/2015. */ public class ShowTest { - - - @Test public void arrayShow() { Array a = array(3, 5, 7); String s = Show.arrayShow(Show.intShow).showS(a); - System.out.println(s); assertTrue(s.equals("Array(3,5,7)")); - } - } diff --git a/core/src/test/java/fj/TryEffectTest.java b/core/src/test/java/fj/TryEffectTest.java new file mode 100644 index 00000000..bb684fc6 --- /dev/null +++ b/core/src/test/java/fj/TryEffectTest.java @@ -0,0 +1,82 @@ +package fj; + +import fj.data.Validation; +import fj.function.TryEffect0; +import fj.function.TryEffect1; +import org.junit.Test; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class TryEffectTest { + + @Test + public void testTryEffect0Success() { + F> f = + TryEffect.f(TryEffect0::f); + Validation v = f.f(new AlwaysSucceed0()); + assertThat(v.isSuccess(), is(true)); + assertThat(v.success(), is(Unit.unit())); + } + + @Test + public void testTryEffect0Fail() { + F> f = + TryEffect.f(TryEffect0::f); + Validation v = f.f(new AlwaysFail0()); + assertThat(v.isFail(), is(true)); + assertThat(v.fail(), is(new TryEffectException())); + } + + @Test + public void testTryEffect1Success() { + F2, Integer, Validation> f = + TryEffect.f(TryEffect1::f); + Validation v = f.f(new AlwaysSucceed1(), 1); + assertThat(v.isSuccess(), is(true)); + assertThat(v.success(), is(Unit.unit())); + } + + @Test + public void testTryEffect1Fail() { + F2, Integer, Validation> f = + TryEffect.f(TryEffect1::f); + Validation v = f.f(new AlwaysFail1(), 1); + assertThat(v.isFail(), is(true)); + assertThat(v.fail(), is(new TryEffectException())); + } + + class AlwaysSucceed0 implements TryEffect0 { + @Override + public void f() throws TryEffectException { + // SUCCESS + } + } + + class AlwaysSucceed1 implements TryEffect1 { + @Override + public void f(Integer i) throws TryEffectException { + // SUCCESS; + } + } + + class AlwaysFail0 implements TryEffect0 { + @Override + public void f() throws TryEffectException { + throw new TryEffectException(); + } + } + + class AlwaysFail1 implements TryEffect1 { + @Override + public void f(Integer i) throws TryEffectException { + throw new TryEffectException(); + } + } + + class TryEffectException extends Exception { + @Override + public boolean equals (Object obj) { + return (obj instanceof TryEffectException); + } + } +} diff --git a/core/src/test/java/fj/TryTest.java b/core/src/test/java/fj/TryTest.java new file mode 100644 index 00000000..bd94e986 --- /dev/null +++ b/core/src/test/java/fj/TryTest.java @@ -0,0 +1,50 @@ +package fj; + +import fj.data.Validation; +import fj.function.Try0; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class TryTest { + + @Test + public void testTrySuccess() { + F, Validation> f = + Try.f(Try0::f); + Validation v = f.f(new AlwaysSucceed()); + assertThat(v.isSuccess(), is(true)); + assertThat(v.success(), is(99)); + } + + @Test + public void testTryFail() { + F, Validation> f = + Try.f(Try0::f); + Validation v = f.f(new AlwaysFail()); + assertThat(v.isFail(), is(true)); + assertThat(v.fail(), is(new TryException())); + } + + class AlwaysSucceed implements Try0 { + @Override + public Integer f() throws TryException { + return 99; + } + } + + class AlwaysFail implements Try0 { + @Override + public Integer f() throws TryException { + throw new TryException(); + } + } + + class TryException extends Exception { + @Override + public boolean equals (Object obj) { + return (obj instanceof TryException); + } + } +} diff --git a/core/src/test/java/fj/data/JavaTest.java b/core/src/test/java/fj/data/JavaTest.java index 3b5a5785..2a9b6bfd 100644 --- a/core/src/test/java/fj/data/JavaTest.java +++ b/core/src/test/java/fj/data/JavaTest.java @@ -6,6 +6,8 @@ import java.util.EnumSet; import static fj.Show.listShow; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; /** * Created by MarkPerry on 14/07/2014. @@ -16,7 +18,7 @@ public class JavaTest { public void test1() { // #33: Fixes ClassCastException final List colors = Java.EnumSet_List().f(EnumSet.allOf(Colors.class)); - listShow(Show.anyShow()).print(colors); + assertThat(listShow(Show.anyShow()).showS(colors), is("List(red,green,blue)")); } enum Colors { diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index 5d2778e5..3eeed489 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -23,7 +23,6 @@ public void traverseList() { int max = 3; List> actual = some(max).traverseList(a -> List.range(1, a + 1)); List> expected = List.range(1, max + 1).map(i -> some(i)); - System.out.println(String.format("actual: %s, expected: %s", actual.toString(), expected.toString())); assertTrue(actual.equals(expected)); } diff --git a/core/src/test/java/fj/data/SeqTest.java b/core/src/test/java/fj/data/SeqTest.java index 27ec26e2..a7c85175 100644 --- a/core/src/test/java/fj/data/SeqTest.java +++ b/core/src/test/java/fj/data/SeqTest.java @@ -3,6 +3,8 @@ import fj.P2; import org.junit.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -40,7 +42,8 @@ public void convertToString() { @Test public void test() { P2, Seq> p2 = Seq.single(1).split(5); - System.out.println(p2); + assertThat(p2._1(), is(Seq.single(1))); + assertThat(p2._2(), is(Seq.empty())); } } diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index 49840b78..b65e115c 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -107,9 +107,16 @@ public void testMinus() { } @Test - public void testSort() { + public void testSortSeq() { Stream s = range(Enumerator.intEnumerator, 99, -99, -1); assertThat(s.sort(Ord.intOrd, Strategy.seqStrategy()), is(s.sort(Ord.intOrd))); } + + @Test + public void testSortThread() { + Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, Strategy.simpleThreadStrategy()), + is(s.sort(Ord.intOrd))); + } } diff --git a/core/src/test/java/fj/data/TreeMapTest.java b/core/src/test/java/fj/data/TreeMapTest.java index d3e60936..96cb95b2 100644 --- a/core/src/test/java/fj/data/TreeMapTest.java +++ b/core/src/test/java/fj/data/TreeMapTest.java @@ -38,10 +38,6 @@ public void split() { Show> ss = Show.setShow(Show.stringShow); Show> so = Show.optionShow(Show.stringShow); Show, Option, Set>> sp3 = Show.p3Show(ss, so, ss); - if (true) { - st.println(m2); - sp3.println(p); - } // assert equals Equal> seq = Equal.setEqual(Equal.stringEqual); @@ -70,13 +66,6 @@ public void splitLookup() { List rightList = List.range(pivot + 1, max + 1); TreeMap rightMap = iterableTreeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString()))); - // debug info - if (true) { - Show> st = Show.treeMapShow(Show.intShow, Show.stringShow); - Show, Option, TreeMap>> sp3 = Show.p3Show(st, Show.optionShow(Show.stringShow), st); - sp3.println(p3); - } - // do the assert Equal> tme = Equal.treeMapEqual(Equal.intEqual, Equal.stringEqual); Equal, Option, TreeMap>> eq = Equal.p3Equal(tme, Equal.optionEqual(Equal.stringEqual), tme); From ae70d20b6370531dca2efcd576eefbeb3e03228a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 29 Jul 2018 14:07:30 -0400 Subject: [PATCH 200/336] Implement Zipper Eq and Hash and add tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/Equal.java | 30 +++--- core/src/main/java/fj/Hash.java | 20 ++++ core/src/main/java/fj/data/Zipper.java | 23 +++-- core/src/test/java/fj/data/ZipperTest.java | 110 +++++++++++++++++++++ 4 files changed, 157 insertions(+), 26 deletions(-) create mode 100644 core/src/test/java/fj/data/ZipperTest.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index f427849a..9cf2a72a 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -1,19 +1,6 @@ package fj; -import fj.data.Array; -import fj.data.Either; -import fj.data.LazyString; -import fj.data.List; -import fj.data.Natural; -import fj.data.NonEmptyList; -import fj.data.Option; -import fj.data.Seq; -import fj.data.Set; -import fj.data.Stream; -import fj.data.Tree; -import fj.data.TreeMap; -import fj.data.Validation; -import fj.data.Writer; +import fj.data.*; import fj.data.hamt.BitSet; import fj.data.hlist.HList; import fj.data.vector.V2; @@ -455,6 +442,21 @@ public static Equal> streamEqual(final Equal ea) { }); } + /** + * An equal instance for the {@link Zipper} type. + * + * @param ea Equality across the elements of the zipper. + * @return An equal instance for the {@link Zipper} type. + */ + public static Equal> zipperEqual(final Equal ea) { + Equal> se = Equal.streamEqual(ea); + return equalDef((a1, a2) -> + se.eq(a1.lefts(), a2.lefts()) && + ea.eq(a1.focus(), a2.focus()) && + se.eq(a1.rights(), a2.rights()) + ); + } + /** * An equal instance for the {@link Array} type. * diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 14f8a9d7..708fe853 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -262,6 +262,26 @@ public static Hash> arrayHash(final Hash ha) { }); } + /** + * A hash instance for the {@link Zipper} type. + * + * @param ha A hash for the elements of the zipper. + * @return A hash instance for the {@link Zipper} type. + */ + public static Hash> zipperHash(final Hash ha) { + Hash> sh = streamHash(ha); + return hash(as -> { + final int p = 419; + int r = 239; + + r = p * r + sh.hash(as.lefts()); + r = p * r + ha.hash(as.focus()); + r = p * r + sh.hash(as.rights()); + + return r; + }); + } + /** * A hash instance for the {@link Tree} type. * diff --git a/core/src/main/java/fj/data/Zipper.java b/core/src/main/java/fj/data/Zipper.java index 24414ed2..2514d8e2 100644 --- a/core/src/main/java/fj/data/Zipper.java +++ b/core/src/main/java/fj/data/Zipper.java @@ -1,17 +1,6 @@ package fj.data; -import fj.Equal; -import fj.F; -import fj.F2; -import fj.F2Functions; -import fj.F3; -import fj.Function; -import fj.Ord; -import fj.P; -import fj.P1; -import fj.P2; -import fj.P3; -import fj.Show; +import fj.*; import fj.function.Integers; import java.util.Iterator; @@ -106,6 +95,16 @@ public static Ord> ord(final Ord o) { return Ord.p3Ord(so, o, so).contramap(Zipper.p_()); } + @Override + public final boolean equals(Object other) { + return Equal.equals0(Zipper.class, this, other, () -> Equal.zipperEqual(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.zipperHash(Hash.anyHash()).hash(this); + } + /** * An Equal instance for Zippers. * diff --git a/core/src/test/java/fj/data/ZipperTest.java b/core/src/test/java/fj/data/ZipperTest.java new file mode 100644 index 00000000..51c7b4ea --- /dev/null +++ b/core/src/test/java/fj/data/ZipperTest.java @@ -0,0 +1,110 @@ +package fj.data; + +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class ZipperTest { + @Test + public void testZipper() { + Zipper z = Zipper.zipper(Stream.nil(), 0, Stream.range(1, 9)); + assertThat(z.map(i -> i + 13).toStream(), is(Stream.range(13, 22))); + } + + @Test + public void testNext() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.single(3)); + z = z.next().some(); + assertThat(z.lefts(), is(Stream.arrayStream(new Integer[]{2, 1}))); + assertThat(z.focus(), is(3)); + assertThat(z.rights(), is(Stream.nil())); + } + + @Test + public void testNextNone() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.nil()); + assertThat(z.next().isNone(), is(true)); + } + + @Test + public void testCycleNext() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.single(3)); + assertThat(z.cycleNext(), is(z.next().some())); + } + + @Test + public void testCycleNextLast() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.nil()); + z = z.cycleNext(); + assertThat(z.lefts(), is(Stream.nil())); + assertThat(z.focus(), is(1)); + assertThat(z.rights(), is(Stream.single(2))); + } + + @Test + public void testPrevious() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.single(3)); + z = z.previous().some(); + assertThat(z.lefts(), is(Stream.nil())); + assertThat(z.focus(), is(1)); + assertThat(z.rights(), is(Stream.arrayStream(new Integer[]{2, 3}))); + } + + @Test + public void testPreviousNone() { + Zipper z = Zipper.zipper(Stream.nil(), 2, Stream.single(3)); + assertThat(z.previous().isNone(), is(true)); + } + + @Test + public void testCyclePrevious() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.single(3)); + assertThat(z.cyclePrevious(), is(z.previous().some())); + } + + @Test + public void testCyclePreviousFirst() { + Zipper z = Zipper.zipper(Stream.nil(), 1, Stream.single(2)); + z = z.cyclePrevious(); + assertThat(z.lefts(), is(Stream.single(1))); + assertThat(z.focus(), is(2)); + assertThat(z.rights(), is(Stream.nil())); + } + + @Test + public void testInsertLeft() { + Zipper z = Zipper.single(2); + z = z.insertLeft(1); + assertThat(z.lefts(), is(Stream.nil())); + assertThat(z.focus(), is(1)); + assertThat(z.rights(), is(Stream.single(2))); + } + + @Test + public void testInsertRight() { + Zipper z = Zipper.single(2); + z = z.insertRight(3); + assertThat(z.lefts(), is(Stream.single(2))); + assertThat(z.focus(), is(3)); + assertThat(z.rights(), is(Stream.nil())); + } + + @Test + public void testDeleteOthers() { + Zipper z = Zipper.zipper(Stream.single(1), 2, Stream.single(3)); + z = z.deleteOthers(); + assertThat(z.lefts(), is(Stream.nil())); + assertThat(z.focus(), is(2)); + assertThat(z.rights(), is(Stream.nil())); + } + + @Test + public void testFind() { + Zipper z = Zipper.zipper(Stream.nil(), 0, Stream.range(1)); + z = z.find(i -> i == 4).some(); + assertThat(z.lefts(), is(Stream.arrayStream(new Integer[]{3, 2, 1, 0}))); + assertThat(z.focus(), is(4)); + assertThat(z.rights().take(3), is(Stream.range(5, 8))); + } +} From 954a12b31c7430fe4af0aecb0492f02960cc0796 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Thu, 2 Aug 2018 17:26:56 -0400 Subject: [PATCH 201/336] Add Vector tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/data/vector/VTest.java | 62 ++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 core/src/test/java/fj/data/vector/VTest.java diff --git a/core/src/test/java/fj/data/vector/VTest.java b/core/src/test/java/fj/data/vector/VTest.java new file mode 100644 index 00000000..027b8407 --- /dev/null +++ b/core/src/test/java/fj/data/vector/VTest.java @@ -0,0 +1,62 @@ +package fj.data.vector; + +import fj.P; +import fj.P2; +import fj.P3; +import fj.P4; +import fj.P5; +import fj.P6; +import fj.P7; +import fj.P8; +import fj.data.Array; +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +public class VTest { + @Test + public void testVectorUp(){ + final P2 p2 = P.p(2, 1); + final V2 v2 = V2.p(p2); + final V3 v3 = V3.cons(P.p(3), v2); + final V4 v4 = V4.cons(P.p(4), v3); + final V5 v5 = V5.cons(P.p(5), v4); + final V6 v6 = V6.cons(P.p(6), v5); + final V7 v7 = V7.cons(P.p(7), v6); + final V8 v8 = V8.cons(P.p(8), v7); + assertThat(v8.toArray(), is(Array.range(1, 9).reverse())); + } + + @Test + public void testVectorP(){ + final P2 p2 = P.p(1, 2); + final V2 v2 = V2.p(p2); + assertThat(v2.toArray(), is(Array.range(1, 3))); + assertThat(v2.p(), is(p2)); + final P3 p3 = p2.append(3); + final V3 v3 = V3.p(p3); + assertThat(v3.toArray(), is(Array.range(1, 4))); + assertThat(v3.p(), is(p3)); + final P4 p4 = p3.append(4); + final V4 v4 = V4.p(p4); + assertThat(v4.toArray(), is(Array.range(1, 5))); + assertThat(v4.p(), is(p4)); + final P5 p5 = p4.append(5); + final V5 v5 = V5.p(p5); + assertThat(v5.toArray(), is(Array.range(1, 6))); + assertThat(v5.p(), is(p5)); + final P6 p6 = p5.append(6); + final V6 v6 = V6.p(p6); + assertThat(v6.toArray(), is(Array.range(1, 7))); + assertThat(v6.p(), is(p6)); + final P7 p7 = p6.append(7); + final V7 v7 = V7.p(p7); + assertThat(v7.toArray(), is(Array.range(1, 8))); + assertThat(v7.p(), is(p7)); + final P8 p8 = p7.append(8); + final V8 v8 = V8.p(p8); + assertThat(v8.toArray(), is(Array.range(1, 9))); + assertThat(v8.p(), is(p8)); + } +} From ba27e71970287988d0ca5125d7316439dd7dd1ef Mon Sep 17 00:00:00 2001 From: Gabor Liptak Date: Thu, 2 Aug 2018 20:41:08 -0400 Subject: [PATCH 202/336] Add Optic tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/data/optic/IsoTest.java | 43 ++++++ .../src/test/java/fj/data/optic/LensTest.java | 123 ++++++++++++++++++ .../test/java/fj/data/optic/OptionalTest.java | 29 +++++ .../test/java/fj/data/optic/PrismTest.java | 29 +++++ .../java/fj/data/optic/TraversalTest.java | 23 ++++ 5 files changed, 247 insertions(+) create mode 100644 core/src/test/java/fj/data/optic/IsoTest.java create mode 100644 core/src/test/java/fj/data/optic/LensTest.java create mode 100644 core/src/test/java/fj/data/optic/OptionalTest.java create mode 100644 core/src/test/java/fj/data/optic/PrismTest.java create mode 100644 core/src/test/java/fj/data/optic/TraversalTest.java diff --git a/core/src/test/java/fj/data/optic/IsoTest.java b/core/src/test/java/fj/data/optic/IsoTest.java new file mode 100644 index 00000000..6cace533 --- /dev/null +++ b/core/src/test/java/fj/data/optic/IsoTest.java @@ -0,0 +1,43 @@ +package fj.data.optic; + +import fj.P; +import fj.P2; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class IsoTest { + @Test + public void testIso() { + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Iso> addressIso = Iso.iso(p -> P.p(p.number, p.street), + p -> new Address(p._1(), p._2())); + final Address a = addressIso.reverseGet(addressIso.get(oldAddress)); + assertThat(a.number, is(oldAddress.number)); + assertThat(a.street, is(oldAddress.street)); + } + + static final class Person { + String name; + Address address; + + Person(String name, Address address) { + this.name = name; + this.address = address; + } + } + + static final class Address { + int number; + String street; + + public Address(int number, String street) { + this.number = number; + this.street = street; + } + } + +} diff --git a/core/src/test/java/fj/data/optic/LensTest.java b/core/src/test/java/fj/data/optic/LensTest.java new file mode 100644 index 00000000..d78fa0d0 --- /dev/null +++ b/core/src/test/java/fj/data/optic/LensTest.java @@ -0,0 +1,123 @@ +package fj.data.optic; + +import fj.F; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class LensTest { + @Test + public void testLensPersonGet() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personNameLens = Lens.lens(p -> p.name, s -> p -> new Person(s, p.address)); + final Lens personAddressLens = Lens.lens(p -> p.address, a -> p -> new Person(p.name, a)); + final Lens addressNumberLens = Lens.lens(a -> a.number, n -> a -> new Address(n, a.street)); + final Lens addressStreetLens = Lens.lens(a -> a.street, s -> a -> new Address(a.number, s)); + final Lens personNumberLens = personAddressLens.composeLens(addressNumberLens); + final Lens personStreetLens = personAddressLens.composeLens(addressStreetLens); + assertThat(personNameLens.get(oldPerson), is(oldName)); + assertThat(personNumberLens.get(oldPerson), is(oldNumber)); + assertThat(personStreetLens.get(oldPerson), is(oldStreet)); + } + + @Test + public void testLensPersonSetName() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personNameLens = Lens.lens(p -> p.name, s -> p -> new Person(s, p.address)); + String newName = "Bill"; + Person p = personNameLens.set(newName).f(oldPerson); + assertThat(p.name, is(newName)); + assertThat(p.address, is(oldPerson.address)); + } + + @Test + public void testLensPersonSetNumber() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personAddressLens = Lens.lens(p -> p.address, a -> p -> new Person(p.name, a)); + final Lens addressNumberLens = Lens.lens(a -> a.number, n -> a -> new Address(n, a.street)); + final Lens personNumberLens = personAddressLens.composeLens(addressNumberLens); + int newNumber = 20; + Person p = personNumberLens.set(newNumber).f(oldPerson); + assertThat(p.name, is(oldName)); + assertThat(p.address.number, is(newNumber)); + assertThat(p.address.street, is(oldStreet)); + } + + @Test + public void testLensPersonSetStreet() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personAddressLens = Lens.lens(p -> p.address, a -> p -> new Person(p.name, a)); + final Lens addressNumberLens = Lens.lens(a -> a.number, n -> a -> new Address(n, a.street)); + final Lens addressStreetLens = Lens.lens(a -> a.street, s -> a -> new Address(a.number, s)); + final Lens personStreetLens = personAddressLens.composeLens(addressStreetLens); + String newStreet = "First St"; + Person p = personStreetLens.set(newStreet).f(oldPerson); + assertThat(p.name, is(oldName)); + assertThat(p.address.number, is(oldPerson.address.number)); + assertThat(p.address.street, is(newStreet)); + } + + @Test + public void testLensPersonSetter() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personNameLens = Lens.lens(p -> p.name, s -> p -> new Person(s, p.address)); + String newName = "Bill"; + F setter = personNameLens.asSetter().set(newName); + Person p = setter.f(oldPerson); + assertThat(p.name, is(newName)); + assertThat(p.address, is(oldPerson.address)); + } + + @Test + public void testLensPersonGetter() { + final String oldName = "Joe"; + final int oldNumber = 10; + final String oldStreet = "Main St"; + final Address oldAddress = new Address(oldNumber, oldStreet); + final Person oldPerson = new Person(oldName, oldAddress); + final Lens personNameLens = Lens.lens(p -> p.name, s -> p -> new Person(s, p.address)); + assertThat(personNameLens.asGetter().get(oldPerson), is(oldName)); + } + + static final class Person { + String name; + Address address; + + Person(String name, Address address) { + this.name = name; + this.address = address; + } + } + + static final class Address { + int number; + String street; + + public Address(int number, String street) { + this.number = number; + this.street = street; + } + } + +} diff --git a/core/src/test/java/fj/data/optic/OptionalTest.java b/core/src/test/java/fj/data/optic/OptionalTest.java new file mode 100644 index 00000000..07c3f79a --- /dev/null +++ b/core/src/test/java/fj/data/optic/OptionalTest.java @@ -0,0 +1,29 @@ +package fj.data.optic; + +import fj.data.Option; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class OptionalTest { + @Test + public void testOptionalSome() { + Optional o = Optional.optional(this::decode, i -> s -> s); + assertThat(o.getOption("18"), is(Option.some(18))); + } + + @Test + public void testOptionalNone() { + Optional o = Optional.optional(this::decode, i -> s -> s); + assertThat(o.getOption("Z"), is(Option.none())); + } + + private Option decode(String s) { + try { + return Option.some(Integer.decode(s)); + } catch (NumberFormatException nfe) { + return Option.none(); + } + } +} diff --git a/core/src/test/java/fj/data/optic/PrismTest.java b/core/src/test/java/fj/data/optic/PrismTest.java new file mode 100644 index 00000000..da128d72 --- /dev/null +++ b/core/src/test/java/fj/data/optic/PrismTest.java @@ -0,0 +1,29 @@ +package fj.data.optic; + +import fj.data.Option; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class PrismTest { + @Test + public void testPrismSome() { + Prism prism = Prism.prism(s -> decode(s), i -> i.toString()); + assertThat(prism.getOption("18"), is(Option.some(18))); + } + + @Test + public void testPrismNone() { + Prism prism = Prism.prism(s -> decode(s), i -> i.toString()); + assertThat(prism.getOption("Z"), is(Option.none())); + } + + private Option decode(String s) { + try { + return Option.some(Integer.decode(s)); + } catch (NumberFormatException nfe) { + return Option.none(); + } + } +} diff --git a/core/src/test/java/fj/data/optic/TraversalTest.java b/core/src/test/java/fj/data/optic/TraversalTest.java new file mode 100644 index 00000000..cadd6ccf --- /dev/null +++ b/core/src/test/java/fj/data/optic/TraversalTest.java @@ -0,0 +1,23 @@ +package fj.data.optic; + +import fj.Monoid; +import fj.data.Either; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class TraversalTest { + @Test + public void testTraversalLeft() { + final Traversal, Integer> t = Traversal.codiagonal(); + assertThat(t.fold(Monoid.intMinMonoid).f(Either.left(3)), is(3)); + } + + @Test + public void testTraversalRight() { + final Traversal, Integer> t = Traversal.codiagonal(); + assertThat(t.fold(Monoid.intMinMonoid).f(Either.right(2)), is(2)); + } + +} From 22cf4b4a06298c79701e61384fa5baffb0eb34a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Fri, 3 Aug 2018 21:03:45 -0400 Subject: [PATCH 203/336] Add Parser tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/Equal.java | 8 +++ core/src/main/java/fj/Hash.java | 20 ++++++++ core/src/main/java/fj/Show.java | 14 ++++++ core/src/main/java/fj/parser/Result.java | 19 +++++++ core/src/test/java/fj/parser/ParserTest.java | 52 ++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 core/src/test/java/fj/parser/ParserTest.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 9cf2a72a..a798a736 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -10,6 +10,7 @@ import fj.data.vector.V6; import fj.data.vector.V7; import fj.data.vector.V8; +import fj.parser.Result; import java.math.BigDecimal; import java.math.BigInteger; @@ -355,6 +356,13 @@ public static Equal> eitherEqual(final Equal ea, final Eq )); } + public static Equal> resultEqual(final Equal ea, final Equal ei) { + Definition eaDef = ea.def; + Definition eiDef= ei.def; + return equalDef((r1, r2) -> eaDef.equal(r1.value(), r2.value()) && eiDef.equal(r1.rest(), r2.rest())); + } + + /** * An equal instance for the {@link Validation} type. * diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 708fe853..da443ab2 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -10,6 +10,7 @@ import fj.data.vector.V6; import fj.data.vector.V7; import fj.data.vector.V8; +import fj.parser.Result; import java.math.BigDecimal; import java.math.BigInteger; @@ -162,6 +163,25 @@ public static Hash> eitherHash(final Hash ha, final Hash< return hash(e -> e.isLeft() ? ha.hash(e.left().value()) : hb.hash(e.right().value())); } + /** + * A hash instance for the {@link Result} type. + * + * @param ha Hash the Result value. + * @param hi Hash the Result remainder. + * @return A hash instance for the {@link Result} type. + */ + public static Hash> resultHash(Hash ha, Hash hi) { + return hash(res -> { + final int p = 419; + int r = 239; + + r = p * r + ha.hash(res.value()); + r = p * r + hi.hash(res.rest()); + + return r; + }); + } + /** * A hash instance for the {@link Validation} type. * diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 2d2c4707..cd57897b 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -12,6 +12,7 @@ import fj.data.vector.V6; import fj.data.vector.V7; import fj.data.vector.V8; +import fj.parser.Result; import java.math.BigDecimal; import java.math.BigInteger; @@ -255,6 +256,19 @@ public static Show> eitherShow(final Show sa, final Show< fromString("Right(").append(sb.f.f(e.right().value())).append(single(')'))); } + /** + * A show instance for the {@link Result} type. + * + * @param sa Show for the {@link Result} value. + * @param si Show for the {@link Result} remainder. + * @return A show instance for the {@link Result} type. + */ + public static Show> resultShow(Show sa, Show si) { + return show(res -> + fromString("Result(").append(sa.f.f(res.value())) + .append(single(',')).append(si.f.f(res.rest())).append(single(')'))); + } + /** * A show instance for the {@link Validation} type. * diff --git a/core/src/main/java/fj/parser/Result.java b/core/src/main/java/fj/parser/Result.java index 51e115f6..b8acc6c4 100644 --- a/core/src/main/java/fj/parser/Result.java +++ b/core/src/main/java/fj/parser/Result.java @@ -1,6 +1,9 @@ package fj.parser; +import fj.Equal; import fj.F; +import fj.Hash; +import fj.Show; import static fj.Function.curry; @@ -21,6 +24,22 @@ private Result(final I i, final A a) { this.a = a; } + @Override + public final int hashCode() { + return Hash.resultHash(Hash.anyHash(), Hash.anyHash()).hash(this); + } + + @Override + public final String toString() { + return Show.resultShow(Show.anyShow(), Show.anyShow()).showS(this); + } + + @Override + public final boolean equals(Object other) { + return Equal.equals0(Result.class, this, other, () -> Equal.resultEqual(Equal.anyEqual(), Equal.anyEqual())); + } + + /** * The remainder of the parse input. * diff --git a/core/src/test/java/fj/parser/ParserTest.java b/core/src/test/java/fj/parser/ParserTest.java new file mode 100644 index 00000000..a3f623f5 --- /dev/null +++ b/core/src/test/java/fj/parser/ParserTest.java @@ -0,0 +1,52 @@ +package fj.parser; + +import fj.F; +import fj.F0; +import fj.data.Stream; +import fj.data.Validation; +import org.junit.Test; + +import static fj.parser.Result.result; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class ParserTest { + @Test + public void testParserFail() { + final Parser fail = Parser.fail(new ParseException()); + assertThat(fail.parse("").fail(), is(new ParseException())); + } + + @Test + public void testParserValue() { + final Parser p = Parser.parser(s -> s.isEmpty() ? + Validation.fail(new ParseException()) : + Validation.success(result(s.substring(1), s.substring(0, 1))) + ); + final Result r = p.parse("abc").success(); + assertThat(r.value(), is("a")); + assertThat(r.rest(), is("bc")); + } + + @Test + public void testParserBind() { + final Parser p = Parser.value("a"); + final Parser fail = Parser.fail(new ParseException()); + assertThat(p.bind(o -> fail).parse("aaaa").fail(), is(new ParseException())); + } + + @Test + public void testParserStream() { + Stream s = Stream.fromString("abc"); + Result, Character> r = Parser.CharsParser.character('a').parse(s).success(); + assertThat(r, is(Result.result(Stream.fromString("bc"), 'a'))); + } + + class ParseException extends Exception { + @Override + public boolean equals (Object obj) { + return (obj instanceof ParseException); + } + } + +} From ca67637f62aba38fc84056378601b9e88bb69a0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 4 Aug 2018 15:24:14 -0400 Subject: [PATCH 204/336] Implement Vector equals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/data/vector/V2.java | 10 ++++ core/src/main/java/fj/data/vector/V3.java | 10 ++++ core/src/main/java/fj/data/vector/V4.java | 10 ++++ core/src/main/java/fj/data/vector/V5.java | 10 ++++ core/src/main/java/fj/data/vector/V6.java | 10 ++++ core/src/main/java/fj/data/vector/V7.java | 10 ++++ core/src/main/java/fj/data/vector/V8.java | 10 ++++ core/src/test/java/fj/data/vector/VTest.java | 60 +++++++++++++++++--- 8 files changed, 122 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/data/vector/V2.java b/core/src/main/java/fj/data/vector/V2.java index fdab115c..d1ec5e74 100644 --- a/core/src/main/java/fj/data/vector/V2.java +++ b/core/src/main/java/fj/data/vector/V2.java @@ -23,6 +23,16 @@ private V2(final P2 inner) { this.inner = inner; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V2.class, this, other, () -> Equal.v2Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v2Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-2 from a homogeneous product-2. * diff --git a/core/src/main/java/fj/data/vector/V3.java b/core/src/main/java/fj/data/vector/V3.java index 9b25258f..523c08ae 100644 --- a/core/src/main/java/fj/data/vector/V3.java +++ b/core/src/main/java/fj/data/vector/V3.java @@ -23,6 +23,16 @@ private V3(final P1 head, final V2 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V3.class, this, other, () -> Equal.v3Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v3Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-3 from a homogeneous product-3. * diff --git a/core/src/main/java/fj/data/vector/V4.java b/core/src/main/java/fj/data/vector/V4.java index 1f39346b..808e7bab 100644 --- a/core/src/main/java/fj/data/vector/V4.java +++ b/core/src/main/java/fj/data/vector/V4.java @@ -23,6 +23,16 @@ private V4(final P1 head, final V3 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V4.class, this, other, () -> Equal.v4Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v4Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-4 from a homogeneous product-4. * diff --git a/core/src/main/java/fj/data/vector/V5.java b/core/src/main/java/fj/data/vector/V5.java index 0119dcf9..8f0583a3 100644 --- a/core/src/main/java/fj/data/vector/V5.java +++ b/core/src/main/java/fj/data/vector/V5.java @@ -23,6 +23,16 @@ private V5(final P1 head, final V4 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V5.class, this, other, () -> Equal.v5Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v5Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-5 from a homogeneous product-5. * diff --git a/core/src/main/java/fj/data/vector/V6.java b/core/src/main/java/fj/data/vector/V6.java index 47a0c4e7..880deaff 100644 --- a/core/src/main/java/fj/data/vector/V6.java +++ b/core/src/main/java/fj/data/vector/V6.java @@ -23,6 +23,16 @@ private V6(final P1 head, final V5 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V6.class, this, other, () -> Equal.v6Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v6Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-6 from a homogeneous product-6. * diff --git a/core/src/main/java/fj/data/vector/V7.java b/core/src/main/java/fj/data/vector/V7.java index c0dfa4b6..2127d5f4 100644 --- a/core/src/main/java/fj/data/vector/V7.java +++ b/core/src/main/java/fj/data/vector/V7.java @@ -23,6 +23,16 @@ private V7(final P1 head, final V6 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V7.class, this, other, () -> Equal.v7Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v7Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-7 from a homogeneous product-7. * diff --git a/core/src/main/java/fj/data/vector/V8.java b/core/src/main/java/fj/data/vector/V8.java index f01dc2fe..9ca7b618 100644 --- a/core/src/main/java/fj/data/vector/V8.java +++ b/core/src/main/java/fj/data/vector/V8.java @@ -23,6 +23,16 @@ private V8(final P1 head, final V7 tail) { this.tail = tail; } + @Override + public final boolean equals(Object other) { + return Equal.equals0(V8.class, this, other, () -> Equal.v8Equal(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.v8Hash(Hash.anyHash()).hash(this); + } + /** * Creates a vector-8 from a homogeneous product-8. * diff --git a/core/src/test/java/fj/data/vector/VTest.java b/core/src/test/java/fj/data/vector/VTest.java index 027b8407..9a3709ac 100644 --- a/core/src/test/java/fj/data/vector/VTest.java +++ b/core/src/test/java/fj/data/vector/VTest.java @@ -1,13 +1,6 @@ package fj.data.vector; -import fj.P; -import fj.P2; -import fj.P3; -import fj.P4; -import fj.P5; -import fj.P6; -import fj.P7; -import fj.P8; +import fj.*; import fj.data.Array; import org.junit.Test; @@ -59,4 +52,55 @@ public void testVectorP(){ assertThat(v8.toArray(), is(Array.range(1, 9))); assertThat(v8.p(), is(p8)); } + + @Test + public void testVectorFunc2() { + V2 v2 = V.v(() -> 2, () -> 1); + F2> fv2 = V.v2(); + V2 vf2 = fv2.f(2, 1); + assertThat(vf2, is(v2)); + } + + @Test + public void testVectorFunc3() { + V3 v3 = V.v(P.p(3), () -> 2, () -> 1); + F3> fv3 = V.v3(); + V3 vf3 = fv3.f(3, 2, 1); + assertThat(vf3, is(v3)); + } + + @Test + public void testVectorFunc4() { + V4 v4 = V.v(P.p(4), P.p(3), () -> 2, () -> 1); + F4> fv4 = V.v4(); + V4 vf4 = fv4.f(4, 3, 2, 1); + assertThat(vf4, is(v4)); + } + + @Test + public void testVectorFunc5() { + V5 v5 = V.v(P.p(5), P.p(4), P.p(3), () -> 2, () -> 1); + F5> fv5 = V.v5(); + V5 vf5 = fv5.f(5, 4, 3, 2, 1); + assertThat(vf5, is(v5)); + } + + @Test + public void testVectorMap() { + final V2 v2 = V.v(() -> 2, () -> 1); + assertThat(v2, is(v2.map(i -> i * 1))); + final V3 v3 = V3.cons(P.p(3), v2); + assertThat(v3, is(v3.map(i -> i * 1))); + final V4 v4 = V4.cons(P.p(4), v3); + assertThat(v4, is(v4.map(i -> i * 1))); + final V5 v5 = V5.cons(P.p(5), v4); + assertThat(v5, is(v5.map(i -> i * 1))); + final V6 v6 = V6.cons(P.p(6), v5); + assertThat(v6, is(v6.map(i -> i * 1))); + final V7 v7 = V7.cons(P.p(7), v6); + assertThat(v7, is(v7.map(i -> i * 1))); + final V8 v8 = V8.cons(P.p(8), v7); + assertThat(v8, is(v8.map(i -> i * 1))); + } + } From 7e149a63b478ce943b4e8c5d2cd5c7c909a71eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 11 Aug 2018 19:42:46 -0400 Subject: [PATCH 205/336] Add FingerTree tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/FWFunctionsTest.java | 1 - .../fj/data/fingertrees/FingerTreeTest.java | 37 ++++++++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/core/src/test/java/fj/FWFunctionsTest.java b/core/src/test/java/fj/FWFunctionsTest.java index b9ce65d5..c1f69718 100644 --- a/core/src/test/java/fj/FWFunctionsTest.java +++ b/core/src/test/java/fj/FWFunctionsTest.java @@ -2,7 +2,6 @@ import org.junit.Test; -import fj.F1W; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 2a64b44b..57e1fae6 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -1,19 +1,19 @@ package fj.data.fingertrees; +import fj.Function; import fj.P; import fj.P2; -import fj.Show; import fj.data.List; -import fj.data.Stream; +import fj.data.Option; import org.junit.Test; -import static fj.P.p; -import static fj.Show.intShow; -import static fj.test.Property.prop; -import static fj.test.Property.property; -import static java.lang.System.out; +import static fj.Monoid.intAdditionMonoid; +import static fj.Monoid.intMinMonoid; +import static fj.data.fingertrees.FingerTree.measured; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; +import static org.hamcrest.core.Is.is; + /** * Created by MarkPerry on 10/10/2015. @@ -24,18 +24,35 @@ public class FingerTreeTest { @Test public void size() { - validateSize(List.list(-92, 68, 54, -77, -18, 67)); - validateSize(List.list(-92, 68, 54, -77, -18, 67, -60, 23, -70, 99, 66, -79, -5)); + validateOperations(List.list(-92, 68, 54, -77, -18, 67)); + validateOperations(List.list(-92, 68, 54, -77, -18, 67, -60, 23, -70, 99, 66, -79, -5)); } - void validateSize(List list) { + void validateOperations(List list) { FingerTree ft = list.foldLeft( (acc, i) -> acc.snoc(i), FingerTree.emptyIntAddition() ); assertThat(ft.measure(), equalTo(list.length())); + assertThat(ft.foldLeft((s, i) -> s + 1, 0), equalTo(list.length())); + assertThat(ft.foldRight((i, s) -> 1 + s, 0), equalTo(list.length())); + assertThat(ft.filter(e -> e.equals(-77)).head(), equalTo(-77)); assertThat(ft.length(), equalTo(list.length())); } + @Test + public void testHeadOption() { + assertThat(Empty.emptyIntAddition().headOption(), is(Option.none())); + FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1); + assertThat(ft.headOption(), is(Option.some(1))); + } + + @Test + public void testUncons() { + assertThat(Empty.emptyIntAddition().uncons(0, (h, t) -> h), is(0)); + FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1); + assertThat(ft.uncons(0, (h, t) -> h), is(1)); + } + public FingerTree midSeq() { FingerTree ft = FingerTree.emptyIntAddition(); return List.range(1, SIZE).foldLeft(ft2 -> i -> ft2.snoc(i), ft); From c2392a12e6e4a4f61508a2fd0f9e905bd5d65c0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 13 Aug 2018 16:40:27 -0400 Subject: [PATCH 206/336] Add Reader/Writer tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- props-core/src/test/java/fj/data/ReaderTest.java | 16 +++++++++++++++- props-core/src/test/java/fj/data/WriterTest.java | 14 ++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 8494336e..87e2b52a 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -11,6 +11,8 @@ import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; import static fj.test.Property.property; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; /** @@ -24,7 +26,6 @@ public void testMap() { // example taken from http://learnyouahaskell.com/for-a-few-monads-more int x = Reader.unit((Integer i) -> i + 3).map(i -> i * 5).f(8); assertTrue(x == 55); -// System.out.println(x); // 55 } @Test @@ -108,6 +109,19 @@ public void testAssociativity() { PropertyAssert.assertResult(p); } + @Test + public void testAndThen() { + final int y = Reader.unit((Integer i) -> i * 2).andThen(i -> i + 10).f(10); + assertThat(y, is(30)); + } + + @Test + public void testBind() { + final int y = Reader.unit((Integer i) -> i * 2) + .bind(a -> Reader.unit(i -> a + i + 11)).f(10); + assertThat(y, is(41)); + } + public Gen> arbReader() { return Arbitrary.arbReader(cogenInteger, arbInteger); } diff --git a/props-core/src/test/java/fj/data/WriterTest.java b/props-core/src/test/java/fj/data/WriterTest.java index 5f0ac122..25f99b22 100644 --- a/props-core/src/test/java/fj/data/WriterTest.java +++ b/props-core/src/test/java/fj/data/WriterTest.java @@ -2,8 +2,7 @@ import fj.Equal; import fj.F; -import fj.data.test.PropertyAssert; -import fj.test.Arbitrary; +import fj.P; import fj.test.Gen; import fj.test.Property; import org.junit.Assert; @@ -14,7 +13,8 @@ import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; import static fj.test.Property.property; -import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.core.Is.is; /** * Created by MarkPerry on 17/12/2014. @@ -107,7 +107,13 @@ public void testAssociativity() { assertResult(p); } - + @Test + public void testUnit() { + Writer w = Writer.unit("+").tell("foo").tell("bar"); + assertThat(w.run(), is(P.p("foobar", "+"))); + assertThat(w.log(), is("foobar")); + assertThat(w.value(), is("+")); + } } From 69fbd1d451d3382aee4e5bca5bd775b6631fc0d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 12 Aug 2018 13:04:21 -0400 Subject: [PATCH 207/336] Add TreeZipper tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/Equal.java | 20 ++++++++++++ core/src/main/java/fj/Hash.java | 26 ++++++++++++++- core/src/main/java/fj/data/TreeZipper.java | 25 +++++++++++++-- core/src/test/java/fj/FFunctionsTest.java | 18 +++++++++++ .../src/test/java/fj/data/TreeZipperTest.java | 32 +++++++++++++++++++ 5 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 core/src/test/java/fj/data/TreeZipperTest.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index a798a736..5cd31aeb 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -3,6 +3,7 @@ import fj.data.*; import fj.data.hamt.BitSet; import fj.data.hlist.HList; +import fj.data.optic.Traversal; import fj.data.vector.V2; import fj.data.vector.V3; import fj.data.vector.V4; @@ -466,6 +467,25 @@ public static Equal> zipperEqual(final Equal ea) { } /** + * An equal instance for the {@link TreeZipper} type. + * + * @param ea Equality across the elements of the tree zipper. + * @return An equal instance for the {@link TreeZipper} type. + */ + public static Equal> treeZipperEqual(final Equal ea) { + final Equal> te = Equal.treeEqual(ea); + final Equal>> st = streamEqual(Equal.treeEqual(ea)); + final Equal>, A, Stream>>>> sp = + streamEqual(p3Equal(streamEqual(treeEqual(ea)), ea, streamEqual(treeEqual(ea)))); + return equalDef((a1, a2) -> + te.eq(a1.focus(), a2.focus()) && + st.eq(a1.lefts(), a2.lefts()) && + st.eq(a1.rights(), a2.rights()) && + sp.eq(a1.parents(), a2.parents()) + ); + } + + /** * An equal instance for the {@link Array} type. * * @param ea Equality across the elements of the array. diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index da443ab2..8d0a4e4c 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -302,7 +302,31 @@ public static Hash> zipperHash(final Hash ha) { }); } - /** + /** + * A hash instance for the {@link TreeZipper} type. + * + * @param ha A hash for the elements of the tree zipper. + * @return A hash instance for the {@link TreeZipper} type. + */ + public static Hash> treeZipperHash(final Hash ha) { + Hash> th = treeHash(ha); + Hash>> sth = streamHash(treeHash(ha)); + Hash>, A, Stream>>>> tsp = + streamHash(p3Hash(streamHash(treeHash(ha)), ha, streamHash(treeHash(ha)))); + return hash(as -> { + final int p = 419; + int r = 239; + + r = p * r + th.hash(as.focus()); + r = p * r + sth.hash(as.lefts()); + r = p * r + sth.hash(as.rights()); + r = p * r + tsp.hash(as.parents()); + + return r; + }); + } + + /** * A hash instance for the {@link Tree} type. * * @param ha A hash for the elements of the tree. diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index c94287cf..46392d20 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -54,7 +54,17 @@ private TreeZipper(final Tree tree, this.parents = parents; } - /** + @Override + public final boolean equals(Object other) { + return Equal.equals0(TreeZipper.class, this, other, () -> Equal.treeZipperEqual(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.treeZipperHash(Hash.anyHash()).hash(this); + } + + /** * Creates a new tree zipper given a currently selected tree, a forest on the left, a forest on the right, * and a stream of parent contexts. * @@ -341,8 +351,17 @@ public Stream> lefts() { * @return the right siblings of the currently focused node. */ public Stream> rights() { - return rights; - } + return rights; + } + + /** + * Returns the parents of the currently focused node. + * + * @return the parents of the currently focused node. + */ + public Stream>, A, Stream>>> parents() { + return parents; + } /** * Indicates whether the current node is at the top of the tree. diff --git a/core/src/test/java/fj/FFunctionsTest.java b/core/src/test/java/fj/FFunctionsTest.java index 9d38e1f5..e13b1f2b 100644 --- a/core/src/test/java/fj/FFunctionsTest.java +++ b/core/src/test/java/fj/FFunctionsTest.java @@ -1,5 +1,7 @@ package fj; +import fj.data.Tree; +import fj.data.TreeZipper; import org.junit.Test; import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; @@ -22,4 +24,20 @@ public void testApply() { F f1 = F2Functions.f(f2, 2); assertThat(F1Functions.f(f1, 1).f(), is(36)); } + + @Test + public void testTreeK() { + final Tree t1 = F1Functions.treeK(Function.identity()).f(1); + final Tree t2 = F1Functions.treeK(Function.identity()).f(2); + assertThat(F1Functions.mapTree(i -> i + 1).f(t1), + is(F1Functions.mapTree(i -> i * 1).f(t2))); + } + + @Test + public void testTreeZipperK() { + final TreeZipper tz1 = F1Functions.treeZipperK(Function.identity()).f(1); + final TreeZipper tz2 = F1Functions.treeZipperK(Function.identity()).f(2); + assertThat(F1Functions.mapTreeZipper(i -> i + 1).f(tz1), + is(F1Functions.mapTreeZipper(i -> i * 1).f(tz2))); + } } diff --git a/core/src/test/java/fj/data/TreeZipperTest.java b/core/src/test/java/fj/data/TreeZipperTest.java new file mode 100644 index 00000000..c52f4111 --- /dev/null +++ b/core/src/test/java/fj/data/TreeZipperTest.java @@ -0,0 +1,32 @@ +package fj.data; + +import org.junit.Test; + +import static fj.data.Option.none; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class TreeZipperTest { + @Test + public void testDelete() { + final Tree t = Tree.node(1, List.single(Tree.leaf(2))); + final TreeZipper tz = TreeZipper.fromTree(t); + assertThat(tz.delete(), is(none())); + } + + @Test + public void testDeleteForest() { + final Tree t = Tree.node(1, List.single(Tree.leaf(2))); + final TreeZipper tz = TreeZipper.fromForest(Stream.single(t)).some(); + assertThat(tz.delete(), is(none())); + + } + + @Test + public void testHash() { + final Tree t = Tree.node(1, List.single(Tree.leaf(2))); + final TreeZipper tz1 = TreeZipper.fromForest(Stream.single(t)).some(); + final TreeZipper tz2 = TreeZipper.fromForest(Stream.single(t)).some(); + assertThat(tz1.hashCode(), is(tz2.hashCode())); + } +} From 02d05ebaa451c33a1c0eedbcc1408e35eec7ad60 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 18 Aug 2018 22:41:08 +0200 Subject: [PATCH 208/336] ChangeLog of 4.8 release. --- .changelogged.yaml | 14 ++++++++++++++ ChangeLog.md | 33 +++++++++++++++++++++++++++++++++ build.gradle | 4 ++-- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 .changelogged.yaml create mode 100644 ChangeLog.md diff --git a/.changelogged.yaml b/.changelogged.yaml new file mode 100644 index 00000000..46180488 --- /dev/null +++ b/.changelogged.yaml @@ -0,0 +1,14 @@ +changelogs: + - changelog: ChangeLog.md + + ignore_files: + - "*ChangeLog*.md" + - .changelogged.yaml + + ignore_commits: [] + +branch: upstream/master + +entry_format: " - %message% (see [%link%](%id%));" + +editor_command: "nano -EiT 2" diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 00000000..24276f35 --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,33 @@ +4.8 +--- + +### Enhancements + +- Enable upload of snapshot artifacts. (see [`e834e8b`](https://github.com/functionaljava/functionaljava/commit/e834e8b)); +- Add append methods to all Px classes. Fix #326 (see [`065ed43`](https://github.com/functionaljava/functionaljava/commit/065ed43)); +- Introduce the Eval monad (see [`98294fc`](https://github.com/functionaljava/functionaljava/commit/98294fc)); +- Fluent Equal/Ord construction (see [#333](https://github.com/functionaljava/functionaljava/pull/333)); +- Implement Zipper Eq and Hash and add tests (see [#343](https://github.com/functionaljava/functionaljava/pull/343)); +- Implement Vector equals (see [#350](https://github.com/functionaljava/functionaljava/pull/350)); + +### Fixes + +- Fixed a bug in the NonEmptyList Semigroup implementation that resulted in the same NonEmptyList appended to itself. (Regression in 4.7, see [`07f94fa`](https://github.com/functionaljava/functionaljava/commit/07f94fa)); +- Fixes #334: exception in Either.LeftProjection.traverseIO (see [#335](https://github.com/functionaljava/functionaljava/pull/335)); + +### Internal + +- Added Scalacheck Arbitrary implementations for Natural and NonEmptyList. (see [`405c3ec`](https://github.com/functionaljava/functionaljava/commit/405c3ec)); +- Added unit test coverage for Semigroup implementations. The StringBuffer and StringBuilder tests fail because both of those types are mutable. The IO test fails because the ArbitraryIO implementation does not implement equals. (see [`ef81130`](https://github.com/functionaljava/functionaljava/commit/ef81130)); +- Fixed the ArbitraryIO implementation and created a Properties object for testing the IO semigroup. (see [`a8e979f`](https://github.com/functionaljava/functionaljava/commit/a8e979f)); +- Added working tests coverage for the StringBuffer and StringBuilder semigroup implementations. Added the Semigroup tests to the list of Scalacheck test suite. (see [`aa4de33`](https://github.com/functionaljava/functionaljava/commit/aa4de33)); +- Equal: remove reference to static field of LazyString. Fix #321 (see [`6c6dabd`](https://github.com/functionaljava/functionaljava/commit/6c6dabd)); +- Add IOFunctions tests (see [#340](https://github.com/functionaljava/functionaljava/pull/340)); +- Add Stream tests (see [#341](https://github.com/functionaljava/functionaljava/pull/341)); +- Add tests for Try, F, FW, Digit (see [#346](https://github.com/functionaljava/functionaljava/pull/346)); +- Add Vector tests (see [#347](https://github.com/functionaljava/functionaljava/pull/347)); +- Add Optic tests (see [#348](https://github.com/functionaljava/functionaljava/pull/348)); +- Add Parser tests (see [#349](https://github.com/functionaljava/functionaljava/pull/349)); +- Add FingerTree tests (see [#351](https://github.com/functionaljava/functionaljava/pull/351)); +- Add TreeZipper tests (see [#352](https://github.com/functionaljava/functionaljava/pull/352)); +- Add Reader/Writer tests (see [#353](https://github.com/functionaljava/functionaljava/pull/353)); \ No newline at end of file diff --git a/build.gradle b/build.gradle index a1098cbb..9410f205 100644 --- a/build.gradle +++ b/build.gradle @@ -45,7 +45,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true + isSnapshot = false fjBaseVersion = "4.8" snapshotAppendix = "-SNAPSHOT" @@ -53,7 +53,7 @@ allprojects { fjConsumeVersion = "4.7" signModule = false - useRetroLambda = false + useRetroLambda = true projectTitle = "Functional Java" projectName = "functionaljava" From 8cce3ee2d3c221a67b06e48f616532ecfa58b122 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 18 Aug 2018 23:29:19 +0200 Subject: [PATCH 209/336] Update readme. Prepare next iteration. --- README.adoc | 18 +++++++++--------- build.gradle | 10 +++++----- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/README.adoc b/README.adoc index 6c5d3c1e..a7e2d3a4 100644 --- a/README.adoc +++ b/README.adoc @@ -35,12 +35,12 @@ The Functional Java artifact is published to Maven Central using the group `org. * Java 8 specific support (`functionaljava-java8`) * property based testing (`functionaljava-quickcheck` or `functionaljava-quickcheck_1.8` if you use Java 8+) -The latest stable version is `4.7`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `4.8`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.7" -compile "org.functionaljava:functionaljava-java8:4.7" -compile "org.functionaljava:functionaljava-quickcheck:4.7" -compile "org.functionaljava:functionaljava-java-core:4.7" +compile "org.functionaljava:functionaljava:4.8" +compile "org.functionaljava:functionaljava-java8:4.8" +compile "org.functionaljava:functionaljava-quickcheck:4.8" +compile "org.functionaljava:functionaljava-java-core:4.8" ---- and in Maven: @@ -48,22 +48,22 @@ and in Maven: org.functionaljava functionaljava - 4.7 + 4.8 org.functionaljava functionaljava-java8 - 4.7 + 4.8 org.functionaljava functionaljava-quickcheck - 4.7 + 4.8 org.functionaljava functionaljava-java-core - 4.7 + 4.8 ---- diff --git a/build.gradle b/build.gradle index 9410f205..fe81f484 100644 --- a/build.gradle +++ b/build.gradle @@ -44,16 +44,16 @@ allprojects { defaultTasks "build" - ext { - isSnapshot = false - fjBaseVersion = "4.8" + ext { + isSnapshot = true + fjBaseVersion = "4.9" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.7" + fjConsumeVersion = "4.8" signModule = false - useRetroLambda = true + useRetroLambda = false projectTitle = "Functional Java" projectName = "functionaljava" From fd9b337abe0927bc8d2f5b149198bc84a77c0b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 18 Aug 2018 18:23:40 -0400 Subject: [PATCH 210/336] Add Visitor tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- .../test/java/fj/function/VisitorTest.java | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 core/src/test/java/fj/function/VisitorTest.java diff --git a/core/src/test/java/fj/function/VisitorTest.java b/core/src/test/java/fj/function/VisitorTest.java new file mode 100644 index 00000000..54efcf24 --- /dev/null +++ b/core/src/test/java/fj/function/VisitorTest.java @@ -0,0 +1,80 @@ +package fj.function; + +import fj.Equal; +import fj.F; +import fj.P; +import fj.P1; +import fj.data.List; +import org.junit.Test; + +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.function.Visitor.*; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class VisitorTest { + @Test + public void testFindFirst() { + assertThat(findFirst(List.list(none(), some(1), none()), () -> -1), is(1)); + } + + @Test + public void testFindFirstDef() { + assertThat(findFirst(List.list(none(), none(), none()), () -> -1), is(-1)); + } + + @Test + public void testNullableFindFirst() { + assertThat(nullablefindFirst(List.list(null, 1, null), () -> -1), is(1)); + } + + @Test + public void testNullableFindFirstDef() { + assertThat(nullablefindFirst(List.list(null, null, null), () -> -1), is(-1)); + } + + @Test + public void testVisitor() { + assertThat(visitor(List.list(i -> some(2 * i)), () -> -1, 10), is(20)); + } + + @Test + public void testVisitorDef() { + assertThat(visitor(List.list(i -> none()), () -> "foo", 10), is("foo")); + } + + @Test + public void testNullableVisitor() { + assertThat(nullableVisitor(List.list(i -> 2 * i), () -> -1, 10), is(20)); + } + + @Test + public void testNullableVisitorDef() { + assertThat(nullableVisitor(List.list(i -> null), () -> "foo", 10), is("foo")); + } + + @Test + public void testAssociation() { + final F> a = association(List.list(P.p(1, "one"), P.p(2, "two")), Equal.intEqual); + assertThat(a.f("foo").f(2), is("two")); + } + + @Test + public void testAssociationDef() { + final F> a = association(List.list(P.p(1, "one"), P.p(2, "two")), Equal.intEqual); + assertThat(a.f("foo").f(3), is("foo")); + } + + @Test + public void testAssociationLazy() { + final F, F> a = associationLazy(List.list(P.p(1, "one"), P.p(2, "two")), Equal.intEqual); + assertThat(a.f(P.p("foo")).f(2), is("two")); + } + + @Test + public void testAssociationLazyDef() { + final F, F> a = associationLazy(List.list(P.p(1, "one"), P.p(2, "two")), Equal.intEqual); + assertThat(a.f(P.p("foo")).f(3), is("foo")); + } +} From f1801d3c4fa3b8c8bdfddd185b7e20bb4ce65860 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 20 Aug 2018 20:01:15 -0400 Subject: [PATCH 211/336] Add DList tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/data/DListTest.java | 31 +++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 core/src/test/java/fj/data/DListTest.java diff --git a/core/src/test/java/fj/data/DListTest.java b/core/src/test/java/fj/data/DListTest.java new file mode 100644 index 00000000..6846ca2d --- /dev/null +++ b/core/src/test/java/fj/data/DListTest.java @@ -0,0 +1,31 @@ +package fj.data; + +import org.junit.Test; + +import static fj.data.DList.*; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class DListTest { + @Test + public void testConsSnoc() { + assertThat(nil().snoc(2).cons(1).toJavaList(), is(single(1).snoc(2).toJavaList())); + } + + @Test + public void testListDList() { + DList d = listDList(List.range(0, 1000)); + assertThat(d.toJavaList(), is(List.range(0, 1000).toJavaList())); + } + + @Test + public void testArrayDList() { + DList d = arrayDList(Array.range(0, 1000).array(Integer[].class)); + assertThat(d.toJavaList(), is(Array.range(0, 1000).toJavaList())); + } + @Test + public void testIter() { + DList d = iteratorDList(List.range(0, 1000).iterator()); + assertThat(d.toJavaList(), is(List.range(0, 1000).toJavaList())); + } +} From 58e0b4b556b870507dc6d7b788101b60f328f8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Thu, 23 Aug 2018 10:05:41 -0400 Subject: [PATCH 212/336] Exclude consume/ from coverage --- codecov.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codecov.yml b/codecov.yml index 8c7fd5e4..b7ddeec5 100644 --- a/codecov.yml +++ b/codecov.yml @@ -1,3 +1,4 @@ ignore: - "demo/.*" - - "performance/.*" \ No newline at end of file + - "consume/.*" + - "performance/.*" From 33d5e8338f9c6a90a44882e61e821632be996990 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Mon, 27 Aug 2018 21:25:41 -0400 Subject: [PATCH 213/336] Add P tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/test/java/fj/PTest.java | 159 +++++++++++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 core/src/test/java/fj/PTest.java diff --git a/core/src/test/java/fj/PTest.java b/core/src/test/java/fj/PTest.java new file mode 100644 index 00000000..2a97303f --- /dev/null +++ b/core/src/test/java/fj/PTest.java @@ -0,0 +1,159 @@ +package fj; + +import org.junit.Test; + +import static fj.Function.identity; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class PTest { + @Test + public void testPF(){ + final F> p1f = P.p1(); + final P1 p1 = p1f.f(1); + F>> p2f = P.p2(); + final P2 p2 = p2f.f(1).f(2); + assertThat(P2.__1().f(p2), is(P1.__1().f(p1))); + final F>>> p3f = P.p3(); + final P3 p3 = p3f.f(1).f(2).f(3); + assertThat(P3.__1().f(p3), is(P2.__1().f(p2))); + assertThat(P3.__2().f(p3), is(P2.__2().f(p2))); + final F>>>> p4f = P.p4(); + final P4 p4 = p4f.f(1).f(2).f(3).f(4); + assertThat(P4.__1().f(p4), is(P3.__1().f(p3))); + assertThat(P4.__2().f(p4), is(P3.__2().f(p3))); + assertThat(P4.__3().f(p4), is(P3.__3().f(p3))); + final F>>>>> p5f = P.p5(); + final P5 p5 = p5f.f(1).f(2).f(3).f(4).f(5); + assertThat(P5.__1().f(p5), is(P4.__1().f(p4))); + assertThat(P5.__2().f(p5), is(P4.__2().f(p4))); + assertThat(P5.__3().f(p5), is(P4.__3().f(p4))); + assertThat(P5.__4().f(p5), is(P4.__4().f(p4))); + final F>>>>>> p6f = P.p6(); + final P6 p6 = p6f.f(1).f(2).f(3).f(4).f(5).f(6); + assertThat(P6.__1().f(p6), + is(P5.__1().f(p5))); + assertThat(P6.__2().f(p6), + is(P5.__2().f(p5))); + assertThat(P6.__3().f(p6), + is(P5.__3().f(p5))); + assertThat(P6.__4().f(p6), + is(P5.__4().f(p5))); + assertThat(P6.__5().f(p6), + is(P5.__5().f(p5))); + final F>>>>>>> p7f = P.p7(); + final P7 p7 = + p7f.f(1).f(2).f(3).f(4).f(5).f(6).f(7); + assertThat(P7.__1().f(p7), + is(P6.__1().f(p6))); + assertThat(P7.__2().f(p7), + is(P6.__2().f(p6))); + assertThat(P7.__3().f(p7), + is(P6.__3().f(p6))); + assertThat(P7.__4().f(p7), + is(P6.__4().f(p6))); + assertThat(P7.__5().f(p7), + is(P6.__5().f(p6))); + assertThat(P7.__6().f(p7), + is(P6.__6().f(p6))); + final F>>>>>>>> p8f = P.p8(); + final P8 p8 = + p8f.f(1).f(2).f(3).f(4).f(5).f(6).f(7).f(8); + assertThat(P8.__1().f(p8), + is(P7.__1().f(p7))); + assertThat(P8.__2().f(p8), + is(P7.__2().f(p7))); + assertThat(P8.__3().f(p8), + is(P7.__3().f(p7))); + assertThat(P8.__4().f(p8), + is(P7.__4().f(p7))); + assertThat(P8.__5().f(p8), + is(P7.__5().f(p7))); + assertThat(P8.__6().f(p8), + is(P7.__6().f(p7))); + assertThat(P8.__7().f(p8), + is(P7.__7().f(p7))); + assertThat(P8.__8().f(p8), is(8)); + } + + @Test + public void testPProject1() { + final P1 p1 = P.p(1); + assertThat(p1.map(identity()), is(p1)); + } + + @Test + public void testPProject2() { + final P2 p2 = P.p(1, 2); + assertThat(p2.map1(identity()), is(p2)); + assertThat(p2.map2(identity()), is(p2)); + } + + @Test + public void testPProject3() { + final P3 p3 = P.p(1, 2, 3); + assertThat(p3.map1(identity()), is(p3)); + assertThat(p3.map2(identity()), is(p3)); + assertThat(p3.map3(identity()), is(p3)); + } + + @Test + public void testPProject4() { + final P4 p4 = P.p(1, 2, 3, 4); + assertThat(p4.map1(identity()), is(p4)); + assertThat(p4.map2(identity()), is(p4)); + assertThat(p4.map3(identity()), is(p4)); + assertThat(p4.map4(identity()), is(p4)); + } + + @Test + public void testPProject5() { + final P5 p5 = P.p(1, 2, 3, 4, 5); + assertThat(p5.map1(identity()), is(p5)); + assertThat(p5.map2(identity()), is(p5)); + assertThat(p5.map3(identity()), is(p5)); + assertThat(p5.map4(identity()), is(p5)); + assertThat(p5.map5(identity()), is(p5)); + } + + @Test + public void testPProject6() { + final P6 p6 = P.p(1, 2, 3, 4, 5, 6); + assertThat(p6.map1(identity()), is(p6)); + assertThat(p6.map2(identity()), is(p6)); + assertThat(p6.map3(identity()), is(p6)); + assertThat(p6.map4(identity()), is(p6)); + assertThat(p6.map5(identity()), is(p6)); + assertThat(p6.map6(identity()), is(p6)); + } + + @Test + public void testPProject7() { + final P7 p7 = + P.p(1, 2, 3, 4, 5, 6, 7); + assertThat(p7.map1(identity()), is(p7)); + assertThat(p7.map2(identity()), is(p7)); + assertThat(p7.map3(identity()), is(p7)); + assertThat(p7.map4(identity()), is(p7)); + assertThat(p7.map5(identity()), is(p7)); + assertThat(p7.map6(identity()), is(p7)); + assertThat(p7.map7(identity()), is(p7)); + } + + @Test + public void testPProject8() { + final P8 p8 = + P.p(1, 2, 3, 4, 5, 6, 7, 8); + assertThat(p8.map1(identity()), is(p8)); + assertThat(p8.map2(identity()), is(p8)); + assertThat(p8.map3(identity()), is(p8)); + assertThat(p8.map4(identity()), is(p8)); + assertThat(p8.map5(identity()), is(p8)); + assertThat(p8.map6(identity()), is(p8)); + assertThat(p8.map7(identity()), is(p8)); + assertThat(p8.map8(identity()), is(p8)); + } +} From ebdceaa7653780d8c896ad08687a22b934538aa5 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 25 Aug 2018 21:16:44 +0200 Subject: [PATCH 214/336] Fix compile under jdk11. Enable jdk11 travis build. --- .travis.yml | 21 +- build.gradle | 13 +- core/src/main/java/fj/data/$.java | 6 - core/src/main/java/fj/data/IOFunctions.java | 234 +++++++++--------- core/src/main/java/fj/data/Java.java | 22 +- core/src/main/java/fj/data/TreeZipper.java | 17 +- demo/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 3 +- java-core/build.gradle | 2 +- props-core-scalacheck/build.gradle | 4 +- .../src/main/java/fj/test/Arbitrary.java | 174 +++++-------- quickcheck/src/main/java/fj/test/Arg.java | 9 +- .../src/main/java/fj/test/CheckResult.java | 18 +- quickcheck/src/main/java/fj/test/Cogen.java | 7 +- quickcheck/src/main/java/fj/test/Gen.java | 2 +- .../src/main/java/fj/test/Property.java | 30 +-- quickcheck/src/main/java/fj/test/Shrink.java | 5 +- .../src/main/java/fj/test/reflect/Check.java | 8 +- .../java/fj/test/reflect/CheckParams.java | 1 + .../src/main/java/fj/test/reflect/Main.java | 3 - .../fj/test/runner/PropertyTestRunner.java | 9 +- .../src/test/java/fj/data/test/TestCheck.java | 12 +- .../src/test/java/fj/data/test/TestNull.java | 10 +- quickcheck/src/test/java/fj/test/GenTest.java | 18 +- 24 files changed, 247 insertions(+), 383 deletions(-) diff --git a/.travis.yml b/.travis.yml index 539e7a45..7c55b120 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,17 +4,22 @@ sudo: false language: java jdk: - - oraclejdk8 + - openjdk11 + +matrix: + + include: + - jdk: openjdk8 + script: + - ./gradlew build coverage -s -i + after_success: + - bash <(curl -s https://codecov.io/bash) + - '[ "$TRAVIS_BRANCH" = "series/4.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] + && ./gradlew uploadArchives' script: - - jdk_switcher use openjdk7 && export JAVA7_HOME=$JAVA_HOME - - jdk_switcher use oraclejdk8 && export JAVA8_HOME=$JAVA_HOME - - ./gradlew build coverage -s -i + - ./gradlew clean test -after_success: - - bash <(curl -s https://codecov.io/bash) - - '[ "$TRAVIS_BRANCH" = "master" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] - && ./gradlew uploadArchives' env: global: diff --git a/build.gradle b/build.gradle index fe81f484..9d98d2b3 100644 --- a/build.gradle +++ b/build.gradle @@ -23,8 +23,6 @@ buildscript { } } -apply plugin: "jacoco" - if (JavaVersion.current().isJava8Compatible()) { allprojects { tasks.withType(Javadoc) { @@ -35,11 +33,10 @@ if (JavaVersion.current().isJava8Compatible()) { allprojects { - + apply plugin: "jacoco" jacoco { - toolVersion = "0.8.1" - + toolVersion = "0.8.2" } defaultTasks "build" @@ -100,8 +97,6 @@ subprojects { } } - apply plugin: "jacoco" - apply from: "$rootDir/lib.gradle" apply plugin: "java" apply plugin: "eclipse" @@ -123,9 +118,13 @@ subprojects { } jacocoTestReport { + additionalSourceDirs = files(sourceSets.main.allSource.srcDirs) + sourceDirectories = files(sourceSets.main.allSource.srcDirs) + classDirectories = files(sourceSets.main.output) reports { html.enabled = true xml.enabled = true + csv.enabled = false } } diff --git a/core/src/main/java/fj/data/$.java b/core/src/main/java/fj/data/$.java index 17b2ac9e..a1aa77bf 100644 --- a/core/src/main/java/fj/data/$.java +++ b/core/src/main/java/fj/data/$.java @@ -17,14 +17,8 @@ public final class $ extends P1 { /** * Returns a function that given an argument, returns a function that ignores its argument. - * @deprecated JDK 8 warns '_' may not be supported after SE 8. As of release 4.4, use {@link #constant} (note the synonym {@link #__}). * @return A function that given an argument, returns a function that ignores its argument. */ - @Deprecated - public static $ _(final B b) { - return constant(b); - } - public static $ __(final B b) { return constant(b); } diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 92263d09..2ea15dfb 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -1,8 +1,19 @@ package fj.data; -import static fj.Bottom.errorF; -import static fj.Function.constant; -import static fj.Function.partialApply2; +import fj.F; +import fj.F0; +import fj.F1Functions; +import fj.F2; +import fj.Function; +import fj.P; +import fj.P1; +import fj.P2; +import fj.Try; +import fj.Unit; +import fj.data.Iteratee.Input; +import fj.data.Iteratee.IterV; +import fj.function.Try0; +import fj.function.Try1; import java.io.BufferedReader; import java.io.Closeable; @@ -14,11 +25,9 @@ import java.nio.charset.Charset; import java.util.Arrays; -import fj.*; -import fj.data.Iteratee.Input; -import fj.data.Iteratee.IterV; -import fj.function.Try0; -import fj.function.Try1; +import static fj.Bottom.errorF; +import static fj.Function.constant; +import static fj.Function.partialApply2; /** * IO monad for processing files, with main methods {@link #enumFileLines }, @@ -170,38 +179,37 @@ public static SafeIO lazySafe(final F0 f) { * A function that feeds an iteratee with lines read from a {@link BufferedReader}. */ public static F, IO>>> lineReader() { - final F, Boolean> isDone = - new F, Boolean>() { - final F>, P1> done = constant(P.p(true)); - final F, IterV>, P1> cont = constant(P.p(false)); - - @Override - public Boolean f(final IterV i) { - return i.fold(done, cont)._1(); - } - }; - - return r -> new F, IO>>() { - final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ - - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return () -> { - IterV i = it; - while (!isDone.f(i)) { - final String s = r.readLine(); - if (s == null) { - return i; - } - final Input input = Input.el(s); - final F, IterV>, P1>> cont = F1Functions.lazy(Function.apply(input)); - i = i.fold(done, cont)._1(); + return LineReader::new; + } + + private static class LineReader implements F, IO>> { + + private final BufferedReader r; + + private final F, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1(); + private final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ + + private LineReader(BufferedReader r) { + this.r = r; + } + + @Override + public IO> f(IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + IterV i = it; + while (!isDone.f(i)) { + final String s = r.readLine(); + if (s == null) { + return i; } - return i; - }; - } - }; + final Input input = Input.el(s); + final F, IterV>, P1>> cont = F1Functions.lazy(Function.apply(input)); + i = i.fold(done, cont)._1(); + } + return i; + }; + } } /** @@ -209,91 +217,91 @@ public IO> f(final IterV it) { * (char[] of size {@link #DEFAULT_BUFFER_SIZE}). */ public static F, IO>>> charChunkReader() { - final F, Boolean> isDone = - new F, Boolean>() { - final F>, P1> done = constant(P.p(true)); - final F, IterV>, P1> cont = constant(P.p(false)); - - @Override - public Boolean f(final IterV i) { - return i.fold(done, cont)._1(); + return CharChunkReader::new; + } + + private static class CharChunkReader implements F, IO>> { + + private final Reader r; + + private final F, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1(); + private final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ + + CharChunkReader(Reader r) { + this.r = r; + } + + @Override + public IO> f(IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + + IterV i = it; + while (!isDone.f(i)) { + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + final int numRead = r.read(buffer); + if (numRead == -1) { + return i; } - }; - - return r -> new F, IO>>() { - final F>, P1>> done = errorF("iteratee is done"); //$NON-NLS-1$ - - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return () -> { - - IterV i = it; - while (!isDone.f(i)) { - char[] buffer = new char[DEFAULT_BUFFER_SIZE]; - final int numRead = r.read(buffer); - if (numRead == -1) { - return i; - } - if (numRead < buffer.length) { - buffer = Arrays.copyOfRange(buffer, 0, numRead); - } - final Input input = Input.el(buffer); - final F, IterV>, P1>> cont = - F1Functions.lazy(Function.apply(input)); - i = i.fold(done, cont)._1(); + if (numRead < buffer.length) { + buffer = Arrays.copyOfRange(buffer, 0, numRead); } - return i; - }; - } - }; + final Input input = Input.el(buffer); + final F, IterV>, P1>> cont = + F1Functions.lazy(Function.apply(input)); + i = i.fold(done, cont)._1(); + } + return i; + }; + } } + + /** * A function that feeds an iteratee with characters read from a {@link Reader} * (chars are read in chunks of size {@link #DEFAULT_BUFFER_SIZE}). */ public static F, IO>>> charChunkReader2() { - final F, Boolean> isDone = - new F, Boolean>() { - final F>, P1> done = constant(P.p(true)); - final F, IterV>, P1> cont = constant(P.p(false)); - - @Override - public Boolean f(final IterV i) { - return i.fold(done, cont)._1(); + return CharChunkReader2::new; + } + + private static class CharChunkReader2 implements F, IO>> { + + private final Reader r; + + private final F, Boolean> isDone = i -> i.fold(constant(P.p(true)), constant(P.p(false)))._1(); + private final F>, IterV> done = errorF("iteratee is done"); //$NON-NLS-1$ + + CharChunkReader2(Reader r) { + this.r = r; + } + + @Override + public IO> f(IterV it) { + // use loop instead of recursion because of missing TCO + return () -> { + + IterV i = it; + while (!isDone.f(i)) { + char[] buffer = new char[DEFAULT_BUFFER_SIZE]; + final int numRead = r.read(buffer); + if (numRead == -1) { + return i; } - }; - - return r -> new F, IO>>() { - final F>, IterV> done = errorF("iteratee is done"); //$NON-NLS-1$ - - @Override - public IO> f(final IterV it) { - // use loop instead of recursion because of missing TCO - return () -> { - - IterV i = it; - while (!isDone.f(i)) { - char[] buffer = new char[DEFAULT_BUFFER_SIZE]; - final int numRead = r.read(buffer); - if (numRead == -1) { - return i; - } - if (numRead < buffer.length) { - buffer = Arrays.copyOfRange(buffer, 0, numRead); - } - for (char c : buffer) { - final Input input = Input.el(c); - final F, IterV>, IterV> cont = - Function.apply(input); - i = i.fold(done, cont); - } + if (numRead < buffer.length) { + buffer = Arrays.copyOfRange(buffer, 0, numRead); } - return i; - }; - } - }; + for (char c : buffer) { + final Input input = Input.el(c); + final F, IterV>, IterV> cont = + Function.apply(input); + i = i.fold(done, cont); + } + } + return i; + }; + } } public static IO map(final IO io, final F f) { diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 487e9703..80a5ec43 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -404,27 +404,7 @@ public static F, SynchronousQueue> Array_SynchronousQueue(final * @return A function that converts streams to iterable. */ public static F, Iterable> Stream_Iterable() { - return as -> () -> new Iterator() { - private Stream x = as; - - public boolean hasNext() { - return x.isNotEmpty(); - } - - public A next() { - if (x.isEmpty()) - throw new NoSuchElementException("Empty iterator"); - else { - final A a = x.head(); - x = x.tail()._1(); - return a; - } - } - - public void remove() { - throw new UnsupportedOperationException(); - } - }; + return as -> as; } /** diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index 46392d20..9ffad4f4 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -628,21 +628,8 @@ private Stream>> uf(final F, Option F, P2, P1>>>> dwn() { - return tz -> P.p(tz, new P1>>() { - private F>, Option, Option>>>> fwd() { - return o -> { - Option, Option>>> r = none(); - for (final TreeZipper c : o) { - r = some(P.p(c, c.right())); - } - return r; - }; - } - - public Stream> _1() { - return unfold(fwd(), tz.firstChild()); - } - }); + F>, Option, Option>>>> fwd = o -> o.map(c -> P.p(c, c.right())); + return tz -> P.p(tz, P.lazy(() -> unfold(fwd, tz.firstChild()))); } /** diff --git a/demo/build.gradle b/demo/build.gradle index 41841cfa..b79cb246 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -17,4 +17,4 @@ test { jacoco { enabled = false } -} \ No newline at end of file +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 717f0389..72c40576 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Sat Aug 25 14:20:05 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip diff --git a/java-core/build.gradle b/java-core/build.gradle index 3b636072..b5ee71ec 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -16,4 +16,4 @@ configureUpload(signingEnabled, signModule) uploadArchives.enabled = true -configureAllRetroLambda() \ No newline at end of file +configureAllRetroLambda() diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index a395a586..10e494c9 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -4,7 +4,7 @@ archivesBaseName = "${project.projectName}-${project.name}" apply plugin: 'scala' ext { - scalaVersion = "2.11.11" + scalaVersion = "2.11.12" scalacheckScalaVersion = "2.11" scalacheckVersion = "1.12.6" signModule = true @@ -20,5 +20,3 @@ dependencies { performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) - - diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index df922af2..95bdedca 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -1,8 +1,6 @@ package fj.test; -import fj.Equal; import fj.F; -import fj.F1Functions; import fj.F2; import fj.F3; import fj.F4; @@ -13,7 +11,6 @@ import fj.Function; import fj.Bottom; -import static fj.Equal.longEqual; import static fj.Function.compose; import static fj.P.p; @@ -30,22 +27,14 @@ import fj.LcgRng; import fj.Ord; -import static fj.data.Either.left; -import static fj.data.Either.right; import static fj.data.Enumerator.charEnumerator; import static fj.data.List.asString; import static fj.data.List.list; -import static fj.data.Option.some; import fj.data.List; import fj.data.Set; -import fj.data.TreeMap; -import fj.function.Booleans; -import fj.function.Effect1; -import fj.function.Longs; import static fj.data.Stream.range; -import static fj.function.Booleans.not; import static fj.test.Gen.choose; import static fj.test.Gen.elements; import static fj.test.Gen.fail; @@ -95,11 +84,7 @@ public final class Arbitrary { * @return An arbitrary for functions. */ public static Gen> arbF(final Cogen c, final Gen a) { - return promote(new F>() { - public Gen f(final A x) { - return c.cogen(x, a); - } - }); + return promote(x -> c.cogen(x, a)); } public static Gen> arbReader(Cogen aa, Gen ab) { @@ -389,19 +374,14 @@ public static Gen> arbF4Invariant(final Gen * max, min, max - 1, min + 1) with a frequency of 1% each then generates from {@link * #arbInteger} the remainder of the time (93%). */ - public static final Gen arbIntegerBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value(0)), - p(1, value(1)), - p(1, value(-1)), - p(1, value(Integer.MAX_VALUE)), - p(1, value(Integer.MIN_VALUE)), - p(1, value(Integer.MAX_VALUE - 1)), - p(1, value(Integer.MIN_VALUE + 1)), - p(93, arbInteger))); - } - }); + public static final Gen arbIntegerBoundaries = sized(i -> frequency(list(p(1, value(0)), + p(1, value(1)), + p(1, value(-1)), + p(1, value(Integer.MAX_VALUE)), + p(1, value(Integer.MIN_VALUE)), + p(1, value(Integer.MAX_VALUE - 1)), + p(1, value(Integer.MIN_VALUE + 1)), + p(93, arbInteger)))); /** * An arbitrary implementation for long values. @@ -414,19 +394,14 @@ public Gen f(final Integer i) { * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbLong} * the remainder of the time (93%). */ - public static final Gen arbLongBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value(0L)), - p(1, value(1L)), - p(1, value(-1L)), - p(1, value(Long.MAX_VALUE)), - p(1, value(Long.MIN_VALUE)), - p(1, value(Long.MAX_VALUE - 1L)), - p(1, value(Long.MIN_VALUE + 1L)), - p(93, arbLong))); - } - }); + public static final Gen arbLongBoundaries = sized(i -> frequency(list(p(1, value(0L)), + p(1, value(1L)), + p(1, value(-1L)), + p(1, value(Long.MAX_VALUE)), + p(1, value(Long.MIN_VALUE)), + p(1, value(Long.MAX_VALUE - 1L)), + p(1, value(Long.MIN_VALUE + 1L)), + p(93, arbLong)))); /** * An arbitrary implementation for byte values. @@ -438,19 +413,14 @@ public Gen f(final Integer i) { * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbByte} * the remainder of the time (93%). */ - public static final Gen arbByteBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value((byte) 0)), - p(1, value((byte) 1)), - p(1, value((byte) -1)), - p(1, value(Byte.MAX_VALUE)), - p(1, value(Byte.MIN_VALUE)), - p(1, value((byte) (Byte.MAX_VALUE - 1))), - p(1, value((byte) (Byte.MIN_VALUE + 1))), - p(93, arbByte))); - } - }); + public static final Gen arbByteBoundaries = sized(i -> frequency(list(p(1, value((byte) 0)), + p(1, value((byte) 1)), + p(1, value((byte) -1)), + p(1, value(Byte.MAX_VALUE)), + p(1, value(Byte.MIN_VALUE)), + p(1, value((byte) (Byte.MAX_VALUE - 1))), + p(1, value((byte) (Byte.MIN_VALUE + 1))), + p(93, arbByte)))); /** * An arbitrary implementation for short values. @@ -462,19 +432,14 @@ public Gen f(final Integer i) { * min, max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbShort} * the remainder of the time (93%). */ - public static final Gen arbShortBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value((short) 0)), - p(1, value((short) 1)), - p(1, value((short) -1)), - p(1, value(Short.MAX_VALUE)), - p(1, value(Short.MIN_VALUE)), - p(1, value((short) (Short.MAX_VALUE - 1))), - p(1, value((short) (Short.MIN_VALUE + 1))), - p(93, arbShort))); - } - }); + public static final Gen arbShortBoundaries = sized(i -> frequency(list(p(1, value((short) 0)), + p(1, value((short) 1)), + p(1, value((short) -1)), + p(1, value(Short.MAX_VALUE)), + p(1, value(Short.MIN_VALUE)), + p(1, value((short) (Short.MAX_VALUE - 1))), + p(1, value((short) (Short.MIN_VALUE + 1))), + p(93, arbShort)))); /** * An arbitrary implementation for character values. @@ -486,16 +451,11 @@ public Gen f(final Integer i) { * max - 1, min + 1) with a frequency of 1% each then generates from {@link #arbCharacter} * the remainder of the time (96%). */ - public static final Gen arbCharacterBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value(Character.MIN_VALUE)), - p(1, value((char) (Character.MIN_VALUE + 1))), - p(1, value(Character.MAX_VALUE)), - p(1, value((char) (Character.MAX_VALUE - 1))), - p(95, arbCharacter))); - } - }); + public static final Gen arbCharacterBoundaries = sized(i -> frequency(list(p(1, value(Character.MIN_VALUE)), + p(1, value((char) (Character.MIN_VALUE + 1))), + p(1, value(Character.MAX_VALUE)), + p(1, value((char) (Character.MAX_VALUE - 1))), + p(95, arbCharacter)))); /** * An arbitrary implementation for double values. @@ -507,21 +467,16 @@ public Gen f(final Integer i) { * min, min (normal), NaN, -infinity, infinity, max - 1) with a frequency of 1% each then * generates from {@link #arbDouble} the remainder of the time (91%). */ - public static final Gen arbDoubleBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value(0D)), - p(1, value(1D)), - p(1, value(-1D)), - p(1, value(Double.MAX_VALUE)), - p(1, value(Double.MIN_VALUE)), - p(1, value(Double.NaN)), - p(1, value(Double.NEGATIVE_INFINITY)), - p(1, value(Double.POSITIVE_INFINITY)), - p(1, value(Double.MAX_VALUE - 1D)), - p(91, arbDouble))); - } - }); + public static final Gen arbDoubleBoundaries = sized(i -> frequency(list(p(1, value(0D)), + p(1, value(1D)), + p(1, value(-1D)), + p(1, value(Double.MAX_VALUE)), + p(1, value(Double.MIN_VALUE)), + p(1, value(Double.NaN)), + p(1, value(Double.NEGATIVE_INFINITY)), + p(1, value(Double.POSITIVE_INFINITY)), + p(1, value(Double.MAX_VALUE - 1D)), + p(91, arbDouble)))); /** * An arbitrary implementation for float values. @@ -533,21 +488,16 @@ public Gen f(final Integer i) { * min, NaN, -infinity, infinity, max - 1) with a frequency of 1% each then generates from * {@link #arbFloat} the remainder of the time (91%). */ - public static final Gen arbFloatBoundaries = sized(new F>() { - @SuppressWarnings("unchecked") - public Gen f(final Integer i) { - return frequency(list(p(1, value(0F)), - p(1, value(1F)), - p(1, value(-1F)), - p(1, value(Float.MAX_VALUE)), - p(1, value(Float.MIN_VALUE)), - p(1, value(Float.NaN)), - p(1, value(Float.NEGATIVE_INFINITY)), - p(1, value(Float.POSITIVE_INFINITY)), - p(1, value(Float.MAX_VALUE - 1F)), - p(91, arbFloat))); - } - }); + public static final Gen arbFloatBoundaries = sized(i -> frequency(list(p(1, value(0F)), + p(1, value(1F)), + p(1, value(-1F)), + p(1, value(Float.MAX_VALUE)), + p(1, value(Float.MIN_VALUE)), + p(1, value(Float.NaN)), + p(1, value(Float.NEGATIVE_INFINITY)), + p(1, value(Float.POSITIVE_INFINITY)), + p(1, value(Float.MAX_VALUE - 1F)), + p(91, arbFloat)))); /** * An arbitrary implementation for string values. @@ -670,7 +620,7 @@ public static Gen> arbNonEmptyList(final Gen aa) { * Returns an arbitrary Validation for the given arbitrary parameters. */ public static Gen> arbValidation(final Gen aa, final Gen ab) { - return arbBoolean.bind(bool -> bool ? ab.map(Validation::success) : aa.map(Validation::fail)); + return arbBoolean.bind(bool -> bool ? ab.map(Validation::success) : aa.map(Validation::fail)); } /** @@ -690,7 +640,7 @@ public static Gen> arbStream(final Gen aa) { * @return An arbitrary implementation for arrays. */ public static Gen> arbArray(final Gen aa) { - return arbList(aa).map(List::toArray); + return arbList(aa).map(List::toArray); } /** @@ -1029,8 +979,8 @@ public static Gen> arbWeakHashMap(final Gen ak, fina */ public static Gen> arbArrayBlockingQueue(final Gen aa) { return arbArray(aa).bind(arbInteger, arbBoolean, - a -> capacity -> fair -> new ArrayBlockingQueue(a.length() + abs(capacity), - fair, a.asJavaList())); + a -> capacity -> fair -> new ArrayBlockingQueue<>(a.length() + abs(capacity), + fair, a.asJavaList())); } /** diff --git a/quickcheck/src/main/java/fj/test/Arg.java b/quickcheck/src/main/java/fj/test/Arg.java index 4187c15d..71df9e2d 100644 --- a/quickcheck/src/main/java/fj/test/Arg.java +++ b/quickcheck/src/main/java/fj/test/Arg.java @@ -1,6 +1,5 @@ package fj.test; -import fj.F; import fj.Show; import static fj.Show.anyShow; @@ -52,10 +51,6 @@ public int shrinks() { /** * The rendering of an argument (uses {@link Object#toString()} for the argument value). */ - public static final Show> argShow = showS(new F, String>() { - public String f(final Arg arg) { - return anyShow().showS(arg.value) + - (arg.shrinks > 0 ? " (" + arg.shrinks + " shrink" + (arg.shrinks == 1 ? "" : 's') + ')' : ""); - } - }); + public static final Show> argShow = showS(arg -> anyShow().showS(arg.value) + + (arg.shrinks > 0 ? " (" + arg.shrinks + " shrink" + (arg.shrinks == 1 ? "" : 's') + ')' : "")); } diff --git a/quickcheck/src/main/java/fj/test/CheckResult.java b/quickcheck/src/main/java/fj/test/CheckResult.java index c9c0a2fe..784fe4e9 100644 --- a/quickcheck/src/main/java/fj/test/CheckResult.java +++ b/quickcheck/src/main/java/fj/test/CheckResult.java @@ -286,16 +286,14 @@ else if (r.isPropException()) { * the result is a failure (falsified, property exception or generator exception). */ public static Show summaryEx(final Show> sa) { - return showS(new F() { - public String f(final CheckResult r) { - final String s = summary(sa).showS(r); - if (r.isProven() || r.isPassed() || r.isExhausted()) - return s; - else if (r.isFalsified() || r.isPropException() || r.isGenException()) - throw new Error(s); - else - throw decons(r.getClass()); - } + return showS(r -> { + final String s = summary(sa).showS(r); + if (r.isProven() || r.isPassed() || r.isExhausted()) + return s; + else if (r.isFalsified() || r.isPropException() || r.isGenException()) + throw new Error(s); + else + throw decons(r.getClass()); }); } } diff --git a/quickcheck/src/main/java/fj/test/Cogen.java b/quickcheck/src/main/java/fj/test/Cogen.java index c4c3b0a0..5770ea21 100644 --- a/quickcheck/src/main/java/fj/test/Cogen.java +++ b/quickcheck/src/main/java/fj/test/Cogen.java @@ -7,7 +7,6 @@ import fj.data.*; -import static fj.data.Array.array; import static fj.data.Array.iterableArray; import static fj.data.List.fromString; import static fj.data.List.nil; @@ -501,11 +500,7 @@ public Gen cogen(final Array as, final Gen g) { * @return A cogen for throwables. */ public static Cogen cogenThrowable(final Cogen cs) { - return cs.contramap(new F() { - public String f(final Throwable t) { - return t.getMessage(); - } - }); + return cs.contramap(Throwable::getMessage); } /** diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 5b0a98bc..a5e30a9d 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -275,7 +275,7 @@ public Gen bind(final Gen gb, final Gen gc, final Gen g * @return A new generator after function application. */ public Gen apply(final Gen> gf) { - return gf.bind(f1 -> map(f1)); + return gf.bind(this::map); } /** diff --git a/quickcheck/src/main/java/fj/test/Property.java b/quickcheck/src/main/java/fj/test/Property.java index 0f77f85e..2a327ebc 100644 --- a/quickcheck/src/main/java/fj/test/Property.java +++ b/quickcheck/src/main/java/fj/test/Property.java @@ -501,11 +501,7 @@ public static Property property(final Gen aa, final F f) { * application of its arguments. */ public static Property propertyP(final Gen aa, final Gen ab, final Shrink sa, final Shrink sb, final F>> f) { - return property(aa, sa, a -> { - return propertyP(ab, sb, b -> { - return f.f(a).f(b); - }); - }); + return property(aa, sa, a -> propertyP(ab, sb, b -> f.f(a).f(b))); } /** @@ -633,9 +629,7 @@ public static Property property(final Gen aa, final Shrink sb, final Shrink sc, final F>> f) { - return property(aa, ab, sa, sb, a -> b -> property(ac, sc, c -> { - return f.f(a).f(b).f(c); - })); + return property(aa, ab, sa, sb, a -> b -> property(ac, sc, c -> f.f(a).f(b).f(c))); } /** @@ -723,9 +717,7 @@ public static Property property(final Gen aa, final Shrink sc, final Shrink sd, final F>>> f) { - return property(aa, ab, ac, sa, sb, sc, a -> b -> c -> property(ad, sd, d -> { - return f.f(a).f(b).f(c).f(d); - })); + return property(aa, ab, ac, sa, sb, sc, a -> b -> c -> property(ad, sd, d -> f.f(a).f(b).f(c).f(d))); } /** @@ -825,9 +817,7 @@ public static Property property(final Gen aa, final Shrink sd, final Shrink se, final F>>>> f) { - return property(aa, ab, ac, ad, sa, sb, sc, sd, a -> b -> c -> d -> property(ae, se, e -> { - return f.f(a).f(b).f(c).f(d).f(e); - })); + return property(aa, ab, ac, ad, sa, sb, sc, sd, a -> b -> c -> d -> property(ae, se, e -> f.f(a).f(b).f(c).f(d).f(e))); } /** @@ -939,9 +929,7 @@ public static Property property(final Gen aa, final Shrink se, final Shrink sf, final F>>>>> f) { - return property(aa, ab, ac, ad, ae, sa, sb, sc, sd, se, a -> b -> c -> d -> e -> property(af, sf, f$ -> { - return f.f(a).f(b).f(c).f(d).f(e).f(f$); - })); + return property(aa, ab, ac, ad, ae, sa, sb, sc, sd, se, a -> b -> c -> d -> e -> property(af, sf, f$ -> f.f(a).f(b).f(c).f(d).f(e).f(f$))); } /** @@ -1065,9 +1053,7 @@ public static Property property(final Gen aa, final Shrink sf, final Shrink sg, final F>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, sa, sb, sc, sd, se, sf, a -> b -> c -> d -> e -> f$ -> property(ag, sg, g -> { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g); - })); + return property(aa, ab, ac, ad, ae, af, sa, sb, sc, sd, se, sf, a -> b -> c -> d -> e -> f$ -> property(ag, sg, g -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g))); } /** @@ -1203,9 +1189,7 @@ public static Property property(final Gen aa, final Shrink sg, final Shrink sh, final F>>>>>>> f) { - return property(aa, ab, ac, ad, ae, af, ag, sa, sb, sc, sd, se, sf, sg, a -> b -> c -> d -> e -> f$ -> g -> property(ah, sh, h -> { - return f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h); - })); + return property(aa, ab, ac, ad, ae, af, ag, sa, sb, sc, sd, se, sf, sg, a -> b -> c -> d -> e -> f$ -> g -> property(ah, sh, h -> f.f(a).f(b).f(c).f(d).f(e).f(f$).f(g).f(h))); } /** diff --git a/quickcheck/src/main/java/fj/test/Shrink.java b/quickcheck/src/main/java/fj/test/Shrink.java index 77c95381..483293e8 100644 --- a/quickcheck/src/main/java/fj/test/Shrink.java +++ b/quickcheck/src/main/java/fj/test/Shrink.java @@ -23,7 +23,7 @@ import static fj.Primitive.Long_Integer; import static fj.Primitive.Long_Short; import static fj.Primitive.Short_Long; -import static fj.data.Array.array; + import fj.data.Conversions; import static fj.data.List.isNotEmpty_; import fj.data.Array; @@ -38,7 +38,6 @@ import static fj.data.Stream.iterate; import static fj.data.Stream.nil; -import static java.lang.System.arraycopy; import static java.math.BigInteger.ZERO; import java.math.BigDecimal; @@ -683,7 +682,7 @@ public static Shrink> shrinkSynchronousQueue(final Shrin final Stream is = cons(ZERO, () -> iterate(x -> x.divide(two), i) .takeWhile(x2 -> eq.notEq(x2, ZERO)) - .map(i::subtract)); + .map(x2 -> i.subtract(x2))); return Ord.bigintOrd.isLessThan(i, ZERO) ? cons(i.negate(), () -> is) : is; } diff --git a/quickcheck/src/main/java/fj/test/reflect/Check.java b/quickcheck/src/main/java/fj/test/reflect/Check.java index eb865e04..a1eea79b 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Check.java +++ b/quickcheck/src/main/java/fj/test/reflect/Check.java @@ -1,6 +1,5 @@ package fj.test.reflect; -import fj.Class; import static fj.Class.clas; import fj.F; import fj.Function; @@ -24,8 +23,7 @@ import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Method; + import static java.lang.reflect.Modifier.isStatic; /** @@ -177,7 +175,7 @@ public static List> check(final java.lang.Class c */ public static List>> properties(final java.lang.Class c, final String... categories) { //noinspection ClassEscapesDefinedScope - final Array>> propFields = properties(array(c.getDeclaredFields()).map((F) f -> new PropertyMember() { + final Array>> propFields = properties(array(c.getDeclaredFields()).map(f -> new PropertyMember() { public java.lang.Class type() { return f.getType(); } @@ -205,7 +203,7 @@ public boolean isProperty() { }), c, categories); //noinspection ClassEscapesDefinedScope - final Array>> propMethods = properties(array(c.getDeclaredMethods()).map((F) m -> { + final Array>> propMethods = properties(array(c.getDeclaredMethods()).map(m -> { //noinspection ProhibitedExceptionDeclared return new PropertyMember() { public java.lang.Class type() { diff --git a/quickcheck/src/main/java/fj/test/reflect/CheckParams.java b/quickcheck/src/main/java/fj/test/reflect/CheckParams.java index 8c8445c1..7951b40e 100644 --- a/quickcheck/src/main/java/fj/test/reflect/CheckParams.java +++ b/quickcheck/src/main/java/fj/test/reflect/CheckParams.java @@ -1,5 +1,6 @@ package fj.test.reflect; +import fj.F0; import fj.test.Property; import java.lang.annotation.Documented; diff --git a/quickcheck/src/main/java/fj/test/reflect/Main.java b/quickcheck/src/main/java/fj/test/reflect/Main.java index 5f6f3dfc..b07997c2 100644 --- a/quickcheck/src/main/java/fj/test/reflect/Main.java +++ b/quickcheck/src/main/java/fj/test/reflect/Main.java @@ -1,10 +1,7 @@ package fj.test.reflect; -import fj.P2; import static fj.data.Array.array; -import fj.function.Effect1; -import fj.test.CheckResult; import static fj.test.CheckResult.summary; import static fj.test.reflect.Check.check; diff --git a/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java b/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java index 876dbff1..8b90d57c 100644 --- a/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java +++ b/quickcheck/src/main/java/fj/test/runner/PropertyTestRunner.java @@ -58,11 +58,10 @@ private static String getLabel(Description d) { } private static CheckResult checkProperty(Property prop, Option params) { - for (CheckParams ps : params) { - return prop.check(ps.minSuccessful(), ps.maxDiscarded(), ps.minSize(), ps.maxSize()); - } - - return prop.check(); + return params.option( + prop::check, + ps -> prop.check(ps.minSuccessful(), ps.maxDiscarded(), ps.minSize(), ps.maxSize()) + ); } @Override diff --git a/quickcheck/src/test/java/fj/data/test/TestCheck.java b/quickcheck/src/test/java/fj/data/test/TestCheck.java index 935f1127..3a4e6a80 100644 --- a/quickcheck/src/test/java/fj/data/test/TestCheck.java +++ b/quickcheck/src/test/java/fj/data/test/TestCheck.java @@ -1,16 +1,10 @@ package fj.data.test; -import fj.F2; -import fj.F3; -import fj.data.List; -import fj.test.Arbitrary; import fj.test.CheckResult; import fj.test.Gen; import fj.test.Property; import org.junit.*; -import static fj.Function.compose; -import static fj.test.Arbitrary.arbLong; import static fj.test.Property.prop; import static fj.test.Property.property; import static org.junit.Assert.*; @@ -19,13 +13,11 @@ public class TestCheck { @Test(timeout=5000 /*ms*/) public void testExceptionsThrownFromGeneratorsArePropagated() { - Gen failingGen = Gen.value(0).map((i) -> { + Gen failingGen = Gen.value(0).map((i) -> { throw new RuntimeException("test failure"); }); - Property p = property(failingGen, (Integer i) -> { - return prop(i == 0); - }); + Property p = property(failingGen, (Integer i) -> prop(i == 0)); CheckResult res = p.check( 1, /*minSuccessful*/ diff --git a/quickcheck/src/test/java/fj/data/test/TestNull.java b/quickcheck/src/test/java/fj/data/test/TestNull.java index 0fd44c6a..fe9dc843 100644 --- a/quickcheck/src/test/java/fj/data/test/TestNull.java +++ b/quickcheck/src/test/java/fj/data/test/TestNull.java @@ -1,16 +1,10 @@ package fj.data.test; -import fj.F2; -import fj.F3; -import fj.data.List; -import fj.test.Arbitrary; import fj.test.CheckResult; import fj.test.Gen; import fj.test.Property; import org.junit.Test; -import static fj.Function.compose; -import static fj.test.Arbitrary.arbLong; import static fj.test.Property.prop; import static fj.test.Property.property; @@ -21,9 +15,7 @@ public class TestNull { @Test public void testShowNullParameters() { - Property p = property(Gen.value(null), (Integer i) -> { - return prop(i != null); - }); + Property p = property(Gen.value(null), (Integer i) -> prop(i != null)); CheckResult.summary.println(p.check()); } diff --git a/quickcheck/src/test/java/fj/test/GenTest.java b/quickcheck/src/test/java/fj/test/GenTest.java index 3bb723b8..900369a7 100644 --- a/quickcheck/src/test/java/fj/test/GenTest.java +++ b/quickcheck/src/test/java/fj/test/GenTest.java @@ -22,9 +22,7 @@ public final class GenTest { @Test public void testCombinationOf_none() { Gen> instance = combinationOf(0, AS); - testPick(100, instance, actual -> { - assertTrue(actual.isEmpty()); - }); + testPick(100, instance, actual -> assertTrue(actual.isEmpty())); } @Test @@ -59,9 +57,7 @@ public void testCombinationOf_three() { @Test public void testSelectionOf_none() { Gen> instance = selectionOf(0, AS); - testPick(100, instance, actual -> { - assertTrue(actual.isEmpty()); - }); + testPick(100, instance, actual -> assertTrue(actual.isEmpty())); } @Test @@ -106,9 +102,7 @@ public void testSelectionOf_four() { @Test public void testPermutationOf_none() { Gen> instance = permutationOf(0, AS); - testPick(100, instance, actual -> { - assertTrue(actual.isEmpty()); - }); + testPick(100, instance, actual -> assertTrue(actual.isEmpty())); } @Test @@ -142,9 +136,7 @@ public void testPermutationOf_three() { @Test public void testWordOf_none() { Gen> instance = wordOf(0, AS); - testPick(100, instance, actual -> { - assertTrue(actual.isEmpty()); - }); + testPick(100, instance, actual -> assertTrue(actual.isEmpty())); } @Test @@ -184,7 +176,7 @@ public void testWordOf_four() { } private static void testPick(int n, Gen> instance, Effect1> test) { - range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test::f); + range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test); } } From 5b6b88979c717c03d47d9d3977912df9b7f72153 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sat, 25 Aug 2018 21:16:44 +0200 Subject: [PATCH 215/336] Initiate 5.x series: build with jdk11 by default. Move java8 to core. --- .travis.yml | 11 +++-- build.gradle | 22 ++++----- core/build.gradle | 2 - .../src/main/java/fj/data/Collectors.java | 0 .../src/main/java/fj/data/Java8.java | 22 ++++----- demo/build.gradle | 2 - java-core/build.gradle | 2 - java8/build.gradle | 18 ------- java8/src/test/java/fj/EmptyTest.java | 17 ------- lib.gradle | 24 ---------- performance/build.gradle | 2 - props-core/build.gradle | 2 - quickcheck/build.gradle | 2 - .../src/main/java/fj/test/Arbitrary.java | 48 +++++++++---------- settings.gradle | 2 +- 15 files changed, 52 insertions(+), 124 deletions(-) rename {java8 => core}/src/main/java/fj/data/Collectors.java (100%) rename {java8 => core}/src/main/java/fj/data/Java8.java (97%) delete mode 100644 java8/build.gradle delete mode 100644 java8/src/test/java/fj/EmptyTest.java diff --git a/.travis.yml b/.travis.yml index 7c55b120..bbe5966b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,19 +4,24 @@ sudo: false language: java jdk: - - openjdk11 + - openjdk10 + - openjdk-ea matrix: include: - - jdk: openjdk8 + - jdk: openjdk11 script: - ./gradlew build coverage -s -i after_success: - bash <(curl -s https://codecov.io/bash) - - '[ "$TRAVIS_BRANCH" = "series/4.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] + - '[ "$TRAVIS_BRANCH" = "series/5.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] && ./gradlew uploadArchives' + allow_failures: + - jdk: openjdk10 + - jdk: openjdk-ea + script: - ./gradlew clean test diff --git a/build.gradle b/build.gradle index 9d98d2b3..b386b5d3 100644 --- a/build.gradle +++ b/build.gradle @@ -7,8 +7,6 @@ ext { buildscript { ext { uptodateVersion = "1.6.3" - retrolambdaPluginVersion = "3.7.0" - retrolambdaVersion = "2.5.4" } repositories { @@ -19,7 +17,6 @@ buildscript { dependencies { classpath "com.ofg:uptodate-gradle-plugin:$uptodateVersion" - classpath "me.tatarka:gradle-retrolambda:$retrolambdaPluginVersion" } } @@ -43,14 +40,13 @@ allprojects { ext { isSnapshot = true - fjBaseVersion = "4.9" + fjBaseVersion = "5.0" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") fjConsumeVersion = "4.8" signModule = false - useRetroLambda = false projectTitle = "Functional Java" projectName = "functionaljava" @@ -71,10 +67,6 @@ allprojects { dependencyJunit = "org.junit.vintage:junit-vintage-engine:5.2.0" displayCompilerWarnings = true - - newJdkEnvVar = "JAVA8_HOME" - oldJdkEnvVar = "JAVA7_HOME" - retroLambdaTarget = JavaVersion.VERSION_1_6 } repositories { @@ -111,11 +103,13 @@ subprojects { } } - if (displayCompilerWarnings) { - tasks.withType(JavaCompile) { + + tasks.withType(JavaCompile) { + options.compilerArgs.addAll(['--release', '10']) + if (displayCompilerWarnings) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" - } - } + } + } jacocoTestReport { additionalSourceDirs = files(sourceSets.main.allSource.srcDirs) @@ -136,7 +130,7 @@ task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { dependsOn = subprojects.coverage executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") // We only care about coverage of: - def projectForFoverage = ["core", "java8", "quickcheck", "java-core"] + def projectForFoverage = ["core", "quickcheck", "java-core"] classDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.output) sourceDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.allSource.srcDirs) diff --git a/core/build.gradle b/core/build.gradle index 71dae913..13d06114 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -15,5 +15,3 @@ performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) uploadArchives.enabled = true - -configureAllRetroLambda() diff --git a/java8/src/main/java/fj/data/Collectors.java b/core/src/main/java/fj/data/Collectors.java similarity index 100% rename from java8/src/main/java/fj/data/Collectors.java rename to core/src/main/java/fj/data/Collectors.java diff --git a/java8/src/main/java/fj/data/Java8.java b/core/src/main/java/fj/data/Java8.java similarity index 97% rename from java8/src/main/java/fj/data/Java8.java rename to core/src/main/java/fj/data/Java8.java index e41f0958..46c5ca2a 100644 --- a/java8/src/main/java/fj/data/Java8.java +++ b/core/src/main/java/fj/data/Java8.java @@ -1,14 +1,5 @@ package fj.data; -import java.util.Iterator; -import java.util.Optional; -import java.util.Spliterators; -import java.util.function.BiFunction; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; -import java.util.stream.StreamSupport; - import fj.F; import fj.F2; import fj.P; @@ -19,6 +10,15 @@ import fj.function.Try1; import fj.function.Try2; +import java.util.Iterator; +import java.util.Optional; +import java.util.Spliterators; +import java.util.function.BiFunction; +import java.util.function.Consumer; +import java.util.function.Function; +import java.util.function.Supplier; +import java.util.stream.StreamSupport; + /** * Created by mperry on 3/06/2014. */ @@ -134,7 +134,7 @@ public static F Consumer_F(final Consumer c) { }; } - public static java.util.stream.Stream Stream_JavaStream(final fj.data.Stream s) { + public static java.util.stream.Stream Stream_JavaStream(final Stream s) { return Iterable_JavaStream(s); } @@ -146,7 +146,7 @@ public static java.util.stream.Stream Iterator_JavaStream(final Iterator< return StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, 0), false); } - public static F, java.util.stream.Stream> Stream_JavaStream() { + public static F, java.util.stream.Stream> Stream_JavaStream() { return Java8::Stream_JavaStream; } diff --git a/demo/build.gradle b/demo/build.gradle index b79cb246..e97f94b8 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -5,8 +5,6 @@ mainClassName = "fj.demo.euler.Problem2" archivesBaseName = "${project.projectName}-${project.name}" -configureAllRetroLambda() - dependencies { compile project(":core") compile project(":quickcheck") diff --git a/java-core/build.gradle b/java-core/build.gradle index b5ee71ec..22bf8970 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -15,5 +15,3 @@ configureUpload(signingEnabled, signModule) uploadArchives.enabled = true - -configureAllRetroLambda() diff --git a/java8/build.gradle b/java8/build.gradle deleted file mode 100644 index d6d4c485..00000000 --- a/java8/build.gradle +++ /dev/null @@ -1,18 +0,0 @@ - -archivesBaseName = "${project.projectName}-${project.name}" - -ext { - signModule = true -} - -dependencies { - compile project(":core") - testCompile dependencyJunit -} - -performSigning(signingEnabled, signModule) -configureUpload(signingEnabled, signModule) - -if (!useRetroLambda) { - uploadArchives.enabled = true -} diff --git a/java8/src/test/java/fj/EmptyTest.java b/java8/src/test/java/fj/EmptyTest.java deleted file mode 100644 index e187cccb..00000000 --- a/java8/src/test/java/fj/EmptyTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package fj; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Created by MarkPerry on 30/08/2015. - */ -public class EmptyTest { - - @Ignore @Test - public void missing() { - Assert.fail("not implemented"); - - } -} diff --git a/lib.gradle b/lib.gradle index 253ed251..39ce7a7e 100644 --- a/lib.gradle +++ b/lib.gradle @@ -77,33 +77,9 @@ void configureUpload(String signingEnabled, Boolean signModule) { } } -void configureAllRetroLambda() { - configureRetroLambda(useRetroLambda, newJdkEnvVar, oldJdkEnvVar, retroLambdaTarget) -} - -void configureRetroLambda(boolean useRetroLambda, String newJdkEnvVar, String oldJdkEnvVar, JavaVersion retroLambdaTarget) { - - if (useRetroLambda) { - apply plugin: 'me.tatarka.retrolambda' - retrolambda { - jdk System.getenv(newJdkEnvVar) - oldJdk System.getenv(oldJdkEnvVar) - javaVersion retroLambdaTarget - defaultMethods true - } - dependencies { - retrolambdaConfig "net.orfjackal.retrolambda:retrolambda:$retrolambdaVersion" - } - } else { - project.archivesBaseName = "${project.archivesBaseName}_1.8" - } -} - ext { findJavaCommand = this.&findJavaCommand doSigning = this.&doSigning performSigning = this.&performSigning configureUpload = this.&configureUpload - configureRetroLambda = this.&configureRetroLambda - configureAllRetroLambda = this.&configureAllRetroLambda } diff --git a/performance/build.gradle b/performance/build.gradle index b5bc2916..cac2f584 100644 --- a/performance/build.gradle +++ b/performance/build.gradle @@ -1,6 +1,4 @@ -configureAllRetroLambda() - dependencies { compile project(":core") testCompile dependencyJunit diff --git a/props-core/build.gradle b/props-core/build.gradle index d697cff5..181ae5b2 100644 --- a/props-core/build.gradle +++ b/props-core/build.gradle @@ -1,8 +1,6 @@ archivesBaseName = "${project.projectName}-${project.name}" -configureAllRetroLambda() - dependencies { compile project(":quickcheck") testCompile dependencyJunit diff --git a/quickcheck/build.gradle b/quickcheck/build.gradle index 45e379da..b477e26a 100644 --- a/quickcheck/build.gradle +++ b/quickcheck/build.gradle @@ -5,8 +5,6 @@ ext { archivesBaseName = "${project.projectName}-${project.name}" -configureAllRetroLambda() - dependencies { compile project(":core") compile dependencyJunit diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 95bdedca..8e5461fd 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -260,13 +260,13 @@ public static Gen> arbF4Invariant(final Gen * @return An arbitrary for function-6. */ public static Gen> arbF6Invariant(final Gen a) { - return a.map(compose(Function.uncurryF6(), - compose(Function.>>>>>constant(), - compose(Function.>>>>constant(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant()))))))); + return a.map(compose(Function.uncurryF6(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + Function.constant()))))))); } /** @@ -301,14 +301,14 @@ public static Gen> arbF4Invariant(final Gen * @return An arbitrary for function-7. */ public static Gen> arbF7Invariant(final Gen a) { - return a.map(compose(Function.uncurryF7(), - compose(Function.>>>>>>constant(), - compose(Function.>>>>>constant(), - compose(Function.>>>>constant(), - compose(Function.>>>constant(), - compose(Function.>>constant(), - compose(Function.>constant(), - Function.constant())))))))); + return a.map(compose(Function.uncurryF7(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), + Function.constant())))))))); } /** @@ -346,17 +346,17 @@ public static Gen> arbF4Invariant(final Gen */ public static Gen> arbF8Invariant( final Gen a) { - return a.map(compose(Function.uncurryF8(), - compose(Function.>>>>>>>constant(), - compose(Function.>>>>>>constant(), - compose(Function.>>>>>constant(), + return a.map(compose(Function.uncurryF8(), + compose(Function.constant(), + compose(Function.constant(), + compose(Function.constant(), compose( - Function.>>>>constant(), - compose(Function.>>>constant(), + Function.constant(), + compose(Function.constant(), compose( - Function.>>constant(), - compose(Function.>constant(), - Function.constant()))))))))); + Function.constant(), + compose(Function.constant(), + Function.constant()))))))))); } /** diff --git a/settings.gradle b/settings.gradle index d231d998..f1a6bd56 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,5 +1,5 @@ rootProject.name = "functionaljava" -include "core", "demo", "consume", "java8", "quickcheck", "props-core", "props-core-scalacheck", "java-core", "performance" +include "core", "demo", "consume", "quickcheck", "props-core", "props-core-scalacheck", "java-core", "performance" From 2e1f2c57176a2bf8974ef0725e681e9042cff9ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 23 Sep 2018 14:28:40 -0400 Subject: [PATCH 216/336] Add Strategy tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- .../fj/control/parallel/StrategyTest.java | 61 +++++++++++++++++++ core/src/test/java/fj/data/StreamTest.java | 16 ----- 2 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 core/src/test/java/fj/control/parallel/StrategyTest.java diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java new file mode 100644 index 00000000..ee3b30df --- /dev/null +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -0,0 +1,61 @@ +package fj.control.parallel; + +import fj.Ord; +import fj.P; +import fj.P1; +import fj.data.Enumerator; +import fj.data.List; +import fj.data.Stream; +import org.junit.Test; + +import java.util.concurrent.*; + +import static fj.control.parallel.Callables.callable; +import static fj.control.parallel.Strategy.*; +import static fj.data.Stream.range; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class StrategyTest { + + @Test + public void testStrategySeq() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, seqStrategy()), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyThread() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, simpleThreadStrategy()), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyExecutor() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + final ExecutorService es = Executors.newFixedThreadPool(10); + assertThat(s.sort(Ord.intOrd, executorStrategy(es)), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyCompletion() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + final ExecutorService es = Executors.newFixedThreadPool(10); + final CompletionService cs = new ExecutorCompletionService(es); + assertThat(s.sort(Ord.intOrd, completionStrategy(cs)), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyMergeAll() { + final List l = List.range(0, 100); + final List> p1s = mergeAll(l.map(x -> CompletableFuture.supplyAsync(() -> x))); + assertThat(P1.sequence(p1s)._1(), is(l)); + } + + @Test + public void testStrategyCallables() throws Exception { + final Strategy> s = strategy(c -> c); + final Strategy> cs = callableStrategy(s); + assertThat(callableStrategy(s).par(P.p(callable(1)))._1().call(), is(1)); + } +} diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index b65e115c..999a3a3e 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -1,9 +1,7 @@ package fj.data; import fj.Equal; -import fj.Ord; import fj.P2; -import fj.control.parallel.Strategy; import org.junit.Test; import java.util.ConcurrentModificationException; @@ -105,18 +103,4 @@ public void testMinus() { assertThat(s1.minus(Equal.charEqual, s2), is(stream(new Character[]{'a', 'c', 'd'}))); } - - @Test - public void testSortSeq() { - Stream s = range(Enumerator.intEnumerator, 99, -99, -1); - assertThat(s.sort(Ord.intOrd, Strategy.seqStrategy()), - is(s.sort(Ord.intOrd))); - } - - @Test - public void testSortThread() { - Stream s = range(Enumerator.intEnumerator, 99, -99, -1); - assertThat(s.sort(Ord.intOrd, Strategy.simpleThreadStrategy()), - is(s.sort(Ord.intOrd))); - } } From 9893314de654075a46f53f6aa6edb4e0426228bd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 11:13:26 +0200 Subject: [PATCH 217/336] Fix regression in lifted semigroup sum. Move lifted definition in Monoid. --- core/src/main/java/fj/Monoid.java | 31 +++++++++++++++++++++++++++ core/src/main/java/fj/Semigroup.java | 24 +-------------------- core/src/test/java/fj/MonoidTest.java | 19 ++++++++++++++++ 3 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 core/src/test/java/fj/MonoidTest.java diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 3fcf1775..cdb8e746 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -17,6 +17,7 @@ import static fj.data.List.nil; import static fj.data.Natural.natural; import static fj.data.Option.none; +import static fj.data.Option.some; import static fj.data.Stream.iterableStream; import java.math.BigInteger; @@ -867,6 +868,36 @@ public List sum(F0>> as) { }); } + /** + * Lift a {@code Semigroup} for A to a {@code Monoid>}, using Option.none() as zero. + * + * @return A monoid for option. + */ + public static Monoid> optionMonoid(Semigroup aSemigroup) { + return monoidDef(new Monoid.Definition>() { + @Override + public Option empty() { + return none(); + } + + @Override + public Option append(Option a1, Option a2) { + return a1.liftM2(a2, aSemigroup::sum).orElse(a1).orElse(a2); + } + + @Override + public Option multiply(int n, Option oa) { + return n > 0 ? oa.map(a -> aSemigroup.multiply1p(n - 1, a)) : none(); + } + + @Override + public Option sum(F0>> oas) { + Stream as = oas.f().bind(Option::toStream); + return as.uncons(none(), h -> tail -> some(aSemigroup.sumStream(h, tail::_1))); + } + }); + } + /** * A monoid for options. * @deprecated since 4.7. Use {@link #firstOptionMonoid()}. diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 16b0d130..f626ded7 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -172,29 +172,7 @@ public Semigroup dual() { * Lifts the semigroup to obtain a trivial monoid. */ public Monoid> lift() { - Definition def = this.def; - return monoidDef(new Monoid.Definition>() { - @Override - public Option empty() { - return none(); - } - - @Override - public Option append(Option a1, Option a2) { - return a1.liftM2(a1, def::append).orElse(a1).orElse(a2); - } - - @Override - public Option multiply(int n, Option oa) { - return n > 0 ? oa.map(a -> def.multiply1p(n - 1, a)) : none(); - } - - @Override - public Option sum(F0>> oas) { - Stream as = oas.f().bind(Option::toStream); - return as.uncons(none(), h -> tail -> some(def.sum(h, tail::_1))); - } - }); + return Monoid.optionMonoid(this); } /** diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java new file mode 100644 index 00000000..8bab5315 --- /dev/null +++ b/core/src/test/java/fj/MonoidTest.java @@ -0,0 +1,19 @@ +package fj; + +import fj.data.Option; +import fj.data.Stream; +import org.junit.Test; + +import static fj.data.Option.some; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class MonoidTest { + + @Test + public void lifted_sum_of_two_numbers() { + Monoid> optionMonoid = Semigroup.intAdditionSemigroup.lift(); + assertThat(optionMonoid.sum(some(3), some(5)), is(some(8))); + assertThat(optionMonoid.sumLeft(Stream.arrayStream(some(3), some(5))), is(some(8))); + } +} From d3d876c28b31b5ad210302614abdd2e8c7b3165f Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 11:25:47 +0200 Subject: [PATCH 218/336] Add Trampoline.suspend(final F0> a). --- core/src/main/java/fj/control/Trampoline.java | 17 ++++++++++++++--- core/src/main/java/fj/data/DList.java | 2 +- core/src/main/java/fj/data/Eval.java | 6 +++--- core/src/main/java/fj/data/List.java | 2 +- core/src/main/java/fj/data/State.java | 3 +-- quickcheck/src/main/java/fj/test/Gen.java | 5 ++--- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 37491c3b..0b6060b1 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -46,7 +46,7 @@ public R fold(final F, R> n, // The monadic bind constructs a new Codense whose subcomputation is still `sub`, and Kleisli-composes the // continuations. public Trampoline bind(final F> f) { - return codense(sub, o -> suspend(P.lazy(() -> cont.f(o).bind(f)))); + return codense(sub, o -> suspend(() -> cont.f(o).bind(f))); } // The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result @@ -126,6 +126,16 @@ public static Trampoline pure(final A a) { return new Pure<>(a); } + /** + * Suspends the given computation in a thunk. + * + * @param a A trampoline suspended in a thunk. + * @return A trampoline whose next step runs the given thunk. + */ + public static Trampoline suspend(final F0> a) { + return new Suspend<>(P.lazy(a)); + } + /** * Suspends the given computation in a thunk. * @@ -136,6 +146,7 @@ public static Trampoline suspend(final P1> a) { return new Suspend<>(a); } + /** * @return The first-class version of `suspend`. */ @@ -255,7 +266,7 @@ public final Trampoline zipWith(final Trampoline b, final F2>, B> eb = b.resume(); for (final P1> x : ea.left()) { for (final P1> y : eb.left()) { - return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(P.lazy(() -> ta.zipWith(tb, f)))))); + return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(() -> ta.zipWith(tb, f))))); } for (final B y : eb.right()) { return suspend(x.map(ta -> ta.map(F2Functions.f(F2Functions.flip(f), y)))); @@ -263,7 +274,7 @@ public final Trampoline zipWith(final Trampoline b, final F2 pure(f.f(x, y)))); + return suspend(() -> pure(f.f(x, y))); } for (final P1> y : eb.left()) { return suspend(y.map(liftM2(F2Functions.curry(f)).f(pure(x)))); diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index af9d68b0..597b6dda 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -126,6 +126,6 @@ public DList append(DList other) { } private static F> kleisliTrampCompose(F> bc, F> ab) { - return (A a) -> ab.f(a).bind((B b) -> Trampoline.suspend(P.lazy(() -> bc.f(b)))); + return (A a) -> ab.f(a).bind((B b) -> Trampoline.suspend(() -> bc.f(b))); } } diff --git a/core/src/main/java/fj/data/Eval.java b/core/src/main/java/fj/data/Eval.java index 3e513075..5d09f913 100644 --- a/core/src/main/java/fj/data/Eval.java +++ b/core/src/main/java/fj/data/Eval.java @@ -204,7 +204,7 @@ private static final class PureTrampolineEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> Trampoline.pure(start.value()))); + return Trampoline.suspend(() -> Trampoline.pure(start.value())); } } @@ -219,7 +219,7 @@ private static final class BindTrampolineEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> next.trampoline().bind(v -> f.f(v).asTrampoline().trampoline()))); + return Trampoline.suspend(() -> next.trampoline().bind(v -> f.f(v).asTrampoline().trampoline())); } } @@ -232,7 +232,7 @@ private static final class DeferEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> memo._1().asTrampoline().trampoline())); + return Trampoline.suspend(() -> memo._1().asTrampoline().trampoline()); } } } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index f58fd73f..e0e12877 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -736,7 +736,7 @@ public final B foldRight(final F2 f, final B b) { * @return A Trampoline containing the final result after the right-fold reduction. */ public final Trampoline foldRightC(final F2 f, final B b) { - return Trampoline.suspend(P.lazy(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head())))); + return Trampoline.suspend(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head()))); } /** diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 1b30a55e..f29d55d7 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -5,7 +5,6 @@ import fj.Unit; import fj.control.Trampoline; -import static fj.P.lazy; import static fj.P.p; import static fj.control.Trampoline.suspend; import static fj.data.List.cons; @@ -75,7 +74,7 @@ public static State> traverse(List list, F State suspended(F>> runF) { - return new State<>(s -> suspend(lazy(() -> runF.f(s)))); + return new State<>(s -> suspend(() -> runF.f(s))); } private final F>> runF; diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index a5e30a9d..323995e1 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -16,7 +16,6 @@ import static fj.Function.flip; import static fj.Monoid.intAdditionMonoid; import static fj.Ord.intOrd; -import static fj.P.lazy; import static fj.P2.__1; import static fj.control.Trampoline.pure; import static fj.control.Trampoline.suspend; @@ -551,7 +550,7 @@ final class Tramp { // Picks elements in constant stack space private Trampoline> tramp(List remainAs, int remainN, int remainALength) { - return suspend(lazy(() -> + return suspend(() -> (remainN == 0) ? // We have picked N elements; stop pure(nil()) : @@ -559,7 +558,7 @@ private Trampoline> tramp(List remainAs, int remainN, int remainALeng (r.choose(0, remainALength - 1) < remainN) ? tramp(remainAs.tail(), remainN - 1, remainALength - 1) .map(pickedTail -> cons(remainAs.head(), pickedTail)) : - tramp(remainAs.tail(), remainN, remainALength - 1))); + tramp(remainAs.tail(), remainN, remainALength - 1)); } } From cf1188acafd62d60f1736a0d945790771029079b Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 11:13:26 +0200 Subject: [PATCH 219/336] Fix regression in lifted semigroup sum. Move lifted definition in Monoid. --- core/src/main/java/fj/Monoid.java | 31 +++++++++++++++++++++++++++ core/src/main/java/fj/Semigroup.java | 24 +-------------------- core/src/test/java/fj/MonoidTest.java | 19 ++++++++++++++++ 3 files changed, 51 insertions(+), 23 deletions(-) create mode 100644 core/src/test/java/fj/MonoidTest.java diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 3fcf1775..cdb8e746 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -17,6 +17,7 @@ import static fj.data.List.nil; import static fj.data.Natural.natural; import static fj.data.Option.none; +import static fj.data.Option.some; import static fj.data.Stream.iterableStream; import java.math.BigInteger; @@ -867,6 +868,36 @@ public List sum(F0>> as) { }); } + /** + * Lift a {@code Semigroup} for A to a {@code Monoid>}, using Option.none() as zero. + * + * @return A monoid for option. + */ + public static Monoid> optionMonoid(Semigroup aSemigroup) { + return monoidDef(new Monoid.Definition>() { + @Override + public Option empty() { + return none(); + } + + @Override + public Option append(Option a1, Option a2) { + return a1.liftM2(a2, aSemigroup::sum).orElse(a1).orElse(a2); + } + + @Override + public Option multiply(int n, Option oa) { + return n > 0 ? oa.map(a -> aSemigroup.multiply1p(n - 1, a)) : none(); + } + + @Override + public Option sum(F0>> oas) { + Stream as = oas.f().bind(Option::toStream); + return as.uncons(none(), h -> tail -> some(aSemigroup.sumStream(h, tail::_1))); + } + }); + } + /** * A monoid for options. * @deprecated since 4.7. Use {@link #firstOptionMonoid()}. diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 16b0d130..f626ded7 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -172,29 +172,7 @@ public Semigroup dual() { * Lifts the semigroup to obtain a trivial monoid. */ public Monoid> lift() { - Definition def = this.def; - return monoidDef(new Monoid.Definition>() { - @Override - public Option empty() { - return none(); - } - - @Override - public Option append(Option a1, Option a2) { - return a1.liftM2(a1, def::append).orElse(a1).orElse(a2); - } - - @Override - public Option multiply(int n, Option oa) { - return n > 0 ? oa.map(a -> def.multiply1p(n - 1, a)) : none(); - } - - @Override - public Option sum(F0>> oas) { - Stream as = oas.f().bind(Option::toStream); - return as.uncons(none(), h -> tail -> some(def.sum(h, tail::_1))); - } - }); + return Monoid.optionMonoid(this); } /** diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java new file mode 100644 index 00000000..8bab5315 --- /dev/null +++ b/core/src/test/java/fj/MonoidTest.java @@ -0,0 +1,19 @@ +package fj; + +import fj.data.Option; +import fj.data.Stream; +import org.junit.Test; + +import static fj.data.Option.some; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class MonoidTest { + + @Test + public void lifted_sum_of_two_numbers() { + Monoid> optionMonoid = Semigroup.intAdditionSemigroup.lift(); + assertThat(optionMonoid.sum(some(3), some(5)), is(some(8))); + assertThat(optionMonoid.sumLeft(Stream.arrayStream(some(3), some(5))), is(some(8))); + } +} From c3ea5d36dd7869e8e4da411b4d9b926a44fb4bcd Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 11:25:47 +0200 Subject: [PATCH 220/336] Add Trampoline.suspend(final F0> a). --- core/src/main/java/fj/control/Trampoline.java | 17 ++++++++++++++--- core/src/main/java/fj/data/DList.java | 2 +- core/src/main/java/fj/data/Eval.java | 6 +++--- core/src/main/java/fj/data/List.java | 2 +- core/src/main/java/fj/data/State.java | 3 +-- quickcheck/src/main/java/fj/test/Gen.java | 5 ++--- 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 37491c3b..0b6060b1 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -46,7 +46,7 @@ public R fold(final F, R> n, // The monadic bind constructs a new Codense whose subcomputation is still `sub`, and Kleisli-composes the // continuations. public Trampoline bind(final F> f) { - return codense(sub, o -> suspend(P.lazy(() -> cont.f(o).bind(f)))); + return codense(sub, o -> suspend(() -> cont.f(o).bind(f))); } // The resumption of a Codense is the resumption of its subcomputation. If that computation is done, its result @@ -126,6 +126,16 @@ public static Trampoline pure(final A a) { return new Pure<>(a); } + /** + * Suspends the given computation in a thunk. + * + * @param a A trampoline suspended in a thunk. + * @return A trampoline whose next step runs the given thunk. + */ + public static Trampoline suspend(final F0> a) { + return new Suspend<>(P.lazy(a)); + } + /** * Suspends the given computation in a thunk. * @@ -136,6 +146,7 @@ public static Trampoline suspend(final P1> a) { return new Suspend<>(a); } + /** * @return The first-class version of `suspend`. */ @@ -255,7 +266,7 @@ public final Trampoline zipWith(final Trampoline b, final F2>, B> eb = b.resume(); for (final P1> x : ea.left()) { for (final P1> y : eb.left()) { - return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(P.lazy(() -> ta.zipWith(tb, f)))))); + return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(() -> ta.zipWith(tb, f))))); } for (final B y : eb.right()) { return suspend(x.map(ta -> ta.map(F2Functions.f(F2Functions.flip(f), y)))); @@ -263,7 +274,7 @@ public final Trampoline zipWith(final Trampoline b, final F2 pure(f.f(x, y)))); + return suspend(() -> pure(f.f(x, y))); } for (final P1> y : eb.left()) { return suspend(y.map(liftM2(F2Functions.curry(f)).f(pure(x)))); diff --git a/core/src/main/java/fj/data/DList.java b/core/src/main/java/fj/data/DList.java index af9d68b0..597b6dda 100644 --- a/core/src/main/java/fj/data/DList.java +++ b/core/src/main/java/fj/data/DList.java @@ -126,6 +126,6 @@ public DList append(DList other) { } private static F> kleisliTrampCompose(F> bc, F> ab) { - return (A a) -> ab.f(a).bind((B b) -> Trampoline.suspend(P.lazy(() -> bc.f(b)))); + return (A a) -> ab.f(a).bind((B b) -> Trampoline.suspend(() -> bc.f(b))); } } diff --git a/core/src/main/java/fj/data/Eval.java b/core/src/main/java/fj/data/Eval.java index 3e513075..5d09f913 100644 --- a/core/src/main/java/fj/data/Eval.java +++ b/core/src/main/java/fj/data/Eval.java @@ -204,7 +204,7 @@ private static final class PureTrampolineEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> Trampoline.pure(start.value()))); + return Trampoline.suspend(() -> Trampoline.pure(start.value())); } } @@ -219,7 +219,7 @@ private static final class BindTrampolineEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> next.trampoline().bind(v -> f.f(v).asTrampoline().trampoline()))); + return Trampoline.suspend(() -> next.trampoline().bind(v -> f.f(v).asTrampoline().trampoline())); } } @@ -232,7 +232,7 @@ private static final class DeferEval extends TrampolineEval { @Override protected final Trampoline trampoline() { - return Trampoline.suspend(P.lazy(() -> memo._1().asTrampoline().trampoline())); + return Trampoline.suspend(() -> memo._1().asTrampoline().trampoline()); } } } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index f58fd73f..e0e12877 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -736,7 +736,7 @@ public final B foldRight(final F2 f, final B b) { * @return A Trampoline containing the final result after the right-fold reduction. */ public final Trampoline foldRightC(final F2 f, final B b) { - return Trampoline.suspend(P.lazy(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head())))); + return Trampoline.suspend(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head()))); } /** diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index 1b30a55e..f29d55d7 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -5,7 +5,6 @@ import fj.Unit; import fj.control.Trampoline; -import static fj.P.lazy; import static fj.P.p; import static fj.control.Trampoline.suspend; import static fj.data.List.cons; @@ -75,7 +74,7 @@ public static State> traverse(List list, F State suspended(F>> runF) { - return new State<>(s -> suspend(lazy(() -> runF.f(s)))); + return new State<>(s -> suspend(() -> runF.f(s))); } private final F>> runF; diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index a5e30a9d..323995e1 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -16,7 +16,6 @@ import static fj.Function.flip; import static fj.Monoid.intAdditionMonoid; import static fj.Ord.intOrd; -import static fj.P.lazy; import static fj.P2.__1; import static fj.control.Trampoline.pure; import static fj.control.Trampoline.suspend; @@ -551,7 +550,7 @@ final class Tramp { // Picks elements in constant stack space private Trampoline> tramp(List remainAs, int remainN, int remainALength) { - return suspend(lazy(() -> + return suspend(() -> (remainN == 0) ? // We have picked N elements; stop pure(nil()) : @@ -559,7 +558,7 @@ private Trampoline> tramp(List remainAs, int remainN, int remainALeng (r.choose(0, remainALength - 1) < remainN) ? tramp(remainAs.tail(), remainN - 1, remainALength - 1) .map(pickedTail -> cons(remainAs.head(), pickedTail)) : - tramp(remainAs.tail(), remainN, remainALength - 1))); + tramp(remainAs.tail(), remainN, remainALength - 1)); } } From e1a0983a365ca6a934dccf14a181a9ba486ccdd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 23 Sep 2018 20:28:40 +0200 Subject: [PATCH 221/336] Add Strategy tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták (cherry picked from commit 2e1f2c57176a2bf8974ef0725e681e9042cff9ec) --- .../fj/control/parallel/StrategyTest.java | 61 +++++++++++++++++++ core/src/test/java/fj/data/StreamTest.java | 16 ----- 2 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 core/src/test/java/fj/control/parallel/StrategyTest.java diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java new file mode 100644 index 00000000..ee3b30df --- /dev/null +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -0,0 +1,61 @@ +package fj.control.parallel; + +import fj.Ord; +import fj.P; +import fj.P1; +import fj.data.Enumerator; +import fj.data.List; +import fj.data.Stream; +import org.junit.Test; + +import java.util.concurrent.*; + +import static fj.control.parallel.Callables.callable; +import static fj.control.parallel.Strategy.*; +import static fj.data.Stream.range; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class StrategyTest { + + @Test + public void testStrategySeq() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, seqStrategy()), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyThread() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + assertThat(s.sort(Ord.intOrd, simpleThreadStrategy()), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyExecutor() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + final ExecutorService es = Executors.newFixedThreadPool(10); + assertThat(s.sort(Ord.intOrd, executorStrategy(es)), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyCompletion() { + final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); + final ExecutorService es = Executors.newFixedThreadPool(10); + final CompletionService cs = new ExecutorCompletionService(es); + assertThat(s.sort(Ord.intOrd, completionStrategy(cs)), is(s.sort(Ord.intOrd))); + } + + @Test + public void testStrategyMergeAll() { + final List l = List.range(0, 100); + final List> p1s = mergeAll(l.map(x -> CompletableFuture.supplyAsync(() -> x))); + assertThat(P1.sequence(p1s)._1(), is(l)); + } + + @Test + public void testStrategyCallables() throws Exception { + final Strategy> s = strategy(c -> c); + final Strategy> cs = callableStrategy(s); + assertThat(callableStrategy(s).par(P.p(callable(1)))._1().call(), is(1)); + } +} diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index b65e115c..999a3a3e 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -1,9 +1,7 @@ package fj.data; import fj.Equal; -import fj.Ord; import fj.P2; -import fj.control.parallel.Strategy; import org.junit.Test; import java.util.ConcurrentModificationException; @@ -105,18 +103,4 @@ public void testMinus() { assertThat(s1.minus(Equal.charEqual, s2), is(stream(new Character[]{'a', 'c', 'd'}))); } - - @Test - public void testSortSeq() { - Stream s = range(Enumerator.intEnumerator, 99, -99, -1); - assertThat(s.sort(Ord.intOrd, Strategy.seqStrategy()), - is(s.sort(Ord.intOrd))); - } - - @Test - public void testSortThread() { - Stream s = range(Enumerator.intEnumerator, 99, -99, -1); - assertThat(s.sort(Ord.intOrd, Strategy.simpleThreadStrategy()), - is(s.sort(Ord.intOrd))); - } } From 7b3cdae5e9d708904d72afffe039710ed8a9ad28 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 20:00:44 +0200 Subject: [PATCH 222/336] Add missing @Deprecated annotations (previously only on javadoc). --- core/src/main/java/fj/P1.java | 3 ++- core/src/main/java/fj/Semigroup.java | 3 ++- core/src/main/java/fj/data/Java.java | 1 + 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 555a28ae..5e627403 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -42,10 +42,11 @@ public static F, A> __1() { /** * Promote any function to a transformation between P1s. * - * @deprecated As of release 4.5, use {@link #map_} + * @deprecated As of release 4.5, use {@link #map_} * @param f A function to promote to a transformation between P1s. * @return A function promoted to operate on P1s. */ + @Deprecated public static F, P1> fmap(final F f) { return map_(f); } diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index f626ded7..075dfeda 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -527,8 +527,9 @@ public NonEmptyList sum(NonEmptyList nea, F0>> neas * A semigroup for optional values. * @deprecated since 4.7. Use {@link #firstOptionSemigroup()}. * - ** @return A semigroup for optional values. + * @return A semigroup for optional values. */ + @Deprecated public static Semigroup> optionSemigroup() { return firstOptionSemigroup(); } diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 80a5ec43..ae7fcf6a 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -1420,6 +1420,7 @@ public static F, List> ArrayList_List() { * * @return A function that converts Java lists to lists. */ + @Deprecated public static F, List> JUList_List() { return Java::JavaList_List; } From 9f489c9428ff06ea39400239faa929eae9d78bba Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 21:08:42 +0200 Subject: [PATCH 223/336] Fix compile warnings. --- core/src/test/java/fj/FWFunctionsTest.java | 4 ++-- core/src/test/java/fj/TryEffectTest.java | 6 ++---- core/src/test/java/fj/control/parallel/StrategyTest.java | 3 ++- props-core/src/test/java/fj/MemoisationTest.java | 9 +++++---- .../test/java/fj/data/fingertrees/FingerTreeTest.java | 6 ++++-- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/core/src/test/java/fj/FWFunctionsTest.java b/core/src/test/java/fj/FWFunctionsTest.java index c1f69718..1c034ab9 100644 --- a/core/src/test/java/fj/FWFunctionsTest.java +++ b/core/src/test/java/fj/FWFunctionsTest.java @@ -9,14 +9,14 @@ public class FWFunctionsTest { @Test public void testLift1() { F f = i -> i + 1; - F1W f1w = F1W.lift(f); + F1W f1w = F1W.lift(f); assertThat(f1w.f(1), is(2)); } @Test public void testLift2() { F2 f2 = (i, j) -> i + j; - F2W f2w = F2W.lift(f2); + F2W f2w = F2W.lift(f2); assertThat(f2w.f(1, 2), is(3)); } diff --git a/core/src/test/java/fj/TryEffectTest.java b/core/src/test/java/fj/TryEffectTest.java index bb684fc6..ea92b8f2 100644 --- a/core/src/test/java/fj/TryEffectTest.java +++ b/core/src/test/java/fj/TryEffectTest.java @@ -11,8 +11,7 @@ public class TryEffectTest { @Test public void testTryEffect0Success() { - F> f = - TryEffect.f(TryEffect0::f); + F, Validation> f = TryEffect.f(TryEffect0::f); Validation v = f.f(new AlwaysSucceed0()); assertThat(v.isSuccess(), is(true)); assertThat(v.success(), is(Unit.unit())); @@ -20,8 +19,7 @@ public void testTryEffect0Success() { @Test public void testTryEffect0Fail() { - F> f = - TryEffect.f(TryEffect0::f); + F, Validation> f = TryEffect.f(TryEffect0::f); Validation v = f.f(new AlwaysFail0()); assertThat(v.isFail(), is(true)); assertThat(v.fail(), is(new TryEffectException())); diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java index ee3b30df..8475b35a 100644 --- a/core/src/test/java/fj/control/parallel/StrategyTest.java +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -3,6 +3,7 @@ import fj.Ord; import fj.P; import fj.P1; +import fj.Unit; import fj.data.Enumerator; import fj.data.List; import fj.data.Stream; @@ -41,7 +42,7 @@ public void testStrategyExecutor() { public void testStrategyCompletion() { final Stream s = range(Enumerator.intEnumerator, 99, -99, -1); final ExecutorService es = Executors.newFixedThreadPool(10); - final CompletionService cs = new ExecutorCompletionService(es); + final CompletionService cs = new ExecutorCompletionService<>(es); assertThat(s.sort(Ord.intOrd, completionStrategy(cs)), is(s.sort(Ord.intOrd))); } diff --git a/props-core/src/test/java/fj/MemoisationTest.java b/props-core/src/test/java/fj/MemoisationTest.java index 65fa83fc..865f76a3 100644 --- a/props-core/src/test/java/fj/MemoisationTest.java +++ b/props-core/src/test/java/fj/MemoisationTest.java @@ -6,6 +6,7 @@ import org.junit.runner.RunWith; import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbString; import static fj.test.CheckResult.summary; import static fj.test.Property.prop; import static fj.test.Property.property; @@ -25,16 +26,16 @@ public Property test1() { } public Property test1_hardMemo() { - return property(arbInteger, a -> { - P1 t = P.hardMemo(() -> new Integer(a)); + return property(arbString, a -> { + P1 t = P.hardMemo(() -> new String(a)); return prop(t._1() == t._1()).and(prop(t._1().equals(a))); }); } @Test public Property test2() { - return property(arbInteger, arbInteger, (a, b) -> { - P2 t = P.lazy(u -> new Integer(a), u -> new Integer(b)).memo(); + return property(arbString, arbString, (a, b) -> { + P2 t = P.lazy(u -> new String(a), u -> new String(b)).memo(); return prop(t._1().equals(t._1()) && t._1().equals(a) && t._2().equals(t._2()) && t._2().equals(b) ); }); } diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 57e1fae6..b25fff51 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -42,14 +42,16 @@ void validateOperations(List list) { @Test public void testHeadOption() { assertThat(Empty.emptyIntAddition().headOption(), is(Option.none())); - FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1); + FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))) + .single(1); assertThat(ft.headOption(), is(Option.some(1))); } @Test public void testUncons() { assertThat(Empty.emptyIntAddition().uncons(0, (h, t) -> h), is(0)); - FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))).single(1); + FingerTree ft = new MakeTree(measured(intAdditionMonoid, Function.constant(1))) + .single(1); assertThat(ft.uncons(0, (h, t) -> h), is(1)); } From 4c93bae8c23385b9d9acc0e2358073384a10ae03 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 21:09:17 +0200 Subject: [PATCH 224/336] Update gradle. Fix gradle warnings. --- build.gradle | 24 ++++++++--------------- gradle/wrapper/gradle-wrapper.jar | Bin 54708 -> 56177 bytes gradle/wrapper/gradle-wrapper.properties | 3 +-- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/build.gradle b/build.gradle index 9d98d2b3..bc292a82 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,11 @@ buildscript { classpath "com.ofg:uptodate-gradle-plugin:$uptodateVersion" classpath "me.tatarka:gradle-retrolambda:$retrolambdaPluginVersion" } + + wrapper { + gradleVersion = "4.10.2" + distributionType = Wrapper.DistributionType.ALL + } } if (JavaVersion.current().isJava8Compatible()) { @@ -117,23 +122,10 @@ subprojects { } } - jacocoTestReport { - additionalSourceDirs = files(sourceSets.main.allSource.srcDirs) - sourceDirectories = files(sourceSets.main.allSource.srcDirs) - classDirectories = files(sourceSets.main.output) - reports { - html.enabled = true - xml.enabled = true - csv.enabled = false - } - } - - task coverage(dependsOn: ["test", "jacocoTestReport"]) << {} - } task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { - dependsOn = subprojects.coverage + dependsOn = subprojects*.test executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") // We only care about coverage of: def projectForFoverage = ["core", "java8", "quickcheck", "java-core"] @@ -192,7 +184,7 @@ configure(subprojects.findAll { it.name != "props-core" }) { } // Output MANIFEST.MF statically so eclipse can see it for plugin development - task eclipsePluginManifest(dependsOn: jar) << { + task eclipsePluginManifest(dependsOn: jar) doLast { file("META-INF").mkdirs() jar.manifest.writeTo(file("META-INF/MANIFEST.MF")) } @@ -200,6 +192,6 @@ configure(subprojects.findAll { it.name != "props-core" }) { eclipseProject.dependsOn eclipsePluginManifest } -task env << { +task env doLast { println System.getenv() } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7a3265ee94c0ab25cf079ac8ccdf87f41d455d42..29953ea141f55e3b8fc691d31b5ca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<~)SR3MUZHUMHDIiwi5WGsZZMDnv@wAWc$1^^4aiUK zZ~e$70Wkkbr6@j$1BI>#>i$3hT2aOamCm38-X!RI^KC*UFpv&(w}1|Klc(qnNJjl{ z5wugxfPb=q#Dj0ZZO2C_(3~#(a>Hi;46bj88L_Vz|>R=85 z;pk$?YUyHZW@pZ7YG=**@1FOM-mwt4Ts1Ju?``{MnuDsQB?12xv4wyTd{Z7BSSn(g z05on#1yYQ296I2yfDQNu(u0?qoNqi4ef|sd z0Al{_F8>t~fq)Qt14Q!!<<2Psc9Z`{RNxIjE%2`=mU(W#o4D{dpv&ODpuBk|z~3M; zaGh?!js3PLtmwZWlm$k>n=qX>o^ZZ`LG<8=9U8!!Fo-uG_=LZpg9S3c8!q`95bifH zNC4C^j}G`ROZngT2`l-pC;SX#Q0F2#;0-VIjklZB{{XXbK@3ai(EkwgKq5=HP*WM8 ztz2*h_jz>azwE3mu#GkwjHLwW6_ETb{S9^HjZ^bHFpvTy{Sz1PX4l{i2)!PZ(?bDD z1%v+oj0D`Fncjd7+Q1-|zyI5R#&%yw2nZxFyI$Z8=&Tb&z5E{V&shHt;0fGH{BHm~ p-JqCdbEt2u3x<%@f8MG(Y}9d{||T4^I-r0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 72c40576..d76b502e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Sat Aug 25 14:20:05 CEST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.8.1-all.zip From b797968ae46d5eafd951b03c68d649b9aae8f654 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Sun, 7 Oct 2018 21:52:42 +0200 Subject: [PATCH 225/336] Fix javadoc warnings. --- core/src/main/java/fj/Function.java | 28 +++++++++---------- core/src/main/java/fj/Monoid.java | 2 +- core/src/main/java/fj/Semigroup.java | 2 +- core/src/main/java/fj/control/Trampoline.java | 12 ++++---- core/src/main/java/fj/data/Enumerator.java | 16 +++++------ core/src/main/java/fj/data/Tree.java | 4 ++- core/src/main/java/fj/data/hlist/HPre.java | 4 +-- core/src/main/java/fj/data/optic/Iso.java | 4 +-- core/src/main/java/fj/data/optic/PIso.java | 16 +++++------ core/src/main/java/fj/data/optic/PLens.java | 26 +++++++++-------- .../main/java/fj/data/optic/POptional.java | 18 ++++++------ core/src/main/java/fj/data/optic/PPrism.java | 17 ++++++----- core/src/main/java/fj/data/optic/PSetter.java | 14 ++++++---- .../main/java/fj/data/optic/PTraversal.java | 6 ++-- quickcheck/src/main/java/fj/test/Gen.java | 12 ++++---- 15 files changed, 96 insertions(+), 85 deletions(-) diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index f95b1c87..995c179d 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -778,11 +778,11 @@ public static F join(final F> f) { /** * Partial application of the second argument to the supplied function to get a function of type - * A -> C. Same as flip(f).f(b). + * {@code A -> C}. Same as {@code flip(f).f(b)}. * * @param f The function to partially apply. * @param b The value to apply to the function. - * @return A new function based on f with its second argument applied. + * @return A new function based on {@code f} with its second argument applied. */ public static F partialApply2(final F> f, final B b) { return a -> uncurryF2(f).f(a, b); @@ -790,11 +790,11 @@ public static F partialApply2(final F> f, final B b) /** * Partial application of the third argument to the supplied function to get a function of type - * A -> B -> D. + * {@code A -> B -> D}. * * @param f The function to partially apply. * @param c The value to apply to the function. - * @return A new function based on f with its third argument applied. + * @return A new function based on {@code f} with its third argument applied. */ public static F> partialApply3(final F>> f, final C c) { return a -> b -> uncurryF3(f).f(a, b, c); @@ -802,11 +802,11 @@ public static F> partialApply3(final F>> /** * Partial application of the fourth argument to the supplied function to get a function of type - * A -> B -> C -> E. + * {@code A -> B -> C -> E}. * * @param f The function to partially apply. * @param d The value to apply to the function. - * @return A new function based on f with its fourth argument applied. + * @return A new function based on {@code f} with its fourth argument applied. */ public static F>> partialApply4(final F>>> f, final D d) { return a -> b -> c -> uncurryF4(f).f(a, b, c, d); @@ -814,11 +814,11 @@ public static F>> partialApply4(final FA -> B -> C -> D -> F$. + * {@code A -> B -> C -> D -> F$}. * * @param f The function to partially apply. * @param e The value to apply to the function. - * @return A new function based on f with its fifth argument applied. + * @return A new function based on {@code f} with its fifth argument applied. */ public static F>>> partialApply5(final F>>>> f, final E e) { @@ -827,11 +827,11 @@ public static F>> partialApply4(final FA -> B -> C -> D -> E -> G. + * {@code A -> B -> C -> D -> E -> G}. * * @param f The function to partially apply. * @param f$ The value to apply to the function. - * @return A new function based on f with its sixth argument applied. + * @return A new function based on {@code f} with its sixth argument applied. */ public static F>>>> partialApply6( final F>>>>> f, final F$ f$) { @@ -840,11 +840,11 @@ public static F>> partialApply4(final FA -> B -> C -> D -> E -> F$ -> H. + * {@code A -> B -> C -> D -> E -> F$ -> H}. * * @param f The function to partially apply. * @param g The value to apply to the function. - * @return A new function based on f with its seventh argument applied. + * @return A new function based on {@code f} with its seventh argument applied. */ public static F>>>>> partialApply7( final F>>>>>> f, final G g) { @@ -853,11 +853,11 @@ public static F>> partialApply4(final FA -> B -> C -> D -> E -> F$ -> G -> I. + * {@code A -> B -> C -> D -> E -> F$ -> G -> I}. * * @param f The function to partially apply. * @param h The value to apply to the function. - * @return A new function based on f with its eigth argument applied. + * @return A new function based on {@code f} with its eigth argument applied. */ public static F>>>>>> partialApply8( final F>>>>>>> f, final H h) { diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index cdb8e746..0c09b558 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -246,7 +246,7 @@ public A zero() { /** * Returns a value summed n times (a + a + ... + a). * The default definition uses peasant multiplication, exploiting - * associativity to only require `O(log n)` uses of + * associativity to only require {@code O(log n)} uses of * {@link #sum(Object, Object)}. * * @param n multiplier diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 075dfeda..42f05f5b 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -134,7 +134,7 @@ public F> sum() { /** * Returns a value summed n + 1 times ( * a + a + ... + a) The default definition uses peasant - * multiplication, exploiting associativity to only require `O(log n)` uses of + * multiplication, exploiting associativity to only require {@code O(log n)} uses of * {@link #sum(Object, Object)}. * * @param n multiplier diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 0b6060b1..47fd282b 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -43,7 +43,7 @@ public R fold(final F, R> n, return gs.f(this); } - // The monadic bind constructs a new Codense whose subcomputation is still `sub`, and Kleisli-composes the + // The monadic bind constructs a new Codense whose subcomputation is still {@code sub}, and Kleisli-composes the // continuations. public Trampoline bind(final F> f) { return codense(sub, o -> suspend(() -> cont.f(o).bind(f))); @@ -110,7 +110,7 @@ private static Codense codense(final Normal a, final F F> pure() { return Trampoline::pure; @@ -148,7 +148,7 @@ public static Trampoline suspend(final P1> a) { /** - * @return The first-class version of `suspend`. + * @return The first-class version of {@code suspend}. */ public static F>, Trampoline> suspend_() { return Trampoline::suspend; @@ -175,21 +175,21 @@ public final Trampoline map(final F f) { } /** - * @return The first-class version of `bind`. + * @return The first-class version of {@code bind}. */ public static F>, F, Trampoline>> bind_() { return f -> a -> a.bind(f); } /** - * @return The first-class version of `map`. + * @return The first-class version of {@code map}. */ public static F, F, Trampoline>> map_() { return f -> a -> a.map(f); } /** - * @return The first-class version of `resume`. + * @return The first-class version of {@code resume}. */ public static F, Either>, A>> resume_() { return Trampoline::resume; diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index 1666d7b2..94f1b2cd 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -18,18 +18,18 @@ /** * Abstracts over a type that may have a successor and/or predecessor value. This implies ordering for that type. A user - * may construct an enumerator with an optimised version for plus, otherwise a default is implemented using + * may construct an enumerator with an optimised version for {@code plus}, otherwise a default is implemented using * the given successor/predecessor implementations. *

      * For any enumerator e, the following laws must satisfy: *

        - *
      • forall a. e.successor(a).forall(\t -> e.predecessor(t).forall(\z -> z == a))
      • - *
      • forall a. e.predecessor(a).forall(\t -> e.successor(t).forall(\z -> z == a))
      • - *
      • e.max().forall(\t -> e.successor(t).isNone)
      • - *
      • e.min().forall(\t -> e.predecessor(t).isNone)
      • - *
      • forall a n. e.plus(a, 0) == Some(a)
      • - *
      • forall a n | n > 0. e.plus(a, n) == e.plus(a, n - 1)
      • - *
      • forall a n | n < 0. e.plus(a, n) == e.plus(a, n + 1)
      • + *
      • {@code forall a. e.successor(a).forall(\t -> e.predecessor(t).forall(\z -> z == a))}
      • + *
      • {@code forall a. e.predecessor(a).forall(\t -> e.successor(t).forall(\z -> z == a))}
      • + *
      • {@code e.max().forall(\t -> e.successor(t).isNone)}
      • + *
      • {@code e.min().forall(\t -> e.predecessor(t).isNone)}
      • + *
      • {@code forall a n. e.plus(a, 0) == Some(a)}
      • + *
      • {@code forall a n | n > 0. e.plus(a, n) == e.plus(a, n - 1)}
      • + *
      • {@code forall a n | n < 0. e.plus(a, n) == e.plus(a, n + 1)}
      • *
      * * @version %build.number% diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index 4b0ce7eb..9eebb932 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -134,8 +134,10 @@ public Stream
      f(final Tree t, final P1> xs) { } /** + *
      {@code
          * flatten :: Tree a -> [a]
          * flatten t = squish t []
      +   * }
      * where squish (Node x ts) xs = x:Prelude.foldr squish xs ts * Puts the elements of the tree into a Stream, in pre-order. * @@ -346,4 +348,4 @@ public int length() { return 1 + subForest._1().map(Tree::length).foldLeft((acc, i) -> acc + i, 0); } -} \ No newline at end of file +} diff --git a/core/src/main/java/fj/data/hlist/HPre.java b/core/src/main/java/fj/data/hlist/HPre.java index 6a2556de..6c6174a4 100644 --- a/core/src/main/java/fj/data/hlist/HPre.java +++ b/core/src/main/java/fj/data/hlist/HPre.java @@ -57,7 +57,7 @@ public static HFalse hFalse() { } /** - * Type-level boolean conjunction. A value of this type represents evidence that AB -> C + * Type-level boolean conjunction. A value of this type represents evidence that {@code AB -> C} * * @param
      A boolean * @param A boolean @@ -92,7 +92,7 @@ public static HAnd hAnd(final HTrue a, final HTrue b) { } /** - * Type-level boolean disjunction. A value of this type represents evidence that A+B -> C + * Type-level boolean disjunction. A value of this type represents evidence that {@code A+B -> C} * * @param A boolean * @param A boolean diff --git a/core/src/main/java/fj/data/optic/Iso.java b/core/src/main/java/fj/data/optic/Iso.java index ea9babac..4b41b1ad 100644 --- a/core/src/main/java/fj/data/optic/Iso.java +++ b/core/src/main/java/fj/data/optic/Iso.java @@ -119,10 +119,10 @@ public static Iso iso(final F get, final F reverseGet) * create an {@link Iso} between any type and itself. id is the zero element of optics composition, for all optics o of type O * (e.g. Lens, Iso, Prism, ...): * - *
      +   * 
      {@code
          *  o composeIso Iso.id == o
          *  Iso.id composeO o == o
      -   * 
      + * }
      * * (replace composeO by composeLens, composeIso, composePrism, ...) */ diff --git a/core/src/main/java/fj/data/optic/PIso.java b/core/src/main/java/fj/data/optic/PIso.java index e10b47bb..b97b416f 100644 --- a/core/src/main/java/fj/data/optic/PIso.java +++ b/core/src/main/java/fj/data/optic/PIso.java @@ -21,18 +21,18 @@ /** * A {@link PIso} defines an isomorphism between types S, A and B, T: * - *
      + * 
      {@code
        *              get                           reverse.get
        *     -------------------->             -------------------->
        *   S                       A         T                       B
        *     <--------------------             <--------------------
        *       reverse.reverseGet                   reverseGet
      - * 
      + * }
      * - * In addition, if f and g forms an isomorphism between `A` and `B`, i.e. if `f . g = id` and `g . f = id`, then a {@link PIso} - * defines an isomorphism between `S` and `T`: + * In addition, if f and g forms an isomorphism between {@code A} and {@code B}, i.e. if {@code f . g = id} and {@code g . f = id}, then a {@link PIso} + * defines an isomorphism between {@code S} and {@code T}: * - *
      + * 
      {@code
        *     S           T                                   S           T
        *     |           |                                   |           |
        *     |           |                                   |           |
      @@ -40,7 +40,7 @@
        *     |           |                                   |           |
        *     |     f     |                                   |     g     |
        *     A --------> B                                   A <-------- B
      - * 
      + * }
      * * A {@link PIso} is also a valid {@link Getter}, {@link Fold}, {@link PLens}, {@link PPrism}, {@link POptional}, * {@link PTraversal} and {@link PSetter} @@ -552,10 +552,10 @@ public PIso reverse() { * create a {@link PIso} between any type and itself. id is the zero element of optics composition, for all optics o of type O * (e.g. Lens, Iso, Prism, ...): * - *
      +   * 
      {@code
          *  o composeIso Iso.id == o
          *  Iso.id composeO o == o
      -   * 
      + * }
      * * (replace composeO by composeLens, composeIso, composePrism, ...) */ diff --git a/core/src/main/java/fj/data/optic/PLens.java b/core/src/main/java/fj/data/optic/PLens.java index 971f76ff..4dcad20b 100644 --- a/core/src/main/java/fj/data/optic/PLens.java +++ b/core/src/main/java/fj/data/optic/PLens.java @@ -17,18 +17,20 @@ import fj.data.vector.V2; /** - * A {@link PLens} can be seen as a pair of functions: - `get: S => A` i.e. from an `S`, we can extract an `A` - `set: (B, S) => - * T` i.e. if we replace an `A` by a `B` in an `S`, we obtain a `T` - * - * A {@link PLens} could also be defined as a weaker {@link PIso} where set requires an additional parameter than reverseGet. - * - * {@link PLens} stands for Polymorphic Lens as it set and modify methods change a type `A` to `B` and `S` to `T`. {@link Lens} - * is a {@link PLens} restricted to monomoprhic updates. - * - * A {@link PLens} is also a valid {@link Getter}, {@link Fold}, {@link POptional}, {@link PTraversal} and {@link PSetter} - * + * A {@link PLens} can be seen as a pair of functions:
        + *
      • {@code get: S => A} i.e. from an {@code S}, we can extract an {@code A}
      • + *
      • {@code set: (B, S) => T} i.e. if we replace an {@code A} by a {@code B} in an {@code S}, we obtain a {@code T}
      • + *
      + *

      + * A {@link PLens} could also be defined as a weaker {@link PIso} where set requires an additional parameter than reverseGet.

      + *

      + * {@link PLens} stands for Polymorphic Lens as it set and modify methods change a type {@code A} to {@code B} and {@code S} to {@code T}. {@link Lens} + * is a {@link PLens} restricted to monomoprhic updates.

      + *

      + * A {@link PLens} is also a valid {@link Getter}, {@link Fold}, {@link POptional}, {@link PTraversal} and {@link PSetter}

      + *

      * Typically a {@link PLens} or {@link Lens} can be defined between a Product (e.g. case class, tuple, HList) and one of it is - * component. + * component.

      * * @param the source of a {@link PLens} * @param the modified source of a {@link PLens} @@ -500,4 +502,4 @@ public F modify(final F f) { } }; } -} \ No newline at end of file +} diff --git a/core/src/main/java/fj/data/optic/POptional.java b/core/src/main/java/fj/data/optic/POptional.java index d35979d8..c70aa4c1 100644 --- a/core/src/main/java/fj/data/optic/POptional.java +++ b/core/src/main/java/fj/data/optic/POptional.java @@ -20,13 +20,15 @@ import fj.data.vector.V2; /** - * A {@link POptional} can be seen as a pair of functions: - `getOrModify: S => T \/ A` - `set : (B, S) => T` - * - * A {@link POptional} could also be defined as a weaker {@link PLens} and weaker {@link PPrism} - * - * {@link POptional} stands for Polymorphic Optional as it set and modify methods change a type `A` to `B` and `S` to `T`. - * {@link Optional} is a {@link POptional} restricted to monomoprhic updates: {{{ type Optional[S, A] = POptional[S, S, A, A] - * }}} + * A {@link POptional} can be seen as a pair of functions:
        + *
      • {@code getOrModify: S => T \/ A}
      • + *
      • {@code set : (B, S) => T}
      • + *
      + *

      + * A {@link POptional} could also be defined as a weaker {@link PLens} and weaker {@link PPrism}

      + *

      + * {@link POptional} stands for Polymorphic Optional as it set and modify methods change a type {@code A} to {@code B} and {@code S} to {@code T}. + * {@link Optional} is a {@link POptional} restricted to monomoprhic updates: {@code type Optional[S, A] = POptional[S, S, A, A]}

      * * @param the source of a {@link POptional} * @param the modified source of a {@link POptional} @@ -479,4 +481,4 @@ public F modify(final F f) { }; } -} \ No newline at end of file +} diff --git a/core/src/main/java/fj/data/optic/PPrism.java b/core/src/main/java/fj/data/optic/PPrism.java index c4a65a68..ffa87ba6 100644 --- a/core/src/main/java/fj/data/optic/PPrism.java +++ b/core/src/main/java/fj/data/optic/PPrism.java @@ -19,14 +19,17 @@ import fj.data.vector.V2; /** - * A {@link PPrism} can be seen as a pair of functions: - `getOrModify: S => T \/ A` - `reverseGet : B => T` - * - * A {@link PPrism} could also be defined as a weaker {@link PIso} where get can fail. - * + * A {@link PPrism} can be seen as a pair of functions:
        + *
      • {@code getOrModify: S => T \/ A}
      • + *
      • {@code reverseGet : B => T}
      • + *
      + *

      + * A {@link PPrism} could also be defined as a weaker {@link PIso} where get can fail.

      + *

      * Typically a {@link PPrism} or {@link Prism} encodes the relation between a Sum or CoProduct type (e.g. sealed trait) and one - * of it is element. + * of it is element.

      * - * {@link PPrism} stands for Polymorphic Prism as it set and modify methods change a type `A` to `B` and `S` to `T`. + * {@link PPrism} stands for Polymorphic Prism as it set and modify methods change a type {@code A} to {@code B} and {@code S} to {@code T}. * {@link Prism} is a {@link PPrism} where the type of target cannot be modified. * * A {@link PPrism} is also a valid {@link Fold}, {@link POptional}, {@link PTraversal} and {@link PSetter} @@ -436,4 +439,4 @@ public Option
      getOption(final S s) { }; } -} \ No newline at end of file +} diff --git a/core/src/main/java/fj/data/optic/PSetter.java b/core/src/main/java/fj/data/optic/PSetter.java index 012920cb..13be7739 100644 --- a/core/src/main/java/fj/data/optic/PSetter.java +++ b/core/src/main/java/fj/data/optic/PSetter.java @@ -5,12 +5,14 @@ import fj.data.Either; /** - * A {@link PSetter} is a generalisation of Functor map: - `map: (A => B) => F[A] => F[B]` - `modify: (A => B) => S => - * T` - * - * {@link PSetter} stands for Polymorphic Setter as it set and modify methods change a type `A` to `B` and `S` to `T`. - * - * {@link PTraversal}, {@link POptional}, {@link PPrism}, {@link PLens} and {@link PIso} are valid {@link PSetter} + * A {@link PSetter} is a generalisation of Functor map:
        + *
      • {@code map: (A => B) => F[A] => F[B]}
      • + *
      • {@code modify: (A => B) => S => T}
      • + *
      + *

      + * {@link PSetter} stands for Polymorphic Setter as it set and modify methods change a type {@code A} to {@code B} and {@code S} to {@code T}.

      + *

      + * {@link PTraversal}, {@link POptional}, {@link PPrism}, {@link PLens} and {@link PIso} are valid {@link PSetter}

      * * @param the source of a {@link PSetter} * @param the modified source of a {@link PSetter} diff --git a/core/src/main/java/fj/data/optic/PTraversal.java b/core/src/main/java/fj/data/optic/PTraversal.java index ee16760f..6087f707 100644 --- a/core/src/main/java/fj/data/optic/PTraversal.java +++ b/core/src/main/java/fj/data/optic/PTraversal.java @@ -24,9 +24,9 @@ /** * A {@link PTraversal} can be seen as a {@link POptional} generalised to 0 to n targets where n can be infinite. - * - * {@link PTraversal} stands for Polymorphic Traversal as it set and modify methods change a type `A` to `B` and `S` to `T`. - * {@link Traversal} is a {@link PTraversal} restricted to monomoprhic updates. + *

      + * {@link PTraversal} stands for Polymorphic Traversal as it set and modify methods change a type {@code A} to {@code B} and {@code S} to {@code T}. + * {@link Traversal} is a {@link PTraversal} restricted to monomoprhic updates.

      * * @param the source of a {@link PTraversal} * @param the modified source of a {@link PTraversal} diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 323995e1..c375874d 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -33,7 +33,7 @@ * allowing various forms of composition of generators.

      A user typically creates an {@link * Arbitrary arbitrary} to return a generator using the 'combinator methods' below. For example, * suppose a class Person: -

      +
      {@code
       class Person {
         final int age;
         final String name;
      @@ -45,23 +45,23 @@ class Person {
           this.male = male;
         }
       }
      -
      +}
      *

      In a case like this one, a user may create a generator over Person by * invoking the {@link #bind(F)} methods — in this case, {@link #bind(Gen , Gen , F)} the one * that takes two generator arguments}, since the class has one more than two fields (the bind * method is invoked on a generator adding the extra one to the count as they are composed). The * class fields are of types for which there exist generators (on {@link Gen} so those can be * used to compose a generator for Person:

      -
      +
      {@code
       static Gen<Person> personArbitrary() {
         return arbInteger.bind(arbString(), arbBoolean(),
             // compose the generators
             {int age => {String name => {boolean male => new Person(age, name, male)}}};
       }
      -
      +}
      *

      * The example above uses Java 7 closure syntax. Here is the same example using objects instead: -

      +
      {@code
       static Gen<Person> personArbitrary() {
         return arbInteger.bind(arbString, arbBoolean,
             // compose the generators
      @@ -79,7 +79,7 @@ public Person f(final Boolean male) {
               }
             });
       }
      -
      +}
      * * @version %build.number% */ From 6dd03d708f5d04c4f3c0fe4ba25eab39cd075073 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 8 Oct 2018 14:21:40 +0200 Subject: [PATCH 226/336] html5 javadoc --- build.gradle | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/build.gradle b/build.gradle index 6104c093..c070903d 100644 --- a/build.gradle +++ b/build.gradle @@ -140,6 +140,10 @@ configure(subprojects.findAll { it.name != "props-core" }) { sourceCompatibility = "1.8" + javadoc { + options.addBooleanOption('html5', true) + } + task javadocJar(type: Jar, dependsOn: "javadoc") { classifier = 'javadoc' from "build/docs/javadoc" From cd201cce91343302d928f72d31ead35021261de9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 8 Oct 2018 17:35:49 +0200 Subject: [PATCH 227/336] 4.8.1 release. --- README.adoc | 18 +++++++++--------- build.gradle | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/README.adoc b/README.adoc index a7e2d3a4..8a3ad347 100644 --- a/README.adoc +++ b/README.adoc @@ -35,12 +35,12 @@ The Functional Java artifact is published to Maven Central using the group `org. * Java 8 specific support (`functionaljava-java8`) * property based testing (`functionaljava-quickcheck` or `functionaljava-quickcheck_1.8` if you use Java 8+) -The latest stable version is `4.8`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `4.8.1`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.8" -compile "org.functionaljava:functionaljava-java8:4.8" -compile "org.functionaljava:functionaljava-quickcheck:4.8" -compile "org.functionaljava:functionaljava-java-core:4.8" +compile "org.functionaljava:functionaljava:4.8.1" +compile "org.functionaljava:functionaljava-java8:4.8.1" +compile "org.functionaljava:functionaljava-quickcheck:4.8.1" +compile "org.functionaljava:functionaljava-java-core:4.8.1" ---- and in Maven: @@ -48,22 +48,22 @@ and in Maven: org.functionaljava functionaljava - 4.8 + 4.8.1 org.functionaljava functionaljava-java8 - 4.8 + 4.8.1 org.functionaljava functionaljava-quickcheck - 4.8 + 4.8.1 org.functionaljava functionaljava-java-core - 4.8 + 4.8.1 ---- diff --git a/build.gradle b/build.gradle index bc292a82..d6c26032 100644 --- a/build.gradle +++ b/build.gradle @@ -47,8 +47,8 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true - fjBaseVersion = "4.9" + isSnapshot = false + fjBaseVersion = "4.8.1" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") From e32fbfdfee3b0f939ec3a9a83cb2c2d094ff3f64 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 8 Oct 2018 17:39:52 +0200 Subject: [PATCH 228/336] Set version to 4.9-SNAPSHOT --- build.gradle | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index d6c26032..67d8cd15 100644 --- a/build.gradle +++ b/build.gradle @@ -47,12 +47,12 @@ allprojects { defaultTasks "build" ext { - isSnapshot = false - fjBaseVersion = "4.8.1" + isSnapshot = true + fjBaseVersion = "4.9" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.8" + fjConsumeVersion = "4.8.1" signModule = false useRetroLambda = false From fcff9d1dc166943906aaa837b26478e74814bfd9 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Giraudeau Date: Mon, 8 Oct 2018 18:11:11 +0200 Subject: [PATCH 229/336] Update changelog with 4.8.1 changes. --- ChangeLog.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 24276f35..acdbedea 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,23 @@ +4.8.1 +----- + +### Enhancements + +- Add Trampoline.suspend(final F0> a). (see [#367](https://github.com/functionaljava/functionaljava/pull/367)); + +### Fixes + +- Fix regression in lifted semigroup sum. Fix #365 (see [#366](https://github.com/functionaljava/functionaljava/pull/366)); + +### Internal + +- Fix compile under jdk11. Enable jdk11 travis build. (see [#361](https://github.com/functionaljava/functionaljava/pull/361)); +- Fix warnings (see [#369](https://github.com/functionaljava/functionaljava/pull/369)); +- Add P tests (see [#360](https://github.com/functionaljava/functionaljava/pull/360)); +- Exclude consume/ from coverage (see [#357](https://github.com/functionaljava/functionaljava/pull/357)); +- Add DList tests (see [#356](https://github.com/functionaljava/functionaljava/pull/356)); +- Add Visitor tests (see [#354](https://github.com/functionaljava/functionaljava/pull/354)); + 4.8 --- @@ -20,7 +40,6 @@ - Added Scalacheck Arbitrary implementations for Natural and NonEmptyList. (see [`405c3ec`](https://github.com/functionaljava/functionaljava/commit/405c3ec)); - Added unit test coverage for Semigroup implementations. The StringBuffer and StringBuilder tests fail because both of those types are mutable. The IO test fails because the ArbitraryIO implementation does not implement equals. (see [`ef81130`](https://github.com/functionaljava/functionaljava/commit/ef81130)); - Fixed the ArbitraryIO implementation and created a Properties object for testing the IO semigroup. (see [`a8e979f`](https://github.com/functionaljava/functionaljava/commit/a8e979f)); -- Added working tests coverage for the StringBuffer and StringBuilder semigroup implementations. Added the Semigroup tests to the list of Scalacheck test suite. (see [`aa4de33`](https://github.com/functionaljava/functionaljava/commit/aa4de33)); - Equal: remove reference to static field of LazyString. Fix #321 (see [`6c6dabd`](https://github.com/functionaljava/functionaljava/commit/6c6dabd)); - Add IOFunctions tests (see [#340](https://github.com/functionaljava/functionaljava/pull/340)); - Add Stream tests (see [#341](https://github.com/functionaljava/functionaljava/pull/341)); @@ -30,4 +49,4 @@ - Add Parser tests (see [#349](https://github.com/functionaljava/functionaljava/pull/349)); - Add FingerTree tests (see [#351](https://github.com/functionaljava/functionaljava/pull/351)); - Add TreeZipper tests (see [#352](https://github.com/functionaljava/functionaljava/pull/352)); -- Add Reader/Writer tests (see [#353](https://github.com/functionaljava/functionaljava/pull/353)); \ No newline at end of file +- Add Reader/Writer tests (see [#353](https://github.com/functionaljava/functionaljava/pull/353)); From 86dabd508306a2cc78fbb692994e158420926c8d Mon Sep 17 00:00:00 2001 From: SoundharyaKamaraj Date: Thu, 25 Oct 2018 12:37:50 -0400 Subject: [PATCH 230/336] #371: fixed failing property test (#373) --- .../src/test/java/fj/data/hamt/BitSetProperties.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java index f3527972..6c3f91a9 100644 --- a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java +++ b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java @@ -156,15 +156,19 @@ Property rangeTest() { int h = list.index(2); int m = Math.max(l, Math.min(list.index(1), h - 1)); int vh = list.index(3); - + BitSet bs1 = longBitSet(x); BitSet bs2 = bs1.range(l, h); + if(l==h){ + return prop(true); + } boolean b = - bs1.isSet(m) == bs2.isSet(m - l) && + bs1.isSet(m) == bs2.isSet(m - l) && bs2.isSet(vh - l) == false; return prop(b); }); } + Property setTest() { return property(arbNaturalLong, arbBitSetSize, (l, i) -> prop(longBitSet(l).set(i).isSet(i))); From c0f0fdbc6ba6e0dd1043fe63d07af4cac6a0c5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 15 Dec 2018 22:21:15 -0500 Subject: [PATCH 231/336] Add Validation tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/data/Validation.java | 8 +- .../src/test/java/fj/data/ValidationTest.java | 244 ++++++++++++++++++ 2 files changed, 248 insertions(+), 4 deletions(-) create mode 100644 core/src/test/java/fj/data/ValidationTest.java diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 58aa5e9c..0b939e57 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -783,7 +783,7 @@ public final Validation, D> accumulate(Validation v2, Va public final Validation, G> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, F6 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6)); if (!list.isEmpty()) { return fail(list); } else { @@ -792,7 +792,7 @@ public final Validation, D> accumulate(Validation v2, Va } public final Validation, H> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, F7 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6, v7)); if (!list.isEmpty()) { return fail(list); } else { @@ -801,7 +801,7 @@ public final Validation, D> accumulate(Validation v2, Va } public final Validation, I> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, Validation v8, F8 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6, v7, v8)); if (!list.isEmpty()) { return fail(list); } else { @@ -860,7 +860,7 @@ public static List fails(List> list) { return list.filter(Validation::isFail).map(v -> v.fail()); } - public static List
      successes(List> list) { + public static List successes(List> list) { return list.filter(Validation::isSuccess).map(v -> v.success()); } diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java new file mode 100644 index 00000000..2d90c9e4 --- /dev/null +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -0,0 +1,244 @@ +package fj.data; + +import org.junit.Test; + +import static fj.data.Validation.*; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import fj.*; + +public class ValidationTest { + @Test + public void testParseShort() { + final List> l = + List.list(parseShort("10"), parseShort("x"), parseShort("20")); + assertThat(successes(l).foldLeft1((s, a) -> (short)(s + a)), is((short)30)); + } + + @Test + public void testParseLong() { + final List> l = + List.list(parseLong("10"), parseLong("x"), parseLong("20")); + P2, List> p2 = partition(l); + assertThat(p2._1().length(), is(1)); + assertThat(p2._2().length(), is(2)); + } + + @Test + public void testParseInt() { + final List> l = + List.list(parseInt("10"), parseInt("x"), parseInt("20")); + assertThat(l.map(v -> v.validation(e -> 0, i -> 1)).foldLeft1((s, a) -> s + a), + is(2)); + } + + @Test + public void testParseFloat() { + final List> l = + List.list(parseFloat("2.0"), parseFloat("x"), parseFloat("3.0")); + assertThat(l.map(v -> v.validation(e -> 0, i -> 1)).foldLeft1((s, a) -> s + a), + is(2)); + } + + @Test + public void testParseByte() { + final List> l = + List.list(parseByte("10"), parseByte("x"), parseByte("-10")); + assertThat(l.map(v -> v.validation(e -> 0, i -> 1)).foldLeft1((s, a) -> s + a), + is(2)); + } + + @Test + public void testAccumulate1() { + final Validation, Double> v = + parseDouble("10.0").accumulate( + f1 -> f1); + assertThat(v.success(), is(10.0)); + } + + @Test + public void testAccumulate1Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + f1 -> f1); + assertThat(v.fail().length(), is(1)); + } + + @Test + public void testAccumulate2() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + (f1, f2) -> f1 + f2); + assertThat(v.success(), is(3.0)); + } + + @Test + public void testAccumulate2Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("y"), + (f1, f2) -> f1 + f2); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate3() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + (f1, f2, f3) -> f1 + f2 + f3); + assertThat(v.success(), is(6.0)); + } + + @Test + public void testAccumulate3Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("y"), + (f1, f2, f3) -> f1 + f2 + f3); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate4() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + (f1, f2, f3, f4) -> f1 + f2 + f3 + f4); + assertThat(v.success(), is(10.0)); + } + + @Test + public void testAccumulate4Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("y"), + (f1, f2, f3, f4) -> f1 + f2 + f3 + f4); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate5() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + (f1, f2, f3, f4, f5) -> f1 + f2 + f3 + f4 + f5); + assertThat(v.success(), is(15.0)); + } + + @Test + public void testAccumulate5Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("y"), + (f1, f2, f3, f4, f5) -> f1 + f2 + f3 + f4 + f5); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate6() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("6.0"), + (f1, f2, f3, f4, f5, f6) -> f1 + f2 + f3 + f4 + f5 + f6); + assertThat(v.success(), is(21.0)); + } + + @Test + public void testAccumulate6Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("y"), + (f1, f2, f3, f4, f5, f6) -> f1 + f2 + f3 + f4 + f5 + f6); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate7() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("6.0"), + parseDouble("7.0"), + (f1, f2, f3, f4, f5, f6, f7) -> f1 + f2 + f3 + f4 + f5 + f6 + f7); + assertThat(v.success(), is(28.0)); + } + + @Test + public void testAccumulate7Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("6.0"), + parseDouble("y"), + (f1, f2, f3, f4, f5, f6, f7) -> f1 + f2 + f3 + f4 + f5 + f6 + f7); + assertThat(v.fail().length(), is(2)); + } + + @Test + public void testAccumulate8() { + final Validation, Double> v = + parseDouble("1.0").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("6.0"), + parseDouble("7.0"), + parseDouble("8.0"), + (f1, f2, f3, f4, f5, f6, f7, f8) -> f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8); + assertThat(v.success(), is(36.0)); + } + + @Test + public void testAccumulate8Fail() { + final Validation, Double> v = + parseDouble("x").accumulate( + parseDouble("2.0"), + parseDouble("3.0"), + parseDouble("4.0"), + parseDouble("5.0"), + parseDouble("6.0"), + parseDouble("7.0"), + parseDouble("y"), + (f1, f2, f3, f4, f5, f6, f7, f8) -> f1 + f2 + f3 + f4 + f5 + f6 + f7 + f8); + assertThat(v.fail().length(), is(2)); + } + + @Test(expected = Error.class) + public void testSuccess() { + parseShort("x").success(); + } + + @Test(expected = Error.class) + public void testFail() { + parseShort("12").fail(); + } +} From 0e8e15232f4953a9396e7b30e5664dc1fb513a12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 16 Dec 2018 13:35:39 -0500 Subject: [PATCH 232/336] Additional Validation tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- .../src/test/java/fj/data/ValidationTest.java | 76 ++++++++++++++++++- 1 file changed, 75 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java index 2d90c9e4..2f438e5c 100644 --- a/core/src/test/java/fj/data/ValidationTest.java +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -1,11 +1,12 @@ package fj.data; +import fj.P2; import org.junit.Test; +import static fj.Semigroup.firstSemigroup; import static fj.data.Validation.*; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import fj.*; public class ValidationTest { @Test @@ -232,6 +233,47 @@ public void testAccumulate8Fail() { assertThat(v.fail().length(), is(2)); } + @Test + public void testAccumulate8s() { + final Validation v1 = parseInt("1"); + final Validation v2 = parseInt("2"); + final Validation v3 = parseInt("3"); + final Validation v4 = parseInt("4"); + final Validation v5 = parseInt("5"); + final Validation v6 = parseInt("6"); + final Validation v7 = parseInt("7"); + final Validation v8 = parseInt("8"); + final Option on2 = v1.accumulate(firstSemigroup(), v2); + assertThat(on2, is(Option.none())); + final Option on3 = v1.accumulate(firstSemigroup(), v2, v3); + assertThat(on3, is(Option.none())); + final Option on4 = v1.accumulate(firstSemigroup(), v2, v3, v4); + assertThat(on4, is(Option.none())); + final Option on5 = v1.accumulate(firstSemigroup(), v2, v3, v4, v5); + assertThat(on5, is(Option.none())); + final Option on6 = v1.accumulate(firstSemigroup(), v2, v3, v4, v5, v6); + assertThat(on6, is(Option.none())); + final Option on7 = v1.accumulate(firstSemigroup(), v2, v3, v4, v5, v6, v7); + assertThat(on7, is(Option.none())); + final Option on8 = v1.accumulate(firstSemigroup(), v2, v3, v4, v5, v6, v7, v8); + assertThat(on8, is(Option.none())); + } + + @Test + public void testAccumulate8sFail() { + final Option on = + parseInt("x").accumulate( + firstSemigroup(), + parseInt("2"), + parseInt("3"), + parseInt("4"), + parseInt("5"), + parseInt("6"), + parseInt("7"), + parseInt("y")); + assertThat(on.some().getMessage(), is("For input string: \"x\"")); + } + @Test(expected = Error.class) public void testSuccess() { parseShort("x").success(); @@ -241,4 +283,36 @@ public void testSuccess() { public void testFail() { parseShort("12").fail(); } + + @Test + public void testCondition() { + final Validation one = condition(true, "not 1", "one"); + assertThat(one.success(), is("one")); + final Validation fail = condition(false, "not 1", "one"); + assertThat(fail.fail(), is("not 1")); + } + + @Test + public void testNel() { + assertThat(Validation.success("success").nel().success(), is("success")); + assertThat(Validation.fail("fail").nel().fail().head(), is("fail")); + } + + @Test + public void testFailNEL() { + Validation, Integer> v = failNEL(new Exception("failed")); + assertThat(v.isFail(), is(true)); + } + + @Test + public void testEither() { + assertThat(either().f(Validation.success("success")).right().value(), is("success")); + assertThat(either().f(Validation.fail("fail")).left().value(), is("fail")); + } + + @Test + public void testValidation() { + assertThat(validation().f(Either.right("success")).success(), is("success")); + assertThat(validation().f(Either.left("fail")).fail(), is("fail")); + } } From 148eab718a81bfd90e5fd8176fb6c4435602da3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sun, 16 Dec 2018 14:12:00 -0500 Subject: [PATCH 233/336] Bring Gradle current MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.jar | Bin 56177 -> 56177 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index c070903d..37a7b7c3 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } wrapper { - gradleVersion = "4.10.2" + gradleVersion = "4.10.3" distributionType = Wrapper.DistributionType.ALL } } @@ -69,7 +69,7 @@ allprojects { sonatypeUploadUrl = isSnapshot ? sonatypeSnapshotUrl : sonatypeReleaseUrl primaryEmail = "functionaljava@googlegroups.com" - dependencyJunit = "org.junit.vintage:junit-vintage-engine:5.2.0" + dependencyJunit = "org.junit.vintage:junit-vintage-engine:5.3.2" displayCompilerWarnings = true } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 29953ea141f55e3b8fc691d31b5ca8816d89fa87..94336fcae912db8a11d55634156fa011f4686124 100644 GIT binary patch delta 75 zcmeykjrrp?<_YF3{B|p=CR)d^elGf0#5nPQ^v3PRCxzG;0=(Hd{+{0VNQ{AjK?H~= bKR6{bS>lv7Sp8=AQ}+Z|K+=;nZ+id$gFGJ; delta 75 zcmeykjrrp?<_YF3`^8VXPqdC<{aEy|h;iZp>5bcsPYN+H1bDM^WdGhdRg8gwK?H~= bKR6{bS>lv7Sp8=AQ}+Z|K+=;nZ+id$ib5We diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d76b502e..ae45383b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From f85a3698a2b2838c0cc6462c85817a4c06c829d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Thu, 28 Feb 2019 20:29:08 -0500 Subject: [PATCH 234/336] Bring Gradle to 5.2.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 5 +++-- consume/build.gradle | 3 ++- core/build.gradle | 3 ++- demo/build.gradle | 3 ++- gradle/wrapper/gradle-wrapper.jar | Bin 56177 -> 55190 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 2 +- gradlew.bat | 2 +- java-core/build.gradle | 3 ++- performance/build.gradle | 3 ++- props-core-scalacheck/build.gradle | 3 ++- props-core/build.gradle | 5 +++-- quickcheck/build.gradle | 2 +- 13 files changed, 22 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 37a7b7c3..b206336a 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } wrapper { - gradleVersion = "4.10.3" + gradleVersion = "5.2.1" distributionType = Wrapper.DistributionType.ALL } } @@ -69,7 +69,8 @@ allprojects { sonatypeUploadUrl = isSnapshot ? sonatypeSnapshotUrl : sonatypeReleaseUrl primaryEmail = "functionaljava@googlegroups.com" - dependencyJunit = "org.junit.vintage:junit-vintage-engine:5.3.2" + junitCompile = "junit:junit:4.12" + junitRuntime = "org.junit.vintage:junit-vintage-engine:5.3.2" displayCompilerWarnings = true } diff --git a/consume/build.gradle b/consume/build.gradle index ff92a601..370ebfbf 100644 --- a/consume/build.gradle +++ b/consume/build.gradle @@ -4,5 +4,6 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { compile("$group:$projectName:$fjConsumeVersion") - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime } diff --git a/core/build.gradle b/core/build.gradle index 13d06114..767904e0 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -6,7 +6,8 @@ ext { archivesBaseName = project.projectName dependencies { - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime testCompile 'com.h2database:h2:1.4.197' testCompile 'commons-dbutils:commons-dbutils:1.7' } diff --git a/demo/build.gradle b/demo/build.gradle index e97f94b8..f19e765f 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -8,7 +8,8 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { compile project(":core") compile project(":quickcheck") - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime } test { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 94336fcae912db8a11d55634156fa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l3}AIy*R;IlEe!xzNio(v6Q!{G=aKkY%jnoMPvgWQPXr!ok2kk92H< zbVir>=szR? z3>-TvlZma7i_8BOxZrHsfehNSe+N2(&+&>I4D%P4^j`%Y!R^^Lf~3si2*JQeUy*j< z{vyF5y($lQK1d2GVF~9ymw`WV{(bkf-i1BwATQ+zM3Bqht9*xW{}5MjN&Z!tteYW7 zZ_pitg7SaeWb-5-5)0ra#TDZJ9t7F{K9s zBY8y%;r@#R^FPg|GV;3)7jl0t6Urj~E6=~;8eU)dH;vbUGC=zg99_L@gR}r*c z5sQ@nBI5k>j$cJBd4&hl{)1=MBm`EELj9BTUwQxkeKbrT{&3DmiT{cJTT>m>NHnj? zfH(XL4+B&kLkD$6pvBnlmH}7+KUz@!=aK#Hhht;#M8B!)R{z&U|LTV(wpRb?i@@tY zR3vNQTTAwTwaY7+(N}dyvjq`wf2)rEr##@-@!yqr?*w%6A^^UO6a20i!Ni|O<_r{> zVEO0Gz0v@Dm9dKJAHJS5BJkV9s|NgA{RxDB-5`11APzYYc@puTWxUd3dR0b@4+t*^ z1Wdll|CN%=D?B#eqg<|&eY*6Hul`kS`wY|S75 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ae45383b..1b2b07cf 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index cccdd3d5..af6708ff 100755 --- a/gradlew +++ b/gradlew @@ -28,7 +28,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..0f8d5937 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/java-core/build.gradle b/java-core/build.gradle index 22bf8970..e7b40bb9 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -7,7 +7,8 @@ ext { dependencies { compile project(":core") - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime } performSigning(signingEnabled, signModule) diff --git a/performance/build.gradle b/performance/build.gradle index cac2f584..c6f4c8a6 100644 --- a/performance/build.gradle +++ b/performance/build.gradle @@ -1,5 +1,6 @@ dependencies { compile project(":core") - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime } diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index 10e494c9..5207bf50 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -15,7 +15,8 @@ dependencies { compile "org.scala-lang:scala-library:$scalaVersion" compile "org.scalacheck:scalacheck_$scalacheckScalaVersion:$scalacheckVersion" - testCompile dependencyJunit + testCompile junitCompile + testRuntime junitRuntime } performSigning(signingEnabled, signModule) diff --git a/props-core/build.gradle b/props-core/build.gradle index 181ae5b2..b991bd47 100644 --- a/props-core/build.gradle +++ b/props-core/build.gradle @@ -2,6 +2,7 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { - compile project(":quickcheck") - testCompile dependencyJunit + compile project(":quickcheck") + testCompile junitCompile + testRuntime junitRuntime } diff --git a/quickcheck/build.gradle b/quickcheck/build.gradle index b477e26a..2e5dbe4c 100644 --- a/quickcheck/build.gradle +++ b/quickcheck/build.gradle @@ -7,7 +7,7 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { compile project(":core") - compile dependencyJunit + compile junitCompile } performSigning(signingEnabled, signModule) From c718d06f8320b56084b507b3d5b2d13a6f51ac3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Wed, 13 Mar 2019 18:00:24 -0400 Subject: [PATCH 235/336] Correct Either.iif Javadoc --- core/src/main/java/fj/data/Either.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index a9a746a9..dcc950f2 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -898,7 +898,7 @@ public static A reduce(final Either e) { } /** - * If the condition satisfies, return the given A in left, otherwise, return the given B in right. + * If the condition satisfies, return the given B in right, otherwise, return the given A in left. * * @param c The condition to test. * @param right The right value to use if the condition satisfies. From 68625ac4f1a40c65b2fb0ad4c24cacbe9288e6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Fri, 15 Mar 2019 22:17:33 -0400 Subject: [PATCH 236/336] Add Integers tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- .../test/java/fj/function/IntegersTest.java | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 core/src/test/java/fj/function/IntegersTest.java diff --git a/core/src/test/java/fj/function/IntegersTest.java b/core/src/test/java/fj/function/IntegersTest.java new file mode 100644 index 00000000..985afba9 --- /dev/null +++ b/core/src/test/java/fj/function/IntegersTest.java @@ -0,0 +1,62 @@ +package fj.function; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import static fj.data.List.list; +import static fj.data.Option.none; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class IntegersTest { + + @Test + public void testSum() { + assertThat(Integers.sum(list(3, 4, 5)), is(12)); + } + + @Test + public void testProduct() { + assertThat(Integers.product(list(3, 4, 5)), is(60)); + } + + @Test + public void testAdd() { + assertThat(Integers.add.f(10).f(20), is(30)); + } + + @Test + public void testMultiply() { + assertThat(Integers.multiply.f(3).f(5), is(15)); + } + + @Test + public void testAbs() { + assertThat(Integers.abs.f(-5), is(5)); + } + + @Test + public void testFromString() { + assertThat(Integers.fromString().f("-123").some(), is(-123)); + } + + @Test + public void testFromStringFail() { + assertThat(Integers.fromString().f("w"), is(none())); + } + + @Test + public void testCannotInstantiate() throws NoSuchMethodException, IllegalAccessException, InstantiationException { + Constructor constructor = Integers.class.getDeclaredConstructor(); + constructor.setAccessible(true); + try { + constructor.newInstance(); + fail("expected InvocationTargetException"); + } catch (InvocationTargetException ite) { + assertTrue(ite.getCause() instanceof UnsupportedOperationException); + } + } + +} From d2319f14e9b7b3293532454e110f6f0f675b26db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 6 Apr 2019 15:22:51 -0400 Subject: [PATCH 237/336] Add openjdk12 to Travis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- .travis.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bbe5966b..8e7c52c9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,12 +5,13 @@ language: java jdk: - openjdk10 + - openjdk11 - openjdk-ea matrix: include: - - jdk: openjdk11 + - jdk: openjdk12 script: - ./gradlew build coverage -s -i after_success: From 40ef6c620aade5633e720f0401991bcfd9f18745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 6 Apr 2019 16:42:41 -0400 Subject: [PATCH 238/336] Add Longs tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- core/src/main/java/fj/function/Longs.java | 39 ++++++++++++ core/src/test/java/fj/function/LongsTest.java | 62 +++++++++++++++++++ 2 files changed, 101 insertions(+) create mode 100644 core/src/test/java/fj/function/LongsTest.java diff --git a/core/src/main/java/fj/function/Longs.java b/core/src/main/java/fj/function/Longs.java index 18667699..0989e8c0 100644 --- a/core/src/main/java/fj/function/Longs.java +++ b/core/src/main/java/fj/function/Longs.java @@ -1,11 +1,16 @@ package fj.function; import fj.F; +import fj.Monoid; +import fj.data.List; +import fj.data.Option; import static fj.Function.curry; import static fj.Semigroup.longAdditionSemigroup; import static fj.Semigroup.longMultiplicationSemigroup; +import static fj.data.Option.none; +import static fj.data.Option.some; import static java.lang.Math.abs; /** @@ -48,4 +53,38 @@ private Longs() { */ public static final F> remainder = curry((a, b) -> a % b); + /** + * Sums a list of longs. + * + * @param longs A list of longs to sum. + * @return The sum of the longs in the list. + */ + public static long sum(final List longs) { + return Monoid.longAdditionMonoid.sumLeft(longs); + } + + /** + * Returns the product of a list of integers. + * + * @param longs A list of longs to multiply together. + * @return The product of the longs in the list. + */ + public static long product(final List longs) { + return Monoid.longMultiplicationMonoid.sumLeft(longs); + } + + /** + * A function that converts strings to integers. + * + * @return A function that converts strings to integers. + */ + public static F> fromString() { + return s -> { + try { return some(Long.valueOf(s)); } + catch (final NumberFormatException ignored) { + return none(); + } + }; + } + } diff --git a/core/src/test/java/fj/function/LongsTest.java b/core/src/test/java/fj/function/LongsTest.java new file mode 100644 index 00000000..d59fc07c --- /dev/null +++ b/core/src/test/java/fj/function/LongsTest.java @@ -0,0 +1,62 @@ +package fj.function; + +import org.junit.Test; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; + +import static fj.data.List.list; +import static fj.data.Option.none; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class LongsTest { + + @Test + public void testSum() { + assertThat(Longs.sum(list(3L, 4L, 5L)), is(12L)); + } + + @Test + public void testProduct() { + assertThat(Longs.product(list(3L, 4L, 5L)), is(60L)); + } + + @Test + public void testAdd() { + assertThat(Longs.add.f(10L).f(20L), is(30L)); + } + + @Test + public void testMultiply() { + assertThat(Longs.multiply.f(3L).f(5L), is(15L)); + } + + @Test + public void testAbs() { + assertThat(Longs.abs.f(-5L), is(5L)); + } + + @Test + public void testFromString() { + assertThat(Longs.fromString().f("-123").some(), is(-123L)); + } + + @Test + public void testFromStringFail() { + assertThat(Longs.fromString().f("w"), is(none())); + } + + @Test + public void testCannotInstantiate() throws NoSuchMethodException, IllegalAccessException, InstantiationException { + Constructor constructor = Longs.class.getDeclaredConstructor(); + constructor.setAccessible(true); + try { + constructor.newInstance(); + fail("expected InvocationTargetException"); + } catch (InvocationTargetException ite) { + assertTrue(ite.getCause() instanceof UnsupportedOperationException); + } + } + +} From 0b8b7f083ce5cac932467e3a839357a568ef6dd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Sat, 12 Oct 2019 13:25:44 -0400 Subject: [PATCH 239/336] Bring Gradle to 5.6.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Gábor Lipták --- build.gradle | 6 +++--- core/build.gradle | 2 +- gradle/wrapper/gradle-wrapper.jar | Bin 55190 -> 55616 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 22 +++++++++++++++++++--- gradlew.bat | 18 +++++++++++++++++- 6 files changed, 41 insertions(+), 9 deletions(-) diff --git a/build.gradle b/build.gradle index b206336a..69c01425 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ buildscript { } wrapper { - gradleVersion = "5.2.1" + gradleVersion = "5.6.2" distributionType = Wrapper.DistributionType.ALL } } @@ -49,7 +49,7 @@ allprojects { snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.8" + fjConsumeVersion = "4.8.1" signModule = false @@ -70,7 +70,7 @@ allprojects { primaryEmail = "functionaljava@googlegroups.com" junitCompile = "junit:junit:4.12" - junitRuntime = "org.junit.vintage:junit-vintage-engine:5.3.2" + junitRuntime = "org.junit.vintage:junit-vintage-engine:5.5.2" displayCompilerWarnings = true } diff --git a/core/build.gradle b/core/build.gradle index 767904e0..cbdad60b 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -8,7 +8,7 @@ archivesBaseName = project.projectName dependencies { testCompile junitCompile testRuntime junitRuntime - testCompile 'com.h2database:h2:1.4.197' + testCompile 'com.h2database:h2:1.4.199' testCompile 'commons-dbutils:commons-dbutils:1.7' } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 87b738cbd051603d91cc39de6cb000dd98fe6b02..5c2d1cf016b3885f6930543d57b744ea8c220a1a 100644 GIT binary patch delta 3320 zcmai0c|2768`iN!wwN(!Oxeo5?`tVU3{m#%jC~noTx!q_nHtNnR`zAgWC@krB#b55 znJk4YA);()+(!K-w|npJuix)IpYu7-^SqzuJ>T~|?;j_-ma(;-@!<_I_B>B@4FVej z11CRtM@$8afpkN^v*te{ycR9yTldxXJbmio?@}x{9}zaw&=aQt(a^ZXN9S3i8a+Z% zGc@&(5}jplZjJKk2wNlTp(mbeKL5J9Gjo==yT{-eVKj?*rT1%bQ@%#Xce~~1f{19^ zoD75QEoSzDVh@!9qG4yl`;9=Ysp?rRX=(8$VDRz=R+oA3>jLxjW-H!-2biNSYuy)U z7-B-qC5l;>qjMTg!DbWPY}h7qxi6xp)_T)_O2+*&NDg?v;RyY@5XtWHx%(ImQ_3E% zA%$s3xrxE0Fk>DhG!pG)4}I!pWJl~QtV_3Jl2W4PuWWssMq^UpGatK+4CING9pB#5 z_NDc)aonVrZuXsr5!RcE#?aXFZQjt2VMd)-p00K$EheT?H!m_D2Mdqq;0moaO=C&y zgJnvzg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base bounded interface --- core/src/main/java/fj/Bounded.java | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 core/src/main/java/fj/Bounded.java diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java new file mode 100644 index 00000000..aea5da25 --- /dev/null +++ b/core/src/main/java/fj/Bounded.java @@ -0,0 +1,10 @@ +package fj; + +public class Bounded { + + public interface Definition { + A min(); + + A max(); + } +} From 78b3f7600f102b2cee62e0a3a300b38131fc3b5e Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 17:38:53 +0300 Subject: [PATCH 241/336] implement bounded with factory methods --- core/src/main/java/fj/Bounded.java | 32 ++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java index aea5da25..9c64a0b7 100644 --- a/core/src/main/java/fj/Bounded.java +++ b/core/src/main/java/fj/Bounded.java @@ -2,9 +2,41 @@ public class Bounded { + private final Definition def; + public interface Definition { A min(); A max(); } + + private Bounded(Definition definition) { + this.def = definition; + } + + public A min() { + return def.min(); + } + + public A max() { + return def.max(); + } + + public static Bounded boundedDef(Definition def) { + return new Bounded<>(def); + } + + public static Bounded bounded(A min, A max) { + return boundedDef(new Definition() { + @Override + public A min() { + return min; + } + + @Override + public A max() { + return max; + } + }); + } } From 0083c800a32140c7fcdb6dadb793f0cdd07b8dba Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 17:46:40 +0300 Subject: [PATCH 242/336] add bounded for integers --- core/src/main/java/fj/Bounded.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java index 9c64a0b7..57827589 100644 --- a/core/src/main/java/fj/Bounded.java +++ b/core/src/main/java/fj/Bounded.java @@ -39,4 +39,7 @@ public A max() { } }); } + + public static final Bounded integerBounded = bounded(Integer.MIN_VALUE, Integer.MAX_VALUE); + } From 68828d3b8d72c8a481974902090f36b80e12bbd8 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 18:49:01 +0300 Subject: [PATCH 243/336] create tests for set monoid fabric methods --- core/src/test/java/fj/MonoidTest.java | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index 8bab5315..99ad5b5e 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -1,6 +1,8 @@ package fj; +import fj.data.Enumerator; import fj.data.Option; +import fj.data.Set; import fj.data.Stream; import org.junit.Test; @@ -16,4 +18,26 @@ public void lifted_sum_of_two_numbers() { assertThat(optionMonoid.sum(some(3), some(5)), is(some(8))); assertThat(optionMonoid.sumLeft(Stream.arrayStream(some(3), some(5))), is(some(8))); } + + @Test + public void intersection_monoid_test() { + Bounded integersBounded = Bounded.bounded(0, 10); + Monoid> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd); + Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); + Set zero = intersectionMonoid.zero(); + Set actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second); + assertThat(actual, is(Set.set(Ord.intOrd, 3, 4))); + } + + @Test + public void union_monoid_test() { + Monoid> intersectionMonoid = Monoid.setMonoid(Ord.intOrd); + Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); + Set zero = intersectionMonoid.zero(); + Set actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second); + assertThat(actual, is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6))); + } + } From 73c31ac71a0605cf36936396f5e3d3646df37abc Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 18:58:16 +0300 Subject: [PATCH 244/336] implement to stream with bounded function in enumerator --- core/src/main/java/fj/data/Enumerator.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index 94f1b2cd..85b8377f 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -1,16 +1,12 @@ package fj.data; -import fj.F; +import fj.*; import static fj.Function.*; import static fj.data.Option.none; import static fj.data.Option.some; -import fj.Function; -import fj.Ord; - import static fj.Ord.*; -import fj.Ordering; import static fj.Ordering.*; import java.math.BigDecimal; @@ -185,6 +181,18 @@ public Stream toStream(final A a) { return Stream.fromFunction(this, id, a); } + /** + * Returns a stream of the values from this enumerator, + * starting at the min of given Bounded, ending at the max, counting up. + * + * @param bounded A value at which to begin the stream. + * @return a stream of the values from this enumerator, cut by bounded, counting up. + */ + public Stream toStream(final Bounded bounded) { + final F id = identity(); + return Stream.fromFunction(this, id, bounded.min()).takeWhile(item -> !item.equals(bounded.max())); + } + /** * Create a new enumerator with the given minimum value. * From fce0df7b4f6fdc01489536c08da9906d406296ac Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 18:59:38 +0300 Subject: [PATCH 245/336] implement intersection monoid for sets --- core/src/main/java/fj/Monoid.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 0c09b558..e66a812f 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -2,14 +2,7 @@ import static fj.F1Functions.dimap; -import fj.data.Array; -import fj.data.DList; -import fj.data.List; -import fj.data.IO; -import fj.data.Natural; -import fj.data.Option; -import fj.data.Set; -import fj.data.Stream; +import fj.data.*; import static fj.Function.*; import static fj.Semigroup.semigroupDef; @@ -1109,6 +1102,20 @@ public Set append(Set a1, Set a2) { }); } + public static Monoid> setIntersectionMonoid(final Bounded bounded, final Enumerator enumerator, final Ord o) { + return monoidDef(new Definition>() { + @Override + public Set empty() { + return Set.iteratorSet(o, enumerator.toStream(bounded).iterator()); + } + + @Override + public Set append(Set a1, Set a2) { + return a1.intersect(a2); + } + }); + } + /** * A monoid for the maximum of elements with ordering o. * @deprecated since 4.7. Use {@link Ord#maxMonoid(Object)} From b550ca45e4bed28153bac587201ac570118df638 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 19:05:28 +0300 Subject: [PATCH 246/336] fix set monoid method docs --- core/src/main/java/fj/Monoid.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index e66a812f..02bba94a 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -1083,7 +1083,7 @@ public Unit append(Unit a1, Unit a2) { }); /** - * A monoid for sets. + * A union monoid for sets. * * @param o An order for set elements. * @return A monoid for sets whose elements have the given order. From 3c4e35fb9cb32ab3584cdf49fde27fe7d8987049 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 19:05:49 +0300 Subject: [PATCH 247/336] add docs for intersection set monoid --- core/src/main/java/fj/Monoid.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 02bba94a..2b3400c0 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -1102,6 +1102,14 @@ public Set append(Set a1, Set a2) { }); } + /** + * A intersection monoid for sets. + * + * @param bounded A bound for all possible elements + * @param enumerator An enumerator for all possible elements + * @param o An order for set elements. + * @return A monoid for sets whose elements have the given order. + */ public static Monoid> setIntersectionMonoid(final Bounded bounded, final Enumerator enumerator, final Ord o) { return monoidDef(new Definition>() { @Override From b602a2c2c598615b7ceb305d6ca79253449a36e5 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 19:50:53 +0300 Subject: [PATCH 248/336] add docs for bounded --- core/src/main/java/fj/Bounded.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java index 57827589..22d59ef5 100644 --- a/core/src/main/java/fj/Bounded.java +++ b/core/src/main/java/fj/Bounded.java @@ -1,9 +1,16 @@ package fj; +/** + * The Bounded class is used to name the upper and lower limits of a type. + * Ord is not a superclass of Bounded since types that are not totally ordered may also have upper and lower bounds. + */ public class Bounded { private final Definition def; + /** + * Minimal definition of Bounded + */ public interface Definition { A min(); From ea6fcc7127219874ba550005d3de20ea76d789b3 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 19:51:11 +0300 Subject: [PATCH 249/336] remove integer bounded implementation --- core/src/main/java/fj/Bounded.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java index 22d59ef5..980ba9a3 100644 --- a/core/src/main/java/fj/Bounded.java +++ b/core/src/main/java/fj/Bounded.java @@ -47,6 +47,4 @@ public A max() { }); } - public static final Bounded integerBounded = bounded(Integer.MIN_VALUE, Integer.MAX_VALUE); - } From 4b25bf8797258361c8ce0624a1f9f4a2721e3384 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 20:01:36 +0300 Subject: [PATCH 250/336] rename monoid variable in union monoid test --- core/src/test/java/fj/MonoidTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index 99ad5b5e..35e71c28 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -32,11 +32,11 @@ public void intersection_monoid_test() { @Test public void union_monoid_test() { - Monoid> intersectionMonoid = Monoid.setMonoid(Ord.intOrd); + Monoid> unionMonoid = Monoid.setMonoid(Ord.intOrd); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); - Set zero = intersectionMonoid.zero(); - Set actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second); + Set zero = unionMonoid.zero(); + Set actual = unionMonoid.sum(unionMonoid.sum(zero, first), second); assertThat(actual, is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6))); } From 606f1e72803937b578e03aaca3f2c4dfd99c7c4c Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 20:01:59 +0300 Subject: [PATCH 251/336] add tests for set semigroup --- core/src/test/java/fj/SemigroupTest.java | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core/src/test/java/fj/SemigroupTest.java diff --git a/core/src/test/java/fj/SemigroupTest.java b/core/src/test/java/fj/SemigroupTest.java new file mode 100644 index 00000000..20ecb2cb --- /dev/null +++ b/core/src/test/java/fj/SemigroupTest.java @@ -0,0 +1,26 @@ +package fj; + +import fj.data.Set; +import org.junit.Test; + +import static org.hamcrest.core.Is.is; +import static org.hamcrest.MatcherAssert.assertThat; + +public class SemigroupTest { + + @Test + public void intersection_semigroup_test() { + Semigroup> intersectionSemigroup = Semigroup.setIntersectionSemigroup(); + Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); + assertThat(intersectionSemigroup.sum(first, second), is(Set.set(Ord.intOrd, 3, 4))); + } + + @Test + public void union_semigroup_test() { + Semigroup> unionSemigroup = Semigroup.setSemigroup(); + Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); + assertThat(unionSemigroup.sum(first, second), is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6))); + } +} From b710672ec4586752c6d3265e3c8b80994d860ff1 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 20 Oct 2019 20:02:16 +0300 Subject: [PATCH 252/336] implement intersection semigroup --- core/src/main/java/fj/Semigroup.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 42f05f5b..c512e383 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -629,4 +629,8 @@ public static Semigroup> setSemigroup() { return semigroupDef(Set::union); } + public static Semigroup> setIntersectionSemigroup() { + return semigroupDef(Set::intersect); + } + } From a6a0d21d6accc1e3b7b19f142e1f492b40845f1c Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Mon, 21 Oct 2019 19:25:49 +0300 Subject: [PATCH 253/336] add tests for zero elements of monoids --- core/src/test/java/fj/MonoidTest.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index 35e71c28..721903b4 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -40,4 +40,21 @@ public void union_monoid_test() { assertThat(actual, is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6))); } + @Test + public void intersection_monoid_zero_test() { + Bounded integersBounded = Bounded.bounded(0, 10); + Monoid> monoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd); + Set set = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set zero = monoid.zero(); + assertThat(monoid.sum(zero, set), is(set)); + } + + @Test + public void union_monoid_zero_test() { + Monoid> monoid = Monoid.setMonoid(Ord.intOrd); + Set set = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set zero = monoid.zero(); + assertThat(monoid.sum(zero, set), is(set)); + } + } From 226c84a74316d7d425610899eed2d0ef22d49599 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Mon, 21 Oct 2019 19:27:41 +0300 Subject: [PATCH 254/336] remove zero from monoids tests --- core/src/test/java/fj/MonoidTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index 721903b4..d61da72f 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -25,8 +25,7 @@ public void intersection_monoid_test() { Monoid> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); - Set zero = intersectionMonoid.zero(); - Set actual = intersectionMonoid.sum(intersectionMonoid.sum(zero, first), second); + Set actual = intersectionMonoid.sum(first, second); assertThat(actual, is(Set.set(Ord.intOrd, 3, 4))); } @@ -35,8 +34,7 @@ public void union_monoid_test() { Monoid> unionMonoid = Monoid.setMonoid(Ord.intOrd); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); - Set zero = unionMonoid.zero(); - Set actual = unionMonoid.sum(unionMonoid.sum(zero, first), second); + Set actual = unionMonoid.sum(first, second); assertThat(actual, is(Set.set(Ord.intOrd, 1, 2, 3, 4, 5, 6))); } From 1a40c67f5502980a1c18fa4e54bc56a0ad9d8362 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Mon, 21 Oct 2019 19:29:31 +0300 Subject: [PATCH 255/336] add docs for semigroups --- core/src/main/java/fj/Semigroup.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index c512e383..ef8029b3 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -621,7 +621,7 @@ public static Semigroup> ioSemigroup(final Semigroup sa) { public static final Semigroup unitSemigroup = unitMonoid.semigroup(); /** - * A semigroup for sets. + * A union semigroup for sets. * * @return a semigroup for sets. */ @@ -629,6 +629,11 @@ public static Semigroup> setSemigroup() { return semigroupDef(Set::union); } + /** + * A intersection semigroup for sets. + * + * @return a semigroup for sets. + */ public static Semigroup> setIntersectionSemigroup() { return semigroupDef(Set::intersect); } From 854d1958fffa8dedc56db0a2a2650f591949d983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Neuville?= Date: Mon, 28 Oct 2019 17:44:16 +0100 Subject: [PATCH 256/336] Basic JPMS (modules) support through 'Automatic-Module-Name' --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index 67d8cd15..91bd5433 100644 --- a/build.gradle +++ b/build.gradle @@ -181,6 +181,7 @@ configure(subprojects.findAll { it.name != "props-core" }) { buildCommand 'org.eclipse.pde.ManifestBuilder' buildCommand 'org.eclipse.pde.SchemaBuilder' } + instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : "-$project.name"}" } // Output MANIFEST.MF statically so eclipse can see it for plugin development From 1fed6abe362ee3a3931b11947570dd76baad9986 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Neuville?= Date: Tue, 29 Oct 2019 12:10:05 +0100 Subject: [PATCH 257/336] Fix previous commit --- build.gradle | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 91bd5433..2ac9a9c0 100644 --- a/build.gradle +++ b/build.gradle @@ -169,9 +169,10 @@ configure(subprojects.findAll { it.name != "props-core" }) { instruction 'Signature-Version', project.fjVersion instruction 'Bundle-ActivationPolicy', 'lazy' instruction 'Bundle-Vendor', 'functionaljava.org' - if(project.name != "core") { - instruction 'Require-Bundle', 'org.functionaljava;bundle-version="'+project.fjBaseVersion+'"' - } + if(project.name != "core") { + instruction 'Require-Bundle', 'org.functionaljava;bundle-version="'+project.fjBaseVersion+'"' + } + instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : "-$project.name"}" } } @@ -181,7 +182,6 @@ configure(subprojects.findAll { it.name != "props-core" }) { buildCommand 'org.eclipse.pde.ManifestBuilder' buildCommand 'org.eclipse.pde.SchemaBuilder' } - instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : "-$project.name"}" } // Output MANIFEST.MF statically so eclipse can see it for plugin development From 57699342be52381724ac34cf2b867cbd1d4ff407 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Neuville?= Date: Tue, 29 Oct 2019 12:29:34 +0100 Subject: [PATCH 258/336] Dash character isn't allowed in modules names --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 2ac9a9c0..c9d8be40 100644 --- a/build.gradle +++ b/build.gradle @@ -172,7 +172,7 @@ configure(subprojects.findAll { it.name != "props-core" }) { if(project.name != "core") { instruction 'Require-Bundle', 'org.functionaljava;bundle-version="'+project.fjBaseVersion+'"' } - instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : "-$project.name"}" + instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : ".$project.name"}" } } From 6cadc81f9b651b90cfb3e2d79c99a3b70caddbe8 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 3 Nov 2019 15:58:10 +0300 Subject: [PATCH 259/336] remove ord parameter and provide it from enumerator --- core/src/main/java/fj/Monoid.java | 5 ++--- core/src/test/java/fj/MonoidTest.java | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 2b3400c0..490dc9d6 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -1107,14 +1107,13 @@ public Set append(Set a1, Set a2) { * * @param bounded A bound for all possible elements * @param enumerator An enumerator for all possible elements - * @param o An order for set elements. * @return A monoid for sets whose elements have the given order. */ - public static Monoid> setIntersectionMonoid(final Bounded bounded, final Enumerator enumerator, final Ord o) { + public static Monoid> setIntersectionMonoid(final Bounded bounded, final Enumerator enumerator) { return monoidDef(new Definition>() { @Override public Set empty() { - return Set.iteratorSet(o, enumerator.toStream(bounded).iterator()); + return Set.iteratorSet(enumerator.order(), enumerator.toStream(bounded).iterator()); } @Override diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index d61da72f..f185a124 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -22,7 +22,7 @@ public void lifted_sum_of_two_numbers() { @Test public void intersection_monoid_test() { Bounded integersBounded = Bounded.bounded(0, 10); - Monoid> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd); + Monoid> intersectionMonoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); Set second = Set.set(Ord.intOrd, 3, 4, 5, 6); Set actual = intersectionMonoid.sum(first, second); @@ -41,7 +41,7 @@ public void union_monoid_test() { @Test public void intersection_monoid_zero_test() { Bounded integersBounded = Bounded.bounded(0, 10); - Monoid> monoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator, Ord.intOrd); + Monoid> monoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator); Set set = Set.set(Ord.intOrd, 1, 2, 3, 4); Set zero = monoid.zero(); assertThat(monoid.sum(zero, set), is(set)); From fe19604e96855faaa6005aeda6b71c24bcb66a53 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 3 Nov 2019 16:03:31 +0300 Subject: [PATCH 260/336] fix missing max value of bounded --- core/src/main/java/fj/data/Enumerator.java | 2 +- core/src/test/java/fj/MonoidTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/Enumerator.java b/core/src/main/java/fj/data/Enumerator.java index 85b8377f..2fa96a6f 100644 --- a/core/src/main/java/fj/data/Enumerator.java +++ b/core/src/main/java/fj/data/Enumerator.java @@ -190,7 +190,7 @@ public Stream toStream(final A a) { */ public Stream toStream(final Bounded bounded) { final F id = identity(); - return Stream.fromFunction(this, id, bounded.min()).takeWhile(item -> !item.equals(bounded.max())); + return Stream.fromFunction(this, id, bounded.min()).takeWhile(item -> order.isLessThanOrEqualTo(item, bounded.max())); } /** diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index f185a124..a54bf672 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -29,7 +29,7 @@ public void intersection_monoid_test() { assertThat(actual, is(Set.set(Ord.intOrd, 3, 4))); } - @Test + @Test public void union_monoid_test() { Monoid> unionMonoid = Monoid.setMonoid(Ord.intOrd); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); @@ -42,7 +42,7 @@ public void union_monoid_test() { public void intersection_monoid_zero_test() { Bounded integersBounded = Bounded.bounded(0, 10); Monoid> monoid = Monoid.setIntersectionMonoid(integersBounded, Enumerator.intEnumerator); - Set set = Set.set(Ord.intOrd, 1, 2, 3, 4); + Set set = Set.set(Ord.intOrd, 7, 8, 9, 10); Set zero = monoid.zero(); assertThat(monoid.sum(zero, set), is(set)); } From 5b6fafccb10c433f52dbcc0aff375e0aef89aaa3 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 3 Nov 2019 16:04:52 +0300 Subject: [PATCH 261/336] make bounded class final --- core/src/main/java/fj/Bounded.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Bounded.java b/core/src/main/java/fj/Bounded.java index 980ba9a3..e100b6d6 100644 --- a/core/src/main/java/fj/Bounded.java +++ b/core/src/main/java/fj/Bounded.java @@ -4,7 +4,7 @@ * The Bounded class is used to name the upper and lower limits of a type. * Ord is not a superclass of Bounded since types that are not totally ordered may also have upper and lower bounds. */ -public class Bounded { +public final class Bounded { private final Definition def; From dc9e0a9de8b897cd3ff53bf5c154494786b9dd98 Mon Sep 17 00:00:00 2001 From: Yaroslav Atroshenko Date: Sun, 3 Nov 2019 16:10:18 +0300 Subject: [PATCH 262/336] code clean up --- core/src/test/java/fj/MonoidTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index a54bf672..1156e729 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -29,7 +29,7 @@ public void intersection_monoid_test() { assertThat(actual, is(Set.set(Ord.intOrd, 3, 4))); } - @Test + @Test public void union_monoid_test() { Monoid> unionMonoid = Monoid.setMonoid(Ord.intOrd); Set first = Set.set(Ord.intOrd, 1, 2, 3, 4); From ac4819d9a71dd82f888db4663f47ab3e39c80cd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Lipt=C3=A1k?= Date: Fri, 13 Dec 2019 09:11:52 -0500 Subject: [PATCH 263/336] Switch to gradle-versions-plugin --- build.gradle | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 69c01425..5fbad7bc 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,9 @@ defaultTasks 'build' -ext { -} +apply plugin: "com.github.ben-manes.versions" buildscript { - ext { - uptodateVersion = "1.6.3" - } - repositories { mavenLocal() jcenter() @@ -16,7 +11,7 @@ buildscript { } dependencies { - classpath "com.ofg:uptodate-gradle-plugin:$uptodateVersion" + classpath "com.github.ben-manes:gradle-versions-plugin:0.27.0" } wrapper { @@ -98,7 +93,6 @@ subprojects { apply from: "$rootDir/lib.gradle" apply plugin: "java" apply plugin: "eclipse" - apply plugin: "com.ofg.uptodate" repositories { mavenLocal() From 560db2e6d9deaf2bb24bea21d65ab7c410977bce Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Tue, 19 May 2020 20:29:26 -0400 Subject: [PATCH 264/336] Add fj.test.Gen.streamOf(Gen), similar to fj.test.Gen.listOf(Gen, int); returns a generator of streams whose values come from the given generator. --- quickcheck/src/main/java/fj/test/Gen.java | 13 +++++++++++++ quickcheck/src/test/java/fj/test/GenTest.java | 16 ++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index c375874d..527d620c 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -9,6 +9,7 @@ import fj.data.Array; import fj.data.List; import fj.data.Option; +import fj.data.Stream; import fj.function.Effect1; import static fj.Bottom.error; @@ -497,6 +498,18 @@ public static Gen> listOf1(final Gen g) { return listOf(g, 1); } + /** + * Returns a generator of streams whose values come from the given generator. + * + * @param g the generator to produce values from for the returned generator + * @param the type of the generator + * + * @return A generator of streams whose values come from the given generator. + */ + public static Gen> streamOf(final Gen g) { + return gen(i -> r -> Stream.cons(g.gen(i, r), () -> streamOf(g).gen(i, r))); + } + /** * Returns a generator that picks one element from the given list. If the given list is empty, then the * returned generator will never produce a value. diff --git a/quickcheck/src/test/java/fj/test/GenTest.java b/quickcheck/src/test/java/fj/test/GenTest.java index 900369a7..9ec0ec79 100644 --- a/quickcheck/src/test/java/fj/test/GenTest.java +++ b/quickcheck/src/test/java/fj/test/GenTest.java @@ -1,16 +1,19 @@ package fj.test; import fj.data.List; +import fj.data.Stream; import fj.function.Effect1; import org.junit.Test; import static fj.Ord.charOrd; import static fj.data.List.list; import static fj.data.List.range; -import static fj.test.Gen.selectionOf; import static fj.test.Gen.combinationOf; -import static fj.test.Gen.wordOf; import static fj.test.Gen.permutationOf; +import static fj.test.Gen.pickOne; +import static fj.test.Gen.selectionOf; +import static fj.test.Gen.streamOf; +import static fj.test.Gen.wordOf; import static fj.test.Rand.standard; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -175,6 +178,15 @@ public void testWordOf_four() { }); } + @Test + public void testStreamOf() { + final Gen> instance = streamOf(pickOne(AS)); + testPick(100, instance.map(stream -> stream.take(4).toList()), actual -> { + assertEquals(4, actual.length()); + assertTrue(actual.forall(actualA -> AS.exists(a -> a.equals(actualA)))); + }); + } + private static void testPick(int n, Gen> instance, Effect1> test) { range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test); } From e98db344df3023beb0898688a682fe73e2c134ec Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Wed, 20 May 2020 19:16:19 -0400 Subject: [PATCH 265/336] Add fj.data.Option.sequence(Validation>). --- core/src/main/java/fj/data/Option.java | 16 +++++++++++--- core/src/test/java/fj/data/OptionTest.java | 25 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 54b4bb01..1a170c2c 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -372,11 +372,11 @@ public final Option> bindProduct(final Option ob) { public final Option> bindProduct(final Option ob, final Option oc) { return bind(ob, oc, P.p3()); } - + public final Option> bindProduct(final Option ob, final Option oc, final Option od) { return bind(ob, oc, od, P.p4()); } - + public final Option> bindProduct(final Option ob, final Option oc, final Option od, final Option oe) { return bind(ob, oc, od, oe, P.p5()); @@ -712,7 +712,7 @@ public static Option join(final Option> o) { } /** - * Sequence through the option monad. + * Sequence a list through the option monad. * * @param a The list of option to sequence. * @return The option of list after sequencing. @@ -723,6 +723,16 @@ public static Option> sequence(final List> a) { a.head().bind(aa -> sequence(a.tail()).map(cons_(aa))); } + /** + * Sequence a validation through the option monad. + * + * @param a The validation of option to sequence. + * @return The option of validation after sequencing. + */ + public static Option> sequence(final Validation> a) { + return a.traverseOption(identity()); + } + /** * Returns an optional value that has a value of the given argument, if the given predicate holds * on that argument, otherwise, returns no value. diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index 3eeed489..0966ece0 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -1,9 +1,15 @@ package fj.data; -import org.junit.Assert; import org.junit.Test; +import static fj.data.List.arrayList; +import static fj.data.List.nil; +import static fj.data.Option.none; +import static fj.data.Option.sequence; import static fj.data.Option.some; +import static fj.data.Validation.fail; +import static fj.data.Validation.success; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; /** @@ -26,4 +32,21 @@ public void traverseList() { assertTrue(actual.equals(expected)); } + @Test + public void sequenceListTest() { + assertEquals(some(nil()), sequence(nil())); + assertEquals(none(), sequence(arrayList(none()))); + assertEquals(some(arrayList(1)), sequence(arrayList(some(1)))); + assertEquals(none(), sequence(arrayList(none(), none()))); + assertEquals(none(), sequence(arrayList(some(1), none()))); + assertEquals(none(), sequence(arrayList(none(), some(2)))); + assertEquals(some(arrayList(1, 2)), sequence(arrayList(some(1), some(2)))); + } + + @Test + public void sequenceValidationTest() { + assertEquals(some(fail(1)), sequence(Validation.>fail(1))); + assertEquals(none(), sequence(Validation.>success(none()))); + assertEquals(some(success("string")), sequence(Validation.>success(some("string")))); + } } From 0a50e8b02c8dd00f7039d40f10eeefc10bfb3547 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Mon, 20 Jul 2020 21:55:04 -0400 Subject: [PATCH 266/336] Fixes #401. Add fj.test.Gen.sequence(Validation>). --- quickcheck/src/main/java/fj/test/Gen.java | 14 ++++++++++++++ quickcheck/src/test/java/fj/test/GenTest.java | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index 527d620c..dabaf9a6 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -10,6 +10,7 @@ import fj.data.List; import fj.data.Option; import fj.data.Stream; +import fj.data.Validation; import fj.function.Effect1; import static fj.Bottom.error; @@ -319,6 +320,19 @@ public static Gen> sequenceN(final int n, final Gen g) { return sequence(replicate(n, g)); } + /** + * Transform a validation for a generator into a generator of validations: if the given validation is a failure, the + * generator produces that failure value; if the given validation is a success, the generator produces success values. + * + * @param gv The validation for a generator. + * @param the type of the value + * @param the type of the failure + * @return if the given validation is a failure, the generator produces that failure value; if the given validation is a success, the generator produces success values. + */ + public static Gen> sequence(final Validation> gv) { + return gen(i -> r -> gv.map(g -> g.gen(i, r))); + } + /** * Constructs a generator that can access its construction arguments — size and random * generator. diff --git a/quickcheck/src/test/java/fj/test/GenTest.java b/quickcheck/src/test/java/fj/test/GenTest.java index 9ec0ec79..c13480a1 100644 --- a/quickcheck/src/test/java/fj/test/GenTest.java +++ b/quickcheck/src/test/java/fj/test/GenTest.java @@ -1,17 +1,27 @@ package fj.test; +import fj.Equal; import fj.data.List; +import fj.data.NonEmptyList; +import fj.data.Option; import fj.data.Stream; +import fj.data.Validation; import fj.function.Effect1; import org.junit.Test; import static fj.Ord.charOrd; import static fj.data.List.list; import static fj.data.List.range; +import static fj.data.NonEmptyList.nel; +import static fj.data.Option.somes; +import static fj.data.Validation.fail; +import static fj.data.Validation.success; import static fj.test.Gen.combinationOf; +import static fj.test.Gen.listOf; import static fj.test.Gen.permutationOf; import static fj.test.Gen.pickOne; import static fj.test.Gen.selectionOf; +import static fj.test.Gen.sequence; import static fj.test.Gen.streamOf; import static fj.test.Gen.wordOf; import static fj.test.Rand.standard; @@ -187,6 +197,15 @@ public void testStreamOf() { }); } + @Test + public void testSequenceValidation() { + final Gen, Character>>> success = listOf(sequence(success(pickOne(AS))), 4); + testPick(100, success, list -> assertEquals(list.length(),somes(list.map(v -> Option.sequence(v.map(c -> AS.elementIndex(Equal.anyEqual(), c))))).length())); + + final Gen, Gen>>> failure = listOf(sequence(fail(nel(new Exception()))), 4); + testPick(100, failure, list -> assertTrue(list.forall(a -> a.isFail()))); + } + private static void testPick(int n, Gen> instance, Effect1> test) { range(0, n).map(ignore -> instance.gen(0, standard)).foreachDoEffect(test); } From b8c309374065364ae5922244795efbe8e40adffe Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 23 Jul 2020 13:42:30 -0400 Subject: [PATCH 267/336] Fixes #403. Add fj.data.Validation.sequence*, fj.data.Validation.traverse*. --- core/src/main/java/fj/data/Validation.java | 358 ++++++++++++++++-- .../src/test/java/fj/data/ValidationTest.java | 209 ++++++++++ 2 files changed, 530 insertions(+), 37 deletions(-) create mode 100644 core/src/test/java/fj/data/ValidationTest.java diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 58aa5e9c..2afb91f3 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -1,17 +1,18 @@ package fj.data; import fj.*; +import fj.control.Trampoline; import fj.function.Effect1; -import static fj.Function.curry; -import static fj.P.p; +import java.util.Iterator; -import static fj.Unit.unit; import static fj.Bottom.error; +import static fj.Function.*; +import static fj.P.p; +import static fj.Unit.unit; +import static fj.data.Either.*; import static fj.data.List.list; -import java.util.Iterator; - /** * Isomorphic to {@link Either} but has renamed functions and represents failure on the left and success on the right. * This type also has accumulating functions that accept a {@link Semigroup} for binding computation while keeping error @@ -825,44 +826,327 @@ public static Validation, List> sequenceNonCumulative(List List> traverseList(F> f){ - return isSuccess() ? - f.f(success()).map(Validation::success) : - List.iterableList(fail(e.left().value())); - } + /** + * Sequence the given validation and collect the output on the left side of an either. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either, R> sequenceEitherLeft(final Validation> validation) { + return validation.traverseEitherLeft(identity()); + } - public final Stream> traverseStream(F> f){ - return isSuccess() ? - f.f(success()).map(Validation::success) : - Stream.iterableStream(fail(e.left().value())); - } + /** + * Sequence the given validation and collect the output on the right side of an either. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either> sequenceEitherRight(final Validation> validation) { + return validation.traverseEitherRight(identity()); + } - public final Option> traverseOption(F> f){ - return isSuccess() ? - f.f(success()).map(Validation::success) : - Option.some(fail(e.left().value())); - } + /** + * Sequence the given validation and collect the output as a function. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of input value + * @param the type of output value + * @return the function + */ + public static final F> sequenceF(final Validation> validation) { + return validation.traverseF(identity()); + } - public final IO> traverseIO(F> f){ - return isSuccess() ? - IOFunctions.map(f.f(success()), Validation::success) : - IOFunctions.unit(fail(e.left().value())); - } + /** + * Sequence the given validation and collect the output as an IO. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the IO value + * @return the IO + */ + public static final IO> sequenceIO(final Validation> validation) { + return validation.traverseIO(identity()); + } - public final P1> traverseP1(F> f){ - return isSuccess() ? - f.f(success()).map(Validation::success) : - p(fail(e.left().value())); - } + /** + * Sequence the given validation and collect the output as a list. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the list value + * @return the list + */ + public static final List> sequenceList(final Validation> validation) { + return validation.traverseList(identity()); + } + + /** + * Sequence the given validation and collect the output as an option. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the option value + * @return the option + */ + public static final Option> sequenceOption(final Validation> validation) { + return validation.traverseOption(identity()); + } + /** + * Sequence the given validation and collect the output as a P1. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the P1 value + * @return the P1 + */ + public static final P1> sequenceP1(final Validation> validation) { + return validation.traverseP1(identity()); + } - public static List fails(List> list) { - return list.filter(Validation::isFail).map(v -> v.fail()); - } + /** + * Sequence the given validation and collect the output as a seq. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the seq value + * @return the seq + */ + public static final Seq> sequenceSeq(final Validation> validation) { + return validation.traverseSeq(identity()); + } - public static List successes(List> list) { - return list.filter(Validation::isSuccess).map(v -> v.success()); - } + /** + * Sequence the given validation and collect the output as a set. + * + * @param ordE the given failure value ord + * @param ordC the given success value ord + * @param validation the given validation + * @param the type of the failure value + * @param the type of the set value + * @return the set + */ + public static final Set> sequenceSet(final Ord ordE, final Ord ordC, final Validation> validation) { + return validation.traverseSet(ordE, ordC, identity()); + } + + /** + * Sequence the given validation and collect the output as a stream. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the stream value + * @return the stream + */ + public static final Stream> sequenceStream(final Validation> validation) { + return validation.traverseStream(identity()); + } + + /** + * Sequence the given validation and collect the output as a trampoline. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the trampoline value + * @return the trampoline + */ + public static final Trampoline> sequenceTrampoline(final Validation> validation) { + return validation.traverseTrampoline(identity()); + } + + /** + * Sequence the given validation and collect the output as a validation. + * + * @param validation the given validation + * @param the type of the failure value + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static final Validation> sequenceValidation(final Validation> validation) { + return validation.traverseValidation(identity()); + } + + /** + * Traverse this validation with the given function and collect the output on the left side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the list + */ + public final Either, R> traverseEitherLeft(final F> f) { + return validation( + failure -> left(fail(failure)), + success -> f.f(success).left().map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the list + */ + public final Either> traverseEitherRight(final F> f) { + return validation( + failure -> right(fail(failure)), + success -> f.f(success).right().map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a function. + * + * @param f the given function + * @param the type of the input value + * @param the type of the output value + * @return the function + */ + public final F> traverseF(final F> f) { + return validation( + failure -> constant(fail(failure)), + success -> andThen(f.f(success), Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as an IO. + * + * @param f the given function + * @param the type of the IO value + * @return the IO + */ + public final IO> traverseIO(final F> f) { + return validation( + failure -> IOFunctions.unit(fail(failure)), + success -> IOFunctions.map(f.f(success), Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a list. + * + * @param f the given function + * @param the type of the list value + * @return the list + */ + public final List> traverseList(final F> f) { + return validation( + failure -> List.single(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as an option. + * + * @param f the given function + * @param the type of the option value + * @return the option + */ + public final Option> traverseOption(F> f) { + return validation( + failure -> Option.some(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a P1. + * + * @param f the given function + * @param the type of the P1 value + * @return the P1 + */ + public final P1> traverseP1(final F> f) { + return validation( + failure -> p(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public final Seq> traverseSeq(final F> f) { + return validation( + failure -> Seq.single(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a set; use the given success and failure value ords to order the set. + * + * @param ordE the given failure value ord + * @param ordC the given success value ord + * @param f the given function + * @param the type of the set value + * @return the set + */ + public final Set> traverseSet(final Ord ordE, final Ord ordC, final F> f) { + final Ord> ord = Ord.validationOrd(ordE, ordC); + return validation( + failure -> Set.single(ord, fail(failure)), + success -> f.f(success).map(ord, Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a stream. + * + * @param f the given function + * @param the type of the stream value + * @return the stream + */ + public final Stream> traverseStream(final F> f) { + return validation( + failure -> Stream.single(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a trampoline. + * + * @param f the given function + * @param the type of the trampoline value + * @return the trampoline + */ + public final Trampoline> traverseTrampoline(final F> f) { + return validation( + failure -> Trampoline.pure(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + /** + * Traverse this validation with the given function and collect the output as a validation. + * + * @param f the given function + * @param the type of the failure value + * @param the type of the seq value + * @return the validation + */ + public final Validation> traverseValidation(final F> f) { + return validation( + failure -> success(fail(failure)), + success -> f.f(success).map(Validation::success)); + } + + + public static List fails(List> list) { + return list.filter(Validation::isFail).map(v -> v.fail()); + } + + public static List successes(List> list) { + return list.filter(Validation::isSuccess).map(v -> v.success()); + } /** * A failing projection of a validation. @@ -1268,7 +1552,7 @@ public static Validation parseShort(final String s } /** - * A function that parses a string into a short. + * A function that parses a string into a short. */ public static final F> parseShort = Validation::parseShort; diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java new file mode 100644 index 00000000..0f1f3216 --- /dev/null +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -0,0 +1,209 @@ +package fj.data; + +import fj.control.Trampoline; +import org.junit.Test; + +import java.io.IOException; + +import static fj.Function.constant; +import static fj.Ord.*; +import static fj.P.p; +import static fj.data.Either.*; +import static fj.data.Option.*; +import static fj.data.Validation.sequenceEitherLeft; +import static fj.data.Validation.sequenceEitherRight; +import static fj.data.Validation.sequenceF; +import static fj.data.Validation.sequenceIO; +import static fj.data.Validation.sequenceList; +import static fj.data.Validation.sequenceOption; +import static fj.data.Validation.sequenceP1; +import static fj.data.Validation.sequenceSeq; +import static fj.data.Validation.sequenceSet; +import static fj.data.Validation.sequenceStream; +import static fj.data.Validation.sequenceTrampoline; +import static fj.data.Validation.sequenceValidation; +import static fj.data.Validation.*; +import static org.junit.Assert.assertEquals; + +public class ValidationTest { + + @Test + public void testSequenceEitherLeft() { + assertEquals(left(fail("zero")), sequenceEitherLeft(fail("zero"))); + assertEquals(left(success("zero")), sequenceEitherLeft(success(left("zero")))); + assertEquals(right("zero"), sequenceEitherLeft(success(right("zero")))); + } + + @Test + public void testSequenceEitherRight() { + assertEquals(right(fail("zero")), sequenceEitherRight(fail("zero"))); + assertEquals(right(success("zero")), sequenceEitherRight(success(right("zero")))); + assertEquals(left("zero"), sequenceEitherRight(success(left("zero")))); + } + + @Test + public void testSequenceF() { + assertEquals(constant(fail("zero")).f(1), sequenceF(fail("zero")).f(1)); + assertEquals(constant(success("zero")).f(1), sequenceF(success(constant("zero"))).f(1)); + } + + @Test + public void testSequenceIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(fail("zero"))).run(), sequenceIO(fail("zero")).run()); + assertEquals(IOFunctions.lazy(constant(success("zero"))).run(), sequenceIO(success(IOFunctions.lazy(constant("zero")))).run()); + } + + @Test + public void testSequenceList() { + assertEquals(List.single(fail("zero")), sequenceList(fail("zero"))); + assertEquals(List.nil(), sequenceList(success(List.nil()))); + assertEquals(List.single(success("zero")), sequenceList(success(List.single("zero")))); + assertEquals(List.arrayList(success("zero"), success("one")), sequenceList(success(List.arrayList("zero", "one")))); + } + + @Test + public void testSequenceOption() { + assertEquals(some(fail("zero")), sequenceOption(fail("zero"))); + assertEquals(none(), sequenceOption(success(none()))); + assertEquals(some(success("zero")), sequenceOption(success(some("zero")))); + } + + @Test + public void testSequenceP1() { + assertEquals(p(fail("zero")), sequenceP1(fail("zero"))); + assertEquals(p(success("zero")), sequenceP1(success(p("zero")))); + } + + @Test + public void testSequenceSeq() { + assertEquals(Seq.single(fail("zero")), sequenceSeq(fail("zero"))); + assertEquals(Seq.empty(), sequenceSeq(success(Seq.empty()))); + assertEquals(Seq.single(success("zero")), sequenceSeq(success(Seq.single("zero")))); + assertEquals(Seq.arraySeq(success("zero"), success("one")), sequenceSeq(success(Seq.arraySeq("zero", "one")))); + } + + @Test + public void testSequenceSet() { + assertEquals(Set.single(validationOrd(stringOrd, intOrd), fail("zero")), sequenceSet(stringOrd, intOrd, fail("zero"))); + assertEquals(Set.empty(validationOrd(stringOrd, intOrd)), sequenceSet(stringOrd, intOrd, success(Set.empty(intOrd)))); + assertEquals(Set.single(validationOrd(intOrd, stringOrd), success("zero")), sequenceSet(intOrd, stringOrd, success(Set.single(stringOrd, "zero")))); + assertEquals(Set.arraySet(validationOrd(intOrd, stringOrd), success("zero"), success("one")), sequenceSet(intOrd, stringOrd, Validation.success(Set.arraySet(stringOrd, "zero", "one")))); + } + + @Test + public void testSequenceStream() { + assertEquals(Stream.single(fail("zero")), sequenceStream(fail("zero"))); + assertEquals(Stream.nil(), sequenceStream(success(Stream.nil()))); + assertEquals(Stream.single(success("zero")), sequenceStream(success(Stream.single("zero")))); + assertEquals(Stream.arrayStream(success("zero"), success("one")), sequenceStream(success(Stream.arrayStream("zero", "one")))); + } + + @Test + public void testSequenceTrampoline() { + assertEquals(Trampoline.pure(fail("zero")).run(), sequenceTrampoline(fail("zero")).run()); + assertEquals(Trampoline.pure(success(0)).run(), sequenceTrampoline(success(Trampoline.pure(0))).run()); + } + + @Test + public void testSequenceValidation() { + assertEquals(success(fail("zero")), sequenceValidation(fail("zero"))); + assertEquals(fail("zero"), sequenceValidation(success(fail("zero")))); + assertEquals(success(success(0)), sequenceValidation(success(success(0)))); + } + + @Test + public void testTraverseEitherLeft() { + assertEquals(left(fail("zero")), fail("zero").traverseEitherLeft(constant(left(0)))); + assertEquals(left(success(0)), success("zero").traverseEitherLeft(constant(left(0)))); + assertEquals(left(fail("zero")), fail("zero").traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), success("zero").traverseEitherLeft(constant(right(0)))); + } + + @Test + public void testTraverseEitherRight() { + assertEquals(right(fail("zero")), fail("zero").traverseEitherRight(constant(right(0)))); + assertEquals(right(success(0)), success("zero").traverseEitherRight(constant(right(0)))); + assertEquals(right(fail("zero")), fail("zero").traverseEitherRight(constant(left(0)))); + assertEquals(left(0), success("zero").traverseEitherRight(constant(left(0)))); + } + + @Test + public void testTraverseF() { + assertEquals(constant(fail("zero")).f(1), fail("zero").traverseF(constant(constant(0))).f(1)); + assertEquals(constant(success(0)).f(1), success("zero").traverseF(constant(constant(0))).f(1)); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(fail("zero"))).run(), fail("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(success(0))).run(), success("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseList() { + assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.nil()))); + assertEquals(List.nil(), success("zero").traverseList(constant(List.nil()))); + assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.single(0)))); + assertEquals(List.single(success(0)), success("zero").traverseList(constant(List.single(0)))); + assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.arrayList(success(0), success(1)), success("zero").traverseList(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseOption() { + assertEquals(some(fail("zero")), fail("zero").traverseOption(constant(none()))); + assertEquals(none(), success("zero").traverseOption(constant(none()))); + assertEquals(some(fail("zero")), fail("zero").traverseOption(constant(some(0)))); + assertEquals(some(success(0)), success("zero").traverseOption(constant(some(0)))); + } + + @Test + public void testTraverseP1() { + assertEquals(p(fail("zero")), fail("zero").traverseP1(constant(p(0)))); + assertEquals(p(success(0)), success("zero").traverseP1(constant(p(0)))); + } + + @Test + public void testTraverseSeq() { + assertEquals(Seq.single(fail("zero")), fail("zero").traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.empty(), success("zero").traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.single(fail("zero")), fail("zero").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(success(0)), success("zero").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(fail("zero")), fail("zero").traverseSeq(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.arraySeq(success(0), success(1)), success("zero").traverseSeq(constant(Seq.arraySeq(0, 1)))); + } + + @Test + public void testTraverseSet() { + assertEquals(Set.single(validationOrd(stringOrd, intOrd), fail("zero")), fail("zero").traverseSet(stringOrd, intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(validationOrd(stringOrd, intOrd)), Validation.success("zero").traverseSet(stringOrd, intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.single(validationOrd(stringOrd, intOrd), fail("zero")), fail("zero").traverseSet(stringOrd, intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(validationOrd(stringOrd, intOrd), success(0)), Validation.success("zero").traverseSet(stringOrd, intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(validationOrd(stringOrd, intOrd), fail("zero")), fail("zero").traverseSet(stringOrd, intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(validationOrd(stringOrd, intOrd), success(0), success(1)), Validation.success("zero").traverseSet(stringOrd, intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.single(fail("zero")), fail("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), success("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(fail("zero")), fail("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(success(0)), success("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(fail("zero")), fail("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(success(0), success(1)), success("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseTrampoline() { + assertEquals(Trampoline.pure(fail("zero")).run(), fail("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(success(0)).run(), success("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); + } + + @Test + public void testTraverseValidation() { + assertEquals(Validation.>success(fail("zero")), Validation.fail("zero").traverseValidation(constant(Validation.fail(0)))); + assertEquals(Validation.>fail(0), Validation.success("zero").traverseValidation(constant(Validation.fail(0)))); + assertEquals(Validation.>success(fail("zero")), Validation.fail("zero").traverseValidation(constant(Validation.success(0)))); + assertEquals(Validation.>success(success(0)), Validation.success("zero").traverseValidation(constant(Validation.success(0)))); + } +} From cb99e095a2fbc2bcf9f527dbe1d272515c715b0c Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 23 Jul 2020 12:04:17 -0400 Subject: [PATCH 268/336] Fixes #403. Add fj.data.Option.sequence*, fj.data.Option.traverse*. --- core/src/main/java/fj/data/Option.java | 351 +++++++++++++++++---- core/src/test/java/fj/data/OptionTest.java | 242 ++++++++++++-- 2 files changed, 515 insertions(+), 78 deletions(-) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 1a170c2c..6b62d2cf 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -1,43 +1,24 @@ package fj.data; -import static fj.Bottom.error; -import fj.F; -import fj.F0; -import fj.F2; -import fj.P; -import fj.P1; -import fj.P2; -import fj.P3; -import fj.P4; -import fj.P5; -import fj.P6; -import fj.P7; -import fj.P8; -import fj.Unit; -import fj.Show; +import fj.*; +import fj.control.Trampoline; +import fj.data.optic.*; import fj.function.Effect1; -import fj.Equal; -import fj.Ord; -import fj.Hash; -import fj.data.optic.Prism; -import fj.data.optic.PPrism; + +import java.lang.Class; +import java.util.*; + +import static fj.Bottom.error; import static fj.Function.*; import static fj.P.p; +import static fj.Show.optionShow; import static fj.Unit.unit; -import static fj.data.List.cons; -import static fj.data.List.cons_; -import static fj.data.Validation.parseByte; -import static fj.data.Validation.parseDouble; -import static fj.data.Validation.parseFloat; -import static fj.data.Validation.parseInt; -import static fj.data.Validation.parseLong; -import static fj.data.Validation.parseShort; -import static fj.data.optic.Prism.prism; +import static fj.control.Trampoline.pure; +import static fj.data.Either.*; +import static fj.data.List.*; +import static fj.data.Validation.*; import static fj.data.optic.PPrism.pPrism; -import static fj.Show.optionShow; - -import java.util.Collection; -import java.util.Iterator; +import static fj.data.optic.Prism.prism; /** * An optional value that may be none (no value) or some (a value). This type is a replacement for @@ -411,45 +392,307 @@ public final Option sequence(final Option o) { return bind(c); } - public final Either> traverseEither(F> f) { - return map(a -> f.f(a).right().map(Option::some)).orSome(Either.right(none())); + /** + * Sequence the given option and collect the output on the right side of an either. + * + * @param option the given option + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either, R> sequenceEitherLeft(final Option> option) { + return option.traverseEitherLeft(identity()); + } + + /** + * Sequence the given option and collect the output on the left side of an either. + * + * @param option the given option + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either> sequenceEitherRight(final Option> option) { + return option.traverseEitherRight(identity()); + } + + /** + * Sequence the given option and collect the output as a function. + * + * @param option the given option + * @param the type of the input value + * @param the type of the output value + * @return the either + */ + public static final F> sequenceF(final Option> option) { + return option.traverseF(identity()); + } + + /** + * Sequence the given option and collect the output as an IO. + * + * @param option the given option + * @param the type of the IO value + * @return the IO + */ + public static final IO> sequenceIO(final Option> option) { + return option.traverseIO(identity()); + } + + /** + * Sequence the given option and collect the output as an list. + * + * @param option the given option + * @param the type of the list value + * @return the list + */ + public static final List> sequenceList(final Option> option) { + return option.traverseList(identity()); } - public final IO> traverseIO(F> f) { - return map(a -> IOFunctions.map(f.f(a), Option::some)).orSome(IOFunctions.lazy(Option::none)); + /** + * Sequence the given option and collect the output as an option. + * + * @param option the given option + * @param the type of the option value + * @return the option + */ + public static final Option> sequenceOption(final Option> option) { + return option.traverseOption(identity()); } - public final List> traverseList(F> f) { - return map(a -> f.f(a).map(Option::some)).orSome(List.list()); + /** + * Sequence the given option and collect the output as a P1. + * + * @param option the given option + * @param the type of the P1 value + * @return the P1 + */ + public static final P1> sequenceP1(final Option> option) { + return option.traverseP1(identity()); } - public final Option> traverseOption(F> f) { - return map(f); + /** + * Sequence the given option and collect the output as a seq. + * + * @param option the given option + * @param the type of the seq value + * @return the seq + */ + public static final Seq> sequenceSeq(final Option> option) { + return option.traverseSeq(identity()); } - public final Stream> traverseStream(F> f) { - return map(a -> f.f(a).map(Option::some)).orSome(Stream.nil()); + /** + * Sequence the given option and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param option the given option + * @param the type of the set value + * @return the either + */ + public static final Set> sequenceSet(final Ord ord, final Option> option) { + return option.traverseSet(ord, identity()); } - public final P1> traverseP1(F> f) { - return map(a -> f.f(a).map(Option::some)).orSome(p(none())); + /** + * Sequence the given option and collect the output as a stream. + * + * @param option the given option + * @param the type of the stream value + * @return the stream + */ + public static final Stream> sequenceStream(final Option> option) { + return option.traverseStream(identity()); } - public final Seq> traverseSeq(F> f) { - return map(a -> f.f(a).map(Option::some)).orSome(Seq.empty()); + /** + * Sequence the given option and collect the output as a trampoline. + * + * @param option the given trampoline + * @param the type of the stream value + * @return the stream + */ + public static final Trampoline> sequenceTrampoline(final Option> option) { + return option.traverseTrampoline(identity()); } - public final Set> traverseSet(Ord ord, F> f) { - Ord> optOrd = Ord.optionOrd(ord); - return map(a -> f.f(a).map(optOrd, Option::some)).orSome(Set.empty(optOrd)); + /** + * Sequence the given option and collect the output as a validation. + * + * @param option the given option + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static final Validation> sequenceValidation(final Option> option) { + return option.traverseValidation(identity()); } - public final F2, F>, Set>> traverseSet() { - return this::traverseSet; + /** + * Traverse this option with the given function and collect the output on the left side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public final Either, R> traverseEitherLeft(final F> f) { + return option( + left(none()), + a -> f.f(a).left().map(Option::some)); } - public final Validation> traverseValidation(F> f) { - return map(a -> f.f(a).map(Option::some)).orSome(Validation.success(none())); + /** + * Traverse this option with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public final Either> traverseEitherRight(final F> f) { + return option( + right(none()), + a -> f.f(a).right().map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a function. + * + * @param f the given function + * @param the type of the input value + * @param the type of the output value + * @return the function + */ + public final F> traverseF(final F> f) { + return option( + constant(none()), + a -> andThen(f.f(a), Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as an IO. + * + * @param f the given function + * @param the type of the IO value + * @return the IO + */ + public final IO> traverseIO(final F> f) { + return option( + IOFunctions.lazy(Option::none), + a -> IOFunctions.map(f.f(a), Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a list. + * + * @param f the given function + * @param the type of the list value + * @return the list + */ + public final List> traverseList(final F> f) { + return option( + List.single(none()), + a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as an option. + * + * @param f the given function + * @param the type of the option value + * @return the option + */ + public final Option> traverseOption(final F> f) { + return option( + some(none()), + a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a P1. + * + * @param f the given function + * @param the type of the P1 value + * @return the P1 + */ + public final P1> traverseP1(final F> f) { + return option( + p(none()), + (F>>) a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output a seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public final Seq> traverseSeq(final F> f) { + return option( + Seq.single(none()), + a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param f the given function + * @param the type of the set value + * @return the set + */ + public final Set> traverseSet(final Ord ord, final F> f) { + final Ord> ordOption = Ord.optionOrd(ord); + return option( + Set.single(ordOption, none()), + a -> f.f(a).map(ordOption, Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a stream. + * + * @param f the given function + * @param the type of the stream value + * @return the stream + */ + public final Stream> traverseStream(final F> f) { + return option( + Stream.single(none()), + a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a trampoline. + * + * @param f the given function + * @param the type of the trampoline value + * @return the trampoline + */ + public final Trampoline> traverseTrampoline(final F> f) { + return option( + pure(none()), + a -> f.f(a).map(Option::some)); + } + + /** + * Traverse this option with the given function and collect the output as a validation. + * + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public final Validation> traverseValidation(final F> f) { + return option( + success(none()), + a -> f.f(a).map(Option::some)); + } + + public final F2, F>, Set>> traverseSet() { + return this::traverseSet; } /** diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index 0966ece0..403cbbd1 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -1,21 +1,35 @@ package fj.data; +import fj.control.Trampoline; import org.junit.Test; -import static fj.data.List.arrayList; -import static fj.data.List.nil; -import static fj.data.Option.none; +import java.io.IOException; + +import static fj.Function.constant; +import static fj.Ord.*; +import static fj.P.p; +import static fj.data.Either.*; +import static fj.data.List.*; import static fj.data.Option.sequence; -import static fj.data.Option.some; +import static fj.data.Option.sequenceF; +import static fj.data.Option.sequenceIO; +import static fj.data.Option.sequenceList; +import static fj.data.Option.sequenceOption; +import static fj.data.Option.sequenceP1; +import static fj.data.Option.sequenceSeq; +import static fj.data.Option.sequenceSet; +import static fj.data.Option.sequenceStream; +import static fj.data.Option.sequenceTrampoline; +import static fj.data.Option.sequenceValidation; +import static fj.data.Option.*; import static fj.data.Validation.fail; -import static fj.data.Validation.success; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static fj.data.Validation.*; +import static org.junit.Assert.*; /** * Created by MarkPerry on 15/01/2015. */ -public class OptionTest { +public final class OptionTest { @Test public void equals() { @@ -32,21 +46,201 @@ public void traverseList() { assertTrue(actual.equals(expected)); } - @Test - public void sequenceListTest() { - assertEquals(some(nil()), sequence(nil())); - assertEquals(none(), sequence(arrayList(none()))); - assertEquals(some(arrayList(1)), sequence(arrayList(some(1)))); - assertEquals(none(), sequence(arrayList(none(), none()))); - assertEquals(none(), sequence(arrayList(some(1), none()))); - assertEquals(none(), sequence(arrayList(none(), some(2)))); - assertEquals(some(arrayList(1, 2)), sequence(arrayList(some(1), some(2)))); - } + @Test + public void sequenceListTest() { + assertEquals(some(nil()), sequence(nil())); + assertEquals(none(), sequence(arrayList(none()))); + assertEquals(some(arrayList(1)), sequence(arrayList(some(1)))); + assertEquals(none(), sequence(arrayList(none(), none()))); + assertEquals(none(), sequence(arrayList(some(1), none()))); + assertEquals(none(), sequence(arrayList(none(), some(2)))); + assertEquals(some(arrayList(1, 2)), sequence(arrayList(some(1), some(2)))); + } - @Test - public void sequenceValidationTest() { - assertEquals(some(fail(1)), sequence(Validation.>fail(1))); - assertEquals(none(), sequence(Validation.>success(none()))); - assertEquals(some(success("string")), sequence(Validation.>success(some("string")))); - } + @Test + public void sequenceValidationTest() { + assertEquals(some(fail(1)), sequence(Validation.>fail(1))); + assertEquals(none(), sequence(Validation.>success(none()))); + assertEquals(some(success("string")), sequence(Validation.>success(some("string")))); + } + + @Test + public void testSequenceEitherLeft() { + assertEquals(left(none()), sequenceEitherLeft(none())); + assertEquals(left(some("0")), sequenceEitherLeft(some(left("0")))); + assertEquals(right("0"), sequenceEitherLeft(some(right("0")))); + } + + @Test + public void testSequenceEitherRight() { + assertEquals(right(none()), sequenceEitherRight(none())); + assertEquals(right(some("0")), sequenceEitherRight(some(right("0")))); + assertEquals(left("0"), sequenceEitherRight(some(left("0")))); + } + + @Test + public void testSequenceF() { + assertEquals(constant(none()).f(1), sequenceF(none()).f(1)); + assertEquals(constant(some("0")).f(1), sequenceF(some(constant("0"))).f(1)); + } + + @Test + public void testSequenceIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(none())).run(), sequenceIO(none()).run()); + assertEquals(IOFunctions.lazy(constant(some("0"))).run(), sequenceIO(some(IOFunctions.lazy(constant("0")))).run()); + } + + @Test + public void testSequenceList() { + assertEquals(List.arrayList(none()), sequenceList(none())); + assertEquals(List.nil(), sequenceList(some(List.nil()))); + assertEquals(List.arrayList(some("0")), sequenceList(some(List.single("0")))); + assertEquals(List.arrayList(some("0"), some("1")), sequenceList(some(List.arrayList("0", "1")))); + } + + @Test + public void testSequenceOption() { + assertEquals(some(none()), sequenceOption(none())); + assertEquals(none(), sequenceOption(some(none()))); + assertEquals(some(some("0")), sequenceOption(some(some("0")))); + } + + @Test + public void testSequenceP1() { + assertEquals(p(none()), sequenceP1(none())); + assertEquals(p(some("0")), sequenceP1(some(p("0")))); + } + + @Test + public void testSequenceSeq() { + assertEquals(Seq.arraySeq(none()), sequenceSeq(none())); + assertEquals(Seq.empty(), sequenceSeq(some(Seq.empty()))); + assertEquals(Seq.arraySeq(some("0")), sequenceSeq(some(Seq.single("0")))); + assertEquals(Seq.arraySeq(some("0"), some("1")), sequenceSeq(some(Seq.arraySeq("0", "1")))); + } + + @Test + public void testSequenceSet() { + assertEquals(Set.arraySet(optionOrd(stringOrd), none()), sequenceSet(stringOrd, none())); + assertEquals(Set.empty(optionOrd(stringOrd)), sequenceSet(stringOrd, some(Set.empty(stringOrd)))); + assertEquals(Set.arraySet(optionOrd(stringOrd), some("0")), sequenceSet(stringOrd, some(Set.single(stringOrd, "0")))); + assertEquals(Set.arraySet(optionOrd(stringOrd), some("0"), some("1")), sequenceSet(stringOrd, some(Set.arraySet(stringOrd, "0", "1")))); + } + + @Test + public void testSequenceStream() { + assertEquals(Stream.arrayStream(none()), sequenceStream(none())); + assertEquals(Stream.nil(), sequenceStream(some(Stream.nil()))); + assertEquals(Stream.arrayStream(some("0")), sequenceStream(some(Stream.single("0")))); + assertEquals(Stream.arrayStream(some("0"), some("1")), sequenceStream(some(Stream.arrayStream("0", "1")))); + } + + @Test + public void testSequenceTrampoline() { + assertEquals(Trampoline.pure(none()).run(), sequenceTrampoline(none()).run()); + assertEquals(Trampoline.pure(some(0)).run(), sequenceTrampoline(some(Trampoline.pure(0))).run()); + } + + @Test + public void testSequenceValidation() { + assertEquals(Validation.success(none()), sequenceValidation(none())); + assertEquals(Validation.fail(0), sequenceValidation(some(Validation.fail(0)))); + assertEquals(Validation.success(some(0)), sequenceValidation(some(Validation.success(0)))); + } + + @Test + public void testTraverseEitherLeft() { + assertEquals(left(none()), none().traverseEitherLeft(constant(left(0)))); + assertEquals(left(some(0)), some("0").traverseEitherLeft(constant(left(0)))); + assertEquals(left(none()), none().traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), some("0").traverseEitherLeft(constant(right(0)))); + } + + @Test + public void testTraverseEitherRight() { + assertEquals(right(none()), none().traverseEitherRight(constant(right(0)))); + assertEquals(right(some(0)), some("0").traverseEitherRight(constant(right(0)))); + assertEquals(right(none()), none().traverseEitherRight(constant(left(0)))); + assertEquals(left(0), some("0").traverseEitherRight(constant(left(0)))); + } + + @Test + public void testTraverseF() { + assertEquals(constant(none()).f(1), none().traverseF(constant(constant(0))).f(1)); + assertEquals(constant(some(0)).f(1), some("0").traverseF(constant(constant(0))).f(1)); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(none())).run(), none().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(some(0))).run(), some("0").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseList() { + assertEquals(List.arrayList(none()), none().traverseList(constant(List.nil()))); + assertEquals(List.nil(), some("0").traverseList(constant(List.nil()))); + assertEquals(List.arrayList(none()), none().traverseList(constant(List.single(0)))); + assertEquals(List.arrayList(some(0)), some("0").traverseList(constant(List.single(0)))); + assertEquals(List.arrayList(none()), none().traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.arrayList(some(0), some(1)), some("0").traverseList(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseOption() { + assertEquals(some(none()), none().traverseOption(constant(none()))); + assertEquals(none(), some("0").traverseOption(constant(none()))); + assertEquals(some(none()), none().traverseOption(constant(some(0)))); + assertEquals(some(some(0)), some("0").traverseOption(constant(some(0)))); + } + + @Test + public void testTraverseP1() { + assertEquals(p(none()), none().traverseP1(constant(p(0)))); + assertEquals(p(some(0)), some("0").traverseP1(constant(p(0)))); + } + + @Test + public void testTraverseSeq() { + assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.empty(), some("0").traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.arraySeq(some(0)), some("0").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.arraySeq(some(0), some(1)), some("0").traverseSeq(constant(Seq.arraySeq(0, 1)))); + } + + @Test + public void testTraverseSet() { + assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(optionOrd(intOrd)), some("0").traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.arraySet(optionOrd(intOrd), some(0)), some("0").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(optionOrd(intOrd), some(0), some(1)), some("0").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), some("0").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(some(0)), some("0").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(some(0), some(1)), some("0").traverseStream(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseTrampoline() { + assertEquals(Trampoline.pure(none()).run(), none().traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(some(0)).run(), some("0").traverseTrampoline(constant(Trampoline.pure(0))).run()); + } + + @Test + public void testTraverseValidation() { + assertEquals(success(none()), none().traverseValidation(constant(Validation.fail(0)))); + assertEquals(fail(0), some("0").traverseValidation(constant(Validation.fail(0)))); + assertEquals(success(none()), none().traverseValidation(constant(Validation.success(0)))); + assertEquals(success(some(0)), some("0").traverseValidation(constant(Validation.success(0)))); + } } From 225622c0e9ac4544868d341455ea5e6894311a10 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 23 Jul 2020 13:38:44 -0400 Subject: [PATCH 269/336] Fixes #403. Add fj.data.Option.sequence*, fj.data.Option.traverse*; correct comment, distinguish between 0 and 0. --- core/src/main/java/fj/data/Option.java | 4 +- core/src/test/java/fj/data/OptionTest.java | 106 +++++++++++---------- 2 files changed, 56 insertions(+), 54 deletions(-) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 6b62d2cf..655463b7 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -393,7 +393,7 @@ public final Option sequence(final Option o) { } /** - * Sequence the given option and collect the output on the right side of an either. + * Sequence the given option and collect the output on the left side of an either. * * @param option the given option * @param the type of the right value @@ -405,7 +405,7 @@ public static final Either, R> sequenceEitherLeft(final Option< } /** - * Sequence the given option and collect the output on the left side of an either. + * Sequence the given option and collect the output on the right side of an either. * * @param option the given option * @param the type of the right value diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index 403cbbd1..db37f1ed 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -11,6 +11,8 @@ import static fj.data.Either.*; import static fj.data.List.*; import static fj.data.Option.sequence; +import static fj.data.Option.sequenceEitherLeft; +import static fj.data.Option.sequenceEitherRight; import static fj.data.Option.sequenceF; import static fj.data.Option.sequenceIO; import static fj.data.Option.sequenceList; @@ -67,72 +69,72 @@ public void sequenceValidationTest() { @Test public void testSequenceEitherLeft() { assertEquals(left(none()), sequenceEitherLeft(none())); - assertEquals(left(some("0")), sequenceEitherLeft(some(left("0")))); - assertEquals(right("0"), sequenceEitherLeft(some(right("0")))); + assertEquals(left(some("zero")), sequenceEitherLeft(some(left("zero")))); + assertEquals(right("zero"), sequenceEitherLeft(some(right("zero")))); } @Test public void testSequenceEitherRight() { assertEquals(right(none()), sequenceEitherRight(none())); - assertEquals(right(some("0")), sequenceEitherRight(some(right("0")))); - assertEquals(left("0"), sequenceEitherRight(some(left("0")))); + assertEquals(right(some("zero")), sequenceEitherRight(some(right("zero")))); + assertEquals(left("zero"), sequenceEitherRight(some(left("zero")))); } @Test public void testSequenceF() { assertEquals(constant(none()).f(1), sequenceF(none()).f(1)); - assertEquals(constant(some("0")).f(1), sequenceF(some(constant("0"))).f(1)); + assertEquals(constant(some("zero")).f(1), sequenceF(some(constant("zero"))).f(1)); } @Test public void testSequenceIO() throws IOException { assertEquals(IOFunctions.lazy(constant(none())).run(), sequenceIO(none()).run()); - assertEquals(IOFunctions.lazy(constant(some("0"))).run(), sequenceIO(some(IOFunctions.lazy(constant("0")))).run()); + assertEquals(IOFunctions.lazy(constant(some("zero"))).run(), sequenceIO(some(IOFunctions.lazy(constant("zero")))).run()); } @Test public void testSequenceList() { - assertEquals(List.arrayList(none()), sequenceList(none())); + assertEquals(List.single(none()), sequenceList(none())); assertEquals(List.nil(), sequenceList(some(List.nil()))); - assertEquals(List.arrayList(some("0")), sequenceList(some(List.single("0")))); - assertEquals(List.arrayList(some("0"), some("1")), sequenceList(some(List.arrayList("0", "1")))); + assertEquals(List.single(some("zero")), sequenceList(some(List.single("zero")))); + assertEquals(List.arrayList(some("zero"), some("one")), sequenceList(some(List.arrayList("zero", "one")))); } @Test public void testSequenceOption() { assertEquals(some(none()), sequenceOption(none())); assertEquals(none(), sequenceOption(some(none()))); - assertEquals(some(some("0")), sequenceOption(some(some("0")))); + assertEquals(some(some("zero")), sequenceOption(some(some("zero")))); } @Test public void testSequenceP1() { assertEquals(p(none()), sequenceP1(none())); - assertEquals(p(some("0")), sequenceP1(some(p("0")))); + assertEquals(p(some("zero")), sequenceP1(some(p("zero")))); } @Test public void testSequenceSeq() { - assertEquals(Seq.arraySeq(none()), sequenceSeq(none())); + assertEquals(Seq.single(none()), sequenceSeq(none())); assertEquals(Seq.empty(), sequenceSeq(some(Seq.empty()))); - assertEquals(Seq.arraySeq(some("0")), sequenceSeq(some(Seq.single("0")))); - assertEquals(Seq.arraySeq(some("0"), some("1")), sequenceSeq(some(Seq.arraySeq("0", "1")))); + assertEquals(Seq.single(some("zero")), sequenceSeq(some(Seq.single("zero")))); + assertEquals(Seq.arraySeq(some("zero"), some("one")), sequenceSeq(some(Seq.arraySeq("zero", "one")))); } @Test public void testSequenceSet() { assertEquals(Set.arraySet(optionOrd(stringOrd), none()), sequenceSet(stringOrd, none())); assertEquals(Set.empty(optionOrd(stringOrd)), sequenceSet(stringOrd, some(Set.empty(stringOrd)))); - assertEquals(Set.arraySet(optionOrd(stringOrd), some("0")), sequenceSet(stringOrd, some(Set.single(stringOrd, "0")))); - assertEquals(Set.arraySet(optionOrd(stringOrd), some("0"), some("1")), sequenceSet(stringOrd, some(Set.arraySet(stringOrd, "0", "1")))); + assertEquals(Set.arraySet(optionOrd(stringOrd), some("zero")), sequenceSet(stringOrd, some(Set.single(stringOrd, "zero")))); + assertEquals(Set.arraySet(optionOrd(stringOrd), some("zero"), some("one")), sequenceSet(stringOrd, some(Set.arraySet(stringOrd, "zero", "one")))); } @Test public void testSequenceStream() { - assertEquals(Stream.arrayStream(none()), sequenceStream(none())); + assertEquals(Stream.single(none()), sequenceStream(none())); assertEquals(Stream.nil(), sequenceStream(some(Stream.nil()))); - assertEquals(Stream.arrayStream(some("0")), sequenceStream(some(Stream.single("0")))); - assertEquals(Stream.arrayStream(some("0"), some("1")), sequenceStream(some(Stream.arrayStream("0", "1")))); + assertEquals(Stream.single(some("zero")), sequenceStream(some(Stream.single("zero")))); + assertEquals(Stream.arrayStream(some("zero"), some("one")), sequenceStream(some(Stream.arrayStream("zero", "one")))); } @Test @@ -151,96 +153,96 @@ public void testSequenceValidation() { @Test public void testTraverseEitherLeft() { assertEquals(left(none()), none().traverseEitherLeft(constant(left(0)))); - assertEquals(left(some(0)), some("0").traverseEitherLeft(constant(left(0)))); + assertEquals(left(some(0)), some("zero").traverseEitherLeft(constant(left(0)))); assertEquals(left(none()), none().traverseEitherLeft(constant(right(0)))); - assertEquals(right(0), some("0").traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), some("zero").traverseEitherLeft(constant(right(0)))); } @Test public void testTraverseEitherRight() { assertEquals(right(none()), none().traverseEitherRight(constant(right(0)))); - assertEquals(right(some(0)), some("0").traverseEitherRight(constant(right(0)))); + assertEquals(right(some(0)), some("zero").traverseEitherRight(constant(right(0)))); assertEquals(right(none()), none().traverseEitherRight(constant(left(0)))); - assertEquals(left(0), some("0").traverseEitherRight(constant(left(0)))); + assertEquals(left(0), some("zero").traverseEitherRight(constant(left(0)))); } @Test public void testTraverseF() { assertEquals(constant(none()).f(1), none().traverseF(constant(constant(0))).f(1)); - assertEquals(constant(some(0)).f(1), some("0").traverseF(constant(constant(0))).f(1)); + assertEquals(constant(some(0)).f(1), some("zero").traverseF(constant(constant(0))).f(1)); } @Test public void testTraverseIO() throws IOException { assertEquals(IOFunctions.lazy(constant(none())).run(), none().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); - assertEquals(IOFunctions.lazy(constant(some(0))).run(), some("0").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(some(0))).run(), some("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); } @Test public void testTraverseList() { - assertEquals(List.arrayList(none()), none().traverseList(constant(List.nil()))); - assertEquals(List.nil(), some("0").traverseList(constant(List.nil()))); - assertEquals(List.arrayList(none()), none().traverseList(constant(List.single(0)))); - assertEquals(List.arrayList(some(0)), some("0").traverseList(constant(List.single(0)))); - assertEquals(List.arrayList(none()), none().traverseList(constant(List.arrayList(0, 1)))); - assertEquals(List.arrayList(some(0), some(1)), some("0").traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.single(none()), none().traverseList(constant(List.nil()))); + assertEquals(List.nil(), some("zero").traverseList(constant(List.nil()))); + assertEquals(List.single(none()), none().traverseList(constant(List.single(0)))); + assertEquals(List.single(some(0)), some("zero").traverseList(constant(List.single(0)))); + assertEquals(List.single(none()), none().traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.arrayList(some(0), some(1)), some("zero").traverseList(constant(List.arrayList(0, 1)))); } @Test public void testTraverseOption() { assertEquals(some(none()), none().traverseOption(constant(none()))); - assertEquals(none(), some("0").traverseOption(constant(none()))); + assertEquals(none(), some("zero").traverseOption(constant(none()))); assertEquals(some(none()), none().traverseOption(constant(some(0)))); - assertEquals(some(some(0)), some("0").traverseOption(constant(some(0)))); + assertEquals(some(some(0)), some("zero").traverseOption(constant(some(0)))); } @Test public void testTraverseP1() { assertEquals(p(none()), none().traverseP1(constant(p(0)))); - assertEquals(p(some(0)), some("0").traverseP1(constant(p(0)))); + assertEquals(p(some(0)), some("zero").traverseP1(constant(p(0)))); } @Test public void testTraverseSeq() { - assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.empty()))); - assertEquals(Seq.empty(), some("0").traverseSeq(constant(Seq.empty()))); - assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.single(0)))); - assertEquals(Seq.arraySeq(some(0)), some("0").traverseSeq(constant(Seq.single(0)))); - assertEquals(Seq.arraySeq(none()), none().traverseSeq(constant(Seq.arraySeq(0, 1)))); - assertEquals(Seq.arraySeq(some(0), some(1)), some("0").traverseSeq(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.single(none()), none().traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.empty(), some("zero").traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.single(none()), none().traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(some(0)), some("zero").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(none()), none().traverseSeq(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.arraySeq(some(0), some(1)), some("zero").traverseSeq(constant(Seq.arraySeq(0, 1)))); } @Test public void testTraverseSet() { assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.empty(intOrd)))); - assertEquals(Set.empty(optionOrd(intOrd)), some("0").traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(optionOrd(intOrd)), some("zero").traverseSet(intOrd, constant(Set.empty(intOrd)))); assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.single(intOrd, 0)))); - assertEquals(Set.arraySet(optionOrd(intOrd), some(0)), some("0").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.arraySet(optionOrd(intOrd), some(0)), some("zero").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); assertEquals(Set.arraySet(optionOrd(intOrd), none()), none().traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); - assertEquals(Set.arraySet(optionOrd(intOrd), some(0), some(1)), some("0").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(optionOrd(intOrd), some(0), some(1)), some("zero").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); } @Test public void testTraverseStream() { - assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.nil()))); - assertEquals(Stream.nil(), some("0").traverseStream(constant(Stream.nil()))); - assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.single(0)))); - assertEquals(Stream.arrayStream(some(0)), some("0").traverseStream(constant(Stream.single(0)))); - assertEquals(Stream.arrayStream(none()), none().traverseStream(constant(Stream.arrayStream(0, 1)))); - assertEquals(Stream.arrayStream(some(0), some(1)), some("0").traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.single(none()), none().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), some("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(none()), none().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(some(0)), some("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(none()), none().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(some(0), some(1)), some("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); } @Test public void testTraverseTrampoline() { assertEquals(Trampoline.pure(none()).run(), none().traverseTrampoline(constant(Trampoline.pure(0))).run()); - assertEquals(Trampoline.pure(some(0)).run(), some("0").traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(some(0)).run(), some("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); } @Test public void testTraverseValidation() { assertEquals(success(none()), none().traverseValidation(constant(Validation.fail(0)))); - assertEquals(fail(0), some("0").traverseValidation(constant(Validation.fail(0)))); + assertEquals(fail(0), some("zero").traverseValidation(constant(Validation.fail(0)))); assertEquals(success(none()), none().traverseValidation(constant(Validation.success(0)))); - assertEquals(success(some(0)), some("0").traverseValidation(constant(Validation.success(0)))); + assertEquals(success(some(0)), some("zero").traverseValidation(constant(Validation.success(0)))); } } From f9ec6ee20804e1db8b6a4c0c238a5a51adbbe888 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 23 Jul 2020 17:56:43 -0400 Subject: [PATCH 270/336] Fixes #403. Add fj.data.Option.sequence*, fj.data.Option.traverse*; add bind tests. --- core/src/test/java/fj/data/OptionTest.java | 187 +++++++++++++++++++-- 1 file changed, 174 insertions(+), 13 deletions(-) diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index db37f1ed..d028d4f6 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -1,5 +1,6 @@ package fj.data; +import fj.P; import fj.control.Trampoline; import org.junit.Test; @@ -7,22 +8,11 @@ import static fj.Function.constant; import static fj.Ord.*; -import static fj.P.p; +import static fj.P.*; import static fj.data.Either.*; import static fj.data.List.*; +import static fj.data.Option.iif; import static fj.data.Option.sequence; -import static fj.data.Option.sequenceEitherLeft; -import static fj.data.Option.sequenceEitherRight; -import static fj.data.Option.sequenceF; -import static fj.data.Option.sequenceIO; -import static fj.data.Option.sequenceList; -import static fj.data.Option.sequenceOption; -import static fj.data.Option.sequenceP1; -import static fj.data.Option.sequenceSeq; -import static fj.data.Option.sequenceSet; -import static fj.data.Option.sequenceStream; -import static fj.data.Option.sequenceTrampoline; -import static fj.data.Option.sequenceValidation; import static fj.data.Option.*; import static fj.data.Validation.fail; import static fj.data.Validation.*; @@ -66,6 +56,177 @@ public void sequenceValidationTest() { assertEquals(some(success("string")), sequence(Validation.>success(some("string")))); } + @Test + public void testBind1() { + range(0, 1).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), 0), list.index(0).bind(Option::some)); + }); + + } + + @Test + public void testBind2() { + range(0, 2).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bind(list.index(1), p2())); + }); + } + + @Test + public void testBind3() { + range(0, 3).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bind(list.index(1), list.index(2), p3())); + }); + + } + + @Test + public void testBind4() { + range(0, 4).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bind(list.index(1), list.index(2), list.index(3), p4())); + }); + + } + + @Test + public void testBind5() { + range(0, 5).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), p5())); + }); + } + + @Test + public void testBind6() { + range(0, 6).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), p6())); + }); + } + + @Test + public void testBind7() { + range(0, 7).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), p7())); + }); + } + + @Test + public void testBind8() { + range(0, 8).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P.p8())); + }); + } + + @Test + public void testBindProduct2() { + range(0, 2).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bindProduct(list.index(1))); + }); + } + + @Test + public void testBindProduct3() { + range(0, 3).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bindProduct(list.index(1), list.index(2))); + }); + + } + + @Test + public void testBindProduct4() { + range(0, 4).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3))); + }); + + } + + @Test + public void testBindProduct5() { + range(0, 5).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4))); + }); + } + + @Test + public void testBindProduct6() { + range(0, 6).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5))); + }); + } + + @Test + public void testBindProduct7() { + range(0, 7).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6))); + }); + } + + @Test + public void testBindProduct8() { + range(0, 8).map(i -> arrayList(Option.none(), some(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) + .forEach(list -> { + assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7))); + }); + } + + @Test public void testSequenceEitherLeft() { assertEquals(left(none()), sequenceEitherLeft(none())); From fc85ee1ede0d15b64d12f4d0ec12d5ecc79ed0f8 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Fri, 24 Jul 2020 16:27:38 -0400 Subject: [PATCH 271/336] Fixes #403. Add fj.data.Option.sequence*, fj.data.Option.traverse.*; add sequenceEither, traverseEither as aliases for sequenceEitherRight, sequenceEitherLeft. --- core/src/main/java/fj/data/Option.java | 24 +++++++++++++++++++ core/src/test/java/fj/data/OptionTest.java | 27 ++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index 655463b7..b6876c63 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -392,6 +392,18 @@ public final Option sequence(final Option o) { return bind(c); } + /** + * Sequence the given option and collect the output on the right side of an either. + * + * @param option the given option + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either> sequenceEither(final Option> option) { + return option.traverseEitherRight(identity()); + } + /** * Sequence the given option and collect the output on the left side of an either. * @@ -529,6 +541,18 @@ public static final Validation> sequenceValidation(final Opt return option.traverseValidation(identity()); } + /** + * Traverse this option with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public final Either> traverseEither(final F> f) { + return traverseEitherRight(f); + } + /** * Traverse this option with the given function and collect the output on the left side of an either. * diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index d028d4f6..da5ef065 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -13,6 +13,19 @@ import static fj.data.List.*; import static fj.data.Option.iif; import static fj.data.Option.sequence; +import static fj.data.Option.sequenceEither; +import static fj.data.Option.sequenceEitherLeft; +import static fj.data.Option.sequenceEitherRight; +import static fj.data.Option.sequenceF; +import static fj.data.Option.sequenceIO; +import static fj.data.Option.sequenceList; +import static fj.data.Option.sequenceOption; +import static fj.data.Option.sequenceP1; +import static fj.data.Option.sequenceSeq; +import static fj.data.Option.sequenceSet; +import static fj.data.Option.sequenceStream; +import static fj.data.Option.sequenceTrampoline; +import static fj.data.Option.sequenceValidation; import static fj.data.Option.*; import static fj.data.Validation.fail; import static fj.data.Validation.*; @@ -226,6 +239,12 @@ public void testBindProduct8() { }); } + @Test + public void testSequenceEither() { + assertEquals(right(none()), sequenceEither(none())); + assertEquals(right(some("zero")), sequenceEither(some(right("zero")))); + assertEquals(left("zero"), sequenceEither(some(left("zero")))); + } @Test public void testSequenceEitherLeft() { @@ -311,6 +330,14 @@ public void testSequenceValidation() { assertEquals(Validation.success(some(0)), sequenceValidation(some(Validation.success(0)))); } + @Test + public void testTraverseEither() { + assertEquals(right(none()), none().traverseEither(constant(right(0)))); + assertEquals(right(some(0)), some("zero").traverseEither(constant(right(0)))); + assertEquals(right(none()), none().traverseEither(constant(left(0)))); + assertEquals(left(0), some("zero").traverseEither(constant(left(0)))); + } + @Test public void testTraverseEitherLeft() { assertEquals(left(none()), none().traverseEitherLeft(constant(left(0)))); From bf3fed02f7ae94107155ed93e271e9f621b0be2a Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Fri, 24 Jul 2020 12:26:28 -0400 Subject: [PATCH 272/336] Fixes #406. Several fj.data.Validation.accumulate functions construct unexpected or incorrect failures; add to ValidationTest. --- core/src/main/java/fj/data/Validation.java | 26 +- .../src/test/java/fj/data/ValidationTest.java | 245 +++++++++++++++++- 2 files changed, 242 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 2afb91f3..e99d64a1 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -738,20 +738,14 @@ public final Validation, B> accumulate(F f) { } - public final Validation, C> accumulate(Validation v2, F2 f) { - List list = List.nil(); - if (isFail()) { - list = list.cons(fail()); - } - if (v2.isFail()) { - list = list.cons(v2.fail()); - } - if (!list.isEmpty()) { - return fail(list); - } else { - return success(f.f(success(), v2.success())); - } + public final Validation, C> accumulate(Validation v2, F2 f) { + List list = fails(list(this, v2)); + if (!list.isEmpty()) { + return fail(list); + } else { + return success(f.f(success(), v2.success())); } + } @@ -784,7 +778,7 @@ public final Validation, D> accumulate(Validation v2, Va public final Validation, G> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, F6 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6)); if (!list.isEmpty()) { return fail(list); } else { @@ -793,7 +787,7 @@ public final Validation, D> accumulate(Validation v2, Va } public final Validation, H> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, F7 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6, v7)); if (!list.isEmpty()) { return fail(list); } else { @@ -802,7 +796,7 @@ public final Validation, D> accumulate(Validation v2, Va } public final Validation, I> accumulate(Validation v2, Validation v3, Validation v4, Validation v5, Validation v6, Validation v7, Validation v8, F8 f) { - List list = fails(list(this, v2, v3, v4, v5)); + List list = fails(list(this, v2, v3, v4, v5, v6, v7, v8)); if (!list.isEmpty()) { return fail(list); } else { diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java index 0f1f3216..0df2deb9 100644 --- a/core/src/test/java/fj/data/ValidationTest.java +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -1,14 +1,16 @@ package fj.data; +import fj.*; import fj.control.Trampoline; import org.junit.Test; import java.io.IOException; -import static fj.Function.constant; +import static fj.Function.*; import static fj.Ord.*; -import static fj.P.p; +import static fj.P.*; import static fj.data.Either.*; +import static fj.data.List.*; import static fj.data.Option.*; import static fj.data.Validation.sequenceEitherLeft; import static fj.data.Validation.sequenceEitherRight; @@ -27,6 +29,223 @@ public class ValidationTest { + @Test + public void testAccumulateSemigroup2() { + range(0, 2).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1), p2())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1), uncurryF2(p2()))); + }); + } + + @Test + public void testAccumulateSemigroup3() { + range(0, 3).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), p3())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), uncurryF3(p3()))); + }); + + } + + @Test + public void testAccumulateSemigroup4() { + range(0, 4).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), p4())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), uncurryF4(p4()))); + }); + + } + + @Test + public void testAccumulateSemigroup5() { + range(0, 5).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), p5())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), uncurryF5(p5()))); + }); + } + + @Test + public void testAccumulateSemigroup6() { + range(0, 6).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), p6())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), uncurryF6(p6()))); + }); + } + + @Test + public void testAccumulateSemigroup7() { + range(0, 7).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), p7())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), uncurryF7(p7()))); + }); + } + + @Test + public void testAccumulateSemigroup8() { + range(0, 8).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> + accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7))); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P.p8())); + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), uncurryF8(P.p8()))); + }); + } + + @Test + public void testAccumulate0() { + range(0, 1).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), 0), list.index(0).accumulate()); + }); + } + + @Test + public void testAccumulate1() { + range(0, 1).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), 0), list.index(0).accumulate(identity())); + }); + + } + + @Test + public void testAccumulate2() { + range(0, 2).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(list.index(1), P::p)); + }); + } + + @Test + public void testAccumulate3() { + range(0, 3).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(list.index(1), list.index(2), P::p)); + }); + + } + + @Test + public void testAccumulate4() { + range(0, 4).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), P::p)); + }); + + } + + @Test + public void testAccumulate5() { + range(0, 5).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), P::p)); + }); + } + + @Test + public void testAccumulate6() { + range(0, 6).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), P::p)); + }); + } + + @Test + public void testAccumulate7() { + range(0, 7).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), P::p)); + }); + } + + @Test + public void testAccumulate8() { + range(0, 8).map(i -> List., Integer>>arrayList(fail(arrayList(String.valueOf(i))), success(i))) + .foldLeft(accumulator -> list -> accumulator.isEmpty() ? + list.map(List::single) : + accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) + .forEach(list -> { + assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P::p)); + }); + } + + @Test + public void testMap() { + assertEquals(Validation.fail("zero"), Validation.fail("zero").map(constant(0))); + assertEquals(Validation.success(0), Validation.success("zero").map(constant(0))); + assertEquals(Validation.fail("zero"), Validation.fail("zero").map(constant(0))); + assertEquals(Validation.success(0), Validation.success("zero").map(constant(0))); + } + + @Test + public void testBind() { + assertEquals(Validation.fail("zero"), Validation.fail("zero").bind(constant(Validation.fail("zero")))); + assertEquals(Validation.fail("zero"), Validation.success("zero").bind(constant(Validation.fail("zero")))); + assertEquals(Validation.fail("zero"), Validation.fail("zero").bind(constant(Validation.success(0)))); + assertEquals(Validation.success(0), Validation.success("zero").bind(constant(Validation.success(0)))); + } + @Test public void testSequenceEitherLeft() { assertEquals(left(fail("zero")), sequenceEitherLeft(fail("zero"))); @@ -55,10 +274,10 @@ public void testSequenceIO() throws IOException { @Test public void testSequenceList() { - assertEquals(List.single(fail("zero")), sequenceList(fail("zero"))); - assertEquals(List.nil(), sequenceList(success(List.nil()))); - assertEquals(List.single(success("zero")), sequenceList(success(List.single("zero")))); - assertEquals(List.arrayList(success("zero"), success("one")), sequenceList(success(List.arrayList("zero", "one")))); + assertEquals(single(fail("zero")), sequenceList(fail("zero"))); + assertEquals(nil(), sequenceList(success(nil()))); + assertEquals(single(success("zero")), sequenceList(success(single("zero")))); + assertEquals(arrayList(success("zero"), success("one")), sequenceList(success(arrayList("zero", "one")))); } @Test @@ -87,7 +306,7 @@ public void testSequenceSet() { assertEquals(Set.single(validationOrd(stringOrd, intOrd), fail("zero")), sequenceSet(stringOrd, intOrd, fail("zero"))); assertEquals(Set.empty(validationOrd(stringOrd, intOrd)), sequenceSet(stringOrd, intOrd, success(Set.empty(intOrd)))); assertEquals(Set.single(validationOrd(intOrd, stringOrd), success("zero")), sequenceSet(intOrd, stringOrd, success(Set.single(stringOrd, "zero")))); - assertEquals(Set.arraySet(validationOrd(intOrd, stringOrd), success("zero"), success("one")), sequenceSet(intOrd, stringOrd, Validation.success(Set.arraySet(stringOrd, "zero", "one")))); + assertEquals(Set.arraySet(validationOrd(intOrd, stringOrd), success("zero"), success("one")), sequenceSet(intOrd, stringOrd, success(Set.arraySet(stringOrd, "zero", "one")))); } @Test @@ -141,12 +360,12 @@ public void testTraverseIO() throws IOException { @Test public void testTraverseList() { - assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.nil()))); - assertEquals(List.nil(), success("zero").traverseList(constant(List.nil()))); - assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.single(0)))); - assertEquals(List.single(success(0)), success("zero").traverseList(constant(List.single(0)))); - assertEquals(List.single(fail("zero")), fail("zero").traverseList(constant(List.arrayList(0, 1)))); - assertEquals(List.arrayList(success(0), success(1)), success("zero").traverseList(constant(List.arrayList(0, 1)))); + assertEquals(single(fail("zero")), fail("zero").traverseList(constant(nil()))); + assertEquals(nil(), success("zero").traverseList(constant(nil()))); + assertEquals(single(fail("zero")), fail("zero").traverseList(constant(single(0)))); + assertEquals(single(success(0)), success("zero").traverseList(constant(single(0)))); + assertEquals(single(fail("zero")), fail("zero").traverseList(constant(arrayList(0, 1)))); + assertEquals(arrayList(success(0), success(1)), success("zero").traverseList(constant(arrayList(0, 1)))); } @Test From 4377adb82a2013d1faee7eac4c0f25821936ed43 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Fri, 24 Jul 2020 16:37:05 -0400 Subject: [PATCH 273/336] Fixes #407. Add fj.data.Seq.bind(F> f). --- core/src/main/java/fj/data/Seq.java | 25 ++++++++++++++++--------- core/src/test/java/fj/data/SeqTest.java | 17 ++++++++++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index abd20162..1ded05eb 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -1,20 +1,15 @@ package fj.data; import fj.*; +import fj.data.List.Buffer; +import fj.data.fingertrees.*; + +import java.util.*; import static fj.Bottom.error; import static fj.Monoid.intAdditionMonoid; import static fj.data.fingertrees.FingerTree.measured; -import fj.data.List.Buffer; -import fj.data.fingertrees.FingerTree; -import fj.data.fingertrees.MakeTree; -import fj.data.fingertrees.Measured; - -import java.util.AbstractList; -import java.util.Iterator; -import java.util.NoSuchElementException; - /** * Provides an immutable finite sequence, implemented as a finger tree. This structure gives O(1) access to * the head and tail, as well as O(log n) random access and concatenation of sequences. @@ -396,4 +391,16 @@ public Seq map(F f) { return new Seq<>(ftree.map(f, Seq.elemMeasured())); } + /** + * Bind the given function across this seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public Seq bind(final F> f) { + return foldRight( + (element, accumulator) -> f.f(element).append(accumulator), + empty()); + } } diff --git a/core/src/test/java/fj/data/SeqTest.java b/core/src/test/java/fj/data/SeqTest.java index a7c85175..b19cb7d4 100644 --- a/core/src/test/java/fj/data/SeqTest.java +++ b/core/src/test/java/fj/data/SeqTest.java @@ -3,11 +3,10 @@ import fj.P2; import org.junit.Test; +import static fj.Function.constant; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Created by MarkPerry on 16/01/2015. @@ -46,4 +45,16 @@ public void test() { assertThat(p2._2(), is(Seq.empty())); } + @Test + public void testBind() { + assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.empty()))); + assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.single(0)))); + assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.empty(), Seq.single("zero").bind(constant(Seq.empty()))); + assertEquals(Seq.single(0), Seq.single("zero").bind(constant(Seq.single(0)))); + assertEquals(Seq.arraySeq(0, 1), Seq.single("zero").bind(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.empty(), Seq.arraySeq("zero", "one").bind(constant(Seq.empty()))); + assertEquals(Seq.arraySeq(0, 0), Seq.arraySeq("zero", "one").bind(constant(Seq.single(0)))); + assertEquals(Seq.arraySeq(0, 1, 0, 1), Seq.arraySeq("zero", "one").bind(constant(Seq.arraySeq(0, 1)))); + } } From 671b9d25e8d5a1db25252a889de06467b0696468 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Fri, 24 Jul 2020 17:05:29 -0400 Subject: [PATCH 274/336] Fixes #408. Add fj.data.List.sequence* function, fj.data.List.traverse* functions. --- core/src/main/java/fj/data/List.java | 413 ++++++++++++++++++----- core/src/test/java/fj/data/ListTest.java | 218 +++++++++++- 2 files changed, 535 insertions(+), 96 deletions(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index e0e12877..422d246b 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -1,54 +1,30 @@ package fj.data; -import static fj.Bottom.error; +import fj.*; +import fj.control.Trampoline; +import fj.control.parallel.*; +import fj.data.optic.Optional; +import fj.data.optic.*; +import fj.data.vector.V2; +import fj.function.Effect1; -import fj.Equal; -import fj.F2Functions; -import fj.Hash; -import fj.Monoid; -import fj.Ord; -import fj.Ordering; -import fj.P; -import fj.P1; -import fj.Semigroup; -import fj.Show; -import fj.Unit; -import fj.P2; -import fj.F0; -import fj.F; -import fj.F2; -import fj.Function; +import java.lang.Class; +import java.util.*; +import static fj.Bottom.error; import static fj.Function.*; -import static fj.P.p; -import static fj.P.p2; +import static fj.Ord.intOrd; +import static fj.Ordering.GT; +import static fj.P.*; import static fj.Unit.unit; import static fj.data.Array.mkArray; +import static fj.data.Either.*; import static fj.data.List.Buffer.*; -import static fj.data.Option.none; -import static fj.data.Option.some; +import static fj.data.Option.*; import static fj.data.optic.Optional.optional; import static fj.data.optic.Prism.prism; import static fj.data.vector.V.v; import static fj.function.Booleans.not; -import static fj.Ordering.GT; -import static fj.Ord.intOrd; - - -import fj.control.Trampoline; -import fj.control.parallel.Promise; -import fj.control.parallel.Strategy; -import fj.data.optic.Optional; -import fj.data.optic.PTraversal; -import fj.data.optic.Prism; -import fj.data.optic.Traversal; -import fj.data.vector.V2; -import fj.function.Effect1; - -import java.util.AbstractCollection; -import java.util.Collection; -import java.util.Iterator; -import java.util.NoSuchElementException; /** * Provides an in-memory, immutable, singly linked list. @@ -604,61 +580,315 @@ public final List sequence(final List bs) { return bind(c); } - /** - * Traverses through the List with the given function - * - * @param f The function that produces Option value - * @return none if applying f returns none to any element of the list or f mapped list in some . - */ - public final Option> traverseOption(final F> f) { - return foldRight( - (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))), - some(List.nil()) - ); - } + /** + * Sequence the given list and collect the output on the right side of an either. + * + * @param list the given list + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either> sequenceEither(final List> list) { + return list.traverseEither(identity()); + } - /** - * Traverse through the List with given function. - * - * @param f The function that produces Either value. - * @return error in left or f mapped list in right. - */ - public final Either> traverseEither(final F> f) { - return foldRight( - (a, acc) -> f.f(a).right().bind(e -> acc.right().map(es -> es.cons(e))), - Either.right(List.nil()) - ); - } + /** + * Sequence the given list and collect the output on the left side of an either. + * + * @param list the given list + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either, R> sequenceEitherLeft(final List> list) { + return list.traverseEitherLeft(identity()); + } - public final Stream> traverseStream(final F> f) { - return foldRight( - (a, acc) -> f.f(a).bind(s -> acc.map(ss -> ss.cons(s))), - Stream.nil() - ); - } + /** + * Sequence the given list and collect the output on the right side of an either. + * + * @param list the given list + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static final Either> sequenceEitherRight(final List> list) { + return list.traverseEitherRight(identity()); + } - public final P1> traverseP1(final F> f){ - return foldRight( - (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - p(List.nil()) - ); - } + /** + * Sequence the given list and collect the output as a function. + * + * @param list the given list + * @param the type of the input value + * @param the type of the output value + * @return the either + */ + public static final F> sequenceF(final List> list) { + return list.traverseF(identity()); + } - public final IO> traverseIO(F> f) { - return this.foldRight( - (a, acc) -> IOFunctions.bind(f.f(a), b -> IOFunctions.map(acc, bs -> bs.cons(b))), - IOFunctions.unit(List.nil()) - ); - } + /** + * Sequence the given list and collect the output as an IO. + * + * @param list the given list + * @param the type of the IO value + * @return the IO + */ + public static final IO> sequenceIO(final List> list) { + return list.traverseIO(identity()); + } + + /** + * Sequence the given list and collect the output as an list. + * + * @param list the given list + * @param the type of the list value + * @return the list + */ + public static final List> sequenceList(final List> list) { + return list.traverseList(identity()); + } + + /** + * Sequence the given list and collect the output as an list. + * + * @param list the given list + * @param the type of the list value + * @return the list + */ + public static final Option> sequenceOption(final List> list) { + return list.traverseOption(identity()); + } + + /** + * Sequence the given list and collect the output as a P1. + * + * @param list the given list + * @param the type of the P1 value + * @return the P1 + */ + public static final P1> sequenceP1(final List> list) { + return list.traverseP1(identity()); + } + + /** + * Sequence the given list and collect the output as a seq. + * + * @param list the given list + * @param the type of the seq value + * @return the seq + */ + public static final Seq> sequenceSeq(final List> list) { + return list.traverseSeq(identity()); + } + + /** + * Sequence the given list and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param list the given list + * @param the type of the set value + * @return the either + */ + public static final Set> sequenceSet(final Ord ord, final List> list) { + return list.traverseSet(ord, identity()); + } + + /** + * Sequence the given list and collect the output as a stream. + * + * @param list the given list + * @param the type of the stream value + * @return the stream + */ + public static final Stream> sequenceStream(final List> list) { + return list.traverseStream(identity()); + } + + /** + * Sequence the given list and collect the output as a trampoline. + * + * @param list the given trampoline + * @param the type of the stream value + * @return the stream + */ + public static final Trampoline> sequenceTrampoline(final List> list) { + return list.traverseTrampoline(identity()); + } + + /** + * Sequence the given list and collect the output as a validation; use the given semigroup to reduce the errors. + * + * @param semigroup the given semigroup + * @param list the given list + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static final Validation> sequenceValidation(final Semigroup semigroup, final List> list) { + return list.traverseValidation(semigroup, identity()); + } + + /** + * Traverse through the List with given function. + * + * @param f The function that produces Either value. + * @return error in left or f mapped list in right. + */ + public final Either> traverseEither(final F> f) { + return foldRight( + (a, acc) -> f.f(a).right().bind(e -> acc.right().map(es -> es.cons(e))), + Either.right(List.nil()) + ); + } + + /** + * Traverse this list with the given function and collect the output on the left side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public final Either, R> traverseEitherLeft(final F> f) { + return foldRight( + (element, either) -> f.f(element).left().bind(elementInner -> either.left().map(list -> list.cons(elementInner))), + left(nil())); + } + /** + * Traverse this list with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public final Either> traverseEitherRight(final F> f) { + return foldRight( + (element, either) -> f.f(element).right().bind(elementInner -> either.right().map(list -> list.cons(elementInner))), + right(nil())); + } + + /** + * Traverse this list with the given function and collect the output as a function. + * + * @param f the given function + * @param the type of the input value + * @param the type of the output value + * @return the function + */ public final F> traverseF(F> f) { return this.foldRight( (a, acc) -> Function.bind(acc, (bs) -> Function.compose(bs::cons, f.f(a))), constant(List.nil()) - ); + ); + } + + /** + * Traverse this list with the given function and collect the output as an IO. + * + * @param f the given function + * @param the type of the IO value + * @return the IO + */ + public final IO> traverseIO(F> f) { + return this.foldRight( + (a, acc) -> IOFunctions.bind(f.f(a), b -> IOFunctions.map(acc, bs -> bs.cons(b))), + IOFunctions.unit(List.nil()) + ); + } + + /** + * Traverse this list with the given function and collect the output as a list. + * + * @param f the given function + * @param the type of the list value + * @return the list + */ + public final List> traverseList(final F> f) { + return foldRight( + (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), + single(List.nil())); } + /** + * Traverses through the List with the given function + * + * @param f The function that produces Option value + * @return none if applying f returns none to any element of the list or f mapped list in some . + */ + public final Option> traverseOption(final F> f) { + return foldRight( + (a, obs) -> f.f(a).bind(o -> obs.map(os -> os.cons(o))), + some(List.nil()) + ); + } + + /** + * Traverse this list with the given function and collect the output as a p1. + * + * @param f the given function + * @param the type of the p1 value + * @return the p1 + */ + public final P1> traverseP1(final F> f) { + return foldRight( + (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), + p(List.nil()) + ); + } + + /** + * Traverse this list with the given function and collect the output as a seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public final Seq> traverseSeq(final F> f) { + return foldRight( + (element, seq) -> f.f(element).bind(elementInner -> seq.map(list -> list.cons(elementInner))), + Seq.single(nil())); + } + + /** + * Traverse this list with the given function and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param f the given function + * @param the type of the set value + * @return the set + */ + public final Set> traverseSet(final Ord ord, final F> f) { + final Ord> listOption = Ord.listOrd(ord); + return foldRight( + (element, set) -> f.f(element).bind(listOption, elementInner -> set.map(listOption, list -> list.cons(elementInner))), + Set.single(listOption, nil())); + } + + /** + * Traverse this list with the given function and collect the output as a stream. + * + * @param f the given function + * @param the type of the stream value + * @return the stream + */ + public final Stream> traverseStream(final F> f) { + return foldRight( + (a, acc) -> f.f(a).bind(s -> acc.map(ss -> ss.cons(s))), + Stream.single(nil())); + } + + /** + * Traverse this list with the given function and collect the output as a trampoline. + * + * @param f the given function + * @param the type of the trampoline value + * @return the trampoline + */ public final Trampoline> traverseTrampoline(final F> f) { return foldRight( (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), @@ -671,12 +901,15 @@ public final Promise> traversePromise(final F> f) { Promise.promise(Strategy.idStrategy(), p(List.nil()))); } - public final List> traverseList(final F> f) { - return foldRight( - (a, acc) -> f.f(a).bind(b -> acc.map(bs -> bs.cons(b))), - single(List.nil())); - } - + /** + * Traverse this list with the given function and collect the output as a validation; use the given semigroup to reduce the errors. + * + * @param s the given semigroup + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ public final Validation> traverseValidation(Semigroup s, final F> f) { return Validation.sequence(s, map(f)); } @@ -1474,7 +1707,7 @@ public final A maximum(final Ord o) { public final Option maximumOption(final Ord o) { return NonEmptyList.fromList(this).map(nel -> nel.maximum(o)); } - + /** * Returns the minimum element in this list according to the given ordering. * @@ -1484,7 +1717,7 @@ public final Option maximumOption(final Ord o) { public final A minimum(final Ord o) { return foldLeft1(o::min); } - + /** * Returns the minimum element in this list according to the given ordering. * diff --git a/core/src/test/java/fj/data/ListTest.java b/core/src/test/java/fj/data/ListTest.java index 3b720fe6..ca7d0f22 100644 --- a/core/src/test/java/fj/data/ListTest.java +++ b/core/src/test/java/fj/data/ListTest.java @@ -1,16 +1,36 @@ package fj.data; -import fj.Equal; -import fj.P2; +import fj.*; +import fj.control.Trampoline; import org.junit.Test; +import java.io.IOException; import java.util.Arrays; +import static fj.Function.constant; +import static fj.Ord.*; +import static fj.P.*; +import static fj.Semigroup.listSemigroup; +import static fj.data.Either.*; +import static fj.data.List.sequenceEither; +import static fj.data.List.sequenceEitherLeft; +import static fj.data.List.sequenceEitherRight; +import static fj.data.List.sequenceF; +import static fj.data.List.sequenceIO; +import static fj.data.List.sequenceList; +import static fj.data.List.sequenceOption; +import static fj.data.List.sequenceP1; +import static fj.data.List.sequenceSeq; +import static fj.data.List.sequenceSet; +import static fj.data.List.sequenceStream; +import static fj.data.List.sequenceTrampoline; +import static fj.data.List.sequenceValidation; +import static fj.data.List.*; +import static fj.data.Option.*; +import static fj.data.Validation.fail; +import static fj.data.Validation.*; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * Created by MarkPerry on 16/01/2015. @@ -91,4 +111,190 @@ public void array() { assertThat(List.range(1, max + 1).array(Integer[].class), equalTo(ints)); } + @Test + public void testSequenceEither() { + assertEquals(right(nil()), sequenceEither(nil())); + assertEquals(right(single("zero")), sequenceEither(single(right("zero")))); + assertEquals(left("zero"), sequenceEither(single(left("zero")))); + } + + @Test + public void testSequenceEitherLeft() { + assertEquals(left(nil()), sequenceEitherLeft(nil())); + assertEquals(left(single("zero")), sequenceEitherLeft(single(left("zero")))); + assertEquals(right("zero"), sequenceEitherLeft(single(right("zero")))); + } + + @Test + public void testSequenceEitherRight() { + assertEquals(right(nil()), sequenceEitherRight(nil())); + assertEquals(right(single("zero")), sequenceEitherRight(single(right("zero")))); + assertEquals(left("zero"), sequenceEitherRight(single(left("zero")))); + } + + @Test + public void testSequenceF() { + assertEquals(constant(nil()).f(1), sequenceF(nil()).f(1)); + assertEquals(constant(single("zero")).f(1), sequenceF(single(constant("zero"))).f(1)); + } + + @Test + public void testSequenceIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(nil())).run(), sequenceIO(nil()).run()); + assertEquals(IOFunctions.lazy(constant(single("zero"))).run(), sequenceIO(single(IOFunctions.lazy(constant("zero")))).run()); + } + + @Test + public void testSequenceList() { + assertEquals(single(nil()), sequenceList(nil())); + assertEquals(List.nil(), sequenceList(single(nil()))); + assertEquals(single(single("zero")), sequenceList(single(single("zero")))); + assertEquals(List.arrayList(single("zero"), single("one")), sequenceList(single(arrayList("zero", "one")))); + } + + @Test + public void testSequenceOption() { + assertEquals(some(nil()), sequenceOption(nil())); + assertEquals(none(), sequenceOption(single(none()))); + assertEquals(some(single("zero")), sequenceOption(single(some("zero")))); + } + + @Test + public void testSequenceP1() { + assertEquals(p(nil()), sequenceP1(nil())); + assertEquals(p(single("zero")), sequenceP1(single(p("zero")))); + } + + @Test + public void testSequenceSeq() { + assertEquals(Seq.single(nil()), sequenceSeq(nil())); + assertEquals(Seq.empty(), sequenceSeq(single(Seq.empty()))); + assertEquals(Seq.single(single("zero")), sequenceSeq(single(Seq.single("zero")))); + assertEquals(Seq.arraySeq(single("zero"), single("one")), sequenceSeq(single(Seq.arraySeq("zero", "one")))); + } + + @Test + public void testSequenceSet() { + assertEquals(Set.arraySet(listOrd(stringOrd), nil()), sequenceSet(stringOrd, nil())); + assertEquals(Set.empty(listOrd(stringOrd)), sequenceSet(stringOrd, single(Set.empty(stringOrd)))); + assertEquals(Set.arraySet(listOrd(stringOrd), single("zero")), sequenceSet(stringOrd, single(Set.single(stringOrd, "zero")))); + assertEquals(Set.arraySet(listOrd(stringOrd), single("zero"), single("one")), sequenceSet(stringOrd, single(Set.arraySet(stringOrd, "zero", "one")))); + } + + @Test + public void testSequenceStream() { + assertEquals(Stream.single(nil()), sequenceStream(nil())); + assertEquals(Stream.nil(), sequenceStream(single(Stream.nil()))); + assertEquals(Stream.single(single("zero")), sequenceStream(single(Stream.single("zero")))); + assertEquals(Stream.arrayStream(single("zero"), single("one")), sequenceStream(single(Stream.arrayStream("zero", "one")))); + } + + @Test + public void testSequenceTrampoline() { + assertEquals(Trampoline.pure(nil()).run(), sequenceTrampoline(nil()).run()); + assertEquals(Trampoline.pure(single(0)).run(), sequenceTrampoline(single(Trampoline.pure(0))).run()); + } + + @Test + public void testSequenceValidation() { + assertEquals(Validation.success(nil()), sequenceValidation(listSemigroup(), nil())); + assertEquals(Validation.fail(single(0)), sequenceValidation(listSemigroup(), single(Validation.fail(single(0))))); + assertEquals(Validation.success(single(0)), sequenceValidation(listSemigroup(), single(Validation.success(0)))); + } + + @Test + public void testTraverseEitherLeft() { + assertEquals(left(nil()), nil().traverseEitherLeft(constant(left(0)))); + assertEquals(left(single(0)), single("zero").traverseEitherLeft(constant(left(0)))); + assertEquals(left(nil()), nil().traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), single("zero").traverseEitherLeft(constant(right(0)))); + } + + @Test + public void testTraverseEitherRight() { + assertEquals(right(nil()), nil().traverseEitherRight(constant(right(0)))); + assertEquals(right(single(0)), single("zero").traverseEitherRight(constant(right(0)))); + assertEquals(right(nil()), nil().traverseEitherRight(constant(left(0)))); + assertEquals(left(0), single("zero").traverseEitherRight(constant(left(0)))); + } + + @Test + public void testTraverseF() { + assertEquals(constant(nil()).f(1), nil().traverseF(constant(constant(0))).f(1)); + assertEquals(constant(single(0)).f(1), single("zero").traverseF(constant(constant(0))).f(1)); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(nil())).run(), nil().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(single(0))).run(), single("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseList() { + assertEquals(single(nil()), nil().traverseList(constant(List.nil()))); + assertEquals(List.nil(), single("zero").traverseList(constant(List.nil()))); + assertEquals(single(nil()), nil().traverseList(constant(single(0)))); + assertEquals(single(single(0)), single("zero").traverseList(constant(single(0)))); + assertEquals(single(nil()), nil().traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.arrayList(single(0), single(1)), single("zero").traverseList(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseOption() { + assertEquals(some(nil()), nil().traverseOption(constant(none()))); + assertEquals(none(), single("zero").traverseOption(constant(none()))); + assertEquals(some(nil()), nil().traverseOption(constant(some(0)))); + assertEquals(some(single(0)), single("zero").traverseOption(constant(some(0)))); + } + + @Test + public void testTraverseP1() { + assertEquals(p(nil()), nil().traverseP1(constant(p(0)))); + assertEquals(p(single(0)), single("zero").traverseP1(constant(p(0)))); + } + + @Test + public void testTraverseSeq() { + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.empty(), single("zero").traverseSeq(constant(Seq.empty()))); + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(single(0)), single("zero").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(Seq.arraySeq(0, 1)))); + assertEquals(Seq.arraySeq(single(0), single(1)), single("zero").traverseSeq(constant(Seq.arraySeq(0, 1)))); + } + + @Test + public void testTraverseSet() { + assertEquals(Set.arraySet(listOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(listOrd(intOrd)), single("zero").traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.single(listOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(listOrd(intOrd), single(0)), single("zero").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(listOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(listOrd(intOrd), single(0), single(1)), single("zero").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), single("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(single(0)), single("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(single(0), single(1)), single("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseTrampoline() { + assertEquals(Trampoline.pure(nil()).run(), nil().traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(single(0)).run(), single("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); + } + + @Test + public void testTraverseValidation() { + assertEquals(success(nil()), nil().traverseValidation(listSemigroup(), constant(Validation.fail(single(0))))); + assertEquals(fail(single(0)), single("zero").traverseValidation(listSemigroup(), constant(Validation.fail(single(0))))); + assertEquals(success(nil()), nil().traverseValidation(listSemigroup(), constant(Validation.success(0)))); + assertEquals(success(single(0)), single("zero").traverseValidation(listSemigroup(), constant(Validation.success(0)))); + } } From 24779066804769cd93a7e4cc4236b44836e43074 Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Fri, 24 Jul 2020 23:39:07 -0400 Subject: [PATCH 275/336] Fixes #412. Add fj.data.Seq.sequence*, fj.data.Seq.traverse* functions. --- core/src/main/java/fj/Ord.java | 51 ++-- core/src/main/java/fj/data/Seq.java | 361 ++++++++++++++++++++++++ core/src/test/java/fj/data/SeqTest.java | 251 +++++++++++++++- 3 files changed, 638 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index 0a778f4d..eef729c4 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -1,23 +1,11 @@ package fj; -import fj.data.Array; -import fj.data.Either; -import fj.data.List; -import fj.data.Natural; -import fj.data.NonEmptyList; -import fj.data.Option; -import fj.data.Set; -import fj.data.Stream; -import fj.data.Validation; - -import java.math.BigDecimal; -import java.math.BigInteger; +import fj.data.*; + +import java.math.*; import java.util.Comparator; -import static fj.Function.apply; -import static fj.Function.compose; -import static fj.Function.curry; -import static fj.Semigroup.semigroup; +import static fj.Function.*; import static fj.Semigroup.semigroupDef; /** @@ -541,6 +529,37 @@ public static Ord> listOrd(final Ord oa) { }); } + /** + * Return a seq ord using the given value ord. + * + * @param ord the given value ord + * @param the type of the seq value + * @return the seq ord + */ + public static Ord> seqOrd(final Ord ord) { + return ordDef((l1, l2) -> { + Seq x1 = l1; + Seq x2 = l2; + + while (x1.isNotEmpty() && x2.isNotEmpty()) { + final Ordering o = ord.compare(x1.head(), x2.head()); + if (o == Ordering.LT || o == Ordering.GT) { + return o; + } + x1 = x1.tail(); + x2 = x2.tail(); + } + + if (x1.isEmpty() && x2.isEmpty()) { + return Ordering.EQ; + } else if (x1.isEmpty()) { + return Ordering.LT; + } else { + return Ordering.GT; + } + }); + } + /** * An order instance for the {@link NonEmptyList} type. * diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index 1ded05eb..3bcb7033 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -1,13 +1,19 @@ package fj.data; import fj.*; +import fj.control.Trampoline; import fj.data.List.Buffer; import fj.data.fingertrees.*; import java.util.*; import static fj.Bottom.error; +import static fj.Function.*; import static fj.Monoid.intAdditionMonoid; +import static fj.P.p; +import static fj.data.Either.*; +import static fj.data.Option.some; +import static fj.data.Validation.success; import static fj.data.fingertrees.FingerTree.measured; /** @@ -403,4 +409,359 @@ public Seq bind(final F> f) { (element, accumulator) -> f.f(element).append(accumulator), empty()); } + + /** + * Sequence the given seq and collect the output on the right side of an either. + * + * @param seq the given seq + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either> sequenceEither(final Seq> seq) { + return seq.traverseEither(identity()); + } + + /** + * Sequence the given seq and collect the output on the left side of an either. + * + * @param seq the given seq + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either, R> sequenceEitherLeft(final Seq> seq) { + return seq.traverseEitherLeft(identity()); + } + + /** + * Sequence the given seq and collect the output on the right side of an either. + * + * @param seq the given seq + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either> sequenceEitherRight(final Seq> seq) { + return seq.traverseEitherRight(identity()); + } + + /** + * Sequence the given seq and collect the output as a function. + * + * @param seq the given seq + * @param the type of the input value + * @param the type of the output value + * @return the either + */ + public static F> sequenceF(final Seq> seq) { + return seq.traverseF(identity()); + } + + /** + * Sequence the given seq and collect the output as an IO. + * + * @param seq the given seq + * @param the type of the IO value + * @return the IO + */ + public static IO> sequenceIO(final Seq> seq) { + return seq.traverseIO(identity()); + } + + /** + * Sequence the given seq and collect the output as a list. + * + * @param seq the given seq + * @param the type of the seq value + * @return the list + */ + public static List> sequenceList(final Seq> seq) { + return seq.traverseList(identity()); + } + + /** + * Sequence the given seq and collect the output as an seq. + * + * @param seq the given seq + * @param the type of the seq value + * @return the seq + */ + public static Option> sequenceOption(final Seq> seq) { + return seq.traverseOption(identity()); + } + + /** + * Sequence the given seq and collect the output as a P1. + * + * @param seq the given seq + * @param the type of the P1 value + * @return the P1 + */ + public static P1> sequenceP1(final Seq> seq) { + return seq.traverseP1(identity()); + } + + /** + * Sequence the given seq and collect the output as a seq. + * + * @param seq the given seq + * @param the type of the seq value + * @return the seq + */ + public static Seq> sequenceSeq(final Seq> seq) { + return seq.traverseSeq(identity()); + } + + /** + * Sequence the given seq and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param seq the given seq + * @param the type of the set value + * @return the either + */ + public static Set> sequenceSet(final Ord ord, final Seq> seq) { + return seq.traverseSet(ord, identity()); + } + + /** + * Sequence the given seq and collect the output as a stream. + * + * @param seq the given seq + * @param the type of the stream value + * @return the stream + */ + public static Stream> sequenceStream(final Seq> seq) { + return seq.traverseStream(identity()); + } + + /** + * Sequence the given seq and collect the output as a trampoline. + * + * @param seq the given trampoline + * @param the type of the stream value + * @return the stream + */ + public static Trampoline> sequenceTrampoline(final Seq> seq) { + return seq.traverseTrampoline(identity()); + } + + /** + * Sequence the given seq and collect the output as a validation. + * + * @param seq the given seq + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static Validation> sequenceValidation(final Seq> seq) { + return seq.traverseValidation(identity()); + } + + /** + * Sequence the given seq and collect the output as a validation; use the given semigroup to reduce the errors. + * + * @param semigroup the given semigroup + * @param seq the given seq + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static Validation> sequenceValidation(final Semigroup semigroup, final Seq> seq) { + return seq.traverseValidation(semigroup, identity()); + } + + /** + * Traverse this seq with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either> traverseEither(final F> f) { + return traverseEitherRight(f); + } + + /** + * Traverse this seq with the given function and collect the output on the left side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either, R> traverseEitherLeft(final F> f) { + return foldRight( + (element, either) -> f.f(element).left().bind(elementInner -> either.left().map(seq -> seq.cons(elementInner))), + left(empty())); + } + + /** + * Traverse this seq with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either> traverseEitherRight(final F> f) { + return foldRight( + (element, either) -> f.f(element).right().bind(elementInner -> either.right().map(seq -> seq.cons(elementInner))), + right(empty())); + } + + /** + * Traverse this seq with the given function and collect the output as a function. + * + * @param f the given function + * @param the type of the input value + * @param the type of the output value + * @return the function + */ + public F> traverseF(final F> f) { + return foldRight( + (element, fInner) -> Function.bind(f.f(element), elementInner -> andThen(fInner, seq -> seq.cons(elementInner))), + constant(empty())); + } + + /** + * Traverse this seq with the given function and collect the output as an IO. + * + * @param f the given function + * @param the type of the IO value + * @return the IO + */ + public IO> traverseIO(final F> f) { + return foldRight( + (element, io) -> IOFunctions.bind(f.f(element), elementInner -> IOFunctions.map(io, seq -> seq.cons(elementInner))), + IOFunctions.unit(empty()) + ); + } + + /** + * Traverse this seq with the given function and collect the output as a list. + * + * @param f the given function + * @param the type of the list value + * @return the list + */ + public List> traverseList(final F> f) { + return foldRight( + (element, list) -> f.f(element).bind(elementInner -> list.map(seq -> seq.cons(elementInner))), + List.single(empty())); + } + + /** + * Traverses through the Seq with the given function + * + * @param f The function that produces Option value + * @return none if applying f returns none to any element of the seq or f mapped seq in some . + */ + public Option> traverseOption(final F> f) { + return foldRight( + (element, option) -> f.f(element).bind(elementInner -> option.map(seq -> seq.cons(elementInner))), + some(empty()) + ); + } + + /** + * Traverse this seq with the given function and collect the output as a p1. + * + * @param f the given function + * @param the type of the p1 value + * @return the p1 + */ + public P1> traverseP1(final F> f) { + return foldRight( + (element, p1) -> f.f(element).bind(elementInner -> p1.map(seq -> seq.cons(elementInner))), + p(empty()) + ); + } + + /** + * Traverse this seq with the given function and collect the output as a seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public Seq> traverseSeq(final F> f) { + return foldRight( + (element, seq) -> f.f(element).bind(elementInner -> seq.map(seqInner -> seqInner.cons(elementInner))), + single(empty())); + } + + /** + * Traverse this seq with the given function and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param f the given function + * @param the type of the set value + * @return the set + */ + public Set> traverseSet(final Ord ord, final F> f) { + final Ord> seqOrd = Ord.seqOrd(ord); + return foldRight( + (element, set) -> f.f(element).bind(seqOrd, elementInner -> set.map(seqOrd, seq -> seq.cons(elementInner))), + Set.single(seqOrd, empty())); + } + + /** + * Traverse this seq with the given function and collect the output as a stream. + * + * @param f the given function + * @param the type of the stream value + * @return the stream + */ + public Stream> traverseStream(final F> f) { + return foldRight( + (element, stream) -> f.f(element).bind(elementInner -> stream.map(seq -> seq.cons(elementInner))), + Stream.single(empty())); + } + + /** + * Traverse this seq with the given function and collect the output as a trampoline. + * + * @param f the given function + * @param the type of the trampoline value + * @return the trampoline + */ + public Trampoline> traverseTrampoline(final F> f) { + return foldRight( + (element, trampoline) -> f.f(element).bind(elementInner -> trampoline.map(seq -> seq.cons(elementInner))), + Trampoline.pure(empty())); + } + + /** + * Traverse this seq with the given function and collect the output as a validation. + * + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public Validation> traverseValidation(final F> f) { + return foldRight( + (element, validation) -> f.f(element).bind(elementInner -> validation.map(seq -> seq.cons(elementInner))), + success(empty()) + ); + } + + /** + * Traverse this seq with the given function and collect the output as a validation; use the given semigroup to reduce the errors. + * + * @param semigroup the given semigroup + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public Validation> traverseValidation(final Semigroup semigroup, final F> f) { + return foldRight( + (element, validation) -> f.f(element).map(Seq::single).accumulate(semigroup, validation, Seq::append), + success(empty()) + ); + } } diff --git a/core/src/test/java/fj/data/SeqTest.java b/core/src/test/java/fj/data/SeqTest.java index b19cb7d4..0b62db00 100644 --- a/core/src/test/java/fj/data/SeqTest.java +++ b/core/src/test/java/fj/data/SeqTest.java @@ -1,9 +1,34 @@ package fj.data; import fj.P2; +import fj.control.Trampoline; import org.junit.Test; +import java.io.IOException; + import static fj.Function.constant; +import static fj.Ord.*; +import static fj.P.p; +import static fj.Semigroup.listSemigroup; +import static fj.data.Either.*; +import static fj.data.List.arrayList; +import static fj.data.Option.*; +import static fj.data.Seq.sequenceEither; +import static fj.data.Seq.sequenceEitherLeft; +import static fj.data.Seq.sequenceEitherRight; +import static fj.data.Seq.sequenceF; +import static fj.data.Seq.sequenceIO; +import static fj.data.Seq.sequenceList; +import static fj.data.Seq.sequenceOption; +import static fj.data.Seq.sequenceP1; +import static fj.data.Seq.sequenceSeq; +import static fj.data.Seq.sequenceSet; +import static fj.data.Seq.sequenceStream; +import static fj.data.Seq.sequenceTrampoline; +import static fj.data.Seq.sequenceValidation; +import static fj.data.Seq.*; +import static fj.data.Validation.fail; +import static fj.data.Validation.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; @@ -47,14 +72,222 @@ public void test() { @Test public void testBind() { - assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.empty()))); - assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.single(0)))); - assertEquals(Seq.empty(), Seq.empty().bind(constant(Seq.arraySeq(0, 1)))); - assertEquals(Seq.empty(), Seq.single("zero").bind(constant(Seq.empty()))); - assertEquals(Seq.single(0), Seq.single("zero").bind(constant(Seq.single(0)))); - assertEquals(Seq.arraySeq(0, 1), Seq.single("zero").bind(constant(Seq.arraySeq(0, 1)))); - assertEquals(Seq.empty(), Seq.arraySeq("zero", "one").bind(constant(Seq.empty()))); - assertEquals(Seq.arraySeq(0, 0), Seq.arraySeq("zero", "one").bind(constant(Seq.single(0)))); - assertEquals(Seq.arraySeq(0, 1, 0, 1), Seq.arraySeq("zero", "one").bind(constant(Seq.arraySeq(0, 1)))); + assertEquals(empty(), empty().bind(constant(empty()))); + assertEquals(empty(), empty().bind(constant(single(0)))); + assertEquals(empty(), empty().bind(constant(arraySeq(0, 1)))); + assertEquals(empty(), single("zero").bind(constant(empty()))); + assertEquals(single(0), single("zero").bind(constant(single(0)))); + assertEquals(arraySeq(0, 1), single("zero").bind(constant(arraySeq(0, 1)))); + assertEquals(empty(), arraySeq("zero", "one").bind(constant(empty()))); + assertEquals(arraySeq(0, 0), arraySeq("zero", "one").bind(constant(single(0)))); + assertEquals(arraySeq(0, 1, 0, 1), arraySeq("zero", "one").bind(constant(arraySeq(0, 1)))); + } + + @Test + public void testSequenceEither() { + assertEquals(right(empty()), sequenceEither(empty())); + assertEquals(right(single("zero")), sequenceEither(single(right("zero")))); + assertEquals(left("zero"), sequenceEither(single(left("zero")))); + } + + @Test + public void testSequenceEitherLeft() { + assertEquals(left(empty()), sequenceEitherLeft(empty())); + assertEquals(left(single("zero")), sequenceEitherLeft(single(left("zero")))); + assertEquals(right("zero"), sequenceEitherLeft(single(right("zero")))); + } + + @Test + public void testSequenceEitherRight() { + assertEquals(right(empty()), sequenceEitherRight(empty())); + assertEquals(right(single("zero")), sequenceEitherRight(single(right("zero")))); + assertEquals(left("zero"), sequenceEitherRight(single(left("zero")))); + } + + @Test + public void testSequenceF() { + assertEquals(constant(empty()).f(1), sequenceF(empty()).f(1)); + assertEquals(constant(single("zero")).f(1), sequenceF(single(constant("zero"))).f(1)); + } + + @Test + public void testSequenceIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(empty())).run(), sequenceIO(empty()).run()); + assertEquals(IOFunctions.lazy(constant(single("zero"))).run(), sequenceIO(single(IOFunctions.lazy(constant("zero")))).run()); + } + + @Test + public void testSequenceList() { + assertEquals(List.single(empty()), sequenceList(empty())); + assertEquals(List.nil(), sequenceList(single(List.nil()))); + assertEquals(List.single(single("zero")), sequenceList(single(List.single("zero")))); + assertEquals(arrayList(single("zero"), single("one")), sequenceList(single(arrayList("zero", "one")))); + } + + @Test + public void testSequenceOption() { + assertEquals(some(empty()), sequenceOption(empty())); + assertEquals(none(), sequenceOption(single(none()))); + assertEquals(some(single("zero")), sequenceOption(single(some("zero")))); + } + + @Test + public void testSequenceP1() { + assertEquals(p(empty()), sequenceP1(empty())); + assertEquals(p(single("zero")), sequenceP1(single(p("zero")))); + } + + @Test + public void testSequenceSeq() { + assertEquals(single(empty()), sequenceSeq(empty())); + assertEquals(empty(), sequenceSeq(single(empty()))); + assertEquals(single(single("zero")), sequenceSeq(single(single("zero")))); + assertEquals(arraySeq(single("zero"), single("one")), sequenceSeq(single(arraySeq("zero", "one")))); + } + + @Test + public void testSequenceSet() { + assertEquals(Set.arraySet(seqOrd(stringOrd), empty()), sequenceSet(stringOrd, empty())); + assertEquals(Set.empty(seqOrd(stringOrd)), sequenceSet(stringOrd, single(Set.empty(stringOrd)))); + assertEquals(Set.arraySet(seqOrd(stringOrd), single("zero")), sequenceSet(stringOrd, single(Set.single(stringOrd, "zero")))); + assertEquals(Set.arraySet(seqOrd(stringOrd), single("zero"), single("one")), sequenceSet(stringOrd, single(Set.arraySet(stringOrd, "zero", "one")))); + } + + @Test + public void testSequenceStream() { + assertEquals(Stream.single(empty()), sequenceStream(empty())); + assertEquals(Stream.nil(), sequenceStream(single(Stream.nil()))); + assertEquals(Stream.single(single("zero")), sequenceStream(single(Stream.single("zero")))); + assertEquals(Stream.arrayStream(single("zero"), single("one")), sequenceStream(single(Stream.arrayStream("zero", "one")))); + } + + @Test + public void testSequenceTrampoline() { + assertEquals(Trampoline.pure(empty()).run(), sequenceTrampoline(empty()).run()); + assertEquals(Trampoline.pure(single(0)).run(), sequenceTrampoline(single(Trampoline.pure(0))).run()); + } + + @Test + public void testSequenceValidation() { + assertEquals(success(empty()), sequenceValidation(empty())); + assertEquals(fail(single(0)), sequenceValidation(single(fail(single(0))))); + assertEquals(success(single(0)), sequenceValidation(single(success(0)))); + } + + @Test + public void testSequenceValidationSemigroup() { + assertEquals(success(empty()), sequenceValidation(listSemigroup(), empty())); + assertEquals(fail(List.single(0)), sequenceValidation(listSemigroup(), single(fail(List.single(0))))); + assertEquals(success(single(0)), sequenceValidation(listSemigroup(), single(success(0)))); + } + + @Test + public void testTraverseEitherLeft() { + assertEquals(left(empty()), empty().traverseEitherLeft(constant(left(0)))); + assertEquals(left(single(0)), single("zero").traverseEitherLeft(constant(left(0)))); + assertEquals(left(empty()), empty().traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), single("zero").traverseEitherLeft(constant(right(0)))); + } + + @Test + public void testTraverseEitherRight() { + assertEquals(right(empty()), empty().traverseEitherRight(constant(right(0)))); + assertEquals(right(single(0)), single("zero").traverseEitherRight(constant(right(0)))); + assertEquals(right(empty()), empty().traverseEitherRight(constant(left(0)))); + assertEquals(left(0), single("zero").traverseEitherRight(constant(left(0)))); + } + + @Test + public void testTraverseF() { + assertEquals(constant(empty()).f(1), empty().traverseF(constant(constant(0))).f(1)); + assertEquals(constant(single(0)).f(1), single("zero").traverseF(constant(constant(0))).f(1)); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(IOFunctions.lazy(constant(empty())).run(), empty().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(single(0))).run(), single("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseList() { + assertEquals(List.single(empty()), empty().traverseList(constant(List.nil()))); + assertEquals(List.nil(), single("zero").traverseList(constant(List.nil()))); + assertEquals(List.single(empty()), empty().traverseList(constant(List.single(0)))); + assertEquals(List.single(single(0)), single("zero").traverseList(constant(List.single(0)))); + assertEquals(List.single(empty()), empty().traverseList(constant(arrayList(0, 1)))); + assertEquals(arrayList(single(0), single(1)), single("zero").traverseList(constant(arrayList(0, 1)))); + } + + @Test + public void testTraverseOption() { + assertEquals(some(empty()), empty().traverseOption(constant(none()))); + assertEquals(none(), single("zero").traverseOption(constant(none()))); + assertEquals(some(empty()), empty().traverseOption(constant(some(0)))); + assertEquals(some(single(0)), single("zero").traverseOption(constant(some(0)))); + } + + @Test + public void testTraverseP1() { + assertEquals(p(empty()), empty().traverseP1(constant(p(0)))); + assertEquals(p(single(0)), single("zero").traverseP1(constant(p(0)))); + } + + @Test + public void testTraverseSeq() { + assertEquals(single(empty()), empty().traverseSeq(constant(empty()))); + assertEquals(empty(), single("zero").traverseSeq(constant(empty()))); + assertEquals(single(empty()), empty().traverseSeq(constant(single(0)))); + assertEquals(single(single(0)), single("zero").traverseSeq(constant(single(0)))); + assertEquals(single(empty()), empty().traverseSeq(constant(arraySeq(0, 1)))); + assertEquals(arraySeq(single(0), single(1)), single("zero").traverseSeq(constant(arraySeq(0, 1)))); + } + + @Test + public void testTraverseSet() { + assertEquals(Set.arraySet(seqOrd(intOrd), empty()), empty().traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(seqOrd(intOrd)), single("zero").traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.single(seqOrd(intOrd), empty()), empty().traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(seqOrd(intOrd), single(0)), single("zero").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(seqOrd(intOrd), empty()), empty().traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(seqOrd(intOrd), single(0), single(1)), single("zero").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.single(empty()), empty().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), single("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(empty()), empty().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(single(0)), single("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(empty()), empty().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(single(0), single(1)), single("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseTrampoline() { + assertEquals(Trampoline.pure(empty()).run(), empty().traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(single(0)).run(), single("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); + } + + @Test + public void testTraverseValidation() { + assertEquals(success(empty()), empty().traverseValidation(constant(fail(single(0))))); + assertEquals(fail(single(0)), single("zero").traverseValidation(constant(fail(single(0))))); + assertEquals(success(empty()), empty().traverseValidation(constant(success(0)))); + assertEquals(success(single(0)), single("zero").traverseValidation(constant(success(0)))); + + assertEquals(success(arraySeq(0, 2, 4, 6, 8)), arraySeq(0, 2, 4, 6, 8).traverseValidation(i -> condition(i% 2 == 0, List.single(i), i))); + assertEquals(fail(List.single(1)), arraySeq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).traverseValidation(i -> condition(i% 2 == 0, List.single(i), i))); + } + + @Test + public void testTraverseValidationSemigroup() { + assertEquals(success(empty()), empty().traverseValidation(listSemigroup(), constant(fail(List.single(0))))); + assertEquals(fail(List.single(0)), single("zero").traverseValidation(listSemigroup(), constant(fail(List.single(0))))); + assertEquals(success(empty()), empty().traverseValidation(listSemigroup(), constant(success(0)))); + assertEquals(success(single(0)), single("zero").traverseValidation(listSemigroup(), constant(success(0)))); + + assertEquals(success(arraySeq(0, 2, 4, 6, 8)), arraySeq(0, 2, 4, 6, 8).traverseValidation(listSemigroup(),i -> condition(i% 2 == 0, List.single(i), i))); + assertEquals(fail(arrayList(1, 3, 5, 7, 9)), arraySeq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).traverseValidation(listSemigroup(),i -> condition(i% 2 == 0, List.single(i), i))); } } From 3bce5e0b885b87d94396d7f1cd6fb889958c0e8c Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Wed, 29 Jul 2020 14:17:37 -0400 Subject: [PATCH 276/336] Fixes #414. Add fj.data.Either.leftMap, rightMap. Also adds LeftProjection.traverseP1, RightProjection.valueE(String), RightProjection.orValue. --- core/src/main/java/fj/data/Either.java | 101 +++- core/src/test/java/fj/data/EitherTest.java | 653 +++++++++++++++++++++ 2 files changed, 739 insertions(+), 15 deletions(-) create mode 100644 core/src/test/java/fj/data/EitherTest.java diff --git a/core/src/main/java/fj/data/Either.java b/core/src/main/java/fj/data/Either.java index a9a746a9..c132ec49 100644 --- a/core/src/main/java/fj/data/Either.java +++ b/core/src/main/java/fj/data/Either.java @@ -1,27 +1,16 @@ package fj.data; -import fj.Equal; -import fj.F; -import fj.F0; -import fj.Function; -import fj.Hash; -import fj.P1; -import fj.Show; -import fj.Unit; +import fj.*; import fj.function.Effect1; -import java.util.Collection; -import java.util.Iterator; +import java.util.*; import static fj.Bottom.error; -import static fj.Function.compose; -import static fj.Function.identity; +import static fj.Function.*; import static fj.P.p; import static fj.Unit.unit; import static fj.data.Array.mkArray; -import static fj.data.List.cons_; -import static fj.data.List.list; -import static fj.data.List.single; +import static fj.data.List.*; import static fj.data.Option.some; /** @@ -321,6 +310,19 @@ public IO> traverseIO(final F> f) { IOFunctions.unit(Either.right(e.right().value())); } + /** + * Traverse this left with the given function and collect the output as a p1. + * + * @param f the given function + * @param the type of the p1 value + * @return the p1 + */ + public P1> traverseP1(final F> f) { + return e.isLeft() ? + f.f(value()).map(left_()) : + p(right(e.right().value())); + } + /** * Returns None if this projection has no value or if the given predicate * p does not hold for the value, otherwise, returns a right in Some. @@ -464,6 +466,16 @@ public Either either() { return e; } + /** + * Returns the value of this projection or fails with the given error message. + * + * @param err The error message to fail with. + * @return The value of this projection + */ + public B valueE(final String err) { + return valueE(p(err)); + } + /** * Returns the value of this projection or fails with the given error message. * @@ -487,6 +499,16 @@ public B value() { return valueE(p("right.value on Left")); } + /** + * The value of this projection or the given argument. + * + * @param a The value to return if this projection has no value. + * @return The value of this projection or the given argument. + */ + public B orValue(final B a) { + return e.isRight() ? value() : a; + } + /** * The value of this projection or the given argument. * @@ -586,12 +608,26 @@ public IO> traverseIO(final F> f) { IOFunctions.lazy(() -> left(e.left().value())); } + /** + * Traverse this right with the given function and collect the output as a p1. + * + * @param f the given function + * @param the type of the p1 value + * @return the p1 + */ public P1> traverseP1(final F> f) { return e.isRight() ? f.f(value()).map(right_()) : p(left(e.left().value())); } + /** + * Traverse this right with the given function and collect the output as an option. + * + * @param f the given function + * @param the type of the option value + * @return the option + */ public Option> traverseOption(final F> f) { return e.isRight() ? f.f(value()).map(right_()) : @@ -758,6 +794,22 @@ public static F, X> either_(final F left, final F the type of the function output + * @return the either + */ + public final Either leftMap(final F f) { + return left().map(f); + } + + /** + * Return a function that maps a given function across this either's left projection. + * + * @param the type of the right value + * @param the type of the left value + * @param the type of the function output * @return A function that maps another function across an either's left projection. */ public static F, F, Either>> leftMap_() { @@ -765,6 +817,22 @@ public static F, F, Either>> leftMap_() { } /** + * Map the given function across this either's right. + * + * @param f the given function + * @param the type of the function output + * @return the either + */ + public final Either rightMap(final F f) { + return right().map(f); + } + + /** + * Return a function that maps a given function across this either's right projection. + * + * @param the type of the right value + * @param the type of the left value + * @param the type of the function output * @return A function that maps another function across an either's right projection. */ public static F, F, Either>> rightMap_() { @@ -796,6 +864,7 @@ public static Either joinRight(final Either> e) { * * @param a The list of values to sequence with the either monad. * @return A sequenced value. + * @see fj.data.List#sequenceEitherLeft */ public static Either, X> sequenceLeft(final List> a) { return a.isEmpty() ? @@ -808,6 +877,8 @@ public static Either, X> sequenceLeft(final List> a) * * @param a The list of values to sequence with the either monad. * @return A sequenced value. + * @see fj.data.List#sequenceEither + * @see fj.data.List#sequenceEitherRight */ public static Either> sequenceRight(final List> a) { return a.isEmpty() ? diff --git a/core/src/test/java/fj/data/EitherTest.java b/core/src/test/java/fj/data/EitherTest.java new file mode 100644 index 00000000..31a83347 --- /dev/null +++ b/core/src/test/java/fj/data/EitherTest.java @@ -0,0 +1,653 @@ +package fj.data; + +import org.junit.Test; + +import java.io.IOException; + +import static fj.Function.constant; +import static fj.P.p; +import static fj.Unit.unit; +import static fj.data.Either.*; +import static org.junit.Assert.*; + +public final class EitherTest { + + public static final class LeftProjectionTest { + @Test + public void testIterator() { + assertEquals(0L, (long) left(0L).left().iterator().next()); + assertFalse(right(0).left().iterator().hasNext()); + } + + @Test + public void testEither() { + assertEquals(left(0), left(0).left().either()); + assertEquals(right(0), right(0).left().either()); + } + + @Test + public void testValueEString() { + assertEquals(0L, (long) left(0L).left().valueE("zero")); + + try { + right(0L).left().valueE("zero"); + fail(); + } catch (final Error error) { + assertEquals("zero", error.getMessage()); + } + } + + @Test + public void testValueEF0() { + assertEquals(0L, (long) left(0L).left().valueE(() -> "zero")); + + try { + right(0L).left().valueE(() -> "zero"); + fail(); + } catch (final Error error) { + assertEquals("zero", error.getMessage()); + } + } + + @Test + public void testValue() { + assertEquals(0L, (long) left(0L).left().value()); + + try { + right(0L).left().value(); + fail(); + } catch (final Error error) { + // pass + } + } + + @Test + public void testOrValue() { + assertEquals(0L, (long) left(0L).left().orValue(1L)); + assertEquals(1L, (long) right(0L).left().orValue(1L)); + } + + @Test + public void testOrValueF0() { + assertEquals(0L, (long) left(0L).left().orValue(() -> 1L)); + assertEquals(1L, (long) right(0L).left().orValue(() -> 1L)); + } + + @Test + public void testOn() { + assertEquals(0L, (long) Either.left(0L).left().on(constant(1L))); + assertEquals(1L, (long) Either.right(0L).left().on(constant(1L))); + } + + @Test + public void testForeach() { + left(0).left().foreach(constant(unit())); + right(0).left().foreach(ignore -> { + fail(); + return unit(); + }); + } + + @Test + public void testForeachDoEffect() { + left(0).left().foreachDoEffect(ignore -> { + }); + right(0).left().foreachDoEffect(ignore -> fail()); + } + + @Test + public void testMap() { + assertEquals(left(0), left("zero").left().map(constant(0))); + assertEquals(right("zero"), right("zero").left().map(constant(0))); + } + + @Test + public void testBind() { + assertEquals(left(0), left("zero").left().bind(constant(left(0)))); + assertEquals(right("zero"), right("zero").left().bind(constant(left(0)))); + } + + @Test + public void testSequence() { + assertEquals(left(0), left("zero").left().sequence(left(0))); + assertEquals(right(0), left("zero").left().sequence(right(0))); + assertEquals(right("zero"), right("zero").left().sequence(left(0))); + assertEquals(right("zero"), right("zero").left().sequence(right("one"))); + } + + @Test + public void testTraverseList() { + assertEquals(List.nil(), left("zero").left().traverseList(constant(List.nil()))); + assertEquals(List.single(left(0)), left("zero").left().traverseList(constant(List.single(0)))); + assertEquals(List.arrayList(left(0), left(1)), left("zero").left().traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.single(right("zero")), right("zero").left().traverseList(constant(List.nil()))); + assertEquals(List.single(right("zero")), right("zero").left().traverseList(constant(List.single(0)))); + assertEquals(List.single(right("zero")), right("zero").left().traverseList(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(left(0), left("zero").left().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(right("zero"), right("zero").left().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseP1() { + assertEquals(p(left(0)), left("zero").left().traverseP1(constant(p(0)))); + assertEquals(p(right("zero")), right("zero").left().traverseP1(constant(p(0)))); + } + + @Test + public void testFilter() { + assertEquals(Option.none(), left(0).left().filter(constant(false))); + assertEquals(Option.none(), right(0).left().filter(constant(false))); + assertEquals(Option.some(left(0)), left(0).left().filter(constant(true))); + assertEquals(Option.none(), right(0).left().filter(constant(true))); + } + + @Test + public void testApply() { + assertEquals(left(1), left("zero").left().apply(left(constant(1)))); + assertEquals(right("zero"), right("zero").left().apply(left(constant(1)))); + } + + @Test + public void testForAll() { + assertFalse(left(0).left().forall(constant(false))); + assertTrue(right(0).left().forall(constant(false))); + assertTrue(left(0).left().forall(constant(true))); + assertTrue(right(0).left().forall(constant(true))); + } + + @Test + public void testExists() { + assertFalse(left(0).left().exists(constant(false))); + assertFalse(right(0).left().exists(constant(false))); + assertTrue(left(0).left().exists(constant(true))); + assertFalse(right(0).left().exists(constant(true))); + } + + @Test + public void testToList() { + assertEquals(List.single(0), left(0).left().toList()); + assertEquals(List.nil(), right(0).left().toList()); + } + + @Test + public void testToOption() { + assertEquals(Option.some(0), left(0).left().toOption()); + assertEquals(Option.none(), right(0).left().toOption()); + } + + @Test + public void testToArray() { + assertEquals(Array.single(0), left(0).left().toArray()); + assertEquals(Array.empty(), right(0).left().toArray()); + } + + @Test + public void testToStream() { + assertEquals(Stream.single(0), left(0).left().toStream()); + assertEquals(Stream.nil(), right(0).left().toStream()); + } + + @Test + public void testToCollection() { + assertEquals(1L, left(0L).left().toCollection().size()); + assertEquals(0L, (long) left(0L).left().toCollection().iterator().next()); + assertTrue(right(0).left().toCollection().isEmpty()); + } + + @Test + public void testTraverseOption() { + assertEquals(Option.none(), left("zero").left().traverseOption(constant(Option.none()))); + assertEquals(Option.some(left(0)), left("zero").left().traverseOption(constant(Option.some(0)))); + assertEquals(Option.some(right("zero")), right("zero").left().traverseOption(constant(Option.none()))); + assertEquals(Option.some(right("zero")), right("zero").left().traverseOption(constant(Option.some(0)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.nil(), left("zero").left().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(left(0)), left("zero").left().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(left(0), left(1)), left("zero").left().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.single(right("zero")), right("zero").left().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(right("zero")), right("zero").left().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(right("zero")), right("zero").left().traverseStream(constant(Stream.arrayStream(0, 1)))); + } + } + + public static final class RightProjectionTest { + @Test + public void testIterator() { + assertEquals(0L, (long) right(0L).right().iterator().next()); + assertFalse(left(0).right().iterator().hasNext()); + } + + @Test + public void testEither() { + assertEquals(right(0), right(0).right().either()); + assertEquals(left(0), left(0).right().either()); + } + + @Test + public void testValueEString() { + assertEquals(0L, (long) right(0L).right().valueE("zero")); + + try { + left(0L).right().valueE("zero"); + fail(); + } catch (final Error error) { + assertEquals("zero", error.getMessage()); + } + } + + @Test + public void testValueEF0() { + assertEquals(0L, (long) right(0L).right().valueE(() -> "zero")); + + try { + left(0L).right().valueE(() -> "zero"); + fail(); + } catch (final Error error) { + assertEquals("zero", error.getMessage()); + } + } + + @Test + public void testValue() { + assertEquals(0L, (long) right(0L).right().value()); + + try { + left(0L).right().value(); + fail(); + } catch (final Error error) { + // pass + } + } + + @Test + public void testOrValue() { + assertEquals(0L, (long) right(0L).right().orValue(1L)); + assertEquals(1L, (long) left(0L).right().orValue(1L)); + } + + @Test + public void testOrValueF0() { + assertEquals(0L, (long) right(0L).right().orValue(() -> 1L)); + assertEquals(1L, (long) left(0L).right().orValue(() -> 1L)); + } + + @Test + public void testOn() { + assertEquals(0L, (long) Either.right(0L).right().on(constant(1L))); + assertEquals(1L, (long) Either.left(0L).right().on(constant(1L))); + } + + @Test + public void testForeach() { + right(0).right().foreach(constant(unit())); + left(0).right().foreach(ignore -> { + fail(); + return unit(); + }); + } + + @Test + public void testForeachDoEffect() { + right(0).right().foreachDoEffect(ignore -> { + }); + left(0).right().foreachDoEffect(ignore -> fail()); + } + + @Test + public void testMap() { + assertEquals(right(0), right("zero").right().map(constant(0))); + assertEquals(left("zero"), left("zero").right().map(constant(0))); + } + + @Test + public void testBind() { + assertEquals(right(0), right("zero").right().bind(constant(right(0)))); + assertEquals(left("zero"), left("zero").right().bind(constant(right(0)))); + } + + @Test + public void testSequence() { + assertEquals(right(0), right("zero").right().sequence(right(0))); + assertEquals(left(0), right("zero").right().sequence(left(0))); + assertEquals(left("zero"), left("zero").right().sequence(right(0))); + assertEquals(left("zero"), left("zero").right().sequence(left("one"))); + } + + @Test + public void testTraverseList() { + assertEquals(List.nil(), right("zero").right().traverseList(constant(List.nil()))); + assertEquals(List.single(right(0)), right("zero").right().traverseList(constant(List.single(0)))); + assertEquals(List.arrayList(right(0), right(1)), right("zero").right().traverseList(constant(List.arrayList(0, 1)))); + assertEquals(List.single(left("zero")), left("zero").right().traverseList(constant(List.nil()))); + assertEquals(List.single(left("zero")), left("zero").right().traverseList(constant(List.single(0)))); + assertEquals(List.single(left("zero")), left("zero").right().traverseList(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseIO() throws IOException { + assertEquals(right(0), right("zero").right().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(left("zero"), left("zero").right().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseP1() { + assertEquals(p(right(0)), right("zero").right().traverseP1(constant(p(0)))); + assertEquals(p(left("zero")), left("zero").right().traverseP1(constant(p(0)))); + } + + @Test + public void testFilter() { + assertEquals(Option.none(), right(0).right().filter(constant(false))); + assertEquals(Option.none(), left(0).right().filter(constant(false))); + assertEquals(Option.some(right(0)), right(0).right().filter(constant(true))); + assertEquals(Option.none(), left(0).right().filter(constant(true))); + } + + @Test + public void testApply() { + assertEquals(right(1), right("zero").right().apply(right(constant(1)))); + assertEquals(left("zero"), left("zero").right().apply(right(constant(1)))); + } + + @Test + public void testForAll() { + assertFalse(right(0).right().forall(constant(false))); + assertTrue(left(0).right().forall(constant(false))); + assertTrue(right(0).right().forall(constant(true))); + assertTrue(left(0).right().forall(constant(true))); + } + + @Test + public void testExists() { + assertFalse(right(0).right().exists(constant(false))); + assertFalse(left(0).right().exists(constant(false))); + assertTrue(right(0).right().exists(constant(true))); + assertFalse(left(0).right().exists(constant(true))); + } + + @Test + public void testToList() { + assertEquals(List.single(0), right(0).right().toList()); + assertEquals(List.nil(), left(0).right().toList()); + } + + @Test + public void testToOption() { + assertEquals(Option.some(0), right(0).right().toOption()); + assertEquals(Option.none(), left(0).right().toOption()); + } + + @Test + public void testToArray() { + assertEquals(Array.single(0), right(0).right().toArray()); + assertEquals(Array.empty(), left(0).right().toArray()); + } + + @Test + public void testToStream() { + assertEquals(Stream.single(0), right(0).right().toStream()); + assertEquals(Stream.nil(), left(0).right().toStream()); + } + + @Test + public void testToCollection() { + assertEquals(1L, right(0L).right().toCollection().size()); + assertEquals(0L, (long) right(0L).right().toCollection().iterator().next()); + assertTrue(left(0).right().toCollection().isEmpty()); + } + + @Test + public void testTraverseOption() { + assertEquals(Option.none(), right("zero").right().traverseOption(constant(Option.none()))); + assertEquals(Option.some(right(0)), right("zero").right().traverseOption(constant(Option.some(0)))); + assertEquals(Option.some(left("zero")), left("zero").right().traverseOption(constant(Option.none()))); + assertEquals(Option.some(left("zero")), left("zero").right().traverseOption(constant(Option.some(0)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.nil(), right("zero").right().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(right(0)), right("zero").right().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(right(0), right(1)), right("zero").right().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.single(left("zero")), left("zero").right().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(left("zero")), left("zero").right().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(left("zero")), left("zero").right().traverseStream(constant(Stream.arrayStream(0, 1)))); + } + } + + @Test + public void testIsLeft() { + assertTrue(left(0).isLeft()); + assertFalse(right(0).isLeft()); + } + + @Test + public void testIsRight() { + assertFalse(left(0).isRight()); + assertTrue(right(0).isRight()); + } + + @Test + public void testEither() { + assertEquals(-1L, (long) left("zero").either(constant(-1L), constant(1L))); + assertEquals(1L, (long) right("zero").either(constant(-1L), constant(1L))); + } + + @Test + public void testBimap() { + assertEquals(left(-1), left("zero").bimap(constant(-1), constant(1))); + assertEquals(right(1), right("zero").bimap(constant(-1), constant(1))); + } + + @Test + public void testTestEquals() { + assertNotEquals(null, left(0)); + assertNotEquals(new Object(), left(0)); + assertNotEquals(left(0), right(0)); + assertEquals(left(0), left(0)); + + assertNotEquals(null, right(0)); + assertNotEquals(new Object(), right(0)); + assertEquals(right(0), right(0)); + assertNotEquals(right(0), left(0)); + } + + @Test + public void testTestHashCode() { + assertEquals(left(0).hashCode(), left(0).hashCode()); + assertEquals(left(0).hashCode(), right(0).hashCode()); + assertEquals(right(0).hashCode(), left(0).hashCode()); + assertEquals(right(0).hashCode(), left(0).hashCode()); + } + + @Test + public void testSwap() { + assertEquals(right(0), left(0).swap()); + assertEquals(left(0), right(0).swap()); + } + + @Test + public void testLeft_() { + assertEquals(left(0), left_().f(0)); + } + + @Test + public void testRight_() { + assertEquals(right(0), right_().f(0)); + } + + @Test + public void testEither_() { + assertEquals(-1L, (long) either_(constant(-1L), constant(1L)).f(left("zero"))); + assertEquals(1L, (long) either_(constant(-1L), constant(1L)).f(right("zero"))); + } + + @Test + public void testLeftMap() { + assertEquals(left(0), left("zero").leftMap(constant(0))); + assertEquals(right("zero"), right("zero").leftMap(constant(0))); + } + + @Test + public void testLeftMap_() { + assertEquals(left(0), leftMap_().f(constant(0)).f(left("zero"))); + assertEquals(right("zero"), leftMap_().f(constant(0)).f(right("zero"))); + } + + @Test + public void testRightMap() { + assertEquals(left("zero"), left("zero").rightMap(constant(0))); + assertEquals(right(0), right("zero").rightMap(constant(0))); + } + + @Test + public void testRightMap_() { + assertEquals(left("zero"), rightMap_().f(constant(0)).f(left("zero"))); + assertEquals(right(0), rightMap_().f(constant(0)).f(right("zero"))); + } + + @Test + public void testJoinLeft() { + assertEquals(left(0), joinLeft(left(left(0)))); + assertEquals(right(0), joinLeft(left(right(0)))); + assertEquals(right(left(0)), joinLeft(right(left(0)))); + assertEquals(right(right(0)), joinLeft(right(right(0)))); + } + + @Test + public void testJoinRight() { + assertEquals(left(left(0)), joinRight(left(left(0)))); + assertEquals(left(right(0)), joinRight(left(right(0)))); + assertEquals(left(0), joinRight(right(left(0)))); + assertEquals(right(0), joinRight(right(right(0)))); + } + + @Test + public void testSequenceLeft() { + assertEquals(left(List.nil()), sequenceLeft(List.nil())); + assertEquals(left(List.single("zero")), sequenceLeft(List.single(left("zero")))); + assertEquals(right("zero"), sequenceLeft(List.single(right("zero")))); + } + + @Test + public void testSequenceRight() { + assertEquals(right(List.nil()), sequenceRight(List.nil())); + assertEquals(right(List.single("zero")), sequenceRight(List.single(right("zero")))); + assertEquals(left("zero"), sequenceRight(List.single(left("zero")))); + } + + @Test + public void testTraverseListRight() { + assertEquals(List.single(left("zero")), left("zero").traverseListRight(constant(List.nil()))); + assertEquals(List.single(left("zero")), left("zero").traverseListRight(constant(List.single(0)))); + assertEquals(List.single(left("zero")), left("zero").traverseListRight(constant(List.arrayList(0, 1)))); + assertEquals(List.nil(), right("zero").traverseListRight(constant(List.nil()))); + assertEquals(List.single(right(0)), right("zero").traverseListRight(constant(List.single(0)))); + assertEquals(List.arrayList(right(0), right(1)), right("zero").traverseListRight(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseListLeft() { + assertEquals(List.nil(), left("zero").traverseListLeft(constant(List.nil()))); + assertEquals(List.single(left(0)), left("zero").traverseListLeft(constant(List.single(0)))); + assertEquals(List.arrayList(left(0), left(1)), left("zero").traverseListLeft(constant(List.arrayList(0, 1)))); + assertEquals(List.single(right("zero")), right("zero").traverseListLeft(constant(List.nil()))); + assertEquals(List.single(right("zero")), right("zero").traverseListLeft(constant(List.single(0)))); + assertEquals(List.single(right("zero")), right("zero").traverseListLeft(constant(List.arrayList(0, 1)))); + } + + @Test + public void testTraverseIORight() throws IOException { + assertEquals(left("zero"), left("zero").traverseIORight(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(right(0), right("zero").traverseIORight(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseIOLeft() throws IOException { + assertEquals(left(0), left("zero").traverseIOLeft(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(right("zero"), right("zero").traverseIOLeft(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseOptionRight() { + assertEquals(Option.some(left("zero")), left("zero").traverseOptionRight(constant(Option.none()))); + assertEquals(Option.some(left("zero")), left("zero").traverseOptionRight(constant(Option.some(0)))); + assertEquals(Option.none(), right("zero").traverseOptionRight(constant(Option.none()))); + assertEquals(Option.some(right(0)), right("zero").traverseOptionRight(constant(Option.some(0)))); + } + + @Test + public void testTraverseOptionLeft() { + assertEquals(Option.none(), left("zero").traverseOptionLeft(constant(Option.none()))); + assertEquals(Option.some(left(0)), left("zero").traverseOptionLeft(constant(Option.some(0)))); + assertEquals(Option.some(right("zero")), right("zero").traverseOptionLeft(constant(Option.none()))); + assertEquals(Option.some(right("zero")), right("zero").traverseOptionLeft(constant(Option.some(0)))); + } + + @Test + public void testTraverseStreamRight() { + assertEquals(Stream.single(left("zero")), left("zero").traverseStreamRight(constant(Stream.nil()))); + assertEquals(Stream.single(left("zero")), left("zero").traverseStreamRight(constant(Stream.single(0)))); + assertEquals(Stream.single(left("zero")), left("zero").traverseStreamRight(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.nil(), right("zero").traverseStreamRight(constant(Stream.nil()))); + assertEquals(Stream.single(right(0)), right("zero").traverseStreamRight(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(right(0), right(1)), right("zero").traverseStreamRight(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseStreamLeft() { + assertEquals(Stream.nil(), left("zero").traverseStreamLeft(constant(Stream.nil()))); + assertEquals(Stream.single(left(0)), left("zero").traverseStreamLeft(constant(Stream.single(0)))); + assertEquals(Stream.arrayStream(left(0), left(1)), left("zero").traverseStreamLeft(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.single(right("zero")), right("zero").traverseStreamLeft(constant(Stream.nil()))); + assertEquals(Stream.single(right("zero")), right("zero").traverseStreamLeft(constant(Stream.single(0)))); + assertEquals(Stream.single(right("zero")), right("zero").traverseStreamLeft(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testReduce() { + assertEquals(0L, (long) reduce(left(0L))); + assertEquals(0L, (long) reduce(right(0L))); + } + + @Test + public void testIif() { + assertEquals(right(-1), iif(true, () -> -1, () -> 1)); + assertEquals(left(1), iif(false, () -> -1, () -> 1)); + } + + @Test + public void testLefts() { + assertEquals(List.nil(), lefts(List.nil())); + assertEquals(List.single(0), lefts(List.single(left(0)))); + assertEquals(List.nil(), lefts(List.single(right(0)))); + assertEquals(List.arrayList(0, 1), lefts(List.arrayList(left(0), left(1)))); + assertEquals(List.single(0), lefts(List.arrayList(left(0), right(1)))); + assertEquals(List.single(1), lefts(List.arrayList(right(0), left(1)))); + assertEquals(List.nil(), lefts(List.arrayList(right(0), right(1)))); + } + + @Test + public void testRights() { + assertEquals(List.nil(), rights(List.nil())); + assertEquals(List.single(0), rights(List.single(right(0)))); + assertEquals(List.single(0), lefts(List.single(left(0)))); + assertEquals(List.arrayList(0, 1), rights(List.arrayList(right(0), right(1)))); + assertEquals(List.single(0), rights(List.arrayList(right(0), left(1)))); + assertEquals(List.single(1), rights(List.arrayList(left(0), right(1)))); + assertEquals(List.nil(), rights(List.arrayList(left(0), left(1)))); + } + + @Test + public void testTestToString() { + assertNotNull(left(0).toString()); + assertNotNull(right(0).toString()); + } +} \ No newline at end of file From 849dc39c6d5e937f9cd650da8e5de5cbf2bf062d Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 6 Aug 2020 10:35:26 -0400 Subject: [PATCH 277/336] Fixes #417. Add fj.data.State.bind(F>). --- core/src/main/java/fj/data/State.java | 18 +++++++++++ core/src/test/java/fj/data/StateTest.java | 39 +++++++++++++++++++++-- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index f29d55d7..f0156b36 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -111,6 +111,24 @@ public State withs(F f) { return suspended(s -> runF.f(f.f(s))); } + /** + * Bind the given function across this state. + * + * @param f the given function + * @param the type of the output value + * @return the state + */ + public State bind(F> f) { + return flatMap(f); + } + + /** + * Bind the given function across this state. + * + * @param f the given function + * @param the type of the output value + * @return the state + */ public State flatMap(F> f) { return suspended(s -> runF.f(s).bind(result -> Trampoline.pure(f.f(result._2()).run(result._1())))); } diff --git a/core/src/test/java/fj/data/StateTest.java b/core/src/test/java/fj/data/StateTest.java index 9fc8a9fb..37b21030 100644 --- a/core/src/test/java/fj/data/StateTest.java +++ b/core/src/test/java/fj/data/StateTest.java @@ -2,14 +2,47 @@ import org.junit.Test; +import static fj.P.p; +import static org.junit.Assert.assertEquals; + /** * Created by MarkPerry on 18/12/2014. */ public class StateTest { - @Test - public void map() { + @Test + public void testBind() { + assertEquals(p(2, "one"), state().run(1)); + assertEquals(p(3, "two"), state().run(2)); + assertEquals(p(4, "three"), state().run(3)); + assertEquals(p(2, "?"), state().bind(state -> State.constant("?")).run(1)); + assertEquals(p(3, "?"), state().bind(state -> State.constant("?")).run(2)); + assertEquals(p(4, "?"), state().bind(state -> State.constant("?")).run(3)); + } + + @Test + public void testFlatMap() { + assertEquals(p(2, "one"), state().run(1)); + assertEquals(p(3, "two"), state().run(2)); + assertEquals(p(4, "three"), state().run(3)); + assertEquals(p(2, "?"), state().flatMap(state -> State.constant("?")).run(1)); + assertEquals(p(3, "?"), state().flatMap(state -> State.constant("?")).run(2)); + assertEquals(p(4, "?"), state().flatMap(state -> State.constant("?")).run(3)); + } - } + private static final State state() { + return State.unit(i -> p(i + 1, toLapine(i))); + } + private static String toLapine( + final int i) { + return i == 1 ? + "one" : + i == 2 ? + "two" : + i == 3 ? + "three" : + i == 4 ? + "four" : "hrair"; + } } From c427a086d6a06a14074719d2f3c9a011ce7ad14d Mon Sep 17 00:00:00 2001 From: Drew Taylor Date: Thu, 22 Oct 2020 07:07:30 -0400 Subject: [PATCH 278/336] Fixes #424. Add fj.data.Stream.sequence*, fj.data.Stream.traverse* functions. --- core/src/main/java/fj/data/Stream.java | 432 +++++++++++++++++- .../test/java/fj/data/IOFunctionsTest.java | 2 +- core/src/test/java/fj/data/StreamTest.java | 237 ++++++++++ 3 files changed, 649 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index a523515b..e05e26bf 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -4,6 +4,7 @@ import fj.F0; import fj.F3; import fj.Hash; +import fj.Semigroup; import fj.Show; import fj.F; import fj.F2; @@ -14,6 +15,7 @@ import fj.P1; import fj.P2; import fj.Unit; +import fj.control.Trampoline; import fj.control.parallel.Promise; import fj.control.parallel.Strategy; import fj.Ordering; @@ -1094,27 +1096,6 @@ public final Stream takeWhile(final F f) { Stream.nil(); } - /** - * Traversable instance of Stream for IO. - * - * @return traversed value - */ - public final IO> traverseIO(F> f) { - return this.foldRight1((a, acc) -> - IOFunctions.bind(acc, (Stream bs) -> - IOFunctions.map(f.f(a), bs::cons)), IOFunctions.unit(Stream.nil())); - - } - - /** - * Traversable instance of Stream for Option. - * - * @return traversed value - */ - public final Option> traverseOption(F> f) { - return this.foldRight1((a, acc) -> acc.bind(bs -> f.f(a).map(bs::cons)), some(Stream.nil())); - } - /** * Removes elements from the head of this stream that do not match the given predicate function * until an element is found that does match or the stream is exhausted. @@ -1669,4 +1650,413 @@ public static F>, F, Stream>> bind_() { public static F, B>>, F, B>>> foldRight() { return curry((f, b, as) -> as.foldRight(f, b)); } + + /** + * Sequence the given stream and collect the output on the right side of an either. + * + * @param stream the given stream + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either> sequenceEither( + final Stream> stream) { + return stream.traverseEither(identity()); + } + + /** + * Sequence the given stream and collect the output on the left side of an either. + * + * @param stream the given stream + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either, R> sequenceEitherLeft( + final Stream> stream) { + return stream.traverseEitherLeft(identity()); + } + + /** + * Sequence the given stream and collect the output on the right side of an either. + * + * @param stream the given stream + * @param the type of the right value + * @param the type of the left value + * @return the either + */ + public static Either> sequenceEitherRight( + final Stream> stream) { + return stream.traverseEitherRight(identity()); + } + + /** + * Sequence the given stream and collect the output as a function. + * + * @param stream the given stream + * @param the type of the input value + * @param the type of the output value + * @return the either + */ + public static F> sequenceF( + final Stream> stream) { + return stream.traverseF(identity()); + } + + /** + * Sequence the given stream and collect the output as an IO. + * + * @param stream the given stream + * @param the type of the IO value + * @return the IO + */ + public static IO> sequenceIO( + final Stream> stream) { + return stream.traverseIO(identity()); + } + + /** + * Sequence the given stream and collect the output as a list. + * + * @param stream the given stream + * @param the type of the list value + * @return the list + */ + public static List> sequenceList( + final Stream> stream) { + return stream.traverseList(identity()); + } + + /** + * Sequence the given stream and collect the output as an stream. + * + * @param stream the given stream + * @param the type of the option value + * @return the stream + */ + public static Option> sequenceOption( + final Stream> stream) { + return stream.traverseOption(identity()); + } + + /** + * Sequence the given stream and collect the output as a P1. + * + * @param stream the given stream + * @param the type of the P1 value + * @return the P1 + */ + public static P1> sequenceP1( + final Stream> stream) { + return stream.traverseP1(identity()); + } + + /** + * Sequence the given stream and collect the output as a seq. + * + * @param stream the given stream + * @param the type of the stream value + * @return the seq + */ + public static Seq> sequenceSeq( + final Stream> stream) { + return stream.traverseSeq(identity()); + } + + /** + * Sequence the given stream and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param stream the given stream + * @param the type of the set value + * @return the either + */ + public static Set> sequenceSet( + final Ord ord, + final Stream> stream) { + return stream.traverseSet(ord, identity()); + } + + /** + * Sequence the given stream and collect the output as a stream. + * + * @param stream the given stream + * @param the type of the stream value + * @return the stream + */ + public static Stream> sequenceStream( + final Stream> stream) { + return stream.traverseStream(identity()); + } + + /** + * Sequence the given stream and collect the output as a trampoline. + * + * @param stream the given trampoline + * @param the type of the stream value + * @return the stream + */ + public static Trampoline> sequenceTrampoline( + final Stream> stream) { + return stream.traverseTrampoline(identity()); + } + + /** + * Sequence the given stream and collect the output as a validation. + * + * @param stream the given stream + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static Validation> sequenceValidation( + final Stream> stream) { + return stream.traverseValidation(identity()); + } + + /** + * Sequence the given stream and collect the output as a validation; use the given semigroup to reduce the errors. + * + * @param semigroup the given semigroup + * @param stream the given stream + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public static Validation> sequenceValidation( + final Semigroup semigroup, + final Stream> stream) { + return stream.traverseValidation(semigroup, identity()); + } + + /** + * Traverse this stream with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either> traverseEither( + final F> f) { + return traverseEitherRight(f); + } + + /** + * Traverse this stream with the given function and collect the output on the left side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either, R> traverseEitherLeft( + final F> f) { + return foldRight1( + ( + element, + either) -> f.f(element).left().bind(elementInner -> either.left().map(stream -> stream.cons(elementInner))), + Either.left(nil())); + } + + /** + * Traverse this stream with the given function and collect the output on the right side of an either. + * + * @param f the given function + * @param the type of the left value + * @param the type of the right value + * @return the either + */ + public Either> traverseEitherRight( + final F> f) { + return foldRight1( + ( + element, + either) -> f.f(element).right().bind(elementInner -> either.right().map(stream -> stream.cons(elementInner))), + Either.right(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a function. + * + * @param f the given function + * @param the type of the input value + * @param the type of the output value + * @return the function + */ + public F> traverseF( + final F> f) { + return foldRight1( + ( + element, + fInner) -> Function.bind(f.f(element), elementInner -> andThen(fInner, stream -> stream.cons(elementInner))), + Function.constant(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as an IO. + * + * @param f the given function + * @param the type of the IO value + * @return the IO + */ + public IO> traverseIO( + final F> f) { + return foldRight1( + ( + element, + io) -> IOFunctions.bind(f.f(element), elementInner -> IOFunctions.map(io, stream -> stream.cons(elementInner))), + IOFunctions.unit(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a list. + * + * @param f the given function + * @param the type of the list value + * @return the list + */ + public List> traverseList( + final F> f) { + return foldRight1( + ( + element, + list) -> f.f(element).bind(elementInner -> list.map(stream -> stream.cons(elementInner))), + List.single(nil())); + } + + /** + * Traverses through the Seq with the given function + * + * @param f The function that produces Option value + * @return none if applying f returns none to any element of the seq or f mapped seq in some . + */ + public Option> traverseOption( + final F> f) { + return foldRight1( + ( + element, + option) -> f.f(element).bind(elementInner -> option.map(stream -> stream.cons(elementInner))), + Option.some(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a p1. + * + * @param f the given function + * @param the type of the p1 value + * @return the p1 + */ + public P1> traverseP1( + final F> f) { + return foldRight1( + ( + element, + p1) -> f.f(element).bind(elementInner -> p1.map(stream -> stream.cons(elementInner))), + P.p(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a seq. + * + * @param f the given function + * @param the type of the seq value + * @return the seq + */ + public Seq> traverseSeq( + final F> f) { + return foldRight1( + ( + element, + seq) -> f.f(element).bind(elementInner -> seq.map(stream -> stream.cons(elementInner))), + Seq.single(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a set; use the given ord to order the set. + * + * @param ord the given ord + * @param f the given function + * @param the type of the set value + * @return the set + */ + public Set> traverseSet( + final Ord ord, + final F> f) { + final Ord> seqOrd = Ord.streamOrd(ord); + return foldRight1( + ( + element, + set) -> f.f(element).bind(seqOrd, elementInner -> set.map(seqOrd, seq -> seq.cons(elementInner))), + Set.single(seqOrd, nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a stream. + * + * @param f the given function + * @param the type of the stream value + * @return the stream + */ + public Stream> traverseStream( + final F> f) { + return foldRight1( + ( + element, + stream) -> f.f(element).bind(elementInner -> stream.map(seq -> seq.cons(elementInner))), + Stream.single(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a trampoline. + * + * @param f the given function + * @param the type of the trampoline value + * @return the trampoline + */ + public Trampoline> traverseTrampoline( + final F> f) { + return foldRight1( + ( + element, + trampoline) -> f.f(element).bind(elementInner -> trampoline.map(seq -> seq.cons(elementInner))), + Trampoline.pure(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a validation. + * + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public final Validation> traverseValidation( + final F> f) { + return foldRight1( + ( + element, + validation) -> f.f(element).bind(elementInner -> validation.map(stream -> stream.cons(elementInner))), + Validation.success(nil())); + } + + /** + * Traverse this stream with the given function and collect the output as a validation; use the given semigroup to + * reduce the errors. + * + * @param semigroup the given semigroup + * @param f the given function + * @param the type of the failure value + * @param the type of the success value + * @return the validation + */ + public final Validation> traverseValidation( + final Semigroup semigroup, + final F> f) { + return foldRight1( + ( + element, + validation) -> f.f(element).map(Stream::single).accumulate(semigroup, validation, (stream1, stream2) -> stream1.append(stream2)), + Validation.success(nil())); + } } diff --git a/core/src/test/java/fj/data/IOFunctionsTest.java b/core/src/test/java/fj/data/IOFunctionsTest.java index b943db36..5213878c 100644 --- a/core/src/test/java/fj/data/IOFunctionsTest.java +++ b/core/src/test/java/fj/data/IOFunctionsTest.java @@ -73,7 +73,7 @@ public void testTraverseIO() throws IOException { System.setOut(new PrintStream(outContent)); stream.traverseIO(IOFunctions::stdoutPrint).run(); System.setOut(originalOut); - assertThat(outContent.toString(), is("foobar3bar2foo1")); + assertThat(outContent.toString(), is("foo1bar2foobar3")); } @Test diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index 999a3a3e..313678aa 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -2,13 +2,40 @@ import fj.Equal; import fj.P2; +import fj.control.Trampoline; import org.junit.Test; +import java.io.IOException; import java.util.ConcurrentModificationException; +import static fj.Function.constant; +import static fj.Ord.*; +import static fj.P.p; +import static fj.Semigroup.listSemigroup; +import static fj.data.Either.left; +import static fj.data.Either.right; +import static fj.data.List.arrayList; +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.data.Seq.arraySeq; +import static fj.data.Seq.empty; +import static fj.data.Stream.sequenceEitherLeft; +import static fj.data.Stream.sequenceEitherRight; +import static fj.data.Stream.sequenceF; +import static fj.data.Stream.sequenceIO; +import static fj.data.Stream.sequenceList; +import static fj.data.Stream.sequenceOption; +import static fj.data.Stream.sequenceP1; +import static fj.data.Stream.sequenceSeq; +import static fj.data.Stream.sequenceSet; +import static fj.data.Stream.sequenceStream; +import static fj.data.Stream.sequenceTrampoline; +import static fj.data.Stream.sequenceValidation; import static fj.data.Stream.*; +import static fj.data.Validation.*; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; /** @@ -103,4 +130,214 @@ public void testMinus() { assertThat(s1.minus(Equal.charEqual, s2), is(stream(new Character[]{'a', 'c', 'd'}))); } + + @Test + public void testSequenceEither() { + assertEquals(right(nil()), sequenceEither(nil())); + assertEquals(right(single("zero")), sequenceEither(single(right("zero")))); + assertEquals(left("zero"), sequenceEither(single(left("zero")))); + } + + @Test + public void testSequenceEitherLeft() { + assertEquals(left(nil()), sequenceEitherLeft(nil())); + assertEquals(left(single("zero")), sequenceEitherLeft(single(left("zero")))); + assertEquals(right("zero"), sequenceEitherLeft(single(right("zero")))); + } + + @Test + public void testSequenceEitherRight() { + assertEquals(right(nil()), sequenceEitherRight(nil())); + assertEquals(right(single("zero")), sequenceEitherRight(single(right("zero")))); + assertEquals(left("zero"), sequenceEitherRight(single(left("zero")))); + } + + @Test + public void testSequenceF() { + assertEquals(constant(nil()).f(1), sequenceF(nil()).f(1)); + assertEquals(constant(single("zero")).f(1), sequenceF(single(constant("zero"))).f(1)); + } + + @Test + public void testSequenceIO() + throws IOException { + assertEquals(IOFunctions.lazy(constant(nil())).run(), sequenceIO(nil()).run()); + assertEquals(IOFunctions.lazy(constant(single("zero"))).run(), sequenceIO(single(IOFunctions.lazy(constant("zero")))).run()); + } + + @Test + public void testSequenceList() { + assertEquals(List.single(nil()), sequenceList(nil())); + assertEquals(List.nil(), sequenceList(single(List.nil()))); + assertEquals(List.single(single("zero")), sequenceList(single(List.single("zero")))); + assertEquals(arrayList(single("zero"), single("one")), sequenceList(single(arrayList("zero", "one")))); + } + + @Test + public void testSequenceOption() { + assertEquals(some(nil()), sequenceOption(nil())); + assertEquals(none(), sequenceOption(single(none()))); + assertEquals(some(single("zero")), sequenceOption(single(some("zero")))); + } + + @Test + public void testSequenceP1() { + assertEquals(p(nil()), sequenceP1(nil())); + assertEquals(p(single("zero")), sequenceP1(single(p("zero")))); + } + + @Test + public void testSequenceSeq() { + assertEquals(Seq.single(nil()), sequenceSeq(nil())); + assertEquals(Seq.empty(), sequenceSeq(single(Seq.empty()))); + assertEquals(Seq.single(single("zero")), sequenceSeq(single(Seq.single("zero")))); + assertEquals(arraySeq(single("zero"), single("one")), sequenceSeq(single(arraySeq("zero", "one")))); + } + + @Test + public void testSequenceSet() { + assertEquals(Set.arraySet(streamOrd(stringOrd), nil()), sequenceSet(stringOrd, nil())); + assertEquals(Set.empty(streamOrd(stringOrd)), sequenceSet(stringOrd, single(Set.empty(stringOrd)))); + assertEquals(Set.arraySet(streamOrd(stringOrd), single("zero")), sequenceSet(stringOrd, single(Set.single(stringOrd, "zero")))); + assertEquals(Set.arraySet(streamOrd(stringOrd), single("zero"), single("one")), sequenceSet(stringOrd, single(Set.arraySet(stringOrd, "zero", "one")))); + } + + @Test + public void testSequenceStream() { + assertEquals(single(nil()), sequenceStream(nil())); + assertEquals(nil(), sequenceStream(single(nil()))); + assertEquals(single(single("zero")), sequenceStream(single(single("zero")))); + assertEquals(arrayStream(single("zero"), single("one")), sequenceStream(single(arrayStream("zero", "one")))); + } + + @Test + public void testSequenceTrampoline() { + assertEquals(Trampoline.pure(nil()).run(), sequenceTrampoline(nil()).run()); + assertEquals(Trampoline.pure(single(0)).run(), sequenceTrampoline(single(Trampoline.pure(0))).run()); + } + + @Test + public void testSequenceValidation() { + assertEquals(success(nil()), sequenceValidation(nil())); + assertEquals(fail(single(0)), sequenceValidation(single(fail(single(0))))); + assertEquals(success(single(0)), sequenceValidation(single(success(0)))); + } + + @Test + public void testSequenceValidationSemigroup() { + assertEquals(success(nil()), sequenceValidation(listSemigroup(), nil())); + assertEquals(fail(List.single(0)), sequenceValidation(listSemigroup(), single(fail(List.single(0))))); + assertEquals(success(single(0)), sequenceValidation(listSemigroup(), single(success(0)))); + } + + @Test + public void testTraverseEitherLeft() { + assertEquals(left(nil()), nil().traverseEitherLeft(constant(left(0)))); + assertEquals(left(single(0)), single("zero").traverseEitherLeft(constant(left(0)))); + assertEquals(left(nil()), nil().traverseEitherLeft(constant(right(0)))); + assertEquals(right(0), single("zero").traverseEitherLeft(constant(right(0)))); + } + + @Test + public void testTraverseEitherRight() { + assertEquals(right(nil()), nil().traverseEitherRight(constant(right(0)))); + assertEquals(right(single(0)), single("zero").traverseEitherRight(constant(right(0)))); + assertEquals(right(nil()), nil().traverseEitherRight(constant(left(0)))); + assertEquals(left(0), single("zero").traverseEitherRight(constant(left(0)))); + } + + @Test + public void testTraverseF() { + assertEquals(constant(nil()).f(1), nil().traverseF(constant(constant(0))).f(1)); + assertEquals(constant(single(0)).f(1), single("zero").traverseF(constant(constant(0))).f(1)); + } + + @Test + public void testTraverseIO() + throws IOException { + assertEquals(IOFunctions.lazy(constant(nil())).run(), nil().traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + assertEquals(IOFunctions.lazy(constant(single(0))).run(), single("zero").traverseIO(constant(IOFunctions.lazy(constant(0)))).run()); + } + + @Test + public void testTraverseList() { + assertEquals(List.single(nil()), nil().traverseList(constant(List.nil()))); + assertEquals(List.nil(), single("zero").traverseList(constant(List.nil()))); + assertEquals(List.single(nil()), nil().traverseList(constant(List.single(0)))); + assertEquals(List.single(single(0)), single("zero").traverseList(constant(List.single(0)))); + assertEquals(List.single(nil()), nil().traverseList(constant(arrayList(0, 1)))); + assertEquals(arrayList(single(0), single(1)), single("zero").traverseList(constant(arrayList(0, 1)))); + } + + @Test + public void testTraverseOption() { + assertEquals(some(nil()), nil().traverseOption(constant(none()))); + assertEquals(none(), single("zero").traverseOption(constant(none()))); + assertEquals(some(nil()), nil().traverseOption(constant(some(0)))); + assertEquals(some(single(0)), single("zero").traverseOption(constant(some(0)))); + } + + @Test + public void testTraverseP1() { + assertEquals(p(nil()), nil().traverseP1(constant(p(0)))); + assertEquals(p(single(0)), single("zero").traverseP1(constant(p(0)))); + } + + @Test + public void testTraverseSeq() { + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(empty()))); + assertEquals(Seq.empty(), single("zero").traverseSeq(constant(empty()))); + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(single(0)), single("zero").traverseSeq(constant(Seq.single(0)))); + assertEquals(Seq.single(nil()), nil().traverseSeq(constant(arraySeq(0, 1)))); + assertEquals(arraySeq(single(0), single(1)), single("zero").traverseSeq(constant(arraySeq(0, 1)))); + } + + @Test + public void testTraverseSet() { + assertEquals(Set.arraySet(streamOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.empty(streamOrd(intOrd)), single("zero").traverseSet(intOrd, constant(Set.empty(intOrd)))); + assertEquals(Set.single(streamOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(streamOrd(intOrd), single(0)), single("zero").traverseSet(intOrd, constant(Set.single(intOrd, 0)))); + assertEquals(Set.single(streamOrd(intOrd), nil()), nil().traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + assertEquals(Set.arraySet(streamOrd(intOrd), single(0), single(1)), single("zero").traverseSet(intOrd, constant(Set.arraySet(intOrd, 0, 1)))); + } + + @Test + public void testTraverseStream() { + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.nil()))); + assertEquals(Stream.nil(), single("zero").traverseStream(constant(Stream.nil()))); + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(single(0)), single("zero").traverseStream(constant(Stream.single(0)))); + assertEquals(Stream.single(nil()), nil().traverseStream(constant(Stream.arrayStream(0, 1)))); + assertEquals(Stream.arrayStream(single(0), single(1)), single("zero").traverseStream(constant(Stream.arrayStream(0, 1)))); + } + + @Test + public void testTraverseTrampoline() { + assertEquals(Trampoline.pure(nil()).run(), nil().traverseTrampoline(constant(Trampoline.pure(0))).run()); + assertEquals(Trampoline.pure(single(0)).run(), single("zero").traverseTrampoline(constant(Trampoline.pure(0))).run()); + } + + @Test + public void testTraverseValidation() { + assertEquals(success(nil()), nil().traverseValidation(constant(fail(single(0))))); + assertEquals(fail(single(0)), single("zero").traverseValidation(constant(fail(single(0))))); + assertEquals(success(nil()), nil().traverseValidation(constant(success(0)))); + assertEquals(success(single(0)), single("zero").traverseValidation(constant(success(0)))); + + assertEquals(success(arraySeq(0, 2, 4, 6, 8)), arraySeq(0, 2, 4, 6, 8).traverseValidation(i -> condition(i % 2 == 0, List.single(i), i))); + assertEquals(fail(List.single(1)), arraySeq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).traverseValidation(i -> condition(i % 2 == 0, List.single(i), i))); + } + + @Test + public void testTraverseValidationSemigroup() { + assertEquals(success(nil()), nil().traverseValidation(listSemigroup(), constant(fail(List.single(0))))); + assertEquals(fail(List.single(0)), single("zero").traverseValidation(listSemigroup(), constant(fail(List.single(0))))); + assertEquals(success(nil()), nil().traverseValidation(listSemigroup(), constant(success(0)))); + assertEquals(success(single(0)), single("zero").traverseValidation(listSemigroup(), constant(success(0)))); + + assertEquals(success(arraySeq(0, 2, 4, 6, 8)), arraySeq(0, 2, 4, 6, 8).traverseValidation(listSemigroup(), i -> condition(i % 2 == 0, List.single(i), i))); + assertEquals(fail(arrayList(1, 3, 5, 7, 9)), arraySeq(0, 1, 2, 3, 4, 5, 6, 7, 8, 9).traverseValidation(listSemigroup(), i -> condition(i % 2 == 0, List.single(i), i))); + } } From 254e3f55d964ef27278dbfb51ef0981f7e07c96f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Feb 2021 14:24:27 +1000 Subject: [PATCH 279/336] Fixed code to not use Java 8 features --- .../fj/control/parallel/StrategyTest.java | 9 +++++- core/src/test/java/fj/data/OptionTest.java | 30 ++++++++--------- .../src/test/java/fj/data/ValidationTest.java | 32 +++++++++---------- 3 files changed, 39 insertions(+), 32 deletions(-) diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java index 8475b35a..0c605829 100644 --- a/core/src/test/java/fj/control/parallel/StrategyTest.java +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -5,6 +5,7 @@ import fj.P1; import fj.Unit; import fj.data.Enumerator; +import fj.data.Java; import fj.data.List; import fj.data.Stream; import org.junit.Test; @@ -49,10 +50,16 @@ public void testStrategyCompletion() { @Test public void testStrategyMergeAll() { final List l = List.range(0, 100); - final List> p1s = mergeAll(l.map(x -> CompletableFuture.supplyAsync(() -> x))); + final List> p1s = mergeAll(l.map(x -> future(x))); assertThat(P1.sequence(p1s)._1(), is(l)); } + public static Future future(A a) { + FutureTask ft = new FutureTask<>(() -> a); + new Thread(ft).start(); + return ft; + } + @Test public void testStrategyCallables() throws Exception { final Strategy> s = strategy(c -> c); diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index da5ef065..5a7bbdbf 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -75,7 +75,7 @@ public void testBind1() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), 0), list.index(0).bind(Option::some)); }); @@ -87,7 +87,7 @@ public void testBind2() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bind(list.index(1), p2())); }); } @@ -98,7 +98,7 @@ public void testBind3() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bind(list.index(1), list.index(2), p3())); }); @@ -110,7 +110,7 @@ public void testBind4() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bind(list.index(1), list.index(2), list.index(3), p4())); }); @@ -122,7 +122,7 @@ public void testBind5() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), p5())); }); } @@ -133,7 +133,7 @@ public void testBind6() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), p6())); }); } @@ -144,7 +144,7 @@ public void testBind7() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), p7())); }); } @@ -155,7 +155,7 @@ public void testBind8() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bind(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P.p8())); }); } @@ -166,7 +166,7 @@ public void testBindProduct2() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1)), list.index(0).bindProduct(list.index(1))); }); } @@ -177,7 +177,7 @@ public void testBindProduct3() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2)), list.index(0).bindProduct(list.index(1), list.index(2))); }); @@ -189,7 +189,7 @@ public void testBindProduct4() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3))); }); @@ -201,7 +201,7 @@ public void testBindProduct5() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4))); }); } @@ -212,7 +212,7 @@ public void testBindProduct6() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5))); }); } @@ -223,7 +223,7 @@ public void testBindProduct7() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6))); }); } @@ -234,7 +234,7 @@ public void testBindProduct8() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List.>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.forall(Option::isSome), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).bindProduct(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7))); }); } diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java index 0df2deb9..bf2c34e9 100644 --- a/core/src/test/java/fj/data/ValidationTest.java +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -35,7 +35,7 @@ public void testAccumulateSemigroup2() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1), p2())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(Semigroup.listSemigroup(), list.index(1), uncurryF2(p2()))); @@ -49,7 +49,7 @@ public void testAccumulateSemigroup3() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), p3())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), uncurryF3(p3()))); @@ -64,7 +64,7 @@ public void testAccumulateSemigroup4() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), p4())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), uncurryF4(p4()))); @@ -79,7 +79,7 @@ public void testAccumulateSemigroup5() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), p5())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), uncurryF5(p5()))); @@ -93,7 +93,7 @@ public void testAccumulateSemigroup6() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), p6())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), uncurryF6(p6()))); @@ -107,7 +107,7 @@ public void testAccumulateSemigroup7() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), p7())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), uncurryF7(p7()))); @@ -121,7 +121,7 @@ public void testAccumulateSemigroup8() { accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(iif(list.exists(Validation::isFail), list.filter(Validation::isFail).bind(validation -> validation.fail())), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7))); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P.p8())); assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).bind(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(Semigroup.listSemigroup(),list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), uncurryF8(P.p8()))); @@ -134,7 +134,7 @@ public void testAccumulate0() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), 0), list.index(0).accumulate()); }); } @@ -145,7 +145,7 @@ public void testAccumulate1() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), 0), list.index(0).accumulate(identity())); }); @@ -157,7 +157,7 @@ public void testAccumulate2() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1)), list.index(0).accumulate(list.index(1), P::p)); }); } @@ -168,7 +168,7 @@ public void testAccumulate3() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2)), list.index(0).accumulate(list.index(1), list.index(2), P::p)); }); @@ -180,7 +180,7 @@ public void testAccumulate4() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), P::p)); }); @@ -192,7 +192,7 @@ public void testAccumulate5() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), P::p)); }); } @@ -203,7 +203,7 @@ public void testAccumulate6() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), P::p)); }); } @@ -214,7 +214,7 @@ public void testAccumulate7() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), P::p)); }); } @@ -225,7 +225,7 @@ public void testAccumulate8() { .foldLeft(accumulator -> list -> accumulator.isEmpty() ? list.map(List::single) : accumulator.bind(accumulatorElement -> list.map(accumulatorElement::snoc)), List., Integer>>>nil()) - .forEach(list -> { + .foreachDoEffect(list -> { assertEquals(condition(list.forall(Validation::isSuccess), list.filter(Validation::isFail).map(validation -> validation.fail()), p(0, 1, 2, 3, 4, 5, 6, 7)), list.index(0).accumulate(list.index(1), list.index(2), list.index(3), list.index(4), list.index(5), list.index(6), list.index(7), P::p)); }); } From 8bf7192dec8054aa77b4db157e1237fc4670f7dd Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Mar 2021 01:12:16 +1000 Subject: [PATCH 280/336] Update release notes for 4.8, 4.8.1 and release notes --- etc/release-notes/release-notes-4.8.1.adoc | 34 ++++++++++++++++++ etc/release-notes/release-notes-4.8.adoc | 41 +++++++++++++++++----- etc/release-process.txt | 35 ++++++++++++++++++ 3 files changed, 102 insertions(+), 8 deletions(-) create mode 100644 etc/release-notes/release-notes-4.8.1.adoc diff --git a/etc/release-notes/release-notes-4.8.1.adoc b/etc/release-notes/release-notes-4.8.1.adoc new file mode 100644 index 00000000..45deb658 --- /dev/null +++ b/etc/release-notes/release-notes-4.8.1.adoc @@ -0,0 +1,34 @@ + += Release 4.8.1 + +Released: 8 Oct 2018 + +== Enhancements + +- Add Trampoline.suspend(final F0> a). See #367 https://github.com/functionaljava/functionaljava/pull/367. + +== Fixes + +- Fix regression in lifted semigroup sum. Fix #365, see #366 https://github.com/functionaljava/functionaljava/pull/366. + +== Internal + +- Fix compile under jdk11. Enable jdk11 travis build, see #361 https://github.com/functionaljava/functionaljava/pull/361. +- Fix warnings, see #369 https://github.com/functionaljava/functionaljava/pull/369. +- Add P tests, see #360 https://github.com/functionaljava/functionaljava/pull/360. +- Exclude consume/ from coverage, see #357 https://github.com/functionaljava/functionaljava/pull/357. +- Add DList tests, see #356 https://github.com/functionaljava/functionaljava/pull/356 +- Add Visitor tests, see #354 https://github.com/functionaljava/functionaljava/pull/354. + +== Breaking Changes + +* None. + +== Documentation + +* None. + +== Contributors + +* Jean Baptiste Giraudeau +* Gabor Liptak diff --git a/etc/release-notes/release-notes-4.8.adoc b/etc/release-notes/release-notes-4.8.adoc index 22dbc552..7e8aed61 100644 --- a/etc/release-notes/release-notes-4.8.adoc +++ b/etc/release-notes/release-notes-4.8.adoc @@ -1,28 +1,53 @@ -= Release += Release 4.8 -Proposed release: +Released: 18 Aug 2018 == Enhancements -* TODO. +- Enable upload of snapshot artifacts, see https://github.com/functionaljava/functionaljava/commit/e834e8b. +- Add append methods to all Px classes. Fix #326, see https://github.com/functionaljava/functionaljava/commit/065ed43. +- Introduce the Eval monad, see https://github.com/functionaljava/functionaljava/commit/98294fc. +- Fluent Equal/Ord construction, see #333 https://github.com/functionaljava/functionaljava/pull/333 +- Implement Zipper Eq and Hash and add tests, see #343 https://github.com/functionaljava/functionaljava/pull/343. +- Implement Vector equals, see #350 https://github.com/functionaljava/functionaljava/pull/350. == Fixes -* TODO. +- Fixed a bug in the NonEmptyList Semigroup implementation that resulted in the same NonEmptyList appended to itself. Regression in 4.7, see https://github.com/functionaljava/functionaljava/commit/07f94fa. +- Fixes #334: exception in Either.LeftProjection.traverseIO, see #335 https://github.com/functionaljava/functionaljava/pull/335 == Internal -* TODO. +- Added Scalacheck Arbitrary implementations for Natural and NonEmptyList, see https://github.com/functionaljava/functionaljava/commit/405c3ec +- Added unit test coverage for Semigroup implementations. The StringBuffer and StringBuilder tests fail because both of those types are mutable. The IO test fails because the ArbitraryIO implementation does not implement equals. See https://github.com/functionaljava/functionaljava/commit/ef81130. +- Fixed the ArbitraryIO implementation and created a Properties object for testing the IO semigroup. See https://github.com/functionaljava/functionaljava/commit/a8e979f. +- Equal: remove reference to static field of LazyString. Fix #321, see https://github.com/functionaljava/functionaljava/commit/6c6dabd. +- Add IOFunctions tests, see #340 https://github.com/functionaljava/functionaljava/pull/340. +- Add Stream tests, see #341 https://github.com/functionaljava/functionaljava/pull/341. +- Add tests for Try, F, FW, Digit. See #346 https://github.com/functionaljava/functionaljava/pull/346 +- Add Vector tests, see #347 https://github.com/functionaljava/functionaljava/pull/347 +- Add Optic tests, see #348 https://github.com/functionaljava/functionaljava/pull/348 +- Add Parser tests, see #349 https://github.com/functionaljava/functionaljava/pull/349 +- Add FingerTree tests, see #351 https://github.com/functionaljava/functionaljava/pull/351 +- Add TreeZipper tests, see #352 https://github.com/functionaljava/functionaljava/pull/352 +- Add Reader/Writer tests, see #353 https://github.com/functionaljava/functionaljava/pull/353 == Breaking Changes -* TODO. +None. == Documentation -* TODO. +None. == Contributors -* TODO. +* Jean Baptiste Giraudeau +* Ryan Johnson +* l1cache (cache@bk.ru) +* Gabor Liptak +* janbols +* Iaroslav Zeigerman +* Signey Quitorio + diff --git a/etc/release-process.txt b/etc/release-process.txt index e9bdbb15..2a87eef2 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -41,3 +41,38 @@ Update the website and Github README.adoc. This includes adding any features to Send a message to the group and social media about the release, TODO. +Setup Artifact Signing +====================== +The below text is a summary from https://gist.github.com/phit/bd3c6d156a2fa5f3b1bc15fa94b3256c. + +As of 2021-02-12, for Windows download Gpg4win 3.1.15 at https://gpg4win.org/index.html. You need to provide 3 things: +- the public key id +- the path to the secret key ring file for your private key +- the passphrase for your private key + +Open a command prompt and run "gpg --gen-key" and follow the prompts. +Get your key id by running: "gpg --list-key" + +Example output: + +gpg: checking the trustdb +gpg: marginals needed: 3 completes needed: 1 trust model: pgp +gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u +gpg: next trustdb check due at 2019-06-17 +C:/Users/phit/AppData/Roaming/gnupg/pubring.kbx +----------------------------------------------- +pub rsa2048 2017-06-17 [SC] [expires: 2019-06-17] + 77273D57FA5140E5A91905087A1B92B81840D019 +uid [ultimate] phit@hush.com +sub rsa2048 2017-06-17 [E] [expires: 2019-06-17] + +In this case we only have one key, 77273D57FA5140E5A91905087A1B92B81840D019 or short* 1840D019 which is basically just the last 8 characters of the long ID. + +Export the key using "gpg --export-secret-key > %UserProfile%\secring.gpg" + +In %UserProfile%\.gradle\gradle.properties, set the values below: + +signing.keyId=XXXXXXXX +signing.password=mypassword +signing.secretKeyRingFile=path/to/secring.gpg + From e9aa23acf3d2b53b9b114dd2e75f163028e52c42 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Mar 2021 01:15:54 +1000 Subject: [PATCH 281/336] Removed obsolete change log file and directed from the readme to the release notes dir --- ChangeLog.md | 52 ---------------------------------------------------- README.adoc | 4 ++++ 2 files changed, 4 insertions(+), 52 deletions(-) delete mode 100644 ChangeLog.md diff --git a/ChangeLog.md b/ChangeLog.md deleted file mode 100644 index acdbedea..00000000 --- a/ChangeLog.md +++ /dev/null @@ -1,52 +0,0 @@ -4.8.1 ------ - -### Enhancements - -- Add Trampoline.suspend(final F0> a). (see [#367](https://github.com/functionaljava/functionaljava/pull/367)); - -### Fixes - -- Fix regression in lifted semigroup sum. Fix #365 (see [#366](https://github.com/functionaljava/functionaljava/pull/366)); - -### Internal - -- Fix compile under jdk11. Enable jdk11 travis build. (see [#361](https://github.com/functionaljava/functionaljava/pull/361)); -- Fix warnings (see [#369](https://github.com/functionaljava/functionaljava/pull/369)); -- Add P tests (see [#360](https://github.com/functionaljava/functionaljava/pull/360)); -- Exclude consume/ from coverage (see [#357](https://github.com/functionaljava/functionaljava/pull/357)); -- Add DList tests (see [#356](https://github.com/functionaljava/functionaljava/pull/356)); -- Add Visitor tests (see [#354](https://github.com/functionaljava/functionaljava/pull/354)); - -4.8 ---- - -### Enhancements - -- Enable upload of snapshot artifacts. (see [`e834e8b`](https://github.com/functionaljava/functionaljava/commit/e834e8b)); -- Add append methods to all Px classes. Fix #326 (see [`065ed43`](https://github.com/functionaljava/functionaljava/commit/065ed43)); -- Introduce the Eval monad (see [`98294fc`](https://github.com/functionaljava/functionaljava/commit/98294fc)); -- Fluent Equal/Ord construction (see [#333](https://github.com/functionaljava/functionaljava/pull/333)); -- Implement Zipper Eq and Hash and add tests (see [#343](https://github.com/functionaljava/functionaljava/pull/343)); -- Implement Vector equals (see [#350](https://github.com/functionaljava/functionaljava/pull/350)); - -### Fixes - -- Fixed a bug in the NonEmptyList Semigroup implementation that resulted in the same NonEmptyList appended to itself. (Regression in 4.7, see [`07f94fa`](https://github.com/functionaljava/functionaljava/commit/07f94fa)); -- Fixes #334: exception in Either.LeftProjection.traverseIO (see [#335](https://github.com/functionaljava/functionaljava/pull/335)); - -### Internal - -- Added Scalacheck Arbitrary implementations for Natural and NonEmptyList. (see [`405c3ec`](https://github.com/functionaljava/functionaljava/commit/405c3ec)); -- Added unit test coverage for Semigroup implementations. The StringBuffer and StringBuilder tests fail because both of those types are mutable. The IO test fails because the ArbitraryIO implementation does not implement equals. (see [`ef81130`](https://github.com/functionaljava/functionaljava/commit/ef81130)); -- Fixed the ArbitraryIO implementation and created a Properties object for testing the IO semigroup. (see [`a8e979f`](https://github.com/functionaljava/functionaljava/commit/a8e979f)); -- Equal: remove reference to static field of LazyString. Fix #321 (see [`6c6dabd`](https://github.com/functionaljava/functionaljava/commit/6c6dabd)); -- Add IOFunctions tests (see [#340](https://github.com/functionaljava/functionaljava/pull/340)); -- Add Stream tests (see [#341](https://github.com/functionaljava/functionaljava/pull/341)); -- Add tests for Try, F, FW, Digit (see [#346](https://github.com/functionaljava/functionaljava/pull/346)); -- Add Vector tests (see [#347](https://github.com/functionaljava/functionaljava/pull/347)); -- Add Optic tests (see [#348](https://github.com/functionaljava/functionaljava/pull/348)); -- Add Parser tests (see [#349](https://github.com/functionaljava/functionaljava/pull/349)); -- Add FingerTree tests (see [#351](https://github.com/functionaljava/functionaljava/pull/351)); -- Add TreeZipper tests (see [#352](https://github.com/functionaljava/functionaljava/pull/352)); -- Add Reader/Writer tests (see [#353](https://github.com/functionaljava/functionaljava/pull/353)); diff --git a/README.adoc b/README.adoc index 8a3ad347..cb53d003 100644 --- a/README.adoc +++ b/README.adoc @@ -122,3 +122,7 @@ A more complete description of the features mentioned above are: == License link:etc/LICENCE[The Functional Java license] uses the BSD 3 license (3-clause license) available at https://en.wikipedia.org/wiki/BSD_licenses[]. + +== Release Notes + +For release notes for each version, see the directory etc/release-notes. \ No newline at end of file From 9da757d0777a6bd19b37c52e44ceefec1bcb26d5 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Mar 2021 01:20:56 +1000 Subject: [PATCH 282/336] Prepare for 4.9 release --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index c9d8be40..c264be1c 100644 --- a/build.gradle +++ b/build.gradle @@ -47,7 +47,7 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true + isSnapshot = false fjBaseVersion = "4.9" snapshotAppendix = "-SNAPSHOT" @@ -55,7 +55,7 @@ allprojects { fjConsumeVersion = "4.8.1" signModule = false - useRetroLambda = false + useRetroLambda = true projectTitle = "Functional Java" projectName = "functionaljava" From c18ab08039573891c54ddd88cc41a77844587272 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Mar 2021 01:43:16 +1000 Subject: [PATCH 283/336] Created 4.9 release notes --- etc/release-notes/release-notes-4.9.adoc | 42 ++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 etc/release-notes/release-notes-4.9.adoc diff --git a/etc/release-notes/release-notes-4.9.adoc b/etc/release-notes/release-notes-4.9.adoc new file mode 100644 index 00000000..62db8e99 --- /dev/null +++ b/etc/release-notes/release-notes-4.9.adoc @@ -0,0 +1,42 @@ + += Release 4.9 + +Released: 14 March 2021 + +== Enhancements + +* Added Gen.streamOf(Gen) +* Added Option.sequence(Validation>) +* Added Gen.sequence(Validation>) +* Added Validation sequence and traverse functions to support various types. Added success and fails functions. +* Added Option sequence and traverse functions for various types. +* Added Seq.bind. +* Added List sequence and traverse functions for various types. +* Added Ord.seqOrd +* Added Seq sequence and traverse functions for various types. +* Added functions to Either. +* Added State bind synonym for flatMap. +* Added Steam sequence and traverse functions for various types. + +== Fixes + +* Fixed Validation.accumulate functions. + +== Internal + +* Support JPMS modules through 'Automatic-Module-Name'. + +== Breaking Changes + +* None. + +== Documentation + +* None. + +== Contributors + +* Jean Baptiste Giraudeau +* Gregoire Neuville +* Drew Taylor +* Mark Perry From c7dbd3fda84fec43b3104e0b60dc2a316a98fff4 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 13 Mar 2021 17:30:24 +1000 Subject: [PATCH 284/336] Prep for 4.9 release --- etc/release-process.txt | 17 +++++++++++++++++ gradle.properties | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/etc/release-process.txt b/etc/release-process.txt index 2a87eef2..b22ec4e4 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -76,3 +76,20 @@ signing.keyId=XXXXXXXX signing.password=mypassword signing.secretKeyRingFile=path/to/secring.gpg +Upload your key + +C:\repos\functionaljava>gpg --list-key +C:/Users/maper/AppData/Roaming/gnupg/pubring.kbx +------------------------------------------------ +pub rsa3072 2021-02-12 [SC] [expires: 2023-02-12] + E86A4EC34F25A9CF6118582A7985AAE03F41B2F9 +uid [ultimate] Mark Perry +sub rsa3072 2021-02-12 [E] [expires: 2023-02-12] + + +C:\repos\functionaljava>gpg --keyserver hkp://keyserver.ubuntu.com --send-keys E86A4EC34F25A9CF6118582A7985AAE03F41B2F9 +gpg: sending key 7985AAE03F41B2F9 to hkp://keyserver.ubuntu.com + +gradle upload (takes about 3 mins) + + diff --git a/gradle.properties b/gradle.properties index d4552a30..07c2b60c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = false +signingEnabled = true From bcb4d199d2a82eafa7adf1b6b91246db29e45818 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 1 Apr 2021 17:45:39 +1000 Subject: [PATCH 285/336] Upgrade from Gradle 5.6.2 to 6.8.3 --- build.gradle | 26 +++++++++++------------- gradle/wrapper/gradle-wrapper.properties | 2 +- props-core-scalacheck/build.gradle | 4 ++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index d1b829d3..bcd01f5e 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ buildscript { dependencies { classpath "com.github.ben-manes:gradle-versions-plugin:0.27.0" + classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:5.3.0" } wrapper { @@ -20,6 +21,7 @@ buildscript { } } + if (JavaVersion.current().isJava8Compatible()) { allprojects { tasks.withType(Javadoc) { @@ -117,8 +119,8 @@ task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { executionData fileTree(project.rootDir.absolutePath).include("**/build/jacoco/*.exec") // We only care about coverage of: def projectForFoverage = ["core", "quickcheck", "java-core"] - classDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.output) - sourceDirectories = files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.allSource.srcDirs) + getClassDirectories().from(files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.output)) + getSourceDirectories().from(files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.allSource.srcDirs)) reports { html.enabled = true @@ -130,8 +132,7 @@ configure(subprojects.findAll { it.name != "props-core" }) { apply plugin: "maven" apply plugin: "signing" - apply plugin: "osgi" - + apply plugin: "biz.aQute.bnd.builder" sourceCompatibility = "1.8" javadoc { @@ -156,16 +157,13 @@ configure(subprojects.findAll { it.name != "props-core" }) { jar { version project.fjVersion - manifest { - name = 'Functional Java' - instruction 'Signature-Version', project.fjVersion - instruction 'Bundle-ActivationPolicy', 'lazy' - instruction 'Bundle-Vendor', 'functionaljava.org' - if(project.name != "core") { - instruction 'Require-Bundle', 'org.functionaljava;bundle-version="'+project.fjBaseVersion+'"' - } - instruction 'Automatic-Module-Name', "functionaljava${project.name == 'core' ? '' : ".$project.name"}" - } + bnd ( + 'Bundle-Name': 'Functional Java', + 'Signature-Version': project.fjVersion, + 'Bundle-ActivationPolicy': 'lazy', + 'Bundle-Vendor': 'functionaljava.org', + 'Automatic-Module-Name': "functionaljava${project.name == 'core' ? '' : ".$project.name"}", + ) } eclipse { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ca9d6281..8cf6eb5a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index 5207bf50..f26b5425 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -19,5 +19,9 @@ dependencies { testRuntime junitRuntime } +tasks.withType(ScalaCompile) { + scalaCompileOptions.additionalParameters = ["-feature", "-language:implicitConversions", "-language:postfixOps"] +} + performSigning(signingEnabled, signModule) configureUpload(signingEnabled, signModule) From 3ddcfe6e15ec840d27719c47c67be493061552d0 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 1 Apr 2021 17:46:08 +1000 Subject: [PATCH 286/336] Target Java 8 JVM --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index bcd01f5e..62f48dde 100644 --- a/build.gradle +++ b/build.gradle @@ -106,7 +106,7 @@ subprojects { } tasks.withType(JavaCompile) { - options.compilerArgs.addAll(['--release', '10']) + options.compilerArgs.addAll(['--release', '8']) if (displayCompilerWarnings) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } From 851245c47700063529f55ac416dea09cb55c7bc2 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 1 Apr 2021 17:52:35 +1000 Subject: [PATCH 287/336] Don't sign modules by default --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 07c2b60c..d4552a30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = true +signingEnabled = false From fe4607210b0fdff9d1824b2e166a084bcd3ec32b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 1 Apr 2021 17:52:54 +1000 Subject: [PATCH 288/336] Updated gradle version to 6.8.3 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 62f48dde..57c36c18 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { } wrapper { - gradleVersion = "5.6.2" + gradleVersion = "6.8.3" distributionType = Wrapper.DistributionType.ALL } } From 50aee0c7e35e128b5bdce7b8278ee98d27b16c4a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 2 Apr 2021 00:15:18 +1000 Subject: [PATCH 289/336] Removed F1Functions, F1W, F2Functions and F2W --- core/src/main/java/fj/F.java | 681 ++++++++- core/src/main/java/fj/F1Functions.java | 687 --------- core/src/main/java/fj/F1W.java | 687 --------- core/src/main/java/fj/F2.java | 274 +++- core/src/main/java/fj/F2Functions.java | 273 ---- core/src/main/java/fj/F2W.java | 254 --- core/src/main/java/fj/Monoid.java | 4 +- core/src/main/java/fj/P1.java | 2 +- core/src/main/java/fj/P2.java | 4 +- core/src/main/java/fj/P3.java | 6 +- core/src/main/java/fj/P4.java | 8 +- core/src/main/java/fj/P5.java | 10 +- core/src/main/java/fj/P6.java | 12 +- core/src/main/java/fj/P7.java | 14 +- core/src/main/java/fj/P8.java | 16 +- core/src/main/java/fj/Semigroup.java | 5 +- core/src/main/java/fj/control/Trampoline.java | 9 +- .../java/fj/control/parallel/ParModule.java | 4 +- core/src/main/java/fj/data/IOFunctions.java | 5 +- core/src/main/java/fj/data/Iteratee.java | 3 +- core/src/main/java/fj/data/List.java | 2 +- core/src/main/java/fj/data/NonEmptyList.java | 3 +- core/src/main/java/fj/data/Reader.java | 3 +- core/src/main/java/fj/data/Tree.java | 4 +- core/src/main/java/fj/data/TreeMap.java | 7 +- core/src/main/java/fj/data/TreeZipper.java | 1356 ++++++++--------- core/src/main/java/fj/data/Zipper.java | 1170 +++++++------- .../java/fj/data/fingertrees/FingerTree.java | 536 +++---- core/src/test/java/fj/FFunctionsTest.java | 90 +- core/src/test/java/fj/FWFunctionsTest.java | 23 - .../test/java/fj/data/IOFunctionsTest.java | 3 +- .../test/java/fj/function/StringsTest.java | 3 +- .../main/java/fj/demo/Comonad_example.java | 3 +- demo/src/main/java/fj/demo/IODemo.java | 5 +- demo/src/main/java/fj/demo/IOWalkthrough.java | 7 +- demo/src/main/java/fj/demo/Primes2.java | 4 +- .../main/java/fj/demo/WriterDemo_Halver.java | 3 +- .../java/fj/demo/concurrent/MapReduce.java | 15 +- .../src/main/java/fj/demo/euler/Problem2.java | 6 +- .../src/test/scala/fj/data/CheckHashMap.scala | 236 +-- .../test/scala/fj/data/CheckIteratee.scala | 3 +- .../src/test/java/fj/data/ReaderTest.java | 6 +- 42 files changed, 2730 insertions(+), 3716 deletions(-) delete mode 100644 core/src/main/java/fj/F1Functions.java delete mode 100644 core/src/main/java/fj/F1W.java delete mode 100644 core/src/main/java/fj/F2Functions.java delete mode 100644 core/src/main/java/fj/F2W.java delete mode 100644 core/src/test/java/fj/FWFunctionsTest.java diff --git a/core/src/main/java/fj/F.java b/core/src/main/java/fj/F.java index e2db316e..d2208236 100644 --- a/core/src/main/java/fj/F.java +++ b/core/src/main/java/fj/F.java @@ -1,12 +1,27 @@ package fj; +import fj.control.parallel.Actor; +import fj.control.parallel.Promise; +import fj.control.parallel.Strategy; +import fj.data.*; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.TreeSet; +import java.util.concurrent.*; +import java.util.function.Function; + +import static fj.data.Option.some; +import static fj.data.Stream.iterableStream; +import static fj.data.Zipper.fromStream; + /** * A transformation or function from A to B. This type can be represented * using the Java 7 closure syntax. * * @version %build.number% */ -public interface F { +public interface F extends Function { /** * Transform A to B. * @@ -15,4 +30,668 @@ public interface F { */ B f(A a); + default B apply(A a) { + return f(a); + } + + /** + * Function composition + * + * @param g A function to compose with this one. + * @return The composed function such that this function is applied last. + */ + default F o(final F g) { + return c -> f(g.f(c)); + } + + /** + * First-class function composition + * + * @return A function that composes this function with another. + */ + default F, F> o() { + return g -> o(g); + } + + /** + * Function composition flipped. + * + * @param g A function with which to compose this one. + * @return The composed function such that this function is applied first. + */ + @SuppressWarnings("unchecked") + default F andThen(final F g) { + return g.o(this); + } + + /** + * First-class composition flipped. + * + * @return A function that invokes this function and then a given function on the result. + */ + default F, F> andThen() { + return g -> andThen(g); + } + + /** + * Binds a given function across this function (Reader Monad). + * + * @param g A function that takes the return value of this function as an argument, yielding a new function. + * @return A function that invokes this function on its argument and then the given function on the result. + */ + default F bind(final F> g) { + return a -> g.f(f(a)).f(a); + } + + /** + * First-class function binding. + * + * @return A function that binds another function across this function. + */ + default F>, F> bind() { + return g -> bind(g); + } + + /** + * Function application in an environment (Applicative Functor). + * + * @param g A function with the same argument type as this function, yielding a function that takes the return + * value of this function. + * @return A new function that invokes the given function on its argument, yielding a new function that is then + * applied to the result of applying this function to the argument. + */ + default F apply(final F> g) { + return a -> g.f(a).f(f(a)); + } + + /** + * First-class function application in an environment. + * + * @return A function that applies a given function within the environment of this function. + */ + default F>, F> apply() { + return g -> apply(g); + } + + /** + * Applies this function over the arguments of another function. + * + * @param g The function over whose arguments to apply this function. + * @return A new function that invokes this function on its arguments before invoking the given function. + */ + default F> on(final F> g) { + return a1 -> a2 -> g.f(f(a1)).f(f(a2)); + } + + + + /** + * Applies this function over the arguments of another function. + * + * @return A function that applies this function over the arguments of another function. + */ + default F>, F>> on() { + return g -> on(g); + } + + /** + * Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1. + * + * @return This function promoted to return its result in a product-1. + */ + default F> lazy() { + return a -> P.lazy(() -> f(a)); + } + + /** + * Partial application. + * + * @param a The A to which to apply this function. + * @return The function partially applied to the given argument to return a lazy value. + */ + default P1 partial(final A a) { + return P.lazy(() -> f(a)); + } + + /** + * Promotes this function to map over a product-1. + * + * @return This function promoted to map over a product-1. + */ + default F, P1> mapP1() { + return p -> p.map(this); + } + + /** + * Promotes this function so that it returns its result in an Option. Kleisli arrow for Option. + * + * @return This function promoted to return its result in an Option. + */ + default F> optionK() { + return a -> some(f(a)); + } + + /** + * Promotes this function to map over an optional value. + * + * @return This function promoted to map over an optional value. + */ + default F, Option> mapOption() { + return o -> o.map(this); + } + + /** + * Promotes this function so that it returns its result in a List. Kleisli arrow for List. + * + * @return This function promoted to return its result in a List. + */ + default F> listK() { + return a -> List.single(f(a)); + } + + /** + * Promotes this function to map over a List. + * + * @return This function promoted to map over a List. + */ + default F, List> mapList() { + return x -> x.map(this); + } + + /** + * Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream. + * + * @return This function promoted to return its result in a Stream. + */ + default F> streamK() { + return a -> Stream.single(f(a)); + } + + /** + * Promotes this function to map over a Stream. + * + * @return This function promoted to map over a Stream. + */ + default F, Stream> mapStream() { + return x -> x.map(this); + } + + /** + * Promotes this function so that it returns its result in a Array. Kleisli arrow for Array. + * + * @return This function promoted to return its result in a Array. + */ + default F> arrayK() { + return a -> Array.single(f(a)); + + } + + /** + * Promotes this function to map over a Array. + * + * @return This function promoted to map over a Array. + */ + default F, Array> mapArray() { + return x -> x.map(this); + } + + /** + * Returns a function that contramaps over a given actor. + * + * @return A function that contramaps over a given actor. + */ + default F, Actor> contramapActor() { + return a -> a.contramap(this); + } + + /** + * Promotes this function to a concurrent function that returns a Promise of a value. + * + * @param s A parallel strategy for concurrent execution. + * @return A concurrent function that returns a Promise of a value. + */ + default F> promiseK(final Strategy s) { + return Promise.promise(s, this); + } + + /** + * Promotes this function to map over a Promise. + * + * @return This function promoted to map over Promises. + */ + default F, Promise> mapPromise() { + return p -> p.fmap(this); + } + + /** + * Promotes this function so that it returns its result on the left side of an Either. + * Kleisli arrow for the Either left projection. + * + * @return This function promoted to return its result on the left side of an Either. + */ + @SuppressWarnings("unchecked") + default F> eitherLeftK() { + return Either.left_().o(this); + } + + /** + * Promotes this function so that it returns its result on the right side of an Either. + * Kleisli arrow for the Either right projection. + * + * @return This function promoted to return its result on the right side of an Either. + */ + @SuppressWarnings("unchecked") + default F> eitherRightK() { + return Either.right_().o(this); + } + + /** + * Promotes this function to map over the left side of an Either. + * + * @return This function promoted to map over the left side of an Either. + */ + @SuppressWarnings("unchecked") + default F, Either> mapLeft() { + return Either.leftMap_().f(this); + } + + /** + * Promotes this function to map over the right side of an Either. + * + * @return This function promoted to map over the right side of an Either. + */ + @SuppressWarnings("unchecked") + default F, Either> mapRight() { + return Either.rightMap_().f(this); + } + + /** + * Returns a function that returns the left side of a given Either, or this function applied to the right side. + * + * @return a function that returns the left side of a given Either, or this function applied to the right side. + */ + default F, B> onLeft() { + return e -> e.left().on(this); + } + + /** + * Returns a function that returns the right side of a given Either, or this function applied to the left side. + * + * @return a function that returns the right side of a given Either, or this function applied to the left side. + */ + default F, B> onRight() { + return e -> e.right().on(this); + } + + /** + * Promotes this function to return its value in an Iterable. + * + * @return This function promoted to return its value in an Iterable. + */ + @SuppressWarnings("unchecked") + default F> iterableK() { + return IterableW.arrow().f(this); + } + + /** + * Promotes this function to map over Iterables. + * + * @return This function promoted to map over Iterables. + */ + @SuppressWarnings("unchecked") + default F, IterableW> mapIterable() { + return IterableW.map().f(this).o(IterableW.wrap()); + } + + /** + * Promotes this function to return its value in a NonEmptyList. + * + * @return This function promoted to return its value in a NonEmptyList. + */ + @SuppressWarnings("unchecked") + default F> nelK() { + return NonEmptyList.nel().o(this); + } + + /** + * Promotes this function to map over a NonEmptyList. + * + * @return This function promoted to map over a NonEmptyList. + */ + default F, NonEmptyList> mapNel() { + return list -> list.map(this); + } + + /** + * Promotes this function to return its value in a Set. + * + * @param o An order for the set. + * @return This function promoted to return its value in a Set. + */ + default F> setK(final Ord o) { + return a -> Set.single(o, f(a)); + } + + /** + * Promotes this function to map over a Set. + * + * @param o An order for the resulting set. + * @return This function promoted to map over a Set. + */ + default F, Set> mapSet(final Ord o) { + return s -> s.map(o, this); + } + + /** + * Promotes this function to return its value in a Tree. + * + * @return This function promoted to return its value in a Tree. + */ + default F> treeK() { + return a -> Tree.leaf(f(a)); + } + + /** + * Promotes this function to map over a Tree. + * + * @return This function promoted to map over a Tree. + */ + @SuppressWarnings("unchecked") + default F, Tree> mapTree() { + return Tree.fmap_().f(this); + } + + /** + * Returns a function that maps this function over a tree and folds it with the given monoid. + * + * @param m The monoid with which to fold the mapped tree. + * @return a function that maps this function over a tree and folds it with the given monoid. + */ + default F, B> foldMapTree(final Monoid m) { + return Tree.foldMap_(this, m); + } + + /** + * Promotes this function to return its value in a TreeZipper. + * + * @return This function promoted to return its value in a TreeZipper. + */ + default F> treeZipperK() { + return treeK().andThen(TreeZipper.fromTree()); + } + + /** + * Promotes this function to map over a TreeZipper. + * + * @return This function promoted to map over a TreeZipper. + */ + default F, TreeZipper> mapTreeZipper() { + return z -> z.map(this); + } + + /** + * Promotes this function so that it returns its result on the failure side of a Validation. + * Kleisli arrow for the Validation failure projection. + * + * @return This function promoted to return its result on the failure side of a Validation. + */ + default F> failK() { + return a -> Validation.fail(f(a)); + + } + + /** + * Promotes this function so that it returns its result on the success side of an Validation. + * Kleisli arrow for the Validation success projection. + * + * @return This function promoted to return its result on the success side of an Validation. + */ + default F> successK() { + return a -> Validation.success(f(a)); + } + + /** + * Promotes this function to map over the failure side of a Validation. + * + * @return This function promoted to map over the failure side of a Validation. + */ + default F, Validation> mapFail() { + return v -> v.f().map(this); + } + + /** + * Promotes this function to map over the success side of a Validation. + * + * @return This function promoted to map over the success side of a Validation. + */ + default F, Validation> mapSuccess() { + return v -> v.map(this); + } + + /** + * Returns a function that returns the failure side of a given Validation, + * or this function applied to the success side. + * + * @return a function that returns the failure side of a given Validation, + * or this function applied to the success side. + */ + default F, B> onFail() { + return v -> v.f().on(this); + } + + /** + * Returns a function that returns the success side of a given Validation, + * or this function applied to the failure side. + * + * @return a function that returns the success side of a given Validation, + * or this function applied to the failure side. + */ + default F, B> onSuccess() { + return v -> v.on(this); + } + + /** + * Promotes this function to return its value in a Zipper. + * + * @return This function promoted to return its value in a Zipper. + */ + default F> zipperK() { + return streamK().andThen(s -> fromStream(s).some()); + } + + /** + * Promotes this function to map over a Zipper. + * + * @return This function promoted to map over a Zipper. + */ + default F, Zipper> mapZipper() { + return z -> z.map(this); + } + + /** + * Promotes this function to map over an Equal as a contravariant functor. + * + * @return This function promoted to map over an Equal as a contravariant functor. + */ + default F, Equal> contramapEqual() { + return e -> e.contramap(this); + } + + /** + * Promotes this function to map over a Hash as a contravariant functor. + * + * @return This function promoted to map over a Hash as a contravariant functor. + */ + default F, Hash> contramapHash() { + return h -> h.contramap(this); + } + + /** + * Promotes this function to map over a Show as a contravariant functor. + * + * @return This function promoted to map over a Show as a contravariant functor. + */ + default F, Show> contramapShow() { + return s -> s.contramap(this); + } + + /** + * Promotes this function to map over the first element of a pair. + * + * @return This function promoted to map over the first element of a pair. + */ + default F, P2> mapFst() { + return P2.map1_(this); + } + + /** + * Promotes this function to map over the second element of a pair. + * + * @return This function promoted to map over the second element of a pair. + */ + default F, P2> mapSnd() { + return P2.map2_(this); + } + + /** + * Promotes this function to map over both elements of a pair. + * + * @return This function promoted to map over both elements of a pair. + */ + default F, P2> mapBoth() { + return p2 -> P2.map(this, p2); + } + + /** + * Maps this function over a SynchronousQueue. + * + * @param as A SynchronousQueue to map this function over. + * @return A new SynchronousQueue with this function applied to each element. + */ + default SynchronousQueue mapJ(final SynchronousQueue as) { + final SynchronousQueue bs = new SynchronousQueue<>(); + bs.addAll(iterableStream(as).map(this).toCollection()); + return bs; + } + + + /** + * Maps this function over a PriorityBlockingQueue. + * + * @param as A PriorityBlockingQueue to map this function over. + * @return A new PriorityBlockingQueue with this function applied to each element. + */ + default PriorityBlockingQueue mapJ(final PriorityBlockingQueue as) { + return new PriorityBlockingQueue<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a LinkedBlockingQueue. + * + * @param as A LinkedBlockingQueue to map this function over. + * @return A new LinkedBlockingQueue with this function applied to each element. + */ + default LinkedBlockingQueue mapJ(final LinkedBlockingQueue as) { + return new LinkedBlockingQueue<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a CopyOnWriteArraySet. + * + * @param as A CopyOnWriteArraySet to map this function over. + * @return A new CopyOnWriteArraySet with this function applied to each element. + */ + default CopyOnWriteArraySet mapJ(final CopyOnWriteArraySet as) { + return new CopyOnWriteArraySet<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a CopyOnWriteArrayList. + * + * @param as A CopyOnWriteArrayList to map this function over. + * @return A new CopyOnWriteArrayList with this function applied to each element. + */ + default CopyOnWriteArrayList mapJ(final CopyOnWriteArrayList as) { + return new CopyOnWriteArrayList<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a ConcurrentLinkedQueue. + * + * @param as A ConcurrentLinkedQueue to map this function over. + * @return A new ConcurrentLinkedQueue with this function applied to each element. + */ + default ConcurrentLinkedQueue mapJ(final ConcurrentLinkedQueue as) { + return new ConcurrentLinkedQueue<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over an ArrayBlockingQueue. + * + * @param as An ArrayBlockingQueue to map this function over. + * @return A new ArrayBlockingQueue with this function applied to each element. + */ + default ArrayBlockingQueue mapJ(final ArrayBlockingQueue as) { + final ArrayBlockingQueue bs = new ArrayBlockingQueue<>(as.size()); + bs.addAll(iterableStream(as).map(this).toCollection()); + return bs; + } + + + /** + * Maps this function over a TreeSet. + * + * @param as A TreeSet to map this function over. + * @return A new TreeSet with this function applied to each element. + */ + default TreeSet mapJ(final TreeSet as) { + return new TreeSet<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a PriorityQueue. + * + * @param as A PriorityQueue to map this function over. + * @return A new PriorityQueue with this function applied to each element. + */ + default java.util.PriorityQueue mapJ(final java.util.PriorityQueue as) { + return new java.util.PriorityQueue<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over a LinkedList. + * + * @param as A LinkedList to map this function over. + * @return A new LinkedList with this function applied to each element. + */ + default LinkedList mapJ(final LinkedList as) { + return new LinkedList<>(iterableStream(as).map(this).toCollection()); + } + + /** + * Maps this function over an ArrayList. + * + * @param as An ArrayList to map this function over. + * @return A new ArrayList with this function applied to each element. + */ + default ArrayList mapJ(final ArrayList as) { + return new ArrayList<>(iterableStream(as).map(this).toCollection()); + } + + default F map(F f) { + return f.o(this); + } + + default F contramap(F f) { + return o(f); + } + + /** + * Both map (with g) and contramap (with f) the target function. (Profunctor pattern) + */ + default F dimap(F f, F g) { + return c -> g.f(f(f.f(c))); + } + + } diff --git a/core/src/main/java/fj/F1Functions.java b/core/src/main/java/fj/F1Functions.java deleted file mode 100644 index 00bdf515..00000000 --- a/core/src/main/java/fj/F1Functions.java +++ /dev/null @@ -1,687 +0,0 @@ -package fj; - -import fj.control.parallel.Actor; -import fj.control.parallel.Promise; -import fj.control.parallel.Strategy; -import fj.data.*; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.PriorityQueue; -import java.util.TreeSet; -import java.util.concurrent.*; - -import static fj.data.Option.some; -import static fj.data.Stream.iterableStream; -import static fj.data.Zipper.fromStream; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F1Functions { - - - private F1Functions() { - } - - /** - * Function composition - * - * @param g A function to compose with this one. - * @return The composed function such that this function is applied last. - */ - public static F o(final F f, final F g) { - return c -> f.f(g.f(c)); - } - - /** - * First-class function composition - * - * @return A function that composes this function with another. - */ - public static F, F> o(final F f) { - return g -> o(f, g); - } - - /** - * Function composition flipped. - * - * @param g A function with which to compose this one. - * @return The composed function such that this function is applied first. - */ - @SuppressWarnings("unchecked") - public static F andThen(final F f, final F g) { - return o(g, f); - } - - /** - * First-class composition flipped. - * - * @return A function that invokes this function and then a given function on the result. - */ - public static F, F> andThen(final F f) { - return g -> andThen(f, g); - } - - /** - * Binds a given function across this function (Reader Monad). - * - * @param g A function that takes the return value of this function as an argument, yielding a new function. - * @return A function that invokes this function on its argument and then the given function on the result. - */ - public static F bind(final F f, final F> g) { - return a -> g.f(f.f(a)).f(a); - } - - /** - * First-class function binding. - * - * @return A function that binds another function across this function. - */ - public static F>, F> bind(final F f) { - return g -> bind(f, g); - } - - /** - * Function application in an environment (Applicative Functor). - * - * @param g A function with the same argument type as this function, yielding a function that takes the return - * value of this function. - * @return A new function that invokes the given function on its argument, yielding a new function that is then - * applied to the result of applying this function to the argument. - */ - public static F apply(final F f, final F> g) { - return a -> g.f(a).f(f.f(a)); - } - - /** - * First-class function application in an environment. - * - * @return A function that applies a given function within the environment of this function. - */ - public static F>, F> apply(final F f) { - return g -> apply(f, g); - } - - /** - * Applies this function over the arguments of another function. - * - * @param g The function over whose arguments to apply this function. - * @return A new function that invokes this function on its arguments before invoking the given function. - */ - public static F> on(final F f, final F> g) { - return a1 -> a2 -> g.f(f.f(a1)).f(f.f(a2)); - } - - - - /** - * Applies this function over the arguments of another function. - * - * @return A function that applies this function over the arguments of another function. - */ - public static F>, F>> on(final F f) { - return g -> on(f, g); - } - - /** - * Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1. - * - * @return This function promoted to return its result in a product-1. - */ - public static F> lazy(final F f) { - return a -> P.lazy(() -> f.f(a)); - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument to return a lazy value. - */ - public static P1 f(final F f, final A a) { - return P.lazy(() -> f.f(a)); - } - - /** - * Promotes this function to map over a product-1. - * - * @return This function promoted to map over a product-1. - */ - public static F, P1> mapP1(final F f) { - return p -> p.map(f); - } - - /** - * Promotes this function so that it returns its result in an Option. Kleisli arrow for Option. - * - * @return This function promoted to return its result in an Option. - */ - public static F> optionK(final F f) { - return a -> some(f.f(a)); - } - - /** - * Promotes this function to map over an optional value. - * - * @return This function promoted to map over an optional value. - */ - public static F, Option> mapOption(final F f) { - return o -> o.map(f); - } - - /** - * Promotes this function so that it returns its result in a List. Kleisli arrow for List. - * - * @return This function promoted to return its result in a List. - */ - public static F> listK(final F f) { - return a -> List.single(f.f(a)); - } - - /** - * Promotes this function to map over a List. - * - * @return This function promoted to map over a List. - */ - public static F, List> mapList(final F f) { - return x -> x.map(f); - } - - /** - * Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream. - * - * @return This function promoted to return its result in a Stream. - */ - public static F> streamK(final F f) { - return a -> Stream.single(f.f(a)); - } - - /** - * Promotes this function to map over a Stream. - * - * @return This function promoted to map over a Stream. - */ - public static F, Stream> mapStream(final F f) { - return x -> x.map(f); - } - - /** - * Promotes this function so that it returns its result in a Array. Kleisli arrow for Array. - * - * @return This function promoted to return its result in a Array. - */ - public static F> arrayK(final F f) { - return a -> Array.single(f.f(a)); - - } - - /** - * Promotes this function to map over a Array. - * - * @return This function promoted to map over a Array. - */ - public static F, Array> mapArray(final F f) { - return x -> x.map(f); - } - - /** - * Returns a function that contramaps over a given actor. - * - * @return A function that contramaps over a given actor. - */ - public static F, Actor> contramapActor(final F f) { - return a -> a.contramap(f); - } - - /** - * Promotes this function to a concurrent function that returns a Promise of a value. - * - * @param s A parallel strategy for concurrent execution. - * @return A concurrent function that returns a Promise of a value. - */ - public static F> promiseK(final F f, final Strategy s) { - return Promise.promise(s, f); - } - - /** - * Promotes this function to map over a Promise. - * - * @return This function promoted to map over Promises. - */ - public static F, Promise> mapPromise(final F f) { - return p -> p.fmap(f); - } - - /** - * Promotes this function so that it returns its result on the left side of an Either. - * Kleisli arrow for the Either left projection. - * - * @return This function promoted to return its result on the left side of an Either. - */ - @SuppressWarnings("unchecked") - public static F> eitherLeftK(final F f) { - return o(Either.left_(), f); - } - - /** - * Promotes this function so that it returns its result on the right side of an Either. - * Kleisli arrow for the Either right projection. - * - * @return This function promoted to return its result on the right side of an Either. - */ - @SuppressWarnings("unchecked") - public static F> eitherRightK(final F f) { - return o(Either.right_(), f); - } - - /** - * Promotes this function to map over the left side of an Either. - * - * @return This function promoted to map over the left side of an Either. - */ - @SuppressWarnings("unchecked") - public static F, Either> mapLeft(final F f) { - return Either.leftMap_().f(f); - } - - /** - * Promotes this function to map over the right side of an Either. - * - * @return This function promoted to map over the right side of an Either. - */ - @SuppressWarnings("unchecked") - public static F, Either> mapRight(final F f) { - return Either.rightMap_().f(f); - } - - /** - * Returns a function that returns the left side of a given Either, or this function applied to the right side. - * - * @return a function that returns the left side of a given Either, or this function applied to the right side. - */ - public static F, B> onLeft(final F f) { - return e -> e.left().on(f); - } - - /** - * Returns a function that returns the right side of a given Either, or this function applied to the left side. - * - * @return a function that returns the right side of a given Either, or this function applied to the left side. - */ - public static F, B> onRight(final F f) { - return e -> e.right().on(f); - } - - /** - * Promotes this function to return its value in an Iterable. - * - * @return This function promoted to return its value in an Iterable. - */ - @SuppressWarnings("unchecked") - public static F> iterableK(final F f) { - return IterableW.arrow().f(f); - } - - /** - * Promotes this function to map over Iterables. - * - * @return This function promoted to map over Iterables. - */ - @SuppressWarnings("unchecked") - public static F, IterableW> mapIterable(final F f) { - return o(IterableW.map().f(f), IterableW.wrap()); - } - - /** - * Promotes this function to return its value in a NonEmptyList. - * - * @return This function promoted to return its value in a NonEmptyList. - */ - @SuppressWarnings("unchecked") - public static F> nelK(final F f) { - return o(NonEmptyList.nel(), f); - } - - /** - * Promotes this function to map over a NonEmptyList. - * - * @return This function promoted to map over a NonEmptyList. - */ - public static F, NonEmptyList> mapNel(final F f) { - return list -> list.map(f); - } - - /** - * Promotes this function to return its value in a Set. - * - * @param o An order for the set. - * @return This function promoted to return its value in a Set. - */ - public static F> setK(final F f, final Ord o - ) { - return a -> Set.single(o, f.f(a)); - } - - /** - * Promotes this function to map over a Set. - * - * @param o An order for the resulting set. - * @return This function promoted to map over a Set. - */ - public static F, Set> mapSet(final F f, final Ord o) { - return s -> s.map(o, f); - } - - /** - * Promotes this function to return its value in a Tree. - * - * @return This function promoted to return its value in a Tree. - */ - public static F> treeK(final F f) { - return a -> Tree.leaf(f.f(a)); - } - - /** - * Promotes this function to map over a Tree. - * - * @return This function promoted to map over a Tree. - */ - @SuppressWarnings("unchecked") - public static F, Tree> mapTree(final F f) { - return Tree.fmap_().f(f); - } - - /** - * Returns a function that maps this function over a tree and folds it with the given monoid. - * - * @param m The monoid with which to fold the mapped tree. - * @return a function that maps this function over a tree and folds it with the given monoid. - */ - public static F, B> foldMapTree(final F f, final Monoid m) { - return Tree.foldMap_(f, m); - } - - /** - * Promotes this function to return its value in a TreeZipper. - * - * @return This function promoted to return its value in a TreeZipper. - */ - public static F> treeZipperK(final F f) { - return andThen(treeK(f), TreeZipper.fromTree()); - } - - /** - * Promotes this function to map over a TreeZipper. - * - * @return This function promoted to map over a TreeZipper. - */ - public static F, TreeZipper> mapTreeZipper(final F f) { - return (z) -> z.map(f); - } - - /** - * Promotes this function so that it returns its result on the failure side of a Validation. - * Kleisli arrow for the Validation failure projection. - * - * @return This function promoted to return its result on the failure side of a Validation. - */ - public static F> failK(final F f) { - return a -> Validation.fail(f.f(a)); - - } - - /** - * Promotes this function so that it returns its result on the success side of an Validation. - * Kleisli arrow for the Validation success projection. - * - * @return This function promoted to return its result on the success side of an Validation. - */ - public static F> successK(final F f) { - return a -> Validation.success(f.f(a)); - } - - /** - * Promotes this function to map over the failure side of a Validation. - * - * @return This function promoted to map over the failure side of a Validation. - */ - public static F, Validation> mapFail(final F f) { - return v -> v.f().map(f); - } - - /** - * Promotes this function to map over the success side of a Validation. - * - * @return This function promoted to map over the success side of a Validation. - */ - public static F, Validation> mapSuccess(final F f) { - return v -> v.map(f); - } - - /** - * Returns a function that returns the failure side of a given Validation, - * or this function applied to the success side. - * - * @return a function that returns the failure side of a given Validation, - * or this function applied to the success side. - */ - public static F, B> onFail(final F f) { - return v -> v.f().on(f); - } - - /** - * Returns a function that returns the success side of a given Validation, - * or this function applied to the failure side. - * - * @return a function that returns the success side of a given Validation, - * or this function applied to the failure side. - */ - public static F, B> onSuccess(final F f) { - return v -> v.on(f); - } - - /** - * Promotes this function to return its value in a Zipper. - * - * @return This function promoted to return its value in a Zipper. - */ - public static F> zipperK(final F f) { - return andThen(streamK(f), s -> fromStream(s).some()); - } - - /** - * Promotes this function to map over a Zipper. - * - * @return This function promoted to map over a Zipper. - */ - public static F, Zipper> mapZipper(final F f) { - return z -> z.map(f); - } - - /** - * Promotes this function to map over an Equal as a contravariant functor. - * - * @return This function promoted to map over an Equal as a contravariant functor. - */ - public static F, Equal> contramapEqual(final F f) { - return e -> e.contramap(f); - } - - /** - * Promotes this function to map over a Hash as a contravariant functor. - * - * @return This function promoted to map over a Hash as a contravariant functor. - */ - public static F, Hash> contramapHash(final F f) { - return h -> h.contramap(f); - } - - /** - * Promotes this function to map over a Show as a contravariant functor. - * - * @return This function promoted to map over a Show as a contravariant functor. - */ - public static F, Show> contramapShow(final F f) { - return s -> s.contramap(f); - } - - /** - * Promotes this function to map over the first element of a pair. - * - * @return This function promoted to map over the first element of a pair. - */ - public static F, P2> mapFst(final F f) { - return P2.map1_(f); - } - - /** - * Promotes this function to map over the second element of a pair. - * - * @return This function promoted to map over the second element of a pair. - */ - public static F, P2> mapSnd(final F f) { - return P2.map2_(f); - } - - /** - * Promotes this function to map over both elements of a pair. - * - * @return This function promoted to map over both elements of a pair. - */ - public static F, P2> mapBoth(final F f) { - return p2 -> P2.map(f, p2); - } - - /** - * Maps this function over a SynchronousQueue. - * - * @param as A SynchronousQueue to map this function over. - * @return A new SynchronousQueue with this function applied to each element. - */ - public static SynchronousQueue mapJ(final F f, final SynchronousQueue as) { - final SynchronousQueue bs = new SynchronousQueue<>(); - bs.addAll(iterableStream(as).map(f).toCollection()); - return bs; - } - - - /** - * Maps this function over a PriorityBlockingQueue. - * - * @param as A PriorityBlockingQueue to map this function over. - * @return A new PriorityBlockingQueue with this function applied to each element. - */ - public static PriorityBlockingQueue mapJ(final F f, final PriorityBlockingQueue as) { - return new PriorityBlockingQueue<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a LinkedBlockingQueue. - * - * @param as A LinkedBlockingQueue to map this function over. - * @return A new LinkedBlockingQueue with this function applied to each element. - */ - public static LinkedBlockingQueue mapJ(final F f, final LinkedBlockingQueue as) { - return new LinkedBlockingQueue<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a CopyOnWriteArraySet. - * - * @param as A CopyOnWriteArraySet to map this function over. - * @return A new CopyOnWriteArraySet with this function applied to each element. - */ - public static CopyOnWriteArraySet mapJ(final F f, final CopyOnWriteArraySet as) { - return new CopyOnWriteArraySet<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a CopyOnWriteArrayList. - * - * @param as A CopyOnWriteArrayList to map this function over. - * @return A new CopyOnWriteArrayList with this function applied to each element. - */ - public static CopyOnWriteArrayList mapJ(final F f, final CopyOnWriteArrayList as) { - return new CopyOnWriteArrayList<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a ConcurrentLinkedQueue. - * - * @param as A ConcurrentLinkedQueue to map this function over. - * @return A new ConcurrentLinkedQueue with this function applied to each element. - */ - public static ConcurrentLinkedQueue mapJ(final F f, final ConcurrentLinkedQueue as) { - return new ConcurrentLinkedQueue<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over an ArrayBlockingQueue. - * - * @param as An ArrayBlockingQueue to map this function over. - * @return A new ArrayBlockingQueue with this function applied to each element. - */ - public static ArrayBlockingQueue mapJ(final F f, final ArrayBlockingQueue as) { - final ArrayBlockingQueue bs = new ArrayBlockingQueue<>(as.size()); - bs.addAll(iterableStream(as).map(f).toCollection()); - return bs; - } - - - /** - * Maps this function over a TreeSet. - * - * @param as A TreeSet to map this function over. - * @return A new TreeSet with this function applied to each element. - */ - public static TreeSet mapJ(final F f, final TreeSet as) { - return new TreeSet<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a PriorityQueue. - * - * @param as A PriorityQueue to map this function over. - * @return A new PriorityQueue with this function applied to each element. - */ - public static PriorityQueue mapJ(final F f, final PriorityQueue as) { - return new PriorityQueue<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over a LinkedList. - * - * @param as A LinkedList to map this function over. - * @return A new LinkedList with this function applied to each element. - */ - public static LinkedList mapJ(final F f, final LinkedList as) { - return new LinkedList<>(iterableStream(as).map(f).toCollection()); - } - - /** - * Maps this function over an ArrayList. - * - * @param as An ArrayList to map this function over. - * @return A new ArrayList with this function applied to each element. - */ - public static ArrayList mapJ(final F f, final ArrayList as) { - return new ArrayList<>(iterableStream(as).map(f).toCollection()); - } - - public static F map(F target, F f) { - return o(f, target); - } - - public static F contramap(F target, F f) { - return o(target, f); - } - - /** - * Both map (with g) and contramap (with f) the target function. (Profunctor pattern) - */ - public static F dimap(F target, F f, F g) { - return c -> g.f(target.f(f.f(c))); - } - -} diff --git a/core/src/main/java/fj/F1W.java b/core/src/main/java/fj/F1W.java deleted file mode 100644 index 611c9e01..00000000 --- a/core/src/main/java/fj/F1W.java +++ /dev/null @@ -1,687 +0,0 @@ -package fj; - -import fj.control.parallel.Actor; -import fj.control.parallel.Promise; -import fj.control.parallel.Strategy; -import fj.data.*; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.PriorityQueue; -import java.util.TreeSet; -import java.util.concurrent.*; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F1W implements F { - - /** - * Function composition - * - * @param g A function to compose with this one. - * @return The composed function such that this function is applied last. - */ - public final F1W o(final F g) { - return lift(F1Functions.o(this, g)); - } - - /** - * First-class function composition - * - * @return A function that composes this function with another. - */ - public final F1W, F> o() { - return lift(F1Functions.o(this)); - } - - /** - * Function composition flipped. - * - * @param g A function with which to compose this one. - * @return The composed function such that this function is applied first. - */ - @SuppressWarnings("unchecked") - public final F1W andThen(final F g) { - return lift(F1Functions.andThen(this, g)); - } - - /** - * First-class composition flipped. - * - * @return A function that invokes this function and then a given function on the result. - */ - public final F1W, F> andThen() { - return lift( F1Functions.andThen(this)); - } - - /** - * Binds a given function across this function (Reader Monad). - * - * @param g A function that takes the return value of this function as an argument, yielding a new function. - * @return A function that invokes this function on its argument and then the given function on the result. - */ - public final F1W bind(final F> g) { - return lift(F1Functions.bind(this, g)); - } - - - /** - * First-class function binding. - * - * @return A function that binds another function across this function. - */ - public final F1W>, F> bind() { - return lift(F1Functions.bind(this)); - } - - /** - * Function application in an environment (Applicative Functor). - * - * @param g A function with the same argument type as this function, yielding a function that takes the return - * value of this function. - * @return A new function that invokes the given function on its argument, yielding a new function that is then - * applied to the result of applying this function to the argument. - */ - public final F1W apply(final F> g) { - return lift(F1Functions.apply(this, g)); - } - - - /** - * First-class function application in an environment. - * - * @return A function that applies a given function within the environment of this function. - */ - public final F1W>, F> apply() { - return lift(F1Functions.apply(this)); - } - - /** - * Applies this function over the arguments of another function. - * - * @param g The function over whose arguments to apply this function. - * @return A new function that invokes this function on its arguments before invoking the given function. - */ - public final F1W> on(final F> g) { - return lift(F1Functions.on(this, g)); - } - - - /** - * Applies this function over the arguments of another function. - * - * @return A function that applies this function over the arguments of another function. - */ - public final F1W>, F>> on() { - return lift(F1Functions.on(this)); - } - - /** - * Promotes this function so that it returns its result in a product-1. Kleisli arrow for P1. - * - * @return This function promoted to return its result in a product-1. - */ - public final F1W> lazy() { - return lift(F1Functions.lazy(this)); - } - - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument to return a lazy value. - */ - public final P1 lazy(final A a) { - return F1Functions.f(this, a); - } - - /** - * Promotes this function to map over a product-1. - * - * @return This function promoted to map over a product-1. - */ - public final F1W, P1> mapP1() { - return lift(F1Functions.mapP1(this)); - } - - /** - * Promotes this function so that it returns its result in an Option. Kleisli arrow for Option. - * - * @return This function promoted to return its result in an Option. - */ - public final F1W> optionK() { - return lift(F1Functions.optionK(this)); - } - - - /** - * Promotes this function to map over an optional value. - * - * @return This function promoted to map over an optional value. - */ - public final F1W, Option> mapOption() { - return lift(F1Functions.mapOption(this)); - } - - /** - * Promotes this function so that it returns its result in a List. Kleisli arrow for List. - * - * @return This function promoted to return its result in a List. - */ - public final F1W> listK() { - return lift( F1Functions.listK(this)); - } - - /** - * Promotes this function to map over a List. - * - * @return This function promoted to map over a List. - */ - public final F1W, List> mapList() { - return lift(F1Functions.mapList(this)); - } - - /** - * Promotes this function so that it returns its result in a Stream. Kleisli arrow for Stream. - * - * @return This function promoted to return its result in a Stream. - */ - public final F1W> streamK() { - return lift(F1Functions.streamK(this)); - } - - /** - * Promotes this function to map over a Stream. - * - * @return This function promoted to map over a Stream. - */ - public final F1W, Stream> mapStream() { - return lift(F1Functions.mapStream(this)); - } - - /** - * Promotes this function so that it returns its result in a Array. Kleisli arrow for Array. - * - * @return This function promoted to return its result in a Array. - */ - public final F1W> arrayK() { - return lift(F1Functions.arrayK(this)); - - } - - /** - * Promotes this function to map over a Array. - * - * @return This function promoted to map over a Array. - */ - public final F1W, Array> mapArray() { - return lift(F1Functions.mapArray(this)); - } - - /** - * Returns a function that contramaps over a given actor. - * - * @return A function that contramaps over a given actor. - */ - public final F1W, Actor> contramapActor() { - return lift(F1Functions.contramapActor(this)); - } - - /** - * Promotes this function to a concurrent function that returns a Promise of a value. - * - * @param s A parallel strategy for concurrent execution. - * @return A concurrent function that returns a Promise of a value. - */ - public final F1W> promiseK(final Strategy s) { - return lift(F1Functions.promiseK(this, s)); - } - - /** - * Promotes this function to map over a Promise. - * - * @return This function promoted to map over Promises. - */ - public final F1W, Promise> mapPromise() { - return lift(F1Functions.mapPromise(this)); - } - - /** - * Promotes this function so that it returns its result on the left side of an Either. - * Kleisli arrow for the Either left projection. - * - * @return This function promoted to return its result on the left side of an Either. - */ - @SuppressWarnings("unchecked") - public final F1W> eitherLeftK() { - return lift(F1Functions.eitherLeftK(this)); - } - - /** - * Promotes this function so that it returns its result on the right side of an Either. - * Kleisli arrow for the Either right projection. - * - * @return This function promoted to return its result on the right side of an Either. - */ - @SuppressWarnings("unchecked") - public final F1W> eitherRightK() { - return lift(F1Functions.eitherRightK(this)); - } - - /** - * Promotes this function to map over the left side of an Either. - * - * @return This function promoted to map over the left side of an Either. - */ - @SuppressWarnings("unchecked") - public final F1W, Either> mapLeft() { - return lift(F1Functions.mapLeft(this)); - } - - /** - * Promotes this function to map over the right side of an Either. - * - * @return This function promoted to map over the right side of an Either. - */ - @SuppressWarnings("unchecked") - public final F1W, Either> mapRight() { - return lift(F1Functions.mapRight(this)); - } - - /** - * Returns a function that returns the left side of a given Either, or this function applied to the right side. - * - * @return a function that returns the left side of a given Either, or this function applied to the right side. - */ - public final F1W, B> onLeft() { - return lift(F1Functions.onLeft(this)); - } - - /** - * Returns a function that returns the right side of a given Either, or this function applied to the left side. - * - * @return a function that returns the right side of a given Either, or this function applied to the left side. - */ - public final F1W, B> onRight() { - return lift(F1Functions.onRight(this)); - } - - /** - * Promotes this function to return its value in an Iterable. - * - * @return This function promoted to return its value in an Iterable. - */ - @SuppressWarnings("unchecked") - public final F1W> iterableK() { - return lift( F1Functions.iterableK(this)); - } - - /** - * Promotes this function to map over Iterables. - * - * @return This function promoted to map over Iterables. - */ - @SuppressWarnings("unchecked") - public final F1W, IterableW> mapIterable() { - return lift( F1Functions.mapIterable(this)); - } - - /** - * Promotes this function to return its value in a NonEmptyList. - * - * @return This function promoted to return its value in a NonEmptyList. - */ - @SuppressWarnings("unchecked") - public final F1W> nelK() { - return lift(F1Functions.nelK(this)); - } - - /** - * Promotes this function to map over a NonEmptyList. - * - * @return This function promoted to map over a NonEmptyList. - */ - public final F1W, NonEmptyList> mapNel() { - return lift(F1Functions.mapNel(this)); - } - - /** - * Promotes this function to return its value in a Set. - * - * @param o An order for the set. - * @return This function promoted to return its value in a Set. - */ - public final F1W> setK(final Ord o) { - return lift(F1Functions.setK(this, o)); - } - - /** - * Promotes this function to map over a Set. - * - * @param o An order for the resulting set. - * @return This function promoted to map over a Set. - */ - public final F1W, Set> mapSet(final Ord o) { - return lift(F1Functions.mapSet(this, o)); - } - - /** - * Promotes this function to return its value in a Tree. - * - * @return This function promoted to return its value in a Tree. - */ - public final F1W> treeK() { - return lift(F1Functions.treeK(this)); - } - - /** - * Promotes this function to map over a Tree. - * - * @return This function promoted to map over a Tree. - */ - @SuppressWarnings("unchecked") - public final F1W, Tree> mapTree() { - return lift(F1Functions.mapTree(this)); - } - - /** - * Returns a function that maps this function over a tree and folds it with the given monoid. - * - * @param m The monoid with which to fold the mapped tree. - * @return a function that maps this function over a tree and folds it with the given monoid. - */ - public final F1W, B> foldMapTree(final Monoid m) { - return lift(F1Functions.foldMapTree(this, m)); - } - - /** - * Promotes this function to return its value in a TreeZipper. - * - * @return This function promoted to return its value in a TreeZipper. - */ - public final F1W> treeZipperK() { - return lift(F1Functions.treeZipperK(this)); - } - - /** - * Promotes this function to map over a TreeZipper. - * - * @return This function promoted to map over a TreeZipper. - */ - public final F1W, TreeZipper> mapTreeZipper() { - return lift(F1Functions.mapTreeZipper(this)); - } - - /** - * Promotes this function so that it returns its result on the failure side of a Validation. - * Kleisli arrow for the Validation failure projection. - * - * @return This function promoted to return its result on the failure side of a Validation. - */ - public final F1W> failK() { - return lift(F1Functions.failK(this)); - } - - /** - * Promotes this function so that it returns its result on the success side of an Validation. - * Kleisli arrow for the Validation success projection. - * - * @return This function promoted to return its result on the success side of an Validation. - */ - public final F1W> successK() { - return lift( F1Functions.successK(this)); - } - - /** - * Promotes this function to map over the failure side of a Validation. - * - * @return This function promoted to map over the failure side of a Validation. - */ - public final F1W, Validation> mapFail() { - return lift(F1Functions.mapFail(this)); - } - - /** - * Promotes this function to map over the success side of a Validation. - * - * @return This function promoted to map over the success side of a Validation. - */ - public final F1W, Validation> mapSuccess() { - return lift(F1Functions.mapSuccess(this)); - } - - /** - * Returns a function that returns the failure side of a given Validation, - * or this function applied to the success side. - * - * @return a function that returns the failure side of a given Validation, - * or this function applied to the success side. - */ - public final F1W, B> onFail() { - return lift(F1Functions.onFail(this)); - } - - /** - * Returns a function that returns the success side of a given Validation, - * or this function applied to the failure side. - * - * @return a function that returns the success side of a given Validation, - * or this function applied to the failure side. - */ - public final F1W, B> onSuccess() { - return lift(F1Functions.onSuccess(this)); - } - - /** - * Promotes this function to return its value in a Zipper. - * - * @return This function promoted to return its value in a Zipper. - */ - public final F1W> zipperK() { - return lift(F1Functions.zipperK(this)); - } - - /** - * Promotes this function to map over a Zipper. - * - * @return This function promoted to map over a Zipper. - */ - public final F1W, Zipper> mapZipper() { - return lift(F1Functions.mapZipper(this)); - } - - /** - * Promotes this function to map over an Equal as a contravariant functor. - * - * @return This function promoted to map over an Equal as a contravariant functor. - */ - public final F1W, Equal> contramapEqual() { - return lift(F1Functions.contramapEqual(this)); - } - - /** - * Promotes this function to map over a Hash as a contravariant functor. - * - * @return This function promoted to map over a Hash as a contravariant functor. - */ - public final F1W, Hash> contramapHash() { - return lift(F1Functions.contramapHash(this)); - } - - /** - * Promotes this function to map over a Show as a contravariant functor. - * - * @return This function promoted to map over a Show as a contravariant functor. - */ - public final F1W, Show> contramapShow() { - return lift(F1Functions.contramapShow(this)); - } - - /** - * Promotes this function to map over the first element of a pair. - * - * @return This function promoted to map over the first element of a pair. - */ - public final F1W, P2> mapFst() { - return lift(F1Functions.mapFst(this)); - } - - /** - * Promotes this function to map over the second element of a pair. - * - * @return This function promoted to map over the second element of a pair. - */ - public final F1W, P2> mapSnd() { - return lift(F1Functions.mapSnd(this)); - } - - /** - * Promotes this function to map over both elements of a pair. - * - * @return This function promoted to map over both elements of a pair. - */ - public final F1W, P2> mapBoth() { - return lift(F1Functions.mapBoth(this)); - } - - /** - * Maps this function over a SynchronousQueue. - * - * @param as A SynchronousQueue to map this function over. - * @return A new SynchronousQueue with this function applied to each element. - */ - public final SynchronousQueue mapJ(final SynchronousQueue as) { - return F1Functions.mapJ(this, as); - } - - - /** - * Maps this function over a PriorityBlockingQueue. - * - * @param as A PriorityBlockingQueue to map this function over. - * @return A new PriorityBlockingQueue with this function applied to each element. - */ - public final PriorityBlockingQueue mapJ(final PriorityBlockingQueue as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a LinkedBlockingQueue. - * - * @param as A LinkedBlockingQueue to map this function over. - * @return A new LinkedBlockingQueue with this function applied to each element. - */ - public final LinkedBlockingQueue mapJ(final LinkedBlockingQueue as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a CopyOnWriteArraySet. - * - * @param as A CopyOnWriteArraySet to map this function over. - * @return A new CopyOnWriteArraySet with this function applied to each element. - */ - public final CopyOnWriteArraySet mapJ(final CopyOnWriteArraySet as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a CopyOnWriteArrayList. - * - * @param as A CopyOnWriteArrayList to map this function over. - * @return A new CopyOnWriteArrayList with this function applied to each element. - */ - public final CopyOnWriteArrayList mapJ(final CopyOnWriteArrayList as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a ConcurrentLinkedQueue. - * - * @param as A ConcurrentLinkedQueue to map this function over. - * @return A new ConcurrentLinkedQueue with this function applied to each element. - */ - public final ConcurrentLinkedQueue mapJ(final ConcurrentLinkedQueue as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over an ArrayBlockingQueue. - * - * @param as An ArrayBlockingQueue to map this function over. - * @return A new ArrayBlockingQueue with this function applied to each element. - */ - public final ArrayBlockingQueue mapJ(final ArrayBlockingQueue as) { - return F1Functions.mapJ(this, as); - } - - - /** - * Maps this function over a TreeSet. - * - * @param as A TreeSet to map this function over. - * @return A new TreeSet with this function applied to each element. - */ - public final TreeSet mapJ(final TreeSet as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a PriorityQueue. - * - * @param as A PriorityQueue to map this function over. - * @return A new PriorityQueue with this function applied to each element. - */ - public final PriorityQueue mapJ(final PriorityQueue as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over a LinkedList. - * - * @param as A LinkedList to map this function over. - * @return A new LinkedList with this function applied to each element. - */ - public final LinkedList mapJ(final LinkedList as) { - return F1Functions.mapJ(this, as); - } - - /** - * Maps this function over an ArrayList. - * - * @param as An ArrayList to map this function over. - * @return A new ArrayList with this function applied to each element. - */ - public final ArrayList mapJ(final ArrayList as) { - return F1Functions.mapJ(this, as); - } - - public final F1W map(F f) { - return lift(F1Functions.map(this, f)); - } - - public final F1W contramap(F f) { - return lift(F1Functions.contramap(this, f)); - } - - public static class F1WFunc extends F1W { - final F func; - public F1WFunc(F f) { - func = f; - } - - @Override - public final B f(A a) { - return func.f(a); - } - } - - /** - * Lifts the function into the fully featured function wrapper - */ - public static F1W lift(final F f) { - return new F1WFunc<>(f); - } -} diff --git a/core/src/main/java/fj/F2.java b/core/src/main/java/fj/F2.java index 63555fd5..ba0e6f2f 100644 --- a/core/src/main/java/fj/F2.java +++ b/core/src/main/java/fj/F2.java @@ -1,12 +1,24 @@ package fj; +import fj.control.parallel.Promise; +import fj.data.*; + +import java.util.function.BiFunction; + +import static fj.P.p; +import static fj.data.IterableW.wrap; +import static fj.data.Set.iterableSet; +import static fj.data.Tree.node; +import static fj.data.TreeZipper.treeZipper; +import static fj.data.Zipper.zipper; + /** * A transformation function of arity-2 from A and B to C. * This type can be represented using the Java 7 closure syntax. * * @version %build.number% */ -public interface F2 { +public interface F2 extends BiFunction { /** * Transform A and B to C. * @@ -16,4 +28,264 @@ public interface F2 { */ C f(A a, B b); + default C apply(A a, B b) { + return f(a, b); + } + + /** + * Partial application. + * + * @param a The A to which to apply this function. + * @return The function partially applied to the given argument. + */ + default F f(final A a) { + return b -> f(a, b); + } + + /** + * Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function. + * + * @return a wrapped function of arity-1 that returns another wrapped function. + */ + default F> curry() { + return a -> b -> f(a, b); + } + + /** + * Flips the arguments of this function. + * + * @return A new function with the arguments of this function flipped. + */ + default F2 flip() { + return (b, a) -> f(a, b); + } + + /** + * Uncurries this function to a function on tuples. + * + * @return A new function that calls this function with the elements of a given tuple. + */ + default F, C> tuple() { + return p -> f(p._1(), p._2()); + } + + /** + * Promotes this function to a function on Arrays. + * + * @return This function promoted to transform Arrays. + */ + default F2, Array, Array> arrayM() { + return (a, b) -> a.bind(b, curry()); + } + + /** + * Promotes this function to a function on Promises. + * + * @return This function promoted to transform Promises. + */ + default F2, Promise, Promise> promiseM() { + return (a, b) -> a.bind(b, curry()); + } + + /** + * Promotes this function to a function on Iterables. + * + * @return This function promoted to transform Iterables. + */ + default F2, Iterable, IterableW> iterableM() { + return (a, b) -> IterableW.liftM2(curry()).f(a).f(b); + } + + /** + * Promotes this function to a function on Lists. + * + * @return This function promoted to transform Lists. + */ + default F2, List, List> listM() { + return (a, b) -> List.liftM2(curry()).f(a).f(b); + } + + /** + * Promotes this function to a function on non-empty lists. + * + * @return This function promoted to transform non-empty lists. + */ + default F2, NonEmptyList, NonEmptyList> nelM() { + return (as, bs) -> NonEmptyList.fromList(as.toList().bind(bs.toList(), this)).some(); + } + + /** + * Promotes this function to a function on Options. + * + * @return This function promoted to transform Options. + */ + default F2, Option, Option> optionM() { + return (a, b) -> Option.liftM2(curry()).f(a).f(b); + } + + /** + * Promotes this function to a function on Sets. + * + * @param o An ordering for the result of the promoted function. + * @return This function promoted to transform Sets. + */ + default F2, Set, Set> setM(final Ord o) { + return (as, bs) -> { + Set cs = Set.empty(o); + for (final A a : as) + for (final B b : bs) + cs = cs.insert(f(a, b)); + return cs; + }; + } + + /** + * Promotes this function to a function on Streams. + * + * @return This function promoted to transform Streams. + */ + default F2, Stream, Stream> streamM() { + return (as, bs) -> as.bind(bs, this); + } + + /** + * Promotes this function to a function on Trees. + * + * @return This function promoted to transform Trees. + */ + default F2, Tree, Tree> treeM() { + F2 outer = this; + return new F2, Tree, Tree>() { + public Tree f(final Tree as, final Tree bs) { + final F2, Tree, Tree> self = this; + return node(outer.f(as.root(), bs.root()), P.lazy(() -> self.streamM().f(as.subForest()._1(), bs.subForest()._1()))); + } + }; + } + + /** + * Promotes this function to zip two arrays, applying the function lock-step over both Arrays. + * + * @return A function that zips two arrays with this function. + */ + default F2, Array, Array> zipArrayM() { + return (as, bs) -> as.zipWith(bs, this); + } + + /** + * Promotes this function to zip two iterables, applying the function lock-step over both iterables. + * + * @return A function that zips two iterables with this function. + */ + default F2, Iterable, Iterable> zipIterableM() { + return (as, bs) -> wrap(as).zipWith(bs, this); + } + + /** + * Promotes this function to zip two lists, applying the function lock-step over both lists. + * + * @return A function that zips two lists with this function. + */ + default F2, List, List> zipListM() { + return (as, bs) -> as.zipWith(bs, this); + } + + + /** + * Promotes this function to zip two streams, applying the function lock-step over both streams. + * + * @return A function that zips two streams with this function. + */ + default F2, Stream, Stream> zipStreamM() { + return (as, bs) -> as.zipWith(bs, this); + } + + /** + * Promotes this function to zip two non-empty lists, applying the function lock-step over both lists. + * + * @return A function that zips two non-empty lists with this function. + */ + default F2, NonEmptyList, NonEmptyList> zipNelM() { + return (as, bs) -> NonEmptyList.fromList(as.toList().zipWith(bs.toList(), this)).some(); + } + + /** + * Promotes this function to zip two sets, applying the function lock-step over both sets. + * + * @param o An ordering for the resulting set. + * @return A function that zips two sets with this function. + */ + default F2, Set, Set> zipSetM(final Ord o) { + return (as, bs) -> iterableSet(o, as.toStream().zipWith(bs.toStream(), this)); + } + + /** + * Promotes this function to zip two trees, applying the function lock-step over both trees. + * The structure of the resulting tree is the structural intersection of the two trees. + * + * @return A function that zips two trees with this function. + */ + default F2, Tree, Tree> zipTreeM() { + F2 outer = this; + return new F2, Tree, Tree>() { + public Tree f(final Tree ta, final Tree tb) { + final F2, Tree, Tree> self = this; + return node(outer.f(ta.root(), tb.root()), P.lazy(() -> self.zipStreamM().f(ta.subForest()._1(), tb.subForest()._1()))); + } + }; + } + + /** + * Promotes this function to zip two zippers, applying the function lock-step over both zippers in both directions. + * The structure of the resulting zipper is the structural intersection of the two zippers. + * + * @return A function that zips two zippers with this function. + */ + default F2, Zipper, Zipper> zipZipperM() { + return (ta, tb) -> { + final F2, Stream, Stream> sf = this.zipStreamM(); + return zipper(sf.f(ta.lefts(), tb.lefts()), f(ta.focus(), tb.focus()), sf.f(ta.rights(), tb.rights())); + }; + } + + /** + * Promotes this function to zip two TreeZippers, applying the function lock-step over both zippers in all directions. + * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. + * + * @return A function that zips two TreeZippers with this function. + */ + default F2, TreeZipper, TreeZipper> zipTreeZipperM() { + F2 outer = this; + return (ta, tb) -> { + final F2>, Stream>, Stream>> sf = outer.treeM().zipStreamM(); + F2>, A, Stream>>, P3>, B, Stream>>, P3>, C, Stream>>> g = + (pa, pb) -> p(outer.treeM().zipStreamM().f(pa._1(), pb._1()), outer.f(pa._2(), pb._2()), + outer.treeM().zipStreamM().f(pa._3(), pb._3())); + final + F2>, A, Stream>>>, + Stream>, B, Stream>>>, + Stream>, C, Stream>>>> + pf = g.zipStreamM(); + return treeZipper(outer.treeM().f(ta.p()._1(), tb.p()._1()), sf.f(ta.lefts(), tb.lefts()), + sf.f(ta.rights(), tb.rights()), pf.f(ta.p()._4(), tb.p()._4())); + }; + } + + default F2 contramapFirst(F f) { + return (z, b) -> f(f.f(z), b); + } + + default F2 contramapSecond(F f) { + return (a, z) -> f(a, f.f(z)); + } + + default F2 contramap(F f, F g) { + return contramapFirst(f).contramapSecond(g); + } + + default F2 map(F f) { + return (a, b) -> f.f(f(a, b)); + } + + } diff --git a/core/src/main/java/fj/F2Functions.java b/core/src/main/java/fj/F2Functions.java deleted file mode 100644 index f69e02ed..00000000 --- a/core/src/main/java/fj/F2Functions.java +++ /dev/null @@ -1,273 +0,0 @@ -package fj; - -import fj.control.parallel.Promise; -import fj.data.*; - -import static fj.P.p; -import static fj.data.IterableW.wrap; -import static fj.data.Set.iterableSet; -import static fj.data.Tree.node; -import static fj.data.TreeZipper.treeZipper; -import static fj.data.Zipper.zipper; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F2Functions { - - - private F2Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F f(final F2 f, final A a) { - return b -> f.f(a, b); - } - - /** - * Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function. - * - * @return a wrapped function of arity-1 that returns another wrapped function. - */ - public static F> curry(final F2 f) { - return a -> b -> f.f(a, b); - } - - /** - * Flips the arguments of this function. - * - * @return A new function with the arguments of this function flipped. - */ - public static F2 flip(final F2 f) { - return (b, a) -> f.f(a, b); - } - - /** - * Uncurries this function to a function on tuples. - * - * @return A new function that calls this function with the elements of a given tuple. - */ - public static F, C> tuple(final F2 f) { - return p -> f.f(p._1(), p._2()); - } - - /** - * Promotes this function to a function on Arrays. - * - * @return This function promoted to transform Arrays. - */ - public static F2, Array, Array> arrayM(final F2 f) { - return (a, b) -> a.bind(b, curry(f)); - } - - /** - * Promotes this function to a function on Promises. - * - * @return This function promoted to transform Promises. - */ - public static F2, Promise, Promise> promiseM(final F2 f) { - return (a, b) -> a.bind(b, curry(f)); - } - - /** - * Promotes this function to a function on Iterables. - * - * @return This function promoted to transform Iterables. - */ - public static F2, Iterable, IterableW> iterableM(final F2 f) { - return (a, b) -> IterableW.liftM2(curry(f)).f(a).f(b); - } - - /** - * Promotes this function to a function on Lists. - * - * @return This function promoted to transform Lists. - */ - public static F2, List, List> listM(final F2 f) { - return (a, b) -> List.liftM2(curry(f)).f(a).f(b); - } - - /** - * Promotes this function to a function on non-empty lists. - * - * @return This function promoted to transform non-empty lists. - */ - public static F2, NonEmptyList, NonEmptyList> nelM(final F2 f) { - return (as, bs) -> NonEmptyList.fromList(as.toList().bind(bs.toList(), f)).some(); - } - - /** - * Promotes this function to a function on Options. - * - * @return This function promoted to transform Options. - */ - public static F2, Option, Option> optionM(final F2 f) { - return (a, b) -> Option.liftM2(curry(f)).f(a).f(b); - } - - /** - * Promotes this function to a function on Sets. - * - * @param o An ordering for the result of the promoted function. - * @return This function promoted to transform Sets. - */ - public static F2, Set, Set> setM(final F2 f, final Ord o) { - return (as, bs) -> { - Set cs = Set.empty(o); - for (final A a : as) - for (final B b : bs) - cs = cs.insert(f.f(a, b)); - return cs; - }; - } - - /** - * Promotes this function to a function on Streams. - * - * @return This function promoted to transform Streams. - */ - public static F2, Stream, Stream> streamM(final F2 f) { - return (as, bs) -> as.bind(bs, f); - } - - /** - * Promotes this function to a function on Trees. - * - * @return This function promoted to transform Trees. - */ - public static F2, Tree, Tree> treeM(final F2 f) { - return new F2, Tree, Tree>() { - public Tree f(final Tree as, final Tree bs) { - final F2, Tree, Tree> self = this; - return node(f.f(as.root(), bs.root()), P.lazy(() -> streamM(self).f(as.subForest()._1(), bs.subForest()._1()))); - } - }; - } - - /** - * Promotes this function to zip two arrays, applying the function lock-step over both Arrays. - * - * @return A function that zips two arrays with this function. - */ - public static F2, Array, Array> zipArrayM(final F2 f) { - return (as, bs) -> as.zipWith(bs, f); - } - - /** - * Promotes this function to zip two iterables, applying the function lock-step over both iterables. - * - * @return A function that zips two iterables with this function. - */ - public static F2, Iterable, Iterable> zipIterableM(final F2 f) { - return (as, bs) -> wrap(as).zipWith(bs, f); - } - - /** - * Promotes this function to zip two lists, applying the function lock-step over both lists. - * - * @return A function that zips two lists with this function. - */ - public static F2, List, List> zipListM(final F2 f) { - return (as, bs) -> as.zipWith(bs, f); - } - - - /** - * Promotes this function to zip two streams, applying the function lock-step over both streams. - * - * @return A function that zips two streams with this function. - */ - public static F2, Stream, Stream> zipStreamM(final F2 f) { - return (as, bs) -> as.zipWith(bs, f); - } - - /** - * Promotes this function to zip two non-empty lists, applying the function lock-step over both lists. - * - * @return A function that zips two non-empty lists with this function. - */ - public static F2, NonEmptyList, NonEmptyList> zipNelM(final F2 f) { - return (as, bs) -> NonEmptyList.fromList(as.toList().zipWith(bs.toList(), f)).some(); - } - - /** - * Promotes this function to zip two sets, applying the function lock-step over both sets. - * - * @param o An ordering for the resulting set. - * @return A function that zips two sets with this function. - */ - public static F2, Set, Set> zipSetM(final F2 f, final Ord o) { - return (as, bs) -> iterableSet(o, as.toStream().zipWith(bs.toStream(), f)); - } - - /** - * Promotes this function to zip two trees, applying the function lock-step over both trees. - * The structure of the resulting tree is the structural intersection of the two trees. - * - * @return A function that zips two trees with this function. - */ - public static F2, Tree, Tree> zipTreeM(final F2 f) { - return new F2, Tree, Tree>() { - public Tree f(final Tree ta, final Tree tb) { - final F2, Tree, Tree> self = this; - return node(f.f(ta.root(), tb.root()), P.lazy(() -> zipStreamM(self).f(ta.subForest()._1(), tb.subForest()._1()))); - } - }; - } - - /** - * Promotes this function to zip two zippers, applying the function lock-step over both zippers in both directions. - * The structure of the resulting zipper is the structural intersection of the two zippers. - * - * @return A function that zips two zippers with this function. - */ - public static F2, Zipper, Zipper> zipZipperM(final F2 f) { - return (ta, tb) -> { - final F2, Stream, Stream> sf = zipStreamM(f); - return zipper(sf.f(ta.lefts(), tb.lefts()), f.f(ta.focus(), tb.focus()), sf.f(ta.rights(), tb.rights())); - }; - } - - /** - * Promotes this function to zip two TreeZippers, applying the function lock-step over both zippers in all directions. - * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. - * - * @return A function that zips two TreeZippers with this function. - */ - public static F2, TreeZipper, TreeZipper> zipTreeZipperM(final F2 f) { - return (ta, tb) -> { - final F2>, Stream>, Stream>> sf = zipStreamM(treeM(f)); - final - F2>, A, Stream>>>, - Stream>, B, Stream>>>, - Stream>, C, Stream>>>> - pf = - zipStreamM((pa, pb) -> p(zipStreamM(treeM(f)).f(pa._1(), pb._1()), f.f(pa._2(), pb._2()), - zipStreamM(treeM(f)).f(pa._3(), pb._3()))); - return treeZipper(treeM(f).f(ta.p()._1(), tb.p()._1()), sf.f(ta.lefts(), tb.lefts()), - sf.f(ta.rights(), tb.rights()), pf.f(ta.p()._4(), tb.p()._4())); - }; - } - - public static F2 contramapFirst(F2 target, F f) { - return (z, b) -> target.f(f.f(z), b); - } - - public static F2 contramapSecond(F2 target, F f) { - return (a, z) -> target.f(a, f.f(z)); - } - - public static F2 contramap(F2 target, F f, F g) { - return contramapSecond(contramapFirst(target, f), g); - } - - public static F2 map(F2 target, F f) { - return (a, b) -> f.f(target.f(a, b)); - } - -} diff --git a/core/src/main/java/fj/F2W.java b/core/src/main/java/fj/F2W.java deleted file mode 100644 index 1f35855a..00000000 --- a/core/src/main/java/fj/F2W.java +++ /dev/null @@ -1,254 +0,0 @@ -package fj; - -import fj.control.parallel.Promise; -import fj.data.*; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F2W implements F2 { - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public final F1W f(final A a) { - return F1W.lift(F2Functions.f(this, a)); - } - - /** - * Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function. - * - * @return a wrapped function of arity-1 that returns another wrapped function. - */ - public final F1W> curry() { - return F1W.lift(F2Functions.curry(this)); - } - - /** - * Flips the arguments of this function. - * - * @return A new function with the arguments of this function flipped. - */ - public final F2W flip() { - return lift(F2Functions.flip(this)); - } - - /** - * Uncurries this function to a function on tuples. - * - * @return A new function that calls this function with the elements of a given tuple. - */ - public final F1W, C> tuple() { - return F1W.lift(F2Functions.tuple(this)); - } - - /** - * Promotes this function to a function on Arrays. - * - * @return This function promoted to transform Arrays. - */ - public final F2W, Array, Array> arrayM() { - return lift(F2Functions.arrayM(this)); - } - - /** - * Promotes this function to a function on Promises. - * - * @return This function promoted to transform Promises. - */ - public final F2W, Promise, Promise> promiseM() { - return lift(F2Functions.promiseM(this)); - } - - /** - * Promotes this function to a function on Iterables. - * - * @return This function promoted to transform Iterables. - */ - public final F2W, Iterable, IterableW> iterableM() { - return lift(F2Functions.iterableM(this)); - } - - /** - * Promotes this function to a function on Lists. - * - * @return This function promoted to transform Lists. - */ - public final F2W, List, List> listM() { - return lift(F2Functions.listM(this)); - } - - /** - * Promotes this function to a function on non-empty lists. - * - * @return This function promoted to transform non-empty lists. - */ - public final F2W, NonEmptyList, NonEmptyList> nelM() { - return lift(F2Functions.nelM(this)); - } - - /** - * Promotes this function to a function on Options. - * - * @return This function promoted to transform Options. - */ - public final F2W, Option, Option> optionM() { - return lift(F2Functions.optionM(this)); - } - - /** - * Promotes this function to a function on Sets. - * - * @param o An ordering for the result of the promoted function. - * @return This function promoted to transform Sets. - */ - public final F2W, Set, Set> setM(final Ord o) { - return lift(F2Functions.setM(this, o)); - } - - /** - * Promotes this function to a function on Streams. - * - * @return This function promoted to transform Streams. - */ - public final F2W, Stream, Stream> streamM() { - return lift(F2Functions.streamM(this)); - } - - /** - * Promotes this function to a function on Trees. - * - * @return This function promoted to transform Trees. - */ - public final F2W, Tree, Tree> treeM() { - return lift(F2Functions.treeM(this)); - } - - /** - * Promotes this function to zip two arrays, applying the function lock-step over both Arrays. - * - * @return A function that zips two arrays with this function. - */ - public final F2W, Array, Array> zipArrayM() { - return lift(F2Functions.zipArrayM(this)); - } - - /** - * Promotes this function to zip two iterables, applying the function lock-step over both iterables. - * - * @return A function that zips two iterables with this function. - */ - public final F2W, Iterable, Iterable> zipIterableM() { - return lift(F2Functions.zipIterableM(this)); - } - - /** - * Promotes this function to zip two lists, applying the function lock-step over both lists. - * - * @return A function that zips two lists with this function. - */ - public final F2W, List, List> zipListM() { - return lift(F2Functions.zipListM(this)); - } - - - /** - * Promotes this function to zip two streams, applying the function lock-step over both streams. - * - * @return A function that zips two streams with this function. - */ - public final F2W, Stream, Stream> zipStreamM() { - return lift(F2Functions.zipStreamM(this)); - } - - /** - * Promotes this function to zip two non-empty lists, applying the function lock-step over both lists. - * - * @return A function that zips two non-empty lists with this function. - */ - public final F2W, NonEmptyList, NonEmptyList> zipNelM() { - return lift(F2Functions.zipNelM(this)); - } - - /** - * Promotes this function to zip two sets, applying the function lock-step over both sets. - * - * @param o An ordering for the resulting set. - * @return A function that zips two sets with this function. - */ - public final F2W, Set, Set> zipSetM(final Ord o) { - return lift(F2Functions.zipSetM(this, o)); - } - - /** - * Promotes this function to zip two trees, applying the function lock-step over both trees. - * The structure of the resulting tree is the structural intersection of the two trees. - * - * @return A function that zips two trees with this function. - */ - public final F2W, Tree, Tree> zipTreeM() { - return lift(F2Functions.zipTreeM(this)); - } - - /** - * Promotes this function to zip two zippers, applying the function lock-step over both zippers in both directions. - * The structure of the resulting zipper is the structural intersection of the two zippers. - * - * @return A function that zips two zippers with this function. - */ - public final F2W, Zipper, Zipper> zipZipperM() { - return lift(F2Functions.zipZipperM(this)); - } - - /** - * Promotes this function to zip two TreeZippers, applying the function lock-step over both zippers in all directions. - * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. - * - * @return A function that zips two TreeZippers with this function. - */ - public final F2W, TreeZipper, TreeZipper> zipTreeZipperM() { - return lift(F2Functions.zipTreeZipperM(this)); - } - - public final F2W contramapFirst(F f) { - return lift(F2Functions.contramapFirst(this, f)); - } - - public final F2W contramapSecond(F f) { - return lift(F2Functions.contramapSecond(this, f)); - } - - public final F2W contramap(F f, F g) { - return lift(F2Functions.contramap(this, f, g)); - } - - public final F2W map(F f) { - return lift(F2Functions.map(this, f)); - } - - - public static class F2WFunc extends F2W { - final F2 func; - public F2WFunc(F2 f) { - func = f; - } - - @Override - public final C f(A a, B b) { - return func.f(a, b); - } - } - - /** - * Lifts the function into the fully featured function wrapper - */ - public static F2W lift(final F2 f) { - return new F2WFunc<>(f); - } - - - -} diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 490dc9d6..96d24b82 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -1,7 +1,5 @@ package fj; -import static fj.F1Functions.dimap; - import fj.data.*; import static fj.Function.*; @@ -146,7 +144,7 @@ public B append(B a1, B a2) { @Override public F prepend(B b) { - return dimap(def.prepend(g.f(b)), g, f); + return def.prepend(g.f(b)).dimap(g, f); } @Override diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 5e627403..420b820b 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -108,7 +108,7 @@ public final P1 bind(final P1 cb, final F> f) { * Binds the given function to the values in the given P1s with a final join. */ public final P1 bind(final P1 cb, final F2 f) { - return bind(cb, F2W.lift(f).curry()); + return bind(cb, f.curry()); } /** diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index b434a0da..841b356e 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -166,7 +166,7 @@ public final Stream sequenceW(final Stream, C>> fs) { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P2.__1()).f(this); + return P2.__1().lazy().f(this); } /** @@ -175,7 +175,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P2.__2()).f(this); + return P2.__2().lazy().f(this); } /** diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index fe980059..6e08a0ba 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -101,7 +101,7 @@ public X _3() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P3.__1()).f(this); + return P3.__1().lazy().f(this); } /** @@ -110,7 +110,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P3.__2()).f(this); + return P3.__2().lazy().f(this); } /** @@ -119,7 +119,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P3.__3()).f(this); + return P3.__3().lazy().f(this); } diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index a7bf8167..4fa2ef8c 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -146,7 +146,7 @@ public X _4() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P4.__1()).f(this); + return P4.__1().lazy().f(this); } /** @@ -155,7 +155,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P4.__2()).f(this); + return P4.__2().lazy().f(this); } /** @@ -164,7 +164,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P4.__3()).f(this); + return P4.__3().lazy().f(this); } /** @@ -173,7 +173,7 @@ public final P1 _3_() { * @return the 1-product projection over the fourth element. */ public final P1 _4_() { - return F1Functions.lazy(P4.__4()).f(this); + return P4.__4().lazy().f(this); } diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index 69262327..fabc4227 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -199,7 +199,7 @@ public X _5() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P5.__1()).f(this); + return P5.__1().lazy().f(this); } /** @@ -208,7 +208,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P5.__2()).f(this); + return P5.__2().lazy().f(this); } /** @@ -217,7 +217,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P5.__3()).f(this); + return P5.__3().lazy().f(this); } /** @@ -226,7 +226,7 @@ public final P1 _3_() { * @return the 1-product projection over the fourth element. */ public final P1 _4_() { - return F1Functions.lazy(P5.__4()).f(this); + return P5.__4().lazy().f(this); } /** @@ -235,7 +235,7 @@ public final P1 _4_() { * @return the 1-product projection over the fifth element. */ public final P1 _5_() { - return F1Functions.lazy(P5.__5()).f(this); + return P5.__5().lazy().f(this); } /** diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index fbf91948..670622c7 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -261,7 +261,7 @@ public X _6() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P6.__1()).f(this); + return P6.__1().lazy().f(this); } /** @@ -270,7 +270,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P6.__2()).f(this); + return P6.__2().lazy().f(this); } /** @@ -279,7 +279,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P6.__3()).f(this); + return P6.__3().lazy().f(this); } /** @@ -288,7 +288,7 @@ public final P1 _3_() { * @return the 1-product projection over the fourth element. */ public final P1 _4_() { - return F1Functions.lazy(P6.__4()).f(this); + return P6.__4().lazy().f(this); } /** @@ -297,7 +297,7 @@ public final P1 _4_() { * @return the 1-product projection over the fifth element. */ public final P1 _5_() { - return F1Functions.lazy(P6.__5()).f(this); + return P6.__5().lazy().f(this); } /** @@ -306,7 +306,7 @@ public final P1 _5_() { * @return the 1-product projection over the sixth element. */ public final P1 _6_() { - return F1Functions.lazy(P6.__6()).f(this); + return P6.__6().lazy().f(this); } /** diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index b1c67b30..6c9ac804 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -330,7 +330,7 @@ public X _7() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P7.__1()).f(this); + return P7.__1().lazy().f(this); } /** @@ -339,7 +339,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P7.__2()).f(this); + return P7.__2().lazy().f(this); } /** @@ -348,7 +348,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P7.__3()).f(this); + return P7.__3().lazy().f(this); } /** @@ -357,7 +357,7 @@ public final P1 _3_() { * @return the 1-product projection over the fourth element. */ public final P1 _4_() { - return F1Functions.lazy(P7.__4()).f(this); + return P7.__4().lazy().f(this); } /** @@ -366,7 +366,7 @@ public final P1 _4_() { * @return the 1-product projection over the fifth element. */ public final P1 _5_() { - return F1Functions.lazy(P7.__5()).f(this); + return P7.__5().lazy().f(this); } /** @@ -375,7 +375,7 @@ public final P1 _5_() { * @return the 1-product projection over the sixth element. */ public final P1 _6_() { - return F1Functions.lazy(P7.__6()).f(this); + return P7.__6().lazy().f(this); } /** @@ -384,7 +384,7 @@ public final P1 _6_() { * @return the 1-product projection over the seventh element. */ public final P1 _7_() { - return F1Functions.lazy(P7.__7()).f(this); + return P7.__7().lazy().f(this); } /** diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index f15d63a1..f3902c5e 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -408,7 +408,7 @@ public X _8() { * @return the 1-product projection over the first element. */ public final P1 _1_() { - return F1Functions.lazy(P8.__1()).f(this); + return P8.__1().lazy().f(this); } /** @@ -417,7 +417,7 @@ public final P1 _1_() { * @return the 1-product projection over the second element. */ public final P1 _2_() { - return F1Functions.lazy(P8.__2()).f(this); + return P8.__2().lazy().f(this); } /** @@ -426,7 +426,7 @@ public final P1 _2_() { * @return the 1-product projection over the third element. */ public final P1 _3_() { - return F1Functions.lazy(P8.__3()).f(this); + return P8.__3().lazy().f(this); } /** @@ -435,7 +435,7 @@ public final P1 _3_() { * @return the 1-product projection over the fourth element. */ public final P1 _4_() { - return F1Functions.lazy(P8.__4()).f(this); + return P8.__4().lazy().f(this); } /** @@ -444,7 +444,7 @@ public final P1 _4_() { * @return the 1-product projection over the fifth element. */ public final P1 _5_() { - return F1Functions.lazy(P8.__5()).f(this); + return P8.__5().lazy().f(this); } /** @@ -453,7 +453,7 @@ public final P1 _5_() { * @return the 1-product projection over the sixth element. */ public final P1 _6_() { - return F1Functions.lazy(P8.__6()).f(this); + return P8.__6().lazy().f(this); } /** @@ -462,7 +462,7 @@ public final P1 _6_() { * @return the 1-product projection over the seventh element. */ public final P1 _7_() { - return F1Functions.lazy(P8.__7()).f(this); + return P8.__7().lazy().f(this); } /** @@ -471,7 +471,7 @@ public final P1 _7_() { * @return the 1-product projection over the eighth element. */ public final P1 _8_() { - return F1Functions.lazy(P8.__8()).f(this); + return P8.__8().lazy().f(this); } /** diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index ef8029b3..6fbc5fc6 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -13,13 +13,10 @@ import java.math.BigDecimal; import java.math.BigInteger; -import static fj.F1Functions.dimap; import static fj.Function.constant; import static fj.Function.identity; import static fj.Monoid.*; import static fj.data.DList.listDList; -import static fj.data.Option.none; -import static fj.data.Option.some; /** * Implementations must satisfy the law of associativity: @@ -193,7 +190,7 @@ public B append(B a1, B a2) { @Override public F prepend(B b) { - return dimap(def.prepend(g.f(b)), g, f); + return def.prepend(g.f(b)).dimap(g, f); } @Override diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index 47fd282b..e3b58e1c 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -171,7 +171,7 @@ public static F>, Trampoline> suspend_() { * @return A new trampoline that runs this trampoline, then applies the given function to the result. */ public final Trampoline map(final F f) { - return bind(F1Functions.o(Trampoline.pure(), f)); + return bind(Trampoline.pure().o(f)); } /** @@ -266,10 +266,11 @@ public final Trampoline zipWith(final Trampoline b, final F2>, B> eb = b.resume(); for (final P1> x : ea.left()) { for (final P1> y : eb.left()) { - return suspend(x.bind(y, F2Functions.curry((ta, tb) -> suspend(() -> ta.zipWith(tb, f))))); + F, F, Trampoline>> z = ta -> tb -> suspend(() -> ta.zipWith(tb, f)); + return suspend(x.bind(y, z)); } for (final B y : eb.right()) { - return suspend(x.map(ta -> ta.map(F2Functions.f(F2Functions.flip(f), y)))); + return suspend(x.map(ta -> ta.map(f.flip().f(y)))); } } for (final A x : ea.right()) { @@ -277,7 +278,7 @@ public final Trampoline zipWith(final Trampoline b, final F2 pure(f.f(x, y))); } for (final P1> y : eb.left()) { - return suspend(y.map(liftM2(F2Functions.curry(f)).f(pure(x)))); + return suspend(y.map(liftM2(f.curry()).f(pure(x)))); } } throw Bottom.error("Match error: Trampoline is neither done nor suspended."); diff --git a/core/src/main/java/fj/control/parallel/ParModule.java b/core/src/main/java/fj/control/parallel/ParModule.java index 514988aa..b9eeacbf 100644 --- a/core/src/main/java/fj/control/parallel/ParModule.java +++ b/core/src/main/java/fj/control/parallel/ParModule.java @@ -67,7 +67,7 @@ public F, Promise> promise() { * that can be claimed in the future. */ public F> promise(final F f) { - return F1Functions.promiseK(f, strategy); + return f.promiseK(strategy); } /** @@ -88,7 +88,7 @@ public F, F>> promisePure() { * that can be claimed in the future. */ public F2> promise(final F2 f) { - return P2.untuple(F1Functions.promiseK(F2Functions.tuple(f), strategy)); + return P2.untuple(f.tuple().promiseK(strategy)); } diff --git a/core/src/main/java/fj/data/IOFunctions.java b/core/src/main/java/fj/data/IOFunctions.java index 2ea15dfb..9573deea 100644 --- a/core/src/main/java/fj/data/IOFunctions.java +++ b/core/src/main/java/fj/data/IOFunctions.java @@ -2,7 +2,6 @@ import fj.F; import fj.F0; -import fj.F1Functions; import fj.F2; import fj.Function; import fj.P; @@ -204,7 +203,7 @@ public IO> f(IterV it) { return i; } final Input input = Input.el(s); - final F, IterV>, P1>> cont = F1Functions.lazy(Function.apply(input)); + final F, IterV>, P1>> cont = Function., IterV>apply(input).lazy(); i = i.fold(done, cont)._1(); } return i; @@ -248,7 +247,7 @@ public IO> f(IterV it) { } final Input input = Input.el(buffer); final F, IterV>, P1>> cont = - F1Functions.lazy(Function.apply(input)); + Function., IterV>apply(input).lazy(); i = i.fold(done, cont)._1(); } return i; diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index bcb03cc0..be68ed02 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -2,7 +2,6 @@ import fj.F; import fj.F0; -import fj.F1Functions; import fj.Function; import fj.P; import fj.P2; @@ -82,7 +81,7 @@ public Z fold(final F>, Z> done, final F, IterV, Option> runCont = new F, Option>() { - final F>, Option> done = F1Functions.andThen(P2.__1(), Option.some_()); + final F>, Option> done = P2.>__1().andThen(Option.some_()); final F, IterV>, Option> cont = Function.constant(Option.none()); @Override diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 422d246b..5b5fff67 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -969,7 +969,7 @@ public final B foldRight(final F2 f, final B b) { * @return A Trampoline containing the final result after the right-fold reduction. */ public final Trampoline foldRightC(final F2 f, final B b) { - return Trampoline.suspend(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(F2Functions.f(f, head()))); + return Trampoline.suspend(() -> isEmpty() ? Trampoline.pure(b) : tail().foldRightC(f, b).map(f.f(head()))); } /** diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index 4073476d..34c8b957 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -169,9 +169,10 @@ public NonEmptyList bind(final F> f) { * @return a NonEmptyList of the sublists of this list. */ public NonEmptyList> sublists() { + F, Option>> f = s -> NonEmptyList.fromList(Conversions.Stream_List().f(s)); return fromList( somes(toList().toStream().substreams() - .map(F1Functions.o(NonEmptyList::fromList, Conversions.Stream_List())).toList())).some(); + .map(f).toList())).some(); } /** diff --git a/core/src/main/java/fj/data/Reader.java b/core/src/main/java/fj/data/Reader.java index af66c87e..9374e300 100644 --- a/core/src/main/java/fj/data/Reader.java +++ b/core/src/main/java/fj/data/Reader.java @@ -1,7 +1,6 @@ package fj.data; import fj.F; -import fj.F1Functions; /** * The Reader monad (also called the function monad, so equivalent to the idea of F). @@ -32,7 +31,7 @@ public final B f(A a) { } public final Reader map(F f) { - return unit(F1Functions.andThen(function, f)); + return unit(function.andThen(f)); } public final Reader andThen(F f) { diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index 9eebb932..f430d6d2 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -127,7 +127,7 @@ public static F, P1>>> subForest_() { public Stream flatten() { final F2, P1>, Stream> squish = new F2, P1>, Stream>() { public Stream f(final Tree t, final P1> xs) { - return cons(t.root(), t.subForest().map(Stream., Stream>foldRight().f(F2Functions.curry(this)).f(xs._1()))); + return cons(t.root(), t.subForest().map(Stream., Stream>foldRight().f(this.curry()).f(xs._1()))); } }; return squish.f(this, P.p(Stream.nil())); @@ -305,7 +305,7 @@ public static Show> show2D(final Show s) { * @return A new tree of the results of applying the given function over this tree and the given tree, position-wise. */ public Tree zipWith(final Tree bs, final F2 f) { - return F2Functions.zipTreeM(f).f(this, bs); + return f.zipTreeM().f(this, bs); } /** diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index cd111d06..38607dbc 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -2,7 +2,6 @@ import fj.Equal; import fj.F; -import fj.F1Functions; import fj.Hash; import fj.Ord; import fj.P; @@ -308,9 +307,9 @@ public TreeMap update(final K k, final F f, final V v) { * and the optional value is the value associated with the given key if present, otherwise None. */ public P3, Option, Set> split(Ord ord, final K k) { - final F>>, Set> getSome = F1Functions.mapSet(F1Functions.o(Option.fromSome(), P2.__2()), ord); + final F>>, Set> getSome = Option.fromSome().o(P2.>__2()).mapSet(ord); return tree.split(p(k, Option.none())).map1(getSome).map3(getSome) - .map2(F1Functions.o(Option.join(), F1Functions.mapOption(P2.__2()))); + .map2(Option.join().o(P2.>__2().mapOption())); } /** @@ -359,7 +358,7 @@ public P3, Option, TreeMap> splitLookup(final K k) { */ @SuppressWarnings("unchecked") public TreeMap map(final F f) { - final F>, P2>> g = compose(p2 -> p(p2._1(), p2._2()), P2.map2_(F1Functions.mapOption(f))); + final F>, P2>> g = compose(p2 -> p(p2._1(), p2._2()), P2.map2_(f.mapOption())); final F>> coord = flip(P.>p2()).f(Option.none()); final Ord o = tree.ord().contramap(coord); return new TreeMap<>(tree.map(TreeMap.ord(o), g)); diff --git a/core/src/main/java/fj/data/TreeZipper.java b/core/src/main/java/fj/data/TreeZipper.java index 9ffad4f4..545238f3 100644 --- a/core/src/main/java/fj/data/TreeZipper.java +++ b/core/src/main/java/fj/data/TreeZipper.java @@ -1,678 +1,678 @@ -package fj.data; - -import fj.*; -import fj.function.Booleans; - -import java.util.Iterator; - -import static fj.Equal.p3Equal; -import static fj.Equal.p4Equal; -import static fj.Equal.streamEqual; -import static fj.Equal.treeEqual; -import static fj.Function.compose; -import static fj.Function.curry; -import static fj.Function.flip; -import static fj.Function.uncurryF2; -import static fj.Show.p3Show; -import static fj.Show.p4Show; -import static fj.Show.streamShow; -import static fj.Show.treeShow; -import static fj.data.Option.none; -import static fj.data.Option.some; -import static fj.data.Stream.nil; -import static fj.data.Stream.unfold; -import static fj.data.Tree.node; -import static fj.data.Tree.unfoldTree; - -/** - * Provides a zipper structure for rose trees, which is a Tree supplied with a location within that tree. - * Provides navigation, insertion, deletion, and memorization of visited locations within a tree. - */ -public final class TreeZipper implements Iterable> { - - /** - * Returns an iterator of all the positions of this TreeZipper. Exists for use with the foreach syntax. - * - * @return An iterator of all the positions of this TreeZipper. - */ - public Iterator> iterator() { - return positions().toTree().iterator(); - } - - private final Tree tree; - private final Stream> lefts; - private final Stream> rights; - private final Stream>, A, Stream>>> parents; - - private TreeZipper(final Tree tree, - final Stream> lefts, - final Stream> rights, - final Stream>, A, Stream>>> parents) { - this.tree = tree; - this.lefts = lefts; - this.rights = rights; - this.parents = parents; - } - - @Override - public final boolean equals(Object other) { - return Equal.equals0(TreeZipper.class, this, other, () -> Equal.treeZipperEqual(Equal.anyEqual())); - } - - @Override - public final int hashCode() { - return Hash.treeZipperHash(Hash.anyHash()).hash(this); - } - - /** - * Creates a new tree zipper given a currently selected tree, a forest on the left, a forest on the right, - * and a stream of parent contexts. - * - * @param tree The currently selected tree. - * @param lefts The selected tree's left siblings, closest first. - * @param rights The selected tree's right siblings, closest first. - * @param parents The parent of the selected tree, and the parent's siblings. - * @return A new zipper with the given tree selected, and the given forests on the left and right. - */ - public static TreeZipper treeZipper(final Tree tree, - final Stream> lefts, - final Stream> rights, - final Stream>, A, Stream>>> parents) { - return new TreeZipper<>(tree, lefts, rights, parents); - } - - /** - * First-class constructor for tree zippers. - * - * @return A function that returns a new tree zipper, given a selected tree, left and right siblings, - * and a parent context. - */ - public static - F, F>, F>, F>, A, Stream>>>, TreeZipper>>>> - treeZipper() { - return curry( - TreeZipper::treeZipper); - } - - /** - * Returns the product-4 representation of this zipper. - * - * @return the product-4 representation of this zipper. - */ - public P4, Stream>, Stream>, Stream>, A, Stream>>>> p() { - return P.p(tree, lefts, rights, parents); - } - - /** - * A first-class function that returns the product-4 representation of a given zipper. - * - * @return a function that converts a given zipper to its product-4 representation. - */ - public static - F, P4, Stream>, Stream>, Stream>, A, Stream>>>>> p_() { - return TreeZipper::p; - } - - /** - * An Equal instance for tree zippers. - * - * @param e An Equal instance for tree elements. - * @return An Equal instance for tree zippers. - */ - public static Equal> eq(final Equal e) { - return p4Equal( - treeEqual(e), - streamEqual(treeEqual(e)), - streamEqual(treeEqual(e)), - streamEqual(p3Equal(streamEqual(treeEqual(e)), e, streamEqual(treeEqual(e))))).contramap(TreeZipper.p_()); - } - - /** - * A Show instance for tree zippers. - * - * @param s A Show instance for tree elements. - * @return A Show instance for tree zippers. - */ - public static Show> show(final Show s) { - return p4Show( - treeShow(s), - streamShow(treeShow(s)), - streamShow(treeShow(s)), - streamShow(p3Show(streamShow(treeShow(s)), s, streamShow(treeShow(s))))).contramap(TreeZipper.p_()); - } - - private static Stream> combChildren(final Stream> ls, - final Tree t, - final Stream> rs) { - return ls.foldLeft(compose(flip(Stream.cons()), P.p1()), Stream.cons(t, P.p(rs))); - } - - /** - * Navigates to the parent of the current location. - * - * @return A new tree zipper focused on the parent node of the current node, - * or none if the current node is the root node. - */ - public Option> parent() { - if (parents.isEmpty()) - return none(); - else { - final P3>, A, Stream>> p = parents.head(); - return some(treeZipper(node(p._2(), combChildren(lefts, tree, rights)), p._1(), p._3(), parents.tail()._1())); - } - } - - /** - * Navigates to the top-most parent of the current location. - * - * @return A new tree zipper focused on the top-most parent of the current node. - */ - public TreeZipper root() { - return parent().option(this, TreeZipper.root_()); - } - - /** - * A first-class version of the root function. - * - * @return A function that returns a new tree-zipper focused on the root of the given tree zipper's tree. - */ - public static F, TreeZipper> root_() { - return TreeZipper::root; - } - - /** - * Navigates to the left sibling of the current location. - * - * @return A new tree zipper focused on the left sibling of the current node, - * or none if there are no siblings on the left. - */ - public Option> left() { - return lefts.isEmpty() ? Option.none() - : some(treeZipper(lefts.head(), lefts.tail()._1(), rights.cons(tree), parents)); - } - - /** - * Navigates to the right sibling of the current location. - * - * @return A new tree zipper focused on the right sibling of the current node, - * or none if there are no siblings on the right. - */ - public Option> right() { - return rights.isEmpty() ? Option.none() - : some(treeZipper(rights.head(), lefts.cons(tree), rights.tail()._1(), parents)); - } - - /** - * Navigtes to the first child of the current location. - * - * @return A new tree zipper focused on the first child of the current node, or none if the node has no children. - */ - public Option> firstChild() { - final Stream> ts = tree.subForest()._1(); - return ts.isEmpty() ? Option.none() - : some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), downParents())); - } - - /** - * Navigtes to the last child of the current location. - * - * @return A new tree zipper focused on the last child of the current node, or none if the node has no children. - */ - public Option> lastChild() { - final Stream> ts = tree.subForest()._1().reverse(); - return ts.isEmpty() ? Option.none() - : some(treeZipper(ts.head(), ts.tail()._1(), Stream.nil(), downParents())); - } - - /** - * Navigates to the given child of the current location, starting at index 0. - * - * @param n The index of the child to which to navigate. - * @return An optional tree zipper focused on the child node at the given index, or none if there is no such child. - */ - public Option> getChild(final int n) { - Option> r = none(); - for (final P2>, Stream>> lr - : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { - r = some(treeZipper(lr._1().head(), lr._1().tail()._1(), lr._2(), downParents())); - } - return r; - } - - /** - * Navigates to the first child of the current location, that satisfies the given predicate. - * - * @param p A predicate to be satisfied by the child node. - * @return An optional tree zipper focused on the first child node that satisfies the given predicate, - * or none if there is no such child. - */ - public Option> findChild(final F, Boolean> p) { - Option> r = none(); - - final F2>, Stream>, Option>, Tree, Stream>>>> split = - new F2>, Stream>, Option>, Tree, Stream>>>>() { - public Option>, Tree, Stream>>> f(final Stream> acc, - final Stream> xs) { - return xs.isNotEmpty() - ? p.f(xs.head()) ? some(P.p(acc, xs.head(), xs.tail()._1())) - : f(acc.cons(xs.head()), xs.tail()._1()) - : Option.none(); - } - }; - - Stream> subforest = tree.subForest()._1(); - if (subforest.isNotEmpty()) { - for (final P3>, Tree, Stream>> ltr - : split.f(Stream.nil(), subforest)) { - r = some(treeZipper(ltr._2(), ltr._1(), ltr._3(), downParents())); - } - } - return r; - } - - private Stream>, A, Stream>>> downParents() { - return parents.cons(P.p(lefts, tree.root(), rights)); - } - - private static Option, Stream>> splitChildren(final Stream acc, - final Stream xs, - final int n) { - return n == 0 ? some(P.p(acc, xs)) - : xs.isNotEmpty() ? splitChildren(acc.cons(xs.head()), xs.tail()._1(), n - 1) - : Option.none(); - } - - private static Stream>, A, Stream>>> lp3nil() { - return nil(); - } - - /** - * Creates a new tree zipper focused on the root of the given tree. - * - * @param t A tree over which to create a new zipper. - * @return a new tree zipper focused on the root of the given tree. - */ - public static TreeZipper fromTree(final Tree t) { - return treeZipper(t, Stream.nil(), Stream.nil(), TreeZipper.lp3nil()); - } - - /** - * Creates a new tree zipper focused on the first element of the given forest. - * - * @param ts A forest over which to create a new zipper. - * @return a new tree zipper focused on the first element of the given forest. - */ - public static Option> fromForest(final Stream> ts) { - return ts.isNotEmpty() - ? some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), TreeZipper.lp3nil())) - : Option.none(); - } - - /** - * Returns the tree containing this location. - * - * @return the tree containing this location. - */ - public Tree toTree() { - return root().tree; - } - - /** - * Returns the forest containing this location. - * - * @return the forest containing this location. - */ - public Stream> toForest() { - final TreeZipper r = root(); - return combChildren(r.lefts, r.tree, r.rights); - } - - /** - * Returns the tree at the currently focused node. - * - * @return the tree at the currently focused node. - */ - public Tree focus() { - return tree; - } - - /** - * Returns the left siblings of the currently focused node. - * - * @return the left siblings of the currently focused node. - */ - public Stream> lefts() { - return lefts; - } - - /** - * Returns the right siblings of the currently focused node. - * - * @return the right siblings of the currently focused node. - */ - public Stream> rights() { - return rights; - } - - /** - * Returns the parents of the currently focused node. - * - * @return the parents of the currently focused node. - */ - public Stream>, A, Stream>>> parents() { - return parents; - } - - /** - * Indicates whether the current node is at the top of the tree. - * - * @return true if the current node is the root of the tree, otherwise false. - */ - public boolean isRoot() { - return parents.isEmpty(); - } - - /** - * Indicates whether the current node is the leftmost tree in the current forest. - * - * @return true if the current node has no left siblings, otherwise false. - */ - public boolean isFirst() { - return lefts.isEmpty(); - } - - /** - * Indicates whether the current node is the rightmost tree in the current forest. - * - * @return true if the current node has no siblings on its right, otherwise false. - */ - public boolean isLast() { - return rights.isEmpty(); - } - - /** - * Indicates whether the current node is at the bottom of the tree. - * - * @return true if the current node has no child nodes, otherwise false. - */ - public boolean isLeaf() { - return tree.subForest()._1().isEmpty(); - } - - /** - * Indicates whether the current node is a child node of another node. - * - * @return true if the current node has a parent node, otherwise false. - */ - public boolean isChild() { - return !isRoot(); - } - - /** - * Indicates whether the current node has any child nodes. - * - * @return true if the current node has child nodes, otherwise false. - */ - public boolean hasChildren() { - return !isLeaf(); - } - - /** - * Replaces the current node with the given tree. - * - * @param t A tree with which to replace the current node. - * @return A new tree zipper in which the focused node is replaced with the given tree. - */ - public TreeZipper setTree(final Tree t) { - return treeZipper(t, lefts, rights, parents); - } - - /** - * Modifies the current node with the given function. - * - * @param f A function with which to modify the current tree. - * @return A new tree zipper in which the focused node has been transformed by the given function. - */ - public TreeZipper modifyTree(final F, Tree> f) { - return setTree(f.f(tree)); - } - - /** - * Modifies the label at the current node with the given function. - * - * @param f A function with which to transform the current node's label. - * @return A new tree zipper with the focused node's label transformed by the given function. - */ - public TreeZipper modifyLabel(final F f) { - return setLabel(f.f(getLabel())); - } - - /** - * Replaces the label of the current node with the given value. - * - * @param v The new value for the node's label. - * @return A new tree zipper with the focused node's label replaced by the given value. - */ - public TreeZipper setLabel(final A v) { - return modifyTree(t -> Tree.node(v, t.subForest())); - } - - /** - * Returns the label at the current node. - * - * @return the label at the current node. - */ - public A getLabel() { - return tree.root(); - } - - /** - * Inserts a tree to the left of the current position. The inserted tree becomes the current tree. - * - * @param t A tree to insert to the left of the current position. - * @return A new tree zipper with the given tree in focus and the current tree on the right. - */ - public TreeZipper insertLeft(final Tree t) { - return treeZipper(t, lefts, rights.cons(tree), parents); - } - - /** - * Inserts a tree to the right of the current position. The inserted tree becomes the current tree. - * - * @param t A tree to insert to the right of the current position. - * @return A new tree zipper with the given tree in focus and the current tree on the left. - */ - public TreeZipper insertRight(final Tree t) { - return treeZipper(t, lefts.cons(tree), rights, parents); - } - - /** - * Inserts a tree as the first child of the current node. The inserted tree becomes the current tree. - * - * @param t A tree to insert. - * @return A new tree zipper with the given tree in focus, as the first child of the current node. - */ - public TreeZipper insertDownFirst(final Tree t) { - return treeZipper(t, Stream.nil(), tree.subForest()._1(), downParents()); - } - - /** - * Inserts a tree as the last child of the current node. The inserted tree becomes the current tree. - * - * @param t A tree to insert. - * @return A new tree zipper with the given tree in focus, as the last child of the current node. - */ - public TreeZipper insertDownLast(final Tree t) { - return treeZipper(t, tree.subForest()._1().reverse(), Stream.nil(), downParents()); - } - - /** - * Inserts a tree at the specified location in the current node's stream of children. The inserted tree - * becomes the current node. - * - * @param n The index at which to insert the given tree, starting at 0. - * @param t A tree to insert. - * @return A new tree zipper with the given tree in focus, at the specified index in the current node's stream - * of children, or None if the current node has fewer than n children. - */ - public Option> insertDownAt(final int n, final Tree t) { - Option> r = none(); - for (final P2>, Stream>> lr - : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { - r = some(treeZipper(t, lr._1(), lr._2(), downParents())); - } - return r; - } - - /** - * Removes the current node from the tree. The new position becomes the right sibling, or the left sibling - * if the current node has no right siblings, or the parent node if the current node has no siblings. - * - * @return A new tree zipper with the current node removed. - */ - public Option> delete() { - Option> r = none(); - if (rights.isNotEmpty()) - r = some(treeZipper(rights.head(), lefts, rights.tail()._1(), parents)); - else if (lefts.isNotEmpty()) - r = some(treeZipper(lefts.head(), lefts.tail()._1(), rights, parents)); - else for (final TreeZipper loc : parent()) - r = some(loc.modifyTree(t -> node(t.root(), Stream.nil()))); - return r; - } - - /** - * Zips the nodes in this zipper with a boolean that indicates whether that node has focus. - * All of the booleans will be false, except for the focused node. - * - * @return A new zipper of pairs, with each node of this zipper paired with a boolean that is true if that - * node has focus, and false otherwise. - */ - public TreeZipper> zipWithFocus() { - final F> f = flip(P.p2()).f(false); - return map(f).modifyLabel(P2.map2_(Booleans.not)); - } - - /** - * Maps the given function across this zipper (covariant functor pattern). - * - * @param f A function to map across this zipper. - * @return A new zipper with the given function applied to the label of every node. - */ - public TreeZipper map(final F f) { - final F, Tree> g = Tree.fmap_().f(f); - final F>, Stream>> h = Stream., Tree>map_().f(g); - return treeZipper(tree.fmap(f), lefts.map(g), rights.map(g), parents.map( - p -> p.map1(h).map2(f).map3(h))); - } - - /** - * First-class conversion of a Tree to the corresponding tree zipper. - * - * @return A function that takes a tree to its tree zipper representation. - */ - public static F, TreeZipper> fromTree() { - return TreeZipper::fromTree; - } - - /** - * A first-class version of the left() function. - * - * @return A function that focuses the given tree zipper on its left sibling. - */ - public static F, Option>> left_() { - return TreeZipper::left; - } - - /** - * A first-class version of the right() function. - * - * @return A function that focuses the given tree zipper on its right sibling. - */ - public static F, Option>> right_() { - return TreeZipper::right; - } - - /** - * Returns a zipper over the tree of all possible permutations of this tree zipper (comonad pattern). - * This tree zipper becomes the focused node of the new zipper. - * - * @return A tree zipper over the tree of all possible permutations of this tree zipper. - */ - public TreeZipper> positions() { - final Tree> t = unfoldTree(TreeZipper.dwn()).f(this); - final Stream>> l = uf(TreeZipper.left_()); - final Stream>> r = uf(TreeZipper.right_()); - final Stream>>, TreeZipper, Stream>>>> p = unfold( - o -> { - Option>>, TreeZipper, Stream>>>, - Option>>> r1 = none(); - for (final TreeZipper z : o) { - r1 = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); - } - return r1; - }, parent()); - return treeZipper(t, l, r, p); - } - - private Stream>> uf(final F, Option>> f) { - return unfold( - o -> { - Option>, Option>>> r = none(); - for (final TreeZipper c : o) { - r = some(P.p(unfoldTree(TreeZipper.dwn()).f(c), f.f(c))); - } - return r; - }, f.f(this)); - } - - private static F, P2, P1>>>> dwn() { - F>, Option, Option>>>> fwd = o -> o.map(c -> P.p(c, c.right())); - return tz -> P.p(tz, P.lazy(() -> unfold(fwd, tz.firstChild()))); - } - - /** - * Maps the given function over the tree of all positions for this zipper (comonad pattern). Returns a zipper - * over the tree of results of the function application. - * - * @param f A function to map over the tree of all positions for this zipper. - * @return A zipper over the tree of results of the function application. - */ - public TreeZipper cobind(final F, B> f) { - return positions().map(f); - } - - /** - * A first-class version of the findChild function. - * - * @return a function that finds the first child, of a given tree zipper, that matches a given predicate. - */ - public static F2, Boolean>, TreeZipper, Option>> findChild() { - return (f, az) -> az.findChild(f); - } - - /** - * Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. - * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. - * - * @param bs A TreeZipper to zip this one with. - * @param f A function with which to zip together the two TreeZippers. - * @return The result of applying the given function over this TreeZipper and the given TreeZipper, location-wise. - */ - public TreeZipper zipWith(final TreeZipper bs, final F2 f) { - return F2Functions.zipTreeZipperM(f).f(this, bs); - } - - /** - * Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. - * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. - * - * @param bs A TreeZipper to zip this one with. - * @param f A function with which to zip together the two TreeZippers. - * @return The result of applying the given function over this TreeZipper and the given TreeZipper, location-wise. - */ - public TreeZipper zipWith(final TreeZipper bs, final F> f) { - return zipWith(bs, uncurryF2(f)); - } -} +package fj.data; + +import fj.*; +import fj.function.Booleans; + +import java.util.Iterator; + +import static fj.Equal.p3Equal; +import static fj.Equal.p4Equal; +import static fj.Equal.streamEqual; +import static fj.Equal.treeEqual; +import static fj.Function.compose; +import static fj.Function.curry; +import static fj.Function.flip; +import static fj.Function.uncurryF2; +import static fj.Show.p3Show; +import static fj.Show.p4Show; +import static fj.Show.streamShow; +import static fj.Show.treeShow; +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.data.Stream.nil; +import static fj.data.Stream.unfold; +import static fj.data.Tree.node; +import static fj.data.Tree.unfoldTree; + +/** + * Provides a zipper structure for rose trees, which is a Tree supplied with a location within that tree. + * Provides navigation, insertion, deletion, and memorization of visited locations within a tree. + */ +public final class TreeZipper implements Iterable> { + + /** + * Returns an iterator of all the positions of this TreeZipper. Exists for use with the foreach syntax. + * + * @return An iterator of all the positions of this TreeZipper. + */ + public Iterator> iterator() { + return positions().toTree().iterator(); + } + + private final Tree tree; + private final Stream> lefts; + private final Stream> rights; + private final Stream>, A, Stream>>> parents; + + private TreeZipper(final Tree tree, + final Stream> lefts, + final Stream> rights, + final Stream>, A, Stream>>> parents) { + this.tree = tree; + this.lefts = lefts; + this.rights = rights; + this.parents = parents; + } + + @Override + public final boolean equals(Object other) { + return Equal.equals0(TreeZipper.class, this, other, () -> Equal.treeZipperEqual(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.treeZipperHash(Hash.anyHash()).hash(this); + } + + /** + * Creates a new tree zipper given a currently selected tree, a forest on the left, a forest on the right, + * and a stream of parent contexts. + * + * @param tree The currently selected tree. + * @param lefts The selected tree's left siblings, closest first. + * @param rights The selected tree's right siblings, closest first. + * @param parents The parent of the selected tree, and the parent's siblings. + * @return A new zipper with the given tree selected, and the given forests on the left and right. + */ + public static TreeZipper treeZipper(final Tree tree, + final Stream> lefts, + final Stream> rights, + final Stream>, A, Stream>>> parents) { + return new TreeZipper<>(tree, lefts, rights, parents); + } + + /** + * First-class constructor for tree zippers. + * + * @return A function that returns a new tree zipper, given a selected tree, left and right siblings, + * and a parent context. + */ + public static + F, F>, F>, F>, A, Stream>>>, TreeZipper>>>> + treeZipper() { + return curry( + TreeZipper::treeZipper); + } + + /** + * Returns the product-4 representation of this zipper. + * + * @return the product-4 representation of this zipper. + */ + public P4, Stream>, Stream>, Stream>, A, Stream>>>> p() { + return P.p(tree, lefts, rights, parents); + } + + /** + * A first-class function that returns the product-4 representation of a given zipper. + * + * @return a function that converts a given zipper to its product-4 representation. + */ + public static + F, P4, Stream>, Stream>, Stream>, A, Stream>>>>> p_() { + return TreeZipper::p; + } + + /** + * An Equal instance for tree zippers. + * + * @param e An Equal instance for tree elements. + * @return An Equal instance for tree zippers. + */ + public static Equal> eq(final Equal e) { + return p4Equal( + treeEqual(e), + streamEqual(treeEqual(e)), + streamEqual(treeEqual(e)), + streamEqual(p3Equal(streamEqual(treeEqual(e)), e, streamEqual(treeEqual(e))))).contramap(TreeZipper.p_()); + } + + /** + * A Show instance for tree zippers. + * + * @param s A Show instance for tree elements. + * @return A Show instance for tree zippers. + */ + public static Show> show(final Show s) { + return p4Show( + treeShow(s), + streamShow(treeShow(s)), + streamShow(treeShow(s)), + streamShow(p3Show(streamShow(treeShow(s)), s, streamShow(treeShow(s))))).contramap(TreeZipper.p_()); + } + + private static Stream> combChildren(final Stream> ls, + final Tree t, + final Stream> rs) { + return ls.foldLeft(compose(flip(Stream.cons()), P.p1()), Stream.cons(t, P.p(rs))); + } + + /** + * Navigates to the parent of the current location. + * + * @return A new tree zipper focused on the parent node of the current node, + * or none if the current node is the root node. + */ + public Option> parent() { + if (parents.isEmpty()) + return none(); + else { + final P3>, A, Stream>> p = parents.head(); + return some(treeZipper(node(p._2(), combChildren(lefts, tree, rights)), p._1(), p._3(), parents.tail()._1())); + } + } + + /** + * Navigates to the top-most parent of the current location. + * + * @return A new tree zipper focused on the top-most parent of the current node. + */ + public TreeZipper root() { + return parent().option(this, TreeZipper.root_()); + } + + /** + * A first-class version of the root function. + * + * @return A function that returns a new tree-zipper focused on the root of the given tree zipper's tree. + */ + public static F, TreeZipper> root_() { + return TreeZipper::root; + } + + /** + * Navigates to the left sibling of the current location. + * + * @return A new tree zipper focused on the left sibling of the current node, + * or none if there are no siblings on the left. + */ + public Option> left() { + return lefts.isEmpty() ? Option.none() + : some(treeZipper(lefts.head(), lefts.tail()._1(), rights.cons(tree), parents)); + } + + /** + * Navigates to the right sibling of the current location. + * + * @return A new tree zipper focused on the right sibling of the current node, + * or none if there are no siblings on the right. + */ + public Option> right() { + return rights.isEmpty() ? Option.none() + : some(treeZipper(rights.head(), lefts.cons(tree), rights.tail()._1(), parents)); + } + + /** + * Navigtes to the first child of the current location. + * + * @return A new tree zipper focused on the first child of the current node, or none if the node has no children. + */ + public Option> firstChild() { + final Stream> ts = tree.subForest()._1(); + return ts.isEmpty() ? Option.none() + : some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), downParents())); + } + + /** + * Navigtes to the last child of the current location. + * + * @return A new tree zipper focused on the last child of the current node, or none if the node has no children. + */ + public Option> lastChild() { + final Stream> ts = tree.subForest()._1().reverse(); + return ts.isEmpty() ? Option.none() + : some(treeZipper(ts.head(), ts.tail()._1(), Stream.nil(), downParents())); + } + + /** + * Navigates to the given child of the current location, starting at index 0. + * + * @param n The index of the child to which to navigate. + * @return An optional tree zipper focused on the child node at the given index, or none if there is no such child. + */ + public Option> getChild(final int n) { + Option> r = none(); + for (final P2>, Stream>> lr + : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { + r = some(treeZipper(lr._1().head(), lr._1().tail()._1(), lr._2(), downParents())); + } + return r; + } + + /** + * Navigates to the first child of the current location, that satisfies the given predicate. + * + * @param p A predicate to be satisfied by the child node. + * @return An optional tree zipper focused on the first child node that satisfies the given predicate, + * or none if there is no such child. + */ + public Option> findChild(final F, Boolean> p) { + Option> r = none(); + + final F2>, Stream>, Option>, Tree, Stream>>>> split = + new F2>, Stream>, Option>, Tree, Stream>>>>() { + public Option>, Tree, Stream>>> f(final Stream> acc, + final Stream> xs) { + return xs.isNotEmpty() + ? p.f(xs.head()) ? some(P.p(acc, xs.head(), xs.tail()._1())) + : f(acc.cons(xs.head()), xs.tail()._1()) + : Option.none(); + } + }; + + Stream> subforest = tree.subForest()._1(); + if (subforest.isNotEmpty()) { + for (final P3>, Tree, Stream>> ltr + : split.f(Stream.nil(), subforest)) { + r = some(treeZipper(ltr._2(), ltr._1(), ltr._3(), downParents())); + } + } + return r; + } + + private Stream>, A, Stream>>> downParents() { + return parents.cons(P.p(lefts, tree.root(), rights)); + } + + private static Option, Stream>> splitChildren(final Stream acc, + final Stream xs, + final int n) { + return n == 0 ? some(P.p(acc, xs)) + : xs.isNotEmpty() ? splitChildren(acc.cons(xs.head()), xs.tail()._1(), n - 1) + : Option.none(); + } + + private static Stream>, A, Stream>>> lp3nil() { + return nil(); + } + + /** + * Creates a new tree zipper focused on the root of the given tree. + * + * @param t A tree over which to create a new zipper. + * @return a new tree zipper focused on the root of the given tree. + */ + public static TreeZipper fromTree(final Tree t) { + return treeZipper(t, Stream.nil(), Stream.nil(), TreeZipper.lp3nil()); + } + + /** + * Creates a new tree zipper focused on the first element of the given forest. + * + * @param ts A forest over which to create a new zipper. + * @return a new tree zipper focused on the first element of the given forest. + */ + public static Option> fromForest(final Stream> ts) { + return ts.isNotEmpty() + ? some(treeZipper(ts.head(), Stream.nil(), ts.tail()._1(), TreeZipper.lp3nil())) + : Option.none(); + } + + /** + * Returns the tree containing this location. + * + * @return the tree containing this location. + */ + public Tree toTree() { + return root().tree; + } + + /** + * Returns the forest containing this location. + * + * @return the forest containing this location. + */ + public Stream> toForest() { + final TreeZipper r = root(); + return combChildren(r.lefts, r.tree, r.rights); + } + + /** + * Returns the tree at the currently focused node. + * + * @return the tree at the currently focused node. + */ + public Tree focus() { + return tree; + } + + /** + * Returns the left siblings of the currently focused node. + * + * @return the left siblings of the currently focused node. + */ + public Stream> lefts() { + return lefts; + } + + /** + * Returns the right siblings of the currently focused node. + * + * @return the right siblings of the currently focused node. + */ + public Stream> rights() { + return rights; + } + + /** + * Returns the parents of the currently focused node. + * + * @return the parents of the currently focused node. + */ + public Stream>, A, Stream>>> parents() { + return parents; + } + + /** + * Indicates whether the current node is at the top of the tree. + * + * @return true if the current node is the root of the tree, otherwise false. + */ + public boolean isRoot() { + return parents.isEmpty(); + } + + /** + * Indicates whether the current node is the leftmost tree in the current forest. + * + * @return true if the current node has no left siblings, otherwise false. + */ + public boolean isFirst() { + return lefts.isEmpty(); + } + + /** + * Indicates whether the current node is the rightmost tree in the current forest. + * + * @return true if the current node has no siblings on its right, otherwise false. + */ + public boolean isLast() { + return rights.isEmpty(); + } + + /** + * Indicates whether the current node is at the bottom of the tree. + * + * @return true if the current node has no child nodes, otherwise false. + */ + public boolean isLeaf() { + return tree.subForest()._1().isEmpty(); + } + + /** + * Indicates whether the current node is a child node of another node. + * + * @return true if the current node has a parent node, otherwise false. + */ + public boolean isChild() { + return !isRoot(); + } + + /** + * Indicates whether the current node has any child nodes. + * + * @return true if the current node has child nodes, otherwise false. + */ + public boolean hasChildren() { + return !isLeaf(); + } + + /** + * Replaces the current node with the given tree. + * + * @param t A tree with which to replace the current node. + * @return A new tree zipper in which the focused node is replaced with the given tree. + */ + public TreeZipper setTree(final Tree t) { + return treeZipper(t, lefts, rights, parents); + } + + /** + * Modifies the current node with the given function. + * + * @param f A function with which to modify the current tree. + * @return A new tree zipper in which the focused node has been transformed by the given function. + */ + public TreeZipper modifyTree(final F, Tree> f) { + return setTree(f.f(tree)); + } + + /** + * Modifies the label at the current node with the given function. + * + * @param f A function with which to transform the current node's label. + * @return A new tree zipper with the focused node's label transformed by the given function. + */ + public TreeZipper modifyLabel(final F f) { + return setLabel(f.f(getLabel())); + } + + /** + * Replaces the label of the current node with the given value. + * + * @param v The new value for the node's label. + * @return A new tree zipper with the focused node's label replaced by the given value. + */ + public TreeZipper setLabel(final A v) { + return modifyTree(t -> Tree.node(v, t.subForest())); + } + + /** + * Returns the label at the current node. + * + * @return the label at the current node. + */ + public A getLabel() { + return tree.root(); + } + + /** + * Inserts a tree to the left of the current position. The inserted tree becomes the current tree. + * + * @param t A tree to insert to the left of the current position. + * @return A new tree zipper with the given tree in focus and the current tree on the right. + */ + public TreeZipper insertLeft(final Tree t) { + return treeZipper(t, lefts, rights.cons(tree), parents); + } + + /** + * Inserts a tree to the right of the current position. The inserted tree becomes the current tree. + * + * @param t A tree to insert to the right of the current position. + * @return A new tree zipper with the given tree in focus and the current tree on the left. + */ + public TreeZipper insertRight(final Tree t) { + return treeZipper(t, lefts.cons(tree), rights, parents); + } + + /** + * Inserts a tree as the first child of the current node. The inserted tree becomes the current tree. + * + * @param t A tree to insert. + * @return A new tree zipper with the given tree in focus, as the first child of the current node. + */ + public TreeZipper insertDownFirst(final Tree t) { + return treeZipper(t, Stream.nil(), tree.subForest()._1(), downParents()); + } + + /** + * Inserts a tree as the last child of the current node. The inserted tree becomes the current tree. + * + * @param t A tree to insert. + * @return A new tree zipper with the given tree in focus, as the last child of the current node. + */ + public TreeZipper insertDownLast(final Tree t) { + return treeZipper(t, tree.subForest()._1().reverse(), Stream.nil(), downParents()); + } + + /** + * Inserts a tree at the specified location in the current node's stream of children. The inserted tree + * becomes the current node. + * + * @param n The index at which to insert the given tree, starting at 0. + * @param t A tree to insert. + * @return A new tree zipper with the given tree in focus, at the specified index in the current node's stream + * of children, or None if the current node has fewer than n children. + */ + public Option> insertDownAt(final int n, final Tree t) { + Option> r = none(); + for (final P2>, Stream>> lr + : splitChildren(Stream.nil(), tree.subForest()._1(), n)) { + r = some(treeZipper(t, lr._1(), lr._2(), downParents())); + } + return r; + } + + /** + * Removes the current node from the tree. The new position becomes the right sibling, or the left sibling + * if the current node has no right siblings, or the parent node if the current node has no siblings. + * + * @return A new tree zipper with the current node removed. + */ + public Option> delete() { + Option> r = none(); + if (rights.isNotEmpty()) + r = some(treeZipper(rights.head(), lefts, rights.tail()._1(), parents)); + else if (lefts.isNotEmpty()) + r = some(treeZipper(lefts.head(), lefts.tail()._1(), rights, parents)); + else for (final TreeZipper loc : parent()) + r = some(loc.modifyTree(t -> node(t.root(), Stream.nil()))); + return r; + } + + /** + * Zips the nodes in this zipper with a boolean that indicates whether that node has focus. + * All of the booleans will be false, except for the focused node. + * + * @return A new zipper of pairs, with each node of this zipper paired with a boolean that is true if that + * node has focus, and false otherwise. + */ + public TreeZipper> zipWithFocus() { + final F> f = flip(P.p2()).f(false); + return map(f).modifyLabel(P2.map2_(Booleans.not)); + } + + /** + * Maps the given function across this zipper (covariant functor pattern). + * + * @param f A function to map across this zipper. + * @return A new zipper with the given function applied to the label of every node. + */ + public TreeZipper map(final F f) { + final F, Tree> g = Tree.fmap_().f(f); + final F>, Stream>> h = Stream., Tree>map_().f(g); + return treeZipper(tree.fmap(f), lefts.map(g), rights.map(g), parents.map( + p -> p.map1(h).map2(f).map3(h))); + } + + /** + * First-class conversion of a Tree to the corresponding tree zipper. + * + * @return A function that takes a tree to its tree zipper representation. + */ + public static F, TreeZipper> fromTree() { + return TreeZipper::fromTree; + } + + /** + * A first-class version of the left() function. + * + * @return A function that focuses the given tree zipper on its left sibling. + */ + public static F, Option>> left_() { + return TreeZipper::left; + } + + /** + * A first-class version of the right() function. + * + * @return A function that focuses the given tree zipper on its right sibling. + */ + public static F, Option>> right_() { + return TreeZipper::right; + } + + /** + * Returns a zipper over the tree of all possible permutations of this tree zipper (comonad pattern). + * This tree zipper becomes the focused node of the new zipper. + * + * @return A tree zipper over the tree of all possible permutations of this tree zipper. + */ + public TreeZipper> positions() { + final Tree> t = unfoldTree(TreeZipper.dwn()).f(this); + final Stream>> l = uf(TreeZipper.left_()); + final Stream>> r = uf(TreeZipper.right_()); + final Stream>>, TreeZipper, Stream>>>> p = unfold( + o -> { + Option>>, TreeZipper, Stream>>>, + Option>>> r1 = none(); + for (final TreeZipper z : o) { + r1 = some(P.p(P.p(z.uf(TreeZipper.left_()), z, z.uf(TreeZipper.right_())), z.parent())); + } + return r1; + }, parent()); + return treeZipper(t, l, r, p); + } + + private Stream>> uf(final F, Option>> f) { + return unfold( + o -> { + Option>, Option>>> r = none(); + for (final TreeZipper c : o) { + r = some(P.p(unfoldTree(TreeZipper.dwn()).f(c), f.f(c))); + } + return r; + }, f.f(this)); + } + + private static F, P2, P1>>>> dwn() { + F>, Option, Option>>>> fwd = o -> o.map(c -> P.p(c, c.right())); + return tz -> P.p(tz, P.lazy(() -> unfold(fwd, tz.firstChild()))); + } + + /** + * Maps the given function over the tree of all positions for this zipper (comonad pattern). Returns a zipper + * over the tree of results of the function application. + * + * @param f A function to map over the tree of all positions for this zipper. + * @return A zipper over the tree of results of the function application. + */ + public TreeZipper cobind(final F, B> f) { + return positions().map(f); + } + + /** + * A first-class version of the findChild function. + * + * @return a function that finds the first child, of a given tree zipper, that matches a given predicate. + */ + public static F2, Boolean>, TreeZipper, Option>> findChild() { + return (f, az) -> az.findChild(f); + } + + /** + * Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. + * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. + * + * @param bs A TreeZipper to zip this one with. + * @param f A function with which to zip together the two TreeZippers. + * @return The result of applying the given function over this TreeZipper and the given TreeZipper, location-wise. + */ + public TreeZipper zipWith(final TreeZipper bs, final F2 f) { + return f.zipTreeZipperM().f(this, bs); + } + + /** + * Zips this TreeZipper with another, applying the given function lock-step over both zippers in all directions. + * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers. + * + * @param bs A TreeZipper to zip this one with. + * @param f A function with which to zip together the two TreeZippers. + * @return The result of applying the given function over this TreeZipper and the given TreeZipper, location-wise. + */ + public TreeZipper zipWith(final TreeZipper bs, final F> f) { + return zipWith(bs, uncurryF2(f)); + } +} diff --git a/core/src/main/java/fj/data/Zipper.java b/core/src/main/java/fj/data/Zipper.java index 2514d8e2..4b96377f 100644 --- a/core/src/main/java/fj/data/Zipper.java +++ b/core/src/main/java/fj/data/Zipper.java @@ -1,585 +1,585 @@ -package fj.data; - -import fj.*; -import fj.function.Integers; - -import java.util.Iterator; - -import static fj.Function.compose; -import static fj.Function.curry; -import static fj.Function.flip; -import static fj.Function.join; -import static fj.Function.uncurryF2; -import static fj.data.Option.none; -import static fj.data.Option.some; -import static fj.data.Stream.nil; -import static fj.data.Stream.repeat; - -/** - * Provides a pointed stream, which is a non-empty zipper-like stream structure that tracks an index (focus) - * position in a stream. Focus can be moved forward and backwards through the stream, elements can be inserted - * before or after the focused position, and the focused item can be deleted. - *

      - * Based on the pointedlist library by Jeff Wheeler. - */ -public final class Zipper implements Iterable> { - private final Stream left; - private final A focus; - private final Stream right; - - private Zipper(final Stream left, final A focus, final Stream right) { - this.left = left; - this.focus = focus; - this.right = right; - } - - - /** - * Creates a new Zipper with the given streams before and after the focus, and the given focused item. - * - * @param left The stream of elements before the focus. - * @param focus The element under focus. - * @param right The stream of elements after the focus. - * @return a new Zipper with the given streams before and after the focus, and the given focused item. - */ - public static Zipper zipper(final Stream left, final A focus, final Stream right) { - return new Zipper<>(left, focus, right); - } - - /** - * Creates a new Zipper from the given triple. - * - * @param p A triple of the elements before the focus, the focus element, and the elements after the focus, - * respectively. - * @return a new Zipper created from the given triple. - */ - public static Zipper zipper(final P3, A, Stream> p) { - return new Zipper<>(p._1(), p._2(), p._3()); - } - - /** - * First-class constructor of zippers. - * - * @return A function that yields a new zipper given streams on the left and right and a focus element. - */ - public static F3, A, Stream, Zipper> zipper() { - return Zipper::zipper; - } - - /** - * Returns the product-3 representation of this Zipper. - * - * @return the product-3 representation of this Zipper. - */ - public P3, A, Stream> p() { - return P.p(left, focus, right); - } - - /** - * A first-class function that yields the product-3 representation of a given Zipper. - * - * @return A first-class function that yields the product-3 representation of a given Zipper. - */ - public static F, P3, A, Stream>> p_() { - return Zipper::p; - } - - /** - * An Ord instance for Zippers. - * - * @param o An Ord instance for the element type. - * @return An Ord instance for Zippers. - */ - public static Ord> ord(final Ord o) { - final Ord> so = Ord.streamOrd(o); - return Ord.p3Ord(so, o, so).contramap(Zipper.p_()); - } - - @Override - public final boolean equals(Object other) { - return Equal.equals0(Zipper.class, this, other, () -> Equal.zipperEqual(Equal.anyEqual())); - } - - @Override - public final int hashCode() { - return Hash.zipperHash(Hash.anyHash()).hash(this); - } - - /** - * An Equal instance for Zippers. - * - * @param e An Equal instance for the element type. - * @return An Equal instance for Zippers. - */ - public static Equal> eq(final Equal e) { - final Equal> se = Equal.streamEqual(e); - return Equal.p3Equal(se, e, se).contramap(Zipper.p_()); - } - - /** - * A Show instance for Zippers. - * - * @param s A Show instance for the element type. - * @return A Show instance for Zippers. - */ - public static Show> show(final Show s) { - final Show> ss = Show.streamShow(s); - return Show.p3Show(ss, s, ss).contramap(Zipper.p_()); - } - - /** - * Maps the given function across the elements of this zipper (covariant functor pattern). - * - * @param f A function to map across this zipper. - * @return A new zipper with the given function applied to all elements. - */ - public Zipper map(final F f) { - return zipper(left.map(f), f.f(focus), right.map(f)); - } - - /** - * Performs a right-fold reduction across this zipper. - * - * @param f The function to apply on each element of this zipper. - * @param z The beginning value to start the application from. - * @return the final result after the right-fold reduction. - */ - public B foldRight(final F> f, final B z) { - return left.foldLeft(flip(f), - right.cons(focus).foldRight(compose( - Function., B, B>andThen().f(P1.__1()), f), z)); - } - - /** - * Creates a new zipper with a single element. - * - * @param a The focus element of the new zipper. - * @return a new zipper with a single element which is in focus. - */ - public static Zipper single(final A a) { - return zipper(Stream.nil(), a, Stream.nil()); - } - - /** - * Possibly create a zipper if the provided stream has at least one element, otherwise None. - * The provided stream's head will be the focus of the zipper, and the rest of the stream will follow - * on the right side. - * - * @param a The stream from which to create a zipper. - * @return a new zipper if the provided stream has at least one element, otherwise None. - */ - @SuppressWarnings("IfMayBeConditional") - public static Option> fromStream(final Stream a) { - if (a.isEmpty()) - return none(); - else - return some(zipper(Stream.nil(), a.head(), a.tail()._1())); - } - - /** - * Possibly create a zipper if the provided stream has at least one element, otherwise None. - * The provided stream's last element will be the focus of the zipper, following the rest of the stream in order, - * to the left. - * - * @param a The stream from which to create a zipper. - * @return a new zipper if the provided stream has at least one element, otherwise None. - */ - public static Option> fromStreamEnd(final Stream a) { - if (a.isEmpty()) - return none(); - else { - final Stream xs = a.reverse(); - return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); - } - } - - /** - * Returns the focus element of this zipper. - * - * @return the focus element of this zipper. - */ - public A focus() { - return focus; - } - - /** - * Possibly moves the focus to the next element in the list. - * - * @return An optional zipper with the focus moved one element to the right, if there are elements to the right of - * focus, otherwise None. - */ - public Option> next() { - return right.isEmpty() ? Option.none() : some(tryNext()); - } - - /** - * Attempts to move the focus to the next element, or throws an error if there are no more elements. - * - * @return A zipper with the focus moved one element to the right, if there are elements to the right of - * focus, otherwise throws an error. - */ - public Zipper tryNext() { - if (right.isEmpty()) - throw new Error("Tried next at the end of a zipper."); - else - return zipper(left.cons(focus), right.head(), right.tail()._1()); - } - - /** - * Possibly moves the focus to the previous element in the list. - * - * @return An optional zipper with the focus moved one element to the left, if there are elements to the left of - * focus, otherwise None. - */ - public Option> previous() { - return left.isEmpty() ? Option.none() : some(tryPrevious()); - } - - /** - * Attempts to move the focus to the previous element, or throws an error if there are no more elements. - * - * @return A zipper with the focus moved one element to the left, if there are elements to the left of - * focus, otherwise throws an error. - */ - public Zipper tryPrevious() { - if (left.isEmpty()) - throw new Error("Tried previous at the beginning of a zipper."); - else - return zipper(left.tail()._1(), left.head(), right.cons(focus)); - } - - /** - * First-class version of the next() function. - * - * @return A function that moves the given zipper's focus to the next element. - */ - public static F, Option>> next_() { - return Zipper::next; - } - - /** - * First-class version of the previous() function. - * - * @return A function that moves the given zipper's focus to the previous element. - */ - public static F, Option>> previous_() { - return Zipper::previous; - } - - /** - * Inserts an element to the left of the focus, then moves the focus to the new element. - * - * @param a A new element to insert into this zipper. - * @return A new zipper with the given element in focus, and the current focus element on its right. - */ - public Zipper insertLeft(final A a) { - return zipper(left, a, right.cons(focus)); - } - - /** - * Inserts an element to the right of the focus, then moves the focus to the new element. - * - * @param a A new element to insert into this zipper. - * @return A new zipper with the given element in focus, and the current focus element on its left. - */ - public Zipper insertRight(final A a) { - return zipper(left.cons(focus), a, right); - } - - /** - * Possibly deletes the element at the focus, then moves the element on the left into focus. - * If no element is on the left, focus on the element to the right. - * Returns None if the focus element is the only element in this zipper. - * - * @return A new zipper with this zipper's focus element removed, or None if deleting the focus element - * would cause the zipper to be empty. - */ - public Option> deleteLeft() { - return left.isEmpty() && right.isEmpty() - ? Option.none() - : some(zipper(left.isEmpty() ? left : left.tail()._1(), - left.isEmpty() ? right.head() : left.head(), - left.isEmpty() ? right.tail()._1() : right)); - } - - /** - * Possibly deletes the element at the focus, then moves the element on the right into focus. - * If no element is on the right, focus on the element to the left. - * Returns None if the focus element is the only element in this zipper. - * - * @return A new zipper with this zipper's focus element removed, or None if deleting the focus element - * would cause the zipper to be empty. - */ - public Option> deleteRight() { - return left.isEmpty() && right.isEmpty() - ? Option.none() - : some(zipper(right.isEmpty() ? left.tail()._1() : left, - right.isEmpty() ? left.head() : right.head(), - right.isEmpty() ? right : right.tail()._1())); - } - - /** - * Deletes all elements in the zipper except the focus. - * - * @return A new zipper with the focus element as the only element. - */ - public Zipper deleteOthers() { - final Stream nil = nil(); - return zipper(nil, focus, nil); - } - - /** - * Returns the length of this zipper. - * - * @return the length of this zipper. - */ - public int length() { - return foldRight(Function.constant(Integers.add.f(1)), 0); - } - - /** - * Returns whether the focus is on the first element. - * - * @return true if the focus is on the first element, otherwise false. - */ - public boolean atStart() { - return left.isEmpty(); - } - - /** - * Returns whether the focus is on the last element. - * - * @return true if the focus is on the last element, otherwise false. - */ - public boolean atEnd() { - return right.isEmpty(); - } - - /** - * Creates a zipper of variations of this zipper, in which each element is focused, - * with this zipper as the focus of the zipper of zippers (comonad pattern). - * - * @return a zipper of variations of the provided zipper, in which each element is focused, - * with this zipper as the focus of the zipper of zippers. - */ - public Zipper> positions() { - final Stream> left = Stream.unfold( - p -> p.previous().map(join(P.p2())), this); - final Stream> right = Stream.unfold( - p -> p.next().map(join(P.p2())), this); - - return zipper(left, this, right); - } - - /** - * Maps over variations of this zipper, such that the given function is applied to each variation (comonad pattern). - * - * @param f The comonadic function to apply for each variation of this zipper. - * @return A new zipper, with the given function applied for each variation of this zipper. - */ - public Zipper cobind(final F, B> f) { - return positions().map(f); - } - - /** - * Zips the elements of this zipper with a boolean that indicates whether that element has focus. - * All of the booleans will be false, except the focused element. - * - * @return A new zipper of pairs, with each element of this zipper paired with a boolean that is true if that - * element has focus, and false otherwise. - */ - public Zipper> zipWithFocus() { - return zipper(left.zip(repeat(false)), P.p(focus, true), right.zip(repeat(false))); - } - - /** - * Move the focus to the specified index. - * - * @param n The index to which to move the focus. - * @return A new zipper with the focus moved to the specified index, or none if there is no such index. - */ - public Option> move(final int n) { - final int ll = left.length(); - final int rl = right.length(); - Option> p = some(this); - if (n < 0 || n >= length()) - return none(); - else if (ll >= n) - for (int i = ll - n; i > 0; i--) - p = p.bind(Zipper.previous_()); - else if (rl >= n) - for (int i = rl - n; i > 0; i--) - p = p.bind(Zipper.next_()); - return p; - } - - /** - * A first-class version of the move function. - * - * @return A function that moves the focus of the given zipper to the given index. - */ - public static F, Option>>> move() { - return curry((i, a) -> a.move(i)); - } - - /** - * Moves the focus to the element matching the given predicate, if present. - * - * @param p A predicate to match. - * @return A new zipper with the nearest matching element focused if it is present in this zipper. - */ - public Option> find(final F p) { - if (p.f(focus())) - return some(this); - else { - final Zipper> ps = positions(); - return ps.lefts().interleave(ps.rights()).find(zipper -> p.f(zipper.focus())); - } - } - - /** - * Returns the index of the focus. - * - * @return the index of the focus. - */ - public int index() { - return left.length(); - } - - /** - * Move the focus to the next element. If the last element is focused, loop to the first element. - * - * @return A new zipper with the next element focused, unless the last element is currently focused, in which case - * the first element becomes focused. - */ - public Zipper cycleNext() { - if (left.isEmpty() && right.isEmpty()) - return this; - else if (right.isEmpty()) { - final Stream xs = left.reverse(); - return zipper(Stream.nil(), xs.head(), xs.tail()._1().snoc(P.p(focus))); - } else - return tryNext(); - } - - /** - * Move the focus to the previous element. If the first element is focused, loop to the last element. - * - * @return A new zipper with the previous element focused, unless the first element is currently focused, - * in which case the last element becomes focused. - */ - public Zipper cyclePrevious() { - if (left.isEmpty() && right.isEmpty()) - return this; - else if (left.isEmpty()) { - final Stream xs = right.reverse(); - return zipper(xs.tail()._1().snoc(P.p(focus)), xs.head(), Stream.nil()); - } else - return tryPrevious(); - } - - /** - * Possibly deletes the element at the focus, then move the element on the left into focus. If no element is on the - * left, focus on the last element. If the deletion will cause the list to be empty, return None. - * - * @return A new zipper with the focused element removed, and focus on the previous element to the left, or the last - * element if there is no element to the left. - */ - public Option> deleteLeftCycle() { - if (left.isEmpty() && right.isEmpty()) - return none(); - else if (left.isNotEmpty()) - return some(zipper(left.tail()._1(), left.head(), right)); - else { - final Stream xs = right.reverse(); - return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); - } - } - - /** - * Possibly deletes the element at the focus, then move the element on the right into focus. If no element is on the - * right, focus on the first element. If the deletion will cause the list to be empty, return None. - * - * @return A new zipper with the focused element removed, and focus on the next element to the right, or the first - * element if there is no element to the right. - */ - public Option> deleteRightCycle() { - if (left.isEmpty() && right.isEmpty()) - return none(); - else if (right.isNotEmpty()) - return some(zipper(left, right.head(), right.tail()._1())); - else { - final Stream xs = left.reverse(); - return some(zipper(Stream.nil(), xs.head(), xs.tail()._1())); - } - } - - /** - * Replaces the element in focus with the given element. - * - * @param a An element to replace the focused element with. - * @return A new zipper with the given element in focus. - */ - public Zipper replace(final A a) { - return zipper(left, a, right); - } - - /** - * Returns the Stream representation of this zipper. - * - * @return A stream that contains all the elements of this zipper. - */ - public Stream toStream() { - return left.reverse().snoc(P.p(focus)).append(right); - } - - /** - * Returns a Stream of the elements to the left of focus. - * - * @return a Stream of the elements to the left of focus. - */ - public Stream lefts() { - return left; - } - - /** - * Returns a Stream of the elements to the right of focus. - * - * @return a Stream of the elements to the right of focus. - */ - public Stream rights() { - return right; - } - - /** - * Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. - * The structure of the resulting Zipper is the structural intersection of the two Zippers. - * - * @param bs A Zipper to zip this one with. - * @param f A function with which to zip together the two Zippers. - * @return The result of applying the given function over this Zipper and the given Zipper, location-wise. - */ - public Zipper zipWith(final Zipper bs, final F2 f) { - return F2Functions.zipZipperM(f).f(this, bs); - } - - - /** - * Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. - * The structure of the resulting Zipper is the structural intersection of the two Zippers. - * - * @param bs A Zipper to zip this one with. - * @param f A function with which to zip together the two Zippers. - * @return The result of applying the given function over this Zipper and the given Zipper, location-wise. - */ - public Zipper zipWith(final Zipper bs, final F> f) { - return zipWith(bs, uncurryF2(f)); - } - - /** - * Returns an iterator of all the positions of this Zipper, starting from the leftmost position. - * - * @return An iterator of all the positions of this Zipper, starting from the leftmost position. - */ - public Iterator> iterator() { return positions().toStream().iterator(); } -} +package fj.data; + +import fj.*; +import fj.function.Integers; + +import java.util.Iterator; + +import static fj.Function.compose; +import static fj.Function.curry; +import static fj.Function.flip; +import static fj.Function.join; +import static fj.Function.uncurryF2; +import static fj.data.Option.none; +import static fj.data.Option.some; +import static fj.data.Stream.nil; +import static fj.data.Stream.repeat; + +/** + * Provides a pointed stream, which is a non-empty zipper-like stream structure that tracks an index (focus) + * position in a stream. Focus can be moved forward and backwards through the stream, elements can be inserted + * before or after the focused position, and the focused item can be deleted. + *

      + * Based on the pointedlist library by Jeff Wheeler. + */ +public final class Zipper implements Iterable> { + private final Stream left; + private final A focus; + private final Stream right; + + private Zipper(final Stream left, final A focus, final Stream right) { + this.left = left; + this.focus = focus; + this.right = right; + } + + + /** + * Creates a new Zipper with the given streams before and after the focus, and the given focused item. + * + * @param left The stream of elements before the focus. + * @param focus The element under focus. + * @param right The stream of elements after the focus. + * @return a new Zipper with the given streams before and after the focus, and the given focused item. + */ + public static Zipper zipper(final Stream left, final A focus, final Stream right) { + return new Zipper<>(left, focus, right); + } + + /** + * Creates a new Zipper from the given triple. + * + * @param p A triple of the elements before the focus, the focus element, and the elements after the focus, + * respectively. + * @return a new Zipper created from the given triple. + */ + public static Zipper zipper(final P3, A, Stream> p) { + return new Zipper<>(p._1(), p._2(), p._3()); + } + + /** + * First-class constructor of zippers. + * + * @return A function that yields a new zipper given streams on the left and right and a focus element. + */ + public static F3, A, Stream, Zipper> zipper() { + return Zipper::zipper; + } + + /** + * Returns the product-3 representation of this Zipper. + * + * @return the product-3 representation of this Zipper. + */ + public P3, A, Stream> p() { + return P.p(left, focus, right); + } + + /** + * A first-class function that yields the product-3 representation of a given Zipper. + * + * @return A first-class function that yields the product-3 representation of a given Zipper. + */ + public static F, P3, A, Stream>> p_() { + return Zipper::p; + } + + /** + * An Ord instance for Zippers. + * + * @param o An Ord instance for the element type. + * @return An Ord instance for Zippers. + */ + public static Ord> ord(final Ord o) { + final Ord> so = Ord.streamOrd(o); + return Ord.p3Ord(so, o, so).contramap(Zipper.p_()); + } + + @Override + public final boolean equals(Object other) { + return Equal.equals0(Zipper.class, this, other, () -> Equal.zipperEqual(Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.zipperHash(Hash.anyHash()).hash(this); + } + + /** + * An Equal instance for Zippers. + * + * @param e An Equal instance for the element type. + * @return An Equal instance for Zippers. + */ + public static Equal> eq(final Equal e) { + final Equal> se = Equal.streamEqual(e); + return Equal.p3Equal(se, e, se).contramap(Zipper.p_()); + } + + /** + * A Show instance for Zippers. + * + * @param s A Show instance for the element type. + * @return A Show instance for Zippers. + */ + public static Show> show(final Show s) { + final Show> ss = Show.streamShow(s); + return Show.p3Show(ss, s, ss).contramap(Zipper.p_()); + } + + /** + * Maps the given function across the elements of this zipper (covariant functor pattern). + * + * @param f A function to map across this zipper. + * @return A new zipper with the given function applied to all elements. + */ + public Zipper map(final F f) { + return zipper(left.map(f), f.f(focus), right.map(f)); + } + + /** + * Performs a right-fold reduction across this zipper. + * + * @param f The function to apply on each element of this zipper. + * @param z The beginning value to start the application from. + * @return the final result after the right-fold reduction. + */ + public B foldRight(final F> f, final B z) { + return left.foldLeft(flip(f), + right.cons(focus).foldRight(compose( + Function., B, B>andThen().f(P1.__1()), f), z)); + } + + /** + * Creates a new zipper with a single element. + * + * @param a The focus element of the new zipper. + * @return a new zipper with a single element which is in focus. + */ + public static Zipper single(final A a) { + return zipper(Stream.nil(), a, Stream.nil()); + } + + /** + * Possibly create a zipper if the provided stream has at least one element, otherwise None. + * The provided stream's head will be the focus of the zipper, and the rest of the stream will follow + * on the right side. + * + * @param a The stream from which to create a zipper. + * @return a new zipper if the provided stream has at least one element, otherwise None. + */ + @SuppressWarnings("IfMayBeConditional") + public static Option> fromStream(final Stream a) { + if (a.isEmpty()) + return none(); + else + return some(zipper(Stream.nil(), a.head(), a.tail()._1())); + } + + /** + * Possibly create a zipper if the provided stream has at least one element, otherwise None. + * The provided stream's last element will be the focus of the zipper, following the rest of the stream in order, + * to the left. + * + * @param a The stream from which to create a zipper. + * @return a new zipper if the provided stream has at least one element, otherwise None. + */ + public static Option> fromStreamEnd(final Stream a) { + if (a.isEmpty()) + return none(); + else { + final Stream xs = a.reverse(); + return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); + } + } + + /** + * Returns the focus element of this zipper. + * + * @return the focus element of this zipper. + */ + public A focus() { + return focus; + } + + /** + * Possibly moves the focus to the next element in the list. + * + * @return An optional zipper with the focus moved one element to the right, if there are elements to the right of + * focus, otherwise None. + */ + public Option> next() { + return right.isEmpty() ? Option.none() : some(tryNext()); + } + + /** + * Attempts to move the focus to the next element, or throws an error if there are no more elements. + * + * @return A zipper with the focus moved one element to the right, if there are elements to the right of + * focus, otherwise throws an error. + */ + public Zipper tryNext() { + if (right.isEmpty()) + throw new Error("Tried next at the end of a zipper."); + else + return zipper(left.cons(focus), right.head(), right.tail()._1()); + } + + /** + * Possibly moves the focus to the previous element in the list. + * + * @return An optional zipper with the focus moved one element to the left, if there are elements to the left of + * focus, otherwise None. + */ + public Option> previous() { + return left.isEmpty() ? Option.none() : some(tryPrevious()); + } + + /** + * Attempts to move the focus to the previous element, or throws an error if there are no more elements. + * + * @return A zipper with the focus moved one element to the left, if there are elements to the left of + * focus, otherwise throws an error. + */ + public Zipper tryPrevious() { + if (left.isEmpty()) + throw new Error("Tried previous at the beginning of a zipper."); + else + return zipper(left.tail()._1(), left.head(), right.cons(focus)); + } + + /** + * First-class version of the next() function. + * + * @return A function that moves the given zipper's focus to the next element. + */ + public static F, Option>> next_() { + return Zipper::next; + } + + /** + * First-class version of the previous() function. + * + * @return A function that moves the given zipper's focus to the previous element. + */ + public static F, Option>> previous_() { + return Zipper::previous; + } + + /** + * Inserts an element to the left of the focus, then moves the focus to the new element. + * + * @param a A new element to insert into this zipper. + * @return A new zipper with the given element in focus, and the current focus element on its right. + */ + public Zipper insertLeft(final A a) { + return zipper(left, a, right.cons(focus)); + } + + /** + * Inserts an element to the right of the focus, then moves the focus to the new element. + * + * @param a A new element to insert into this zipper. + * @return A new zipper with the given element in focus, and the current focus element on its left. + */ + public Zipper insertRight(final A a) { + return zipper(left.cons(focus), a, right); + } + + /** + * Possibly deletes the element at the focus, then moves the element on the left into focus. + * If no element is on the left, focus on the element to the right. + * Returns None if the focus element is the only element in this zipper. + * + * @return A new zipper with this zipper's focus element removed, or None if deleting the focus element + * would cause the zipper to be empty. + */ + public Option> deleteLeft() { + return left.isEmpty() && right.isEmpty() + ? Option.none() + : some(zipper(left.isEmpty() ? left : left.tail()._1(), + left.isEmpty() ? right.head() : left.head(), + left.isEmpty() ? right.tail()._1() : right)); + } + + /** + * Possibly deletes the element at the focus, then moves the element on the right into focus. + * If no element is on the right, focus on the element to the left. + * Returns None if the focus element is the only element in this zipper. + * + * @return A new zipper with this zipper's focus element removed, or None if deleting the focus element + * would cause the zipper to be empty. + */ + public Option> deleteRight() { + return left.isEmpty() && right.isEmpty() + ? Option.none() + : some(zipper(right.isEmpty() ? left.tail()._1() : left, + right.isEmpty() ? left.head() : right.head(), + right.isEmpty() ? right : right.tail()._1())); + } + + /** + * Deletes all elements in the zipper except the focus. + * + * @return A new zipper with the focus element as the only element. + */ + public Zipper deleteOthers() { + final Stream nil = nil(); + return zipper(nil, focus, nil); + } + + /** + * Returns the length of this zipper. + * + * @return the length of this zipper. + */ + public int length() { + return foldRight(Function.constant(Integers.add.f(1)), 0); + } + + /** + * Returns whether the focus is on the first element. + * + * @return true if the focus is on the first element, otherwise false. + */ + public boolean atStart() { + return left.isEmpty(); + } + + /** + * Returns whether the focus is on the last element. + * + * @return true if the focus is on the last element, otherwise false. + */ + public boolean atEnd() { + return right.isEmpty(); + } + + /** + * Creates a zipper of variations of this zipper, in which each element is focused, + * with this zipper as the focus of the zipper of zippers (comonad pattern). + * + * @return a zipper of variations of the provided zipper, in which each element is focused, + * with this zipper as the focus of the zipper of zippers. + */ + public Zipper> positions() { + final Stream> left = Stream.unfold( + p -> p.previous().map(join(P.p2())), this); + final Stream> right = Stream.unfold( + p -> p.next().map(join(P.p2())), this); + + return zipper(left, this, right); + } + + /** + * Maps over variations of this zipper, such that the given function is applied to each variation (comonad pattern). + * + * @param f The comonadic function to apply for each variation of this zipper. + * @return A new zipper, with the given function applied for each variation of this zipper. + */ + public Zipper cobind(final F, B> f) { + return positions().map(f); + } + + /** + * Zips the elements of this zipper with a boolean that indicates whether that element has focus. + * All of the booleans will be false, except the focused element. + * + * @return A new zipper of pairs, with each element of this zipper paired with a boolean that is true if that + * element has focus, and false otherwise. + */ + public Zipper> zipWithFocus() { + return zipper(left.zip(repeat(false)), P.p(focus, true), right.zip(repeat(false))); + } + + /** + * Move the focus to the specified index. + * + * @param n The index to which to move the focus. + * @return A new zipper with the focus moved to the specified index, or none if there is no such index. + */ + public Option> move(final int n) { + final int ll = left.length(); + final int rl = right.length(); + Option> p = some(this); + if (n < 0 || n >= length()) + return none(); + else if (ll >= n) + for (int i = ll - n; i > 0; i--) + p = p.bind(Zipper.previous_()); + else if (rl >= n) + for (int i = rl - n; i > 0; i--) + p = p.bind(Zipper.next_()); + return p; + } + + /** + * A first-class version of the move function. + * + * @return A function that moves the focus of the given zipper to the given index. + */ + public static F, Option>>> move() { + return curry((i, a) -> a.move(i)); + } + + /** + * Moves the focus to the element matching the given predicate, if present. + * + * @param p A predicate to match. + * @return A new zipper with the nearest matching element focused if it is present in this zipper. + */ + public Option> find(final F p) { + if (p.f(focus())) + return some(this); + else { + final Zipper> ps = positions(); + return ps.lefts().interleave(ps.rights()).find(zipper -> p.f(zipper.focus())); + } + } + + /** + * Returns the index of the focus. + * + * @return the index of the focus. + */ + public int index() { + return left.length(); + } + + /** + * Move the focus to the next element. If the last element is focused, loop to the first element. + * + * @return A new zipper with the next element focused, unless the last element is currently focused, in which case + * the first element becomes focused. + */ + public Zipper cycleNext() { + if (left.isEmpty() && right.isEmpty()) + return this; + else if (right.isEmpty()) { + final Stream xs = left.reverse(); + return zipper(Stream.nil(), xs.head(), xs.tail()._1().snoc(P.p(focus))); + } else + return tryNext(); + } + + /** + * Move the focus to the previous element. If the first element is focused, loop to the last element. + * + * @return A new zipper with the previous element focused, unless the first element is currently focused, + * in which case the last element becomes focused. + */ + public Zipper cyclePrevious() { + if (left.isEmpty() && right.isEmpty()) + return this; + else if (left.isEmpty()) { + final Stream xs = right.reverse(); + return zipper(xs.tail()._1().snoc(P.p(focus)), xs.head(), Stream.nil()); + } else + return tryPrevious(); + } + + /** + * Possibly deletes the element at the focus, then move the element on the left into focus. If no element is on the + * left, focus on the last element. If the deletion will cause the list to be empty, return None. + * + * @return A new zipper with the focused element removed, and focus on the previous element to the left, or the last + * element if there is no element to the left. + */ + public Option> deleteLeftCycle() { + if (left.isEmpty() && right.isEmpty()) + return none(); + else if (left.isNotEmpty()) + return some(zipper(left.tail()._1(), left.head(), right)); + else { + final Stream xs = right.reverse(); + return some(zipper(xs.tail()._1(), xs.head(), Stream.nil())); + } + } + + /** + * Possibly deletes the element at the focus, then move the element on the right into focus. If no element is on the + * right, focus on the first element. If the deletion will cause the list to be empty, return None. + * + * @return A new zipper with the focused element removed, and focus on the next element to the right, or the first + * element if there is no element to the right. + */ + public Option> deleteRightCycle() { + if (left.isEmpty() && right.isEmpty()) + return none(); + else if (right.isNotEmpty()) + return some(zipper(left, right.head(), right.tail()._1())); + else { + final Stream xs = left.reverse(); + return some(zipper(Stream.nil(), xs.head(), xs.tail()._1())); + } + } + + /** + * Replaces the element in focus with the given element. + * + * @param a An element to replace the focused element with. + * @return A new zipper with the given element in focus. + */ + public Zipper replace(final A a) { + return zipper(left, a, right); + } + + /** + * Returns the Stream representation of this zipper. + * + * @return A stream that contains all the elements of this zipper. + */ + public Stream toStream() { + return left.reverse().snoc(P.p(focus)).append(right); + } + + /** + * Returns a Stream of the elements to the left of focus. + * + * @return a Stream of the elements to the left of focus. + */ + public Stream lefts() { + return left; + } + + /** + * Returns a Stream of the elements to the right of focus. + * + * @return a Stream of the elements to the right of focus. + */ + public Stream rights() { + return right; + } + + /** + * Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. + * The structure of the resulting Zipper is the structural intersection of the two Zippers. + * + * @param bs A Zipper to zip this one with. + * @param f A function with which to zip together the two Zippers. + * @return The result of applying the given function over this Zipper and the given Zipper, location-wise. + */ + public Zipper zipWith(final Zipper bs, final F2 f) { + return f.zipZipperM().f(this, bs); + } + + + /** + * Zips this Zipper with another, applying the given function lock-step over both zippers in both directions. + * The structure of the resulting Zipper is the structural intersection of the two Zippers. + * + * @param bs A Zipper to zip this one with. + * @param f A function with which to zip together the two Zippers. + * @return The result of applying the given function over this Zipper and the given Zipper, location-wise. + */ + public Zipper zipWith(final Zipper bs, final F> f) { + return zipWith(bs, uncurryF2(f)); + } + + /** + * Returns an iterator of all the positions of this Zipper, starting from the leftmost position. + * + * @return An iterator of all the positions of this Zipper, starting from the leftmost position. + */ + public Iterator> iterator() { return positions().toStream().iterator(); } +} diff --git a/core/src/main/java/fj/data/fingertrees/FingerTree.java b/core/src/main/java/fj/data/fingertrees/FingerTree.java index 160b5508..ab0effb0 100644 --- a/core/src/main/java/fj/data/fingertrees/FingerTree.java +++ b/core/src/main/java/fj/data/fingertrees/FingerTree.java @@ -1,268 +1,268 @@ -package fj.data.fingertrees; - -import fj.*; -import fj.data.Option; -import fj.data.Seq; -import fj.data.Stream; - -import static fj.Monoid.intAdditionMonoid; -import static fj.Monoid.intMaxMonoid; -import static fj.data.Stream.nil; - -/** - * Provides 2-3 finger trees, a functional representation of persistent sequences supporting access to the ends in - * amortized O(1) time. Concatenation and splitting time is O(log n) in the size of the smaller piece. - * A general purpose data structure that can serve as a sequence, priority queue, search tree, priority search queue - * and more. - *

      - * This class serves as a datastructure construction kit, rather than a datastructure in its own right. By supplying - * a monoid, a measurement function, insertion, deletion, and so forth, any purely functional datastructure can be - * emulated. See {@link Seq} for an example. - *

      - * Based on "Finger trees: a simple general-purpose data structure", by Ralf Hinze and Ross Paterson. - * - * @param The monoidal type with which to annotate nodes. - * @param The type of the tree's elements. - */ -public abstract class FingerTree { - private final Measured m; - - /** - * Folds the tree to the right with the given function and the given initial element. - * - * @param f A function with which to fold the tree. - * @param z An initial element to apply to the fold. - * @return A reduction of this tree by applying the given function, associating to the right. - */ - public abstract B foldRight(final F> f, final B z); - - public final B foldRight(final F2 f, final B z) { - return foldRight(F2Functions.curry(f), z); - } - - /** - * Folds the tree to the right with the given function. - * - * @param f A function with which to fold the tree. - * @return A reduction of this tree by applying the given function, associating to the right. - */ - public abstract A reduceRight(final F> f); - - /** - * Folds the tree to the left with the given function and the given initial element. - * - * @param f A function with which to fold the tree. - * @param z An initial element to apply to the fold. - * @return A reduction of this tree by applying the given function, associating to the left. - */ - public abstract B foldLeft(final F> f, final B z); - - public final B foldLeft(final F2 f, final B z) { - return foldLeft(F2Functions.curry(f), z); - } - - /** - * Folds the tree to the left with the given function. - * - * @param f A function with which to fold the tree. - * @return A reduction of this tree by applying the given function, associating to the right. - */ - public abstract A reduceLeft(final F> f); - - /** - * Maps the given function across this tree, measuring with the given Measured instance. - * - * @param f A function to map across the values of this tree. - * @param m A measuring with which to annotate the tree. - * @return A new tree with the same structure as this tree, with each element transformed by the given function, - * and nodes annotated according to the given measuring. - */ - public abstract FingerTree map(final F f, final Measured m); - - public final FingerTree filter(final F f) { - FingerTree tree = new Empty<>(m); - return foldLeft((acc, a) -> f.f(a) ? acc.snoc(a) : acc, tree); - } - - /** - * Returns the sum of this tree's annotations. - * - * @return the sum of this tree's annotations. - */ - public abstract V measure(); - - /** - * Indicates whether this tree is empty. - * - * @return true if this tree is the empty tree, otherwise false. - */ - public final boolean isEmpty() { - return this instanceof Empty; - } - - public final Measured measured() { - return m; - } - - /** - * Provides pattern matching on trees. This is the Church encoding of the FingerTree datatype. - * - * @param empty The function to apply to this empty tree. - * @param single A function to apply if this tree contains a single element. - * @param deep A function to apply if this tree contains more than one element. - * @return The result of the function that matches this tree structurally, applied to this tree. - */ - public abstract B match(final F, B> empty, final F, B> single, - final F, B> deep); - - FingerTree(final Measured m) { - this.m = m; - } - - /** - * Constructs a Measured instance for the element type, given a monoid and a measuring function. - * - * @param monoid A monoid for the measures. - * @param measure A function with which to measure element values. - * @return A Measured instance for the given element type, that uses the given monoid and measuring function. - */ - public static Measured measured(final Monoid monoid, final F measure) { - return Measured.measured(monoid, measure); - } - - /** - * Returns a builder of trees and tree components that annotates them using the given Measured instance. - * - * @param m A Measured instance with which to annotate trees, digits, and nodes. - * @return A builder of trees and tree components that annotates them using the given Measured instance. - */ - public static MakeTree mkTree(final Measured m) { - return new MakeTree<>(m); - } - - /** - * Adds the given element to this tree as the first element. - * - * @param a The element to add to the front of this tree. - * @return A new tree with the given element at the front. - */ - public abstract FingerTree cons(final A a); - - /** - * Adds the given element to this tree as the last element. - * - * @param a The element to add to the end of this tree. - * @return A new tree with the given element at the end. - */ - public abstract FingerTree snoc(final A a); - - /** - * The first element of this tree. This is an O(1) operation. - * - * @return The first element if this tree is nonempty, otherwise throws an error. - */ - public abstract A head(); - - public final Option headOption() { - return isEmpty() ? Option.none() : Option.some(head()); - } - - /** - * Performs a reduction on this finger tree using the given arguments. - * - * @param nil The value to return if this finger tree is empty. - * @param cons The function to apply to the head and tail of this finger tree if it is not empty. - * @return A reduction on this finger tree. - */ - public final B uncons(B nil, F2, B> cons) { - return isEmpty() ? nil : cons.f(head(), tail()); - } - - - /** - * The last element of this tree. This is an O(1) operation. - * - * @return The last element if this tree is nonempty, otherwise throws an error. - */ - public abstract A last(); - - /** - * The tree without the first element. This is an O(1) operation. - * - * @return The tree without the first element if this tree is nonempty, otherwise throws an error. - */ - public abstract FingerTree tail(); - - /** - * The tree without the last element. This is an O(1) operation. - * - * @return The tree without the last element if this tree is nonempty, otherwise throws an error. - */ - public abstract FingerTree init(); - - /** - * Appends one finger tree to another. - * - * @param t A finger tree to append to this one. - * @return A new finger tree which is a concatenation of this tree and the given tree. - */ - public abstract FingerTree append(final FingerTree t); - - /** - * Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, - * changes from false to true. This is a O(log(n)) operation. - * - * @return Pair: the subtree containing elements before the point where pred first holds and the subtree - * containing element at and after the point where pred first holds. Empty if pred never holds. - */ - public final P2, FingerTree> split(final F predicate) { - if (!isEmpty() && predicate.f(measure())) { - final P3, A, FingerTree> lxr = split1(predicate); - return P.p(lxr._1(), lxr._3().cons(lxr._2())); - } else { - return P.p(this, mkTree(m).empty()); - } - } - - /** - * Like split, but returns the element where pred first holds separately. - * - * Throws an error if the tree is empty. - */ - public final P3, A, FingerTree> split1(final F predicate) { - return split1(predicate, measured().zero()); - } - - abstract P3, A, FingerTree> split1(final F predicate, final V acc); - - public abstract P2 lookup(final F o, final int i); - - public abstract int length(); - - public static FingerTree emptyIntAddition() { - return empty(intAdditionMonoid, Function.constant(1)); - } - - /** - * Creates an empty finger tree with elements of type A and node annotations - * of type V. - * - * @param m A monoid to combine node annotations - * @param f Function to convert node element to annotation. - * @return An empty finger tree. - */ - public static FingerTree empty(Monoid m, F f) { - return FingerTree.mkTree(measured(m, f)).empty(); - } - - /** - * Returns a finger tree which combines the integer node annotations with the - * maximum function. A priority queue with integer priorities. - */ - public static FingerTree> emptyIntMax() { - return empty(intMaxMonoid, (P2 p) -> p._1()); - } - - public abstract Stream toStream(); - -} +package fj.data.fingertrees; + +import fj.*; +import fj.data.Option; +import fj.data.Seq; +import fj.data.Stream; + +import static fj.Monoid.intAdditionMonoid; +import static fj.Monoid.intMaxMonoid; +import static fj.data.Stream.nil; + +/** + * Provides 2-3 finger trees, a functional representation of persistent sequences supporting access to the ends in + * amortized O(1) time. Concatenation and splitting time is O(log n) in the size of the smaller piece. + * A general purpose data structure that can serve as a sequence, priority queue, search tree, priority search queue + * and more. + *

      + * This class serves as a datastructure construction kit, rather than a datastructure in its own right. By supplying + * a monoid, a measurement function, insertion, deletion, and so forth, any purely functional datastructure can be + * emulated. See {@link Seq} for an example. + *

      + * Based on "Finger trees: a simple general-purpose data structure", by Ralf Hinze and Ross Paterson. + * + * @param The monoidal type with which to annotate nodes. + * @param The type of the tree's elements. + */ +public abstract class FingerTree { + private final Measured m; + + /** + * Folds the tree to the right with the given function and the given initial element. + * + * @param f A function with which to fold the tree. + * @param z An initial element to apply to the fold. + * @return A reduction of this tree by applying the given function, associating to the right. + */ + public abstract B foldRight(final F> f, final B z); + + public final B foldRight(final F2 f, final B z) { + return foldRight(f.curry(), z); + } + + /** + * Folds the tree to the right with the given function. + * + * @param f A function with which to fold the tree. + * @return A reduction of this tree by applying the given function, associating to the right. + */ + public abstract A reduceRight(final F> f); + + /** + * Folds the tree to the left with the given function and the given initial element. + * + * @param f A function with which to fold the tree. + * @param z An initial element to apply to the fold. + * @return A reduction of this tree by applying the given function, associating to the left. + */ + public abstract B foldLeft(final F> f, final B z); + + public final B foldLeft(final F2 f, final B z) { + return foldLeft(f.curry(), z); + } + + /** + * Folds the tree to the left with the given function. + * + * @param f A function with which to fold the tree. + * @return A reduction of this tree by applying the given function, associating to the right. + */ + public abstract A reduceLeft(final F> f); + + /** + * Maps the given function across this tree, measuring with the given Measured instance. + * + * @param f A function to map across the values of this tree. + * @param m A measuring with which to annotate the tree. + * @return A new tree with the same structure as this tree, with each element transformed by the given function, + * and nodes annotated according to the given measuring. + */ + public abstract FingerTree map(final F f, final Measured m); + + public final FingerTree filter(final F f) { + FingerTree tree = new Empty<>(m); + return foldLeft((acc, a) -> f.f(a) ? acc.snoc(a) : acc, tree); + } + + /** + * Returns the sum of this tree's annotations. + * + * @return the sum of this tree's annotations. + */ + public abstract V measure(); + + /** + * Indicates whether this tree is empty. + * + * @return true if this tree is the empty tree, otherwise false. + */ + public final boolean isEmpty() { + return this instanceof Empty; + } + + public final Measured measured() { + return m; + } + + /** + * Provides pattern matching on trees. This is the Church encoding of the FingerTree datatype. + * + * @param empty The function to apply to this empty tree. + * @param single A function to apply if this tree contains a single element. + * @param deep A function to apply if this tree contains more than one element. + * @return The result of the function that matches this tree structurally, applied to this tree. + */ + public abstract B match(final F, B> empty, final F, B> single, + final F, B> deep); + + FingerTree(final Measured m) { + this.m = m; + } + + /** + * Constructs a Measured instance for the element type, given a monoid and a measuring function. + * + * @param monoid A monoid for the measures. + * @param measure A function with which to measure element values. + * @return A Measured instance for the given element type, that uses the given monoid and measuring function. + */ + public static Measured measured(final Monoid monoid, final F measure) { + return Measured.measured(monoid, measure); + } + + /** + * Returns a builder of trees and tree components that annotates them using the given Measured instance. + * + * @param m A Measured instance with which to annotate trees, digits, and nodes. + * @return A builder of trees and tree components that annotates them using the given Measured instance. + */ + public static MakeTree mkTree(final Measured m) { + return new MakeTree<>(m); + } + + /** + * Adds the given element to this tree as the first element. + * + * @param a The element to add to the front of this tree. + * @return A new tree with the given element at the front. + */ + public abstract FingerTree cons(final A a); + + /** + * Adds the given element to this tree as the last element. + * + * @param a The element to add to the end of this tree. + * @return A new tree with the given element at the end. + */ + public abstract FingerTree snoc(final A a); + + /** + * The first element of this tree. This is an O(1) operation. + * + * @return The first element if this tree is nonempty, otherwise throws an error. + */ + public abstract A head(); + + public final Option headOption() { + return isEmpty() ? Option.none() : Option.some(head()); + } + + /** + * Performs a reduction on this finger tree using the given arguments. + * + * @param nil The value to return if this finger tree is empty. + * @param cons The function to apply to the head and tail of this finger tree if it is not empty. + * @return A reduction on this finger tree. + */ + public final B uncons(B nil, F2, B> cons) { + return isEmpty() ? nil : cons.f(head(), tail()); + } + + + /** + * The last element of this tree. This is an O(1) operation. + * + * @return The last element if this tree is nonempty, otherwise throws an error. + */ + public abstract A last(); + + /** + * The tree without the first element. This is an O(1) operation. + * + * @return The tree without the first element if this tree is nonempty, otherwise throws an error. + */ + public abstract FingerTree tail(); + + /** + * The tree without the last element. This is an O(1) operation. + * + * @return The tree without the last element if this tree is nonempty, otherwise throws an error. + */ + public abstract FingerTree init(); + + /** + * Appends one finger tree to another. + * + * @param t A finger tree to append to this one. + * @return A new finger tree which is a concatenation of this tree and the given tree. + */ + public abstract FingerTree append(final FingerTree t); + + /** + * Splits this tree into a pair of subtrees at the point where the given predicate, based on the measure, + * changes from false to true. This is a O(log(n)) operation. + * + * @return Pair: the subtree containing elements before the point where pred first holds and the subtree + * containing element at and after the point where pred first holds. Empty if pred never holds. + */ + public final P2, FingerTree> split(final F predicate) { + if (!isEmpty() && predicate.f(measure())) { + final P3, A, FingerTree> lxr = split1(predicate); + return P.p(lxr._1(), lxr._3().cons(lxr._2())); + } else { + return P.p(this, mkTree(m).empty()); + } + } + + /** + * Like split, but returns the element where pred first holds separately. + * + * Throws an error if the tree is empty. + */ + public final P3, A, FingerTree> split1(final F predicate) { + return split1(predicate, measured().zero()); + } + + abstract P3, A, FingerTree> split1(final F predicate, final V acc); + + public abstract P2 lookup(final F o, final int i); + + public abstract int length(); + + public static FingerTree emptyIntAddition() { + return empty(intAdditionMonoid, Function.constant(1)); + } + + /** + * Creates an empty finger tree with elements of type A and node annotations + * of type V. + * + * @param m A monoid to combine node annotations + * @param f Function to convert node element to annotation. + * @return An empty finger tree. + */ + public static FingerTree empty(Monoid m, F f) { + return FingerTree.mkTree(measured(m, f)).empty(); + } + + /** + * Returns a finger tree which combines the integer node annotations with the + * maximum function. A priority queue with integer priorities. + */ + public static FingerTree> emptyIntMax() { + return empty(intMaxMonoid, (P2 p) -> p._1()); + } + + public abstract Stream toStream(); + +} diff --git a/core/src/test/java/fj/FFunctionsTest.java b/core/src/test/java/fj/FFunctionsTest.java index e13b1f2b..e0df9164 100644 --- a/core/src/test/java/fj/FFunctionsTest.java +++ b/core/src/test/java/fj/FFunctionsTest.java @@ -1,43 +1,47 @@ -package fj; - -import fj.data.Tree; -import fj.data.TreeZipper; -import org.junit.Test; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; - -public class FFunctionsTest { - @Test - public void testApply() { - F8 f8 = - (i1, i2, i3, i4, i5, i6, i7, i8) -> - i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8; - F7 f7 = F8Functions.f(f8, 8); - F6 f6 = - F7Functions.f(f7, 7); - F5 f5 = F6Functions.f(f6, 6); - F4 f4 = F5Functions.f(f5, 5); - F3 f3 = F4Functions.f(f4, 4); - F2 f2 = F3Functions.f(f3, 3); - F f1 = F2Functions.f(f2, 2); - assertThat(F1Functions.f(f1, 1).f(), is(36)); - } - - @Test - public void testTreeK() { - final Tree t1 = F1Functions.treeK(Function.identity()).f(1); - final Tree t2 = F1Functions.treeK(Function.identity()).f(2); - assertThat(F1Functions.mapTree(i -> i + 1).f(t1), - is(F1Functions.mapTree(i -> i * 1).f(t2))); - } - - @Test - public void testTreeZipperK() { - final TreeZipper tz1 = F1Functions.treeZipperK(Function.identity()).f(1); - final TreeZipper tz2 = F1Functions.treeZipperK(Function.identity()).f(2); - assertThat(F1Functions.mapTreeZipper(i -> i + 1).f(tz1), - is(F1Functions.mapTreeZipper(i -> i * 1).f(tz2))); - } -} +package fj; + +import fj.data.Tree; +import fj.data.TreeZipper; +import org.junit.Test; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.*; + +public class FFunctionsTest { + @Test + public void testApply() { + F8 f8 = + (i1, i2, i3, i4, i5, i6, i7, i8) -> + i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8; + F7 f7 = F8Functions.f(f8, 8); + F6 f6 = + F7Functions.f(f7, 7); + F5 f5 = F6Functions.f(f6, 6); + F4 f4 = F5Functions.f(f5, 5); + F3 f3 = F4Functions.f(f4, 4); + F2 f2 = F3Functions.f(f3, 3); + F f1 = f2.f(2); + assertThat(f1.f(1), is(36)); + } + + @Test + public void testTreeK() { + final Tree t1 = Function.identity().treeK().f(1); + final Tree t2 = Function.identity().treeK().f(2); + F f = i -> i + 1; + F g = i -> i * 1; + assertThat(f.mapTree().f(t1), + is(g.mapTree().f(t2))); + } + + @Test + public void testTreeZipperK() { + final TreeZipper tz1 = Function.identity().treeZipperK().f(1); + final TreeZipper tz2 = Function.identity().treeZipperK().f(2); + F f = i -> i + 1; + F g = i -> i * 1; + assertThat(f.mapTreeZipper().f(tz1), + is(g.mapTreeZipper().f(tz2))); + } +} diff --git a/core/src/test/java/fj/FWFunctionsTest.java b/core/src/test/java/fj/FWFunctionsTest.java deleted file mode 100644 index 1c034ab9..00000000 --- a/core/src/test/java/fj/FWFunctionsTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package fj; - -import org.junit.Test; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; - -public class FWFunctionsTest { - @Test - public void testLift1() { - F f = i -> i + 1; - F1W f1w = F1W.lift(f); - assertThat(f1w.f(1), is(2)); - } - - @Test - public void testLift2() { - F2 f2 = (i, j) -> i + j; - F2W f2w = F2W.lift(f2); - assertThat(f2w.f(1, 2), is(3)); - } - -} diff --git a/core/src/test/java/fj/data/IOFunctionsTest.java b/core/src/test/java/fj/data/IOFunctionsTest.java index 5213878c..adad0d11 100644 --- a/core/src/test/java/fj/data/IOFunctionsTest.java +++ b/core/src/test/java/fj/data/IOFunctionsTest.java @@ -107,7 +107,8 @@ public void testReplicateM() throws IOException { @Test public void testLift() throws IOException { final IO readName = () -> new BufferedReader(new StringReader("foo")).readLine(); - final F> upperCaseAndPrint = F1Functions., String>o(this::println).f(String::toUpperCase); + F> f = this::println; + final F> upperCaseAndPrint = f.o().f(String::toUpperCase); final IO readAndPrintUpperCasedName = IOFunctions.bind(readName, upperCaseAndPrint); assertThat(readAndPrintUpperCasedName.run(), is("FOO")); } diff --git a/core/src/test/java/fj/function/StringsTest.java b/core/src/test/java/fj/function/StringsTest.java index 92cf44d3..c13e1b81 100644 --- a/core/src/test/java/fj/function/StringsTest.java +++ b/core/src/test/java/fj/function/StringsTest.java @@ -3,7 +3,6 @@ import fj.Function; import org.junit.Test; -import static fj.F1Functions.o; import static fj.Function.compose; import static fj.function.Strings.*; import static org.junit.Assert.*; @@ -17,7 +16,7 @@ public void testLines() { @Test public void testLinesEmpty() { - assertThat(o(unlines(), lines()).f(""), is("")); + assertThat(unlines().o(lines()).f(""), is("")); } @Test diff --git a/demo/src/main/java/fj/demo/Comonad_example.java b/demo/src/main/java/fj/demo/Comonad_example.java index 8d5bc683..3b5661f8 100644 --- a/demo/src/main/java/fj/demo/Comonad_example.java +++ b/demo/src/main/java/fj/demo/Comonad_example.java @@ -1,6 +1,5 @@ package fj.demo; -import fj.F1Functions; import fj.P; import static fj.data.List.asString; import static fj.data.List.fromString; @@ -26,7 +25,7 @@ public static Stream> perms(final Stream s) { for (final Zipper z : fromStream(s)) r = join(z.cobind(zp -> perms(zp.lefts().reverse().append(zp.rights())).map( - F1Functions.o(Stream.cons().f(zp.focus()), P.p1()) + Stream.cons().f(zp.focus()).o(P.p1()) ) ).toStream()); return r; diff --git a/demo/src/main/java/fj/demo/IODemo.java b/demo/src/main/java/fj/demo/IODemo.java index 6451a46b..ea313e77 100644 --- a/demo/src/main/java/fj/demo/IODemo.java +++ b/demo/src/main/java/fj/demo/IODemo.java @@ -4,7 +4,6 @@ import fj.data.IOFunctions; import fj.data.LazyString; -import static fj.F1W.lift; import static fj.data.IOFunctions.interact; import static fj.data.IOFunctions.runSafe; import static fj.data.LazyString.lines_; @@ -29,7 +28,7 @@ public static void main(String[] args) { * and prints that last line. */ public final void readFirstShortLine() { - F f = lift(lines_()).andThen(l -> l.filter(s -> s.length() < 3)).andThen(unlines_()); + F f = lines_().andThen(l -> l.filter(s -> s.length() < 3)).andThen(unlines_()); runSafe(interact(f)); } @@ -37,7 +36,7 @@ public final void readFirstShortLine() { * Read a stream of input lazily using interact, in effect reading the first line */ public final void readFirstLine() { - F f = lift(LazyString::lines).andThen(unlines_()); + F f = lines_().andThen(unlines_()); runSafe(interact(f)); } diff --git a/demo/src/main/java/fj/demo/IOWalkthrough.java b/demo/src/main/java/fj/demo/IOWalkthrough.java index 609d2502..5c1c4663 100644 --- a/demo/src/main/java/fj/demo/IOWalkthrough.java +++ b/demo/src/main/java/fj/demo/IOWalkthrough.java @@ -1,8 +1,6 @@ package fj.demo; import fj.F; -import fj.F1Functions; -import fj.F1W; import fj.Unit; import fj.data.IO; import fj.data.IOFunctions; @@ -49,7 +47,7 @@ public static void main(String[] args) { // now we create a function which takes a string, upper cases it and creates an IO value that would print the upper cased string if executed - final F> upperCaseAndPrint = F1Functions., String>o(IOFunctions::stdoutPrintln).f(String::toUpperCase); + final F> upperCaseAndPrint = s -> stdoutPrintln(s.toUpperCase()); // we now want to compose reading the name with printing it, for that we need to have access to the runtime value that is returned when the // IO value for read is executed, hence we use fj.data.IOFunctions.bind instead of fj.data.IOFunctions.append @@ -73,10 +71,11 @@ public static void main(String[] args) { // assigning the functions to variables like above, but you can use the fj.F1W syntax wrapper for composing single-argument functions and fj.data.IOW // for composing IO values instead, the entire program can be written like so: + F f = String::toUpperCase; IOW.lift(stdoutPrintln("What's your name again?")) .append(stdoutPrint("Name: ")) .append(stdinReadLine()) - .bind(F1W.lift((String s) -> s.toUpperCase()).andThen(IOFunctions::stdoutPrintln)) + .bind(f.andThen(IOFunctions::stdoutPrintln)) .safe().run().on((IOException e) -> { e.printStackTrace(); return Unit.unit(); }); } } diff --git a/demo/src/main/java/fj/demo/Primes2.java b/demo/src/main/java/fj/demo/Primes2.java index 96a852f3..37bfb249 100644 --- a/demo/src/main/java/fj/demo/Primes2.java +++ b/demo/src/main/java/fj/demo/Primes2.java @@ -1,7 +1,5 @@ package fj.demo; -import fj.F1Functions; - import static fj.data.Enumerator.naturalEnumerator; import fj.Show; @@ -21,7 +19,7 @@ public class Primes2 { // Finds primes in a given stream. public static Stream sieve(final Stream xs) { - return cons(xs.head(), () -> sieve(xs.tail()._1().removeAll(F1Functions.o(naturalOrd.equal().eq(ZERO), mod.f(xs.head()))))); + return cons(xs.head(), () -> sieve(xs.tail()._1().removeAll(naturalOrd.equal().eq(ZERO).o(mod.f(xs.head()))))); } // A stream of all primes less than n. diff --git a/demo/src/main/java/fj/demo/WriterDemo_Halver.java b/demo/src/main/java/fj/demo/WriterDemo_Halver.java index a2a270f6..8473e588 100644 --- a/demo/src/main/java/fj/demo/WriterDemo_Halver.java +++ b/demo/src/main/java/fj/demo/WriterDemo_Halver.java @@ -4,7 +4,6 @@ import fj.P2; import fj.data.Writer; -import static fj.F1Functions.map; import static fj.Monoid.stringMonoid; /** @@ -24,7 +23,7 @@ static void testWriter() { Integer init = 32; P2 p1 = half().f(init).flatMap(half()).flatMap(half()).run(); System.out.println(p1); - System.out.println(map(half(), w -> w.flatMap(half()).flatMap(half()).run()).f(init)); + System.out.println(half().map(w -> w.flatMap(half()).flatMap(half()).run()).f(init)); } } diff --git a/demo/src/main/java/fj/demo/concurrent/MapReduce.java b/demo/src/main/java/fj/demo/concurrent/MapReduce.java index 3cb2d761..38a62caa 100644 --- a/demo/src/main/java/fj/demo/concurrent/MapReduce.java +++ b/demo/src/main/java/fj/demo/concurrent/MapReduce.java @@ -35,14 +35,15 @@ public static Promise countWords(final List> documents, // Main program does the requisite IO gymnastics public static void main(final String[] args) { + F z = fileName -> { + try { + return new BufferedReader(new FileReader(new File(fileName))); + } catch (FileNotFoundException e) { + throw new Error(e); + } + }; final List> documents = list(args).map( - F1Functions.andThen(fileName -> { - try { - return new BufferedReader(new FileReader(new File(fileName))); - } catch (FileNotFoundException e) { - throw new Error(e); - } - }, new F>() { + z.andThen(new F>() { public Stream f(final BufferedReader reader) { final Option s; try { diff --git a/demo/src/main/java/fj/demo/euler/Problem2.java b/demo/src/main/java/fj/demo/euler/Problem2.java index eda4a72d..a5639ab9 100644 --- a/demo/src/main/java/fj/demo/euler/Problem2.java +++ b/demo/src/main/java/fj/demo/euler/Problem2.java @@ -1,8 +1,6 @@ package fj.demo.euler; -import fj.F1Functions; import fj.F2; -import fj.F2Functions; import fj.data.Stream; import static fj.data.Stream.cons; import static fj.function.Integers.even; @@ -23,13 +21,13 @@ public static void main(final String[] args) { static void java7() { final Stream fibs = new F2>() { public Stream f(final Integer a, final Integer b) { - return cons(a, F1Functions.lazy(F2Functions.curry(this).f(b)).f(a + b)); + return cons(a, this.curry().f(b).lazy().f(a + b)); } }.f(1, 2); out.println(sum(fibs.filter(even).takeWhile(intOrd.isLessThan(4000001)).toList())); } - static F2> fibsJava8 = (a, b) -> cons(a, F1Functions.lazy(F2Functions.curry(Problem2.fibsJava8).f(b)).f(a + b)); + static F2> fibsJava8 = (a, b) -> cons(a, Problem2.fibsJava8.curry().f(b).lazy().f(a + b)); static void java8() { out.println(sum(fibsJava8.f(1, 2).filter(even).takeWhile(intOrd.isLessThan(4000001)).toList())); diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala index dd95dabf..dfde81e3 100755 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala @@ -1,119 +1,119 @@ -package fj -package data - -import fj.function.Effect1 -import org.scalacheck.Prop._ -import ArbitraryHashMap._ -import Equal._ -import Hash._ -import Ord._ -import fj.data.Option._ -import scala.collection.JavaConversions._ -import org.scalacheck.{Arbitrary, Properties} -import data.ArbitraryList._ -import org.scalacheck.Arbitrary._ -import java.util.Map - -object CheckHashMap extends Properties("HashMap") { - implicit val equalInt: Equal[Int] = intEqual contramap ((x: Int) => (x: java.lang.Integer)) - implicit val hashInt: Hash[Int] = intHash contramap ((x: Int) => (x: java.lang.Integer)) - - implicit def arbitraryListOfIterableP2: Arbitrary[java.lang.Iterable[P2[Int, String]]] = - Arbitrary(listOf(arbitrary[(Int, String)]) - .map(_.map((tuple: (Int, String)) => P.p(tuple._1, tuple._2)) - .asInstanceOf[java.lang.Iterable[P2[Int, String]]])) - - property("eq") = forAll((m: HashMap[Int, String], x: Int, y: Int) => m.eq(x, y) == equalInt.eq(x, y)) - - property("hash") = forAll((m: HashMap[Int, String], x: Int) => m.hash(x) == hashInt.hash(x)) - - property("get") = forAll((m: HashMap[Int, String], k: Int) => optionEqual(stringEqual).eq(m.get(k), m.get.f(k))) - - property("set") = forAll((m: HashMap[Int, String], k: Int, v: String) => { - m.set(k, v) - m.get(k).some == v - }) - - property("clear") = forAll((m: HashMap[Int, String], k: Int) => { - m.clear - m.get(k).isNone - }) - - property("contains") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isSome == m.contains(k)) - - property("keys") = forAll((m: HashMap[Int, String]) => m.keys.forall((k: Int) => (m.get(k).isSome): java.lang.Boolean)) - - property("isEmpty") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isNone || !m.isEmpty) - - property("size") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isNone || m.size != 0) - - property("delete") = forAll((m: HashMap[Int, String], k: Int) => { - m.delete(k) - m.get(k).isNone - }) - - property("toList") = forAll((m: HashMap[Int, String]) => { - val list = m.toList - list.length() == m.keys().length() && list.forall((entry: P2[Int, String]) => - optionEqual(stringEqual).eq(m.get(entry._1()), some(entry._2())).asInstanceOf[java.lang.Boolean]) - }) - - property("getDelete") = forAll((m: HashMap[Int, String], k: Int) => { - val x = m.get(k) - val y = m.getDelete(k) - val z = m.get(k) - - z.isNone && optionEqual(stringEqual).eq(x, y) - }) - - property("from") = forAll((entries: java.lang.Iterable[P2[Int, String]]) => { - val map = HashMap.iterableHashMap[Int, String](equalInt, hashInt, entries) - entries.groupBy(_._1) - .forall((e: (Int, Iterable[P2[Int, String]])) => e._2 - .exists((elem: P2[Int, String]) => optionEqual(stringEqual).eq(map.get(e._1), Option.some(elem._2)))) - }) - - property("map") = forAll((m: HashMap[Int, String]) => { - val keyFunction: F[Int, String] = (i: Int) => i.toString - val valueFunction: (String) => String = (s: String) => s + "a" - val mapped = m.map(keyFunction, valueFunction, stringEqual, stringHash) - val keysAreEqual = m.keys().map(keyFunction).toSet == mapped.keys.toSet - val appliedFunctionsToKeysAndValues: Boolean = m.keys().forall((key: Int) => { - val mappedValue = mapped.get(keyFunction.f(key)) - val oldValueMapped = some(valueFunction.f(m.get(key).some())) - Equal.optionEqual(stringEqual).eq(mappedValue, oldValueMapped) - }) - - keysAreEqual && appliedFunctionsToKeysAndValues - }) - - property("toMap") = forAll((m: HashMap[Int, String]) => { - val toMap: Map[Int, String] = m.toMap - m.keys().forall((key: Int) => m.get(key).some() == toMap.get(key)) - }) - - property("fromMap") = forAll((m: HashMap[Int, String]) => { - val map = new java.util.HashMap[Int, String]() - m.keys().foreach((key: Int) => { - map.put(key, m.get(key).some()) - Unit.unit() - }) - val fromMap: HashMap[Int, String] = new HashMap[Int, String](map) - val keysAreEqual = m.keys.toSet == fromMap.keys.toSet - val valuesAreEqual = m.keys().forall((key: Int) => - optionEqual(stringEqual).eq(m.get(key), fromMap.get(key))) - keysAreEqual && valuesAreEqual - }) - - property("No null values") = forAll((m: List[Int]) => { - val map = HashMap.hashMap[Int, Int]() - m.foreachDoEffect(new Effect1[Int] { - def f(a: Int) { - map.set(a, null.asInstanceOf[Int]) - } - }) - m.forall(new F[Int, java.lang.Boolean]() { - def f(a: Int) = map.contains(a) == false - }) - }) +package fj +package data + +import fj.function.Effect1 +import org.scalacheck.Prop._ +import ArbitraryHashMap._ +import Equal._ +import Hash._ +import Ord._ +import fj.data.Option._ +import scala.collection.JavaConversions._ +import org.scalacheck.{Arbitrary, Properties} +import data.ArbitraryList._ +import org.scalacheck.Arbitrary._ +import java.util.Map + +object CheckHashMap extends Properties("HashMap") { + implicit val equalInt: Equal[Int] = intEqual contramap ((x: Int) => (x: java.lang.Integer)) + implicit val hashInt: Hash[Int] = intHash contramap ((x: Int) => (x: java.lang.Integer)) + + implicit def arbitraryListOfIterableP2: Arbitrary[java.lang.Iterable[P2[Int, String]]] = + Arbitrary(listOf(arbitrary[(Int, String)]) + .map(_.map((tuple: (Int, String)) => P.p(tuple._1, tuple._2)) + .asInstanceOf[java.lang.Iterable[P2[Int, String]]])) + + property("eq") = forAll((m: HashMap[Int, String], x: Int, y: Int) => m.eq(x, y) == equalInt.eq(x, y)) + + property("hash") = forAll((m: HashMap[Int, String], x: Int) => m.hash(x) == hashInt.hash(x)) + + property("get") = forAll((m: HashMap[Int, String], k: Int) => optionEqual(stringEqual).eq(m.get(k), m.get.f(k))) + + property("set") = forAll((m: HashMap[Int, String], k: Int, v: String) => { + m.set(k, v) + m.get(k).some == v + }) + + property("clear") = forAll((m: HashMap[Int, String], k: Int) => { + m.clear + m.get(k).isNone + }) + + property("contains") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isSome == m.contains(k)) + + property("keys") = forAll((m: HashMap[Int, String]) => m.keys.forall((k: Int) => (m.get(k).isSome): java.lang.Boolean)) + + property("isEmpty") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isNone || !m.isEmpty) + + property("size") = forAll((m: HashMap[Int, String], k: Int) => m.get(k).isNone || m.size != 0) + + property("delete") = forAll((m: HashMap[Int, String], k: Int) => { + m.delete(k) + m.get(k).isNone + }) + + property("toList") = forAll((m: HashMap[Int, String]) => { + val list = m.toList + list.length() == m.keys().length() && list.forall((entry: P2[Int, String]) => + optionEqual(stringEqual).eq(m.get(entry._1()), some(entry._2())).asInstanceOf[java.lang.Boolean]) + }) + + property("getDelete") = forAll((m: HashMap[Int, String], k: Int) => { + val x = m.get(k) + val y = m.getDelete(k) + val z = m.get(k) + + z.isNone && optionEqual(stringEqual).eq(x, y) + }) + + property("from") = forAll((entries: java.lang.Iterable[P2[Int, String]]) => { + val map = HashMap.iterableHashMap[Int, String](equalInt, hashInt, entries) + entries.groupBy(_._1) + .forall((e: (Int, Iterable[P2[Int, String]])) => e._2 + .exists((elem: P2[Int, String]) => optionEqual(stringEqual).eq(map.get(e._1), Option.some(elem._2)))) + }) + + property("map") = forAll((m: HashMap[Int, String]) => { + val keyFunction: F[Int, String] = (i: Int) => i.toString + val valueFunction: (String) => String = (s: String) => s + "a" + val mapped = m.map(keyFunction, valueFunction, stringEqual, stringHash) + val keysAreEqual = m.keys().map(keyFunction).toSet == mapped.keys.toSet + val appliedFunctionsToKeysAndValues: Boolean = m.keys().forall((key: Int) => { + val mappedValue = mapped.get(keyFunction.f(key)) + val oldValueMapped = some(valueFunction.f(m.get(key).some())) + Equal.optionEqual(stringEqual).eq(mappedValue, oldValueMapped) + }) + + keysAreEqual && appliedFunctionsToKeysAndValues + }) + + property("toMap") = forAll((m: HashMap[Int, String]) => { + val toMap: Map[Int, String] = m.toMap + m.keys().forall((key: Int) => m.get(key).some() == toMap.get(key)) + }) + + property("fromMap") = forAll((m: HashMap[Int, String]) => { + val map = new java.util.HashMap[Int, String]() + m.keys().foreach((key: Int) => { + map.put(key, m.get(key).some()) + Unit.unit() + }) + val fromMap: HashMap[Int, String] = new HashMap[Int, String](map) + val keysAreEqual = m.keys.toSet == fromMap.keys.toSet + val valuesAreEqual = m.keys().forall((key: Int) => + optionEqual(stringEqual).eq(m.get(key), fromMap.get(key))) + keysAreEqual && valuesAreEqual + }) + + property("No null values") = forAll((list: List[Int]) => { + val m = HashMap.hashMap[Int, Int]() + list.foreachDoEffect(new Effect1[Int] { + def f(a: Int) { + m.set(a, null.asInstanceOf[Int]) + } + }) + list.forall(new F[Int, java.lang.Boolean]() { + def f(a: Int) = m.contains(a) == false + }) + }) } \ No newline at end of file diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckIteratee.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckIteratee.scala index 86feeb7a..ff085f87 100644 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckIteratee.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckIteratee.scala @@ -7,7 +7,6 @@ import Unit.unit import List.{list, nil} import Option.{some, none} import fj.Function._ -import fj.F1Functions import fj.data.Iteratee._ import org.scalacheck.Prop._ @@ -50,7 +49,7 @@ object CheckIteratee extends Properties("Iteratee") { var tail = l while(!isDone(i) && !tail.isEmpty) { val input = Input.el(tail.head) - val cont: F[F[Input[E], IterV[E, A]], P1[IterV[E, A]]] = F1Functions.`lazy`(Function.apply(input)) + val cont: F[F[Input[E], IterV[E, A]], P1[IterV[E, A]]] = Function.apply(input).`lazy`() i = i.fold(done, cont)._1 tail = tail.tail } diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 87e2b52a..044595d0 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -5,8 +5,6 @@ import fj.test.*; import org.junit.Test; -import static fj.F1Functions.bind; -import static fj.F1Functions.map; import static fj.test.Arbitrary.*; import static fj.test.Cogen.cogenInteger; import static fj.test.Property.prop; @@ -44,7 +42,7 @@ public void testMapProp() { arbF(cogenInteger, arbInteger), arbInteger, (f, g, i) -> { - int expected = map(f, g).f(i); + int expected = f.map(g).f(i); // System.out.println(String.format("input: %d, result: %d", i, expected)); return prop(expected == Reader.unit(f).map(g).f(i)); }); @@ -59,7 +57,7 @@ public void testFlatMapProp() { a, arbInteger, (f, g, i) -> { - int expected = bind(f, j -> g.f(j).getFunction()).f(i); + int expected = f.bind(j -> g.f(j).getFunction()).f(i); // System.out.println(String.format("input: %d, result: %d", i, expected)); return prop(expected == Reader.unit(f).flatMap(g).f(i)); } From 2f005d9ff90641085e7678f9199a171177813af8 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 2 Apr 2021 00:27:14 +1000 Subject: [PATCH 290/336] Removed FxFunctions and FxW for arity 3-8 --- core/src/main/java/fj/F3Functions.java | 22 ---------------------- core/src/main/java/fj/F3W.java | 8 -------- core/src/main/java/fj/F4Functions.java | 21 --------------------- core/src/main/java/fj/F4W.java | 9 --------- core/src/main/java/fj/F5Functions.java | 21 --------------------- core/src/main/java/fj/F5W.java | 9 --------- core/src/main/java/fj/F6Functions.java | 22 ---------------------- core/src/main/java/fj/F6W.java | 9 --------- core/src/main/java/fj/F7Functions.java | 22 ---------------------- core/src/main/java/fj/F7W.java | 9 --------- core/src/main/java/fj/F8Functions.java | 20 -------------------- core/src/main/java/fj/F8W.java | 9 --------- core/src/test/java/fj/FFunctionsTest.java | 17 ----------------- 13 files changed, 198 deletions(-) delete mode 100644 core/src/main/java/fj/F3Functions.java delete mode 100644 core/src/main/java/fj/F3W.java delete mode 100644 core/src/main/java/fj/F4Functions.java delete mode 100644 core/src/main/java/fj/F4W.java delete mode 100644 core/src/main/java/fj/F5Functions.java delete mode 100644 core/src/main/java/fj/F5W.java delete mode 100644 core/src/main/java/fj/F6Functions.java delete mode 100644 core/src/main/java/fj/F6W.java delete mode 100644 core/src/main/java/fj/F7Functions.java delete mode 100644 core/src/main/java/fj/F7W.java delete mode 100644 core/src/main/java/fj/F8Functions.java delete mode 100644 core/src/main/java/fj/F8W.java diff --git a/core/src/main/java/fj/F3Functions.java b/core/src/main/java/fj/F3Functions.java deleted file mode 100644 index 18e811d9..00000000 --- a/core/src/main/java/fj/F3Functions.java +++ /dev/null @@ -1,22 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F3Functions { - - - private F3Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F2 f(final F3 f, final A a) { - return (b, c) -> f.f(a, b, c); - } - -} diff --git a/core/src/main/java/fj/F3W.java b/core/src/main/java/fj/F3W.java deleted file mode 100644 index d6ffa80b..00000000 --- a/core/src/main/java/fj/F3W.java +++ /dev/null @@ -1,8 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F3W implements F3 { - -} diff --git a/core/src/main/java/fj/F4Functions.java b/core/src/main/java/fj/F4Functions.java deleted file mode 100644 index cb353764..00000000 --- a/core/src/main/java/fj/F4Functions.java +++ /dev/null @@ -1,21 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F4Functions { - - private F4Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F3 f(final F4 f, final A a) { - return (b, c, d) -> f.f(a, b, c, d); - } - -} diff --git a/core/src/main/java/fj/F4W.java b/core/src/main/java/fj/F4W.java deleted file mode 100644 index 3cc92e55..00000000 --- a/core/src/main/java/fj/F4W.java +++ /dev/null @@ -1,9 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F4W implements F4 { - - -} diff --git a/core/src/main/java/fj/F5Functions.java b/core/src/main/java/fj/F5Functions.java deleted file mode 100644 index c39b228f..00000000 --- a/core/src/main/java/fj/F5Functions.java +++ /dev/null @@ -1,21 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F5Functions { - - private F5Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F4 f(final F5 f, final A a) { - return (b, c, d, e) -> f.f(a, b, c, d, e); - } - -} diff --git a/core/src/main/java/fj/F5W.java b/core/src/main/java/fj/F5W.java deleted file mode 100644 index 5fa407cd..00000000 --- a/core/src/main/java/fj/F5W.java +++ /dev/null @@ -1,9 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F5W implements F5 { - - -} diff --git a/core/src/main/java/fj/F6Functions.java b/core/src/main/java/fj/F6Functions.java deleted file mode 100644 index 320b95f4..00000000 --- a/core/src/main/java/fj/F6Functions.java +++ /dev/null @@ -1,22 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F6Functions { - - private F6Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F5 f(final F6 func, final A a) { - return (b, c, d, e, f) -> func.f(a, b, c, d, e, f); - } - - -} diff --git a/core/src/main/java/fj/F6W.java b/core/src/main/java/fj/F6W.java deleted file mode 100644 index adaf723f..00000000 --- a/core/src/main/java/fj/F6W.java +++ /dev/null @@ -1,9 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F6W implements F6 { - - -} diff --git a/core/src/main/java/fj/F7Functions.java b/core/src/main/java/fj/F7Functions.java deleted file mode 100644 index e583ba4b..00000000 --- a/core/src/main/java/fj/F7Functions.java +++ /dev/null @@ -1,22 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F7Functions { - - private F7Functions() { - } - - /** - * Partial application. - * - * @param a The A to which to apply this function. - * @return The function partially applied to the given argument. - */ - public static F6 f(final F7 func, final A a) { - return (b, c, d, e, f, g) -> func.f(a, b, c, d, e, f, g); - } - - -} diff --git a/core/src/main/java/fj/F7W.java b/core/src/main/java/fj/F7W.java deleted file mode 100644 index fdcec3d5..00000000 --- a/core/src/main/java/fj/F7W.java +++ /dev/null @@ -1,9 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F7W implements F7 { - - -} diff --git a/core/src/main/java/fj/F8Functions.java b/core/src/main/java/fj/F8Functions.java deleted file mode 100644 index 8b9883a3..00000000 --- a/core/src/main/java/fj/F8Functions.java +++ /dev/null @@ -1,20 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 6/04/2014. - */ -public final class F8Functions { - - private F8Functions() { - } - - /** - * Partial application. - * - * @return The function partially applied to the given argument. - */ - public static F7 f(final F8 func, final A a) { - return (b, c, d, e, f, g, h) -> func.f(a, b, c, d, e, f, g, h); - } - -} diff --git a/core/src/main/java/fj/F8W.java b/core/src/main/java/fj/F8W.java deleted file mode 100644 index d0a9f861..00000000 --- a/core/src/main/java/fj/F8W.java +++ /dev/null @@ -1,9 +0,0 @@ -package fj; - -/** - * Created by MarkPerry on 22/01/2015. - */ -public abstract class F8W implements F8 { - - -} diff --git a/core/src/test/java/fj/FFunctionsTest.java b/core/src/test/java/fj/FFunctionsTest.java index e0df9164..b235ff67 100644 --- a/core/src/test/java/fj/FFunctionsTest.java +++ b/core/src/test/java/fj/FFunctionsTest.java @@ -7,23 +7,6 @@ import static org.junit.Assert.*; public class FFunctionsTest { - @Test - public void testApply() { - F8 f8 = - (i1, i2, i3, i4, i5, i6, i7, i8) -> - i1 + i2 + i3 + i4 + i5 + i6 + i7 + i8; - F7 f7 = F8Functions.f(f8, 8); - F6 f6 = - F7Functions.f(f7, 7); - F5 f5 = F6Functions.f(f6, 6); - F4 f4 = F5Functions.f(f5, 5); - F3 f3 = F4Functions.f(f4, 4); - F2 f2 = F3Functions.f(f3, 3); - F f1 = f2.f(2); - assertThat(f1.f(1), is(36)); - } @Test public void testTreeK() { From 202f88c5eb051fe74cfff9ff71952058f47d936a Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 2 Apr 2021 00:31:15 +1000 Subject: [PATCH 291/336] Added functional interface annotations to functions --- core/src/main/java/fj/F.java | 1 + core/src/main/java/fj/F0.java | 1 + core/src/main/java/fj/F2.java | 1 + core/src/main/java/fj/F3.java | 1 + core/src/main/java/fj/F4.java | 1 + core/src/main/java/fj/F5.java | 1 + core/src/main/java/fj/F6.java | 1 + core/src/main/java/fj/F7.java | 1 + core/src/main/java/fj/F8.java | 1 + 9 files changed, 9 insertions(+) diff --git a/core/src/main/java/fj/F.java b/core/src/main/java/fj/F.java index d2208236..45cec4fe 100644 --- a/core/src/main/java/fj/F.java +++ b/core/src/main/java/fj/F.java @@ -21,6 +21,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F extends Function { /** * Transform A to B. diff --git a/core/src/main/java/fj/F0.java b/core/src/main/java/fj/F0.java index eab82a01..14c00ca2 100644 --- a/core/src/main/java/fj/F0.java +++ b/core/src/main/java/fj/F0.java @@ -3,6 +3,7 @@ /** * Created by MarkPerry on 21/01/2015. */ +@FunctionalInterface public interface F0 { A f(); diff --git a/core/src/main/java/fj/F2.java b/core/src/main/java/fj/F2.java index ba0e6f2f..4f7c306d 100644 --- a/core/src/main/java/fj/F2.java +++ b/core/src/main/java/fj/F2.java @@ -18,6 +18,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F2 extends BiFunction { /** * Transform A and B to C. diff --git a/core/src/main/java/fj/F3.java b/core/src/main/java/fj/F3.java index 540afdaa..b8c4dcf3 100644 --- a/core/src/main/java/fj/F3.java +++ b/core/src/main/java/fj/F3.java @@ -6,6 +6,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F3 { /** * Transform A, B and C to D. diff --git a/core/src/main/java/fj/F4.java b/core/src/main/java/fj/F4.java index 84dcfafa..d63f03a7 100644 --- a/core/src/main/java/fj/F4.java +++ b/core/src/main/java/fj/F4.java @@ -6,6 +6,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F4 { /** * Transform A, B, C and D to E. diff --git a/core/src/main/java/fj/F5.java b/core/src/main/java/fj/F5.java index 5fea676b..f63ae797 100644 --- a/core/src/main/java/fj/F5.java +++ b/core/src/main/java/fj/F5.java @@ -7,6 +7,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F5 { /** * Transform A, B, C, D and E to diff --git a/core/src/main/java/fj/F6.java b/core/src/main/java/fj/F6.java index 20101cf7..558c17fc 100644 --- a/core/src/main/java/fj/F6.java +++ b/core/src/main/java/fj/F6.java @@ -7,6 +7,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F6 { /** * Transform A, B, C, D, E and diff --git a/core/src/main/java/fj/F7.java b/core/src/main/java/fj/F7.java index 5a3ea1ef..05caefb4 100644 --- a/core/src/main/java/fj/F7.java +++ b/core/src/main/java/fj/F7.java @@ -7,6 +7,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F7 { /** * Transform A, B, C, D, E, diff --git a/core/src/main/java/fj/F8.java b/core/src/main/java/fj/F8.java index 8b986456..5aa103f2 100644 --- a/core/src/main/java/fj/F8.java +++ b/core/src/main/java/fj/F8.java @@ -7,6 +7,7 @@ * * @version %build.number% */ +@FunctionalInterface public interface F8 { /** * Transform A, B, C, D, E, From 2ee2950ab391a7213b01d9e0f6a81473e8b4c76e Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 2 Apr 2021 01:37:55 +1000 Subject: [PATCH 292/336] Removed IOW --- core/src/main/java/fj/data/IO.java | 28 ++++++++++++ core/src/main/java/fj/data/IOW.java | 45 ------------------- core/src/main/java/fj/data/SafeIO.java | 1 + demo/src/main/java/fj/demo/IOWalkthrough.java | 3 +- 4 files changed, 30 insertions(+), 47 deletions(-) delete mode 100644 core/src/main/java/fj/data/IOW.java diff --git a/core/src/main/java/fj/data/IO.java b/core/src/main/java/fj/data/IO.java index ee27bdb7..992abaf2 100644 --- a/core/src/main/java/fj/data/IO.java +++ b/core/src/main/java/fj/data/IO.java @@ -4,6 +4,9 @@ * Created by MarkPerry on 19/06/2014. */ +import fj.F; +import fj.Unit; + import java.io.IOException; /** @@ -13,8 +16,33 @@ * * @param the type of the result produced by the IO */ +@FunctionalInterface public interface IO { A run() throws IOException; + default SafeIO> safe() { + return IOFunctions.toSafeValidation(this); + } + + default IO map(F f) { + return IOFunctions.map(this, f); + } + + default IO bind(F> f) { + return IOFunctions.bind(this, f); + } + + default IO append(IO iob) { + return IOFunctions.append(this, iob); + } + + public static IO getContents() { + return () -> IOFunctions.getContents().run(); + } + + public static IO interact(F f) { + return () -> IOFunctions.interact(f).run(); + } + } diff --git a/core/src/main/java/fj/data/IOW.java b/core/src/main/java/fj/data/IOW.java deleted file mode 100644 index 859c9cdb..00000000 --- a/core/src/main/java/fj/data/IOW.java +++ /dev/null @@ -1,45 +0,0 @@ -package fj.data; - -import fj.F; -import fj.Unit; - -import java.io.IOException; - -/** - * Created by MarkPerry on 9/06/2015. - */ -public final class IOW implements IO { - - private final IO io; - - private IOW(IO in) { - io = in; - } - - public static IOW lift(IO io) { - return new IOW<>(io); - } - - @Override - public A run() throws IOException { - return io.run(); - } - - public SafeIO> safe() { - return IOFunctions.toSafeValidation(io); - } - - public IOW map(F f) { return lift(IOFunctions.map(io, f)); } - - public IOW bind(F> f) { return lift(IOFunctions.bind(io, f)); } - - public IOW append(IO iob) { return lift(IOFunctions.append(io, iob)); } - - public static IOW getContents() { - return lift(() -> IOFunctions.getContents().run()); - } - - public static IOW interact(F f) { - return lift(() -> IOFunctions.interact(f).run()); - } -} diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index ef4c608c..11fdc31a 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -3,6 +3,7 @@ /** * Created by MarkPerry on 3/07/2014. */ +@FunctionalInterface public interface SafeIO extends IO { @Override diff --git a/demo/src/main/java/fj/demo/IOWalkthrough.java b/demo/src/main/java/fj/demo/IOWalkthrough.java index 5c1c4663..2f1cb9eb 100644 --- a/demo/src/main/java/fj/demo/IOWalkthrough.java +++ b/demo/src/main/java/fj/demo/IOWalkthrough.java @@ -4,7 +4,6 @@ import fj.Unit; import fj.data.IO; import fj.data.IOFunctions; -import fj.data.IOW; import java.io.BufferedReader; import java.io.IOException; @@ -72,7 +71,7 @@ public static void main(String[] args) { // for composing IO values instead, the entire program can be written like so: F f = String::toUpperCase; - IOW.lift(stdoutPrintln("What's your name again?")) + stdoutPrintln("What's your name again?") .append(stdoutPrint("Name: ")) .append(stdinReadLine()) .bind(f.andThen(IOFunctions::stdoutPrintln)) From ef68abe9ecdf083cdfecc2b0c6c367073d0a4867 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 5 Apr 2021 12:18:51 +1000 Subject: [PATCH 293/336] Removed deprecated monoid methods --- core/src/main/java/fj/Monoid.java | 51 +------------------------------ 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 96d24b82..765026b3 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -466,20 +466,6 @@ public A append(A a1, A a2) { }); } - /** - * Constructs a monoid from the given semigroup and zero value, which must follow the monoidal laws. - * @deprecated since 4.7. Use {@link #monoidDef(Semigroup.Definition, Object)} or {@link Semigroup#monoid(Object)} instead. - * - * @param s The semigroup for the monoid. - * @param zero The zero for the monoid. - * @return A monoid instance that uses the given sun function and zero value. - */ - @Deprecated - public static Monoid monoid(final Semigroup s, final A zero) { - return s.monoid(zero); - } - - /** * A monoid that adds integers. */ @@ -528,19 +514,7 @@ public Integer multiply(int n, Integer integer) { return n <= 0 ? 1 : (int) StrictMath.pow(integer.doubleValue(), n); } }); - - /** - * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws - */ - @Deprecated - public static final Monoid doubleAdditionMonoid = monoidDef((d1, d2) -> d1 + d2, 0.0); - - /** - * @deprecated Since 4.7. Due to rounding errors, multiplication of doubles does not comply with monoid laws - */ - @Deprecated - public static final Monoid doubleMultiplicationMonoid = monoidDef((d1, d2) -> d1 * d2, 1.0); - + /** * A monoid that adds big integers. */ @@ -889,17 +863,6 @@ public Option sum(F0>> oas) { }); } - /** - * A monoid for options. - * @deprecated since 4.7. Use {@link #firstOptionMonoid()}. - * - * @return A monoid for options. - */ - @Deprecated - public static Monoid> optionMonoid() { - return firstOptionMonoid(); - } - /** * A monoid for options that take the first available value. * @@ -1121,16 +1084,4 @@ public Set append(Set a1, Set a2) { }); } - /** - * A monoid for the maximum of elements with ordering o. - * @deprecated since 4.7. Use {@link Ord#maxMonoid(Object)} - * - * @param o An ordering of elements. - * @param zero The minimum element. - */ - @Deprecated - public static Monoid ordMaxMonoid(final Ord o, final A zero) { - return o.maxMonoid(zero); - } - } From 3b0f9b951f0a503b6326c1e40f48c43d6d381683 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 5 Apr 2021 13:27:22 +1000 Subject: [PATCH 294/336] Removed deprecated methods from core --- core/src/main/java/fj/Monoid.java | 2 +- core/src/main/java/fj/Ord.java | 38 ---------- core/src/main/java/fj/P.java | 7 ++ core/src/main/java/fj/P1.java | 31 +------- core/src/main/java/fj/Semigroup.java | 23 ------ core/src/main/java/fj/data/Array.java | 13 ---- core/src/main/java/fj/data/HashMap.java | 20 ----- core/src/main/java/fj/data/Java.java | 11 --- core/src/main/java/fj/data/List.java | 90 ----------------------- core/src/main/java/fj/data/Seq.java | 16 ---- core/src/main/java/fj/data/Set.java | 24 ------ core/src/main/java/fj/data/Stream.java | 53 ------------- core/src/main/java/fj/data/TreeMap.java | 20 +---- core/src/test/java/fj/data/ArrayTest.java | 1 + 14 files changed, 13 insertions(+), 336 deletions(-) diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index 765026b3..bc09250d 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -514,7 +514,7 @@ public Integer multiply(int n, Integer integer) { return n <= 0 ? 1 : (int) StrictMath.pow(integer.doubleValue(), n); } }); - + /** * A monoid that adds big integers. */ diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index eef729c4..ae4d3fda 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -687,44 +687,6 @@ public static > Ord comparableOrd() { return ordDef((a1, a2) -> Ordering.fromInt(a1.compareTo(a2))); } - /** - * An order instance that uses {@link Object#hashCode()} for computing the order and equality, - * thus objects returning the same hashCode are considered to be equals. - * This is not safe and therefore this method is deprecated. - * - * @return An order instance that is based on {@link Object#hashCode()}. - * - * @deprecated As of release 4.7. - */ - @Deprecated - public static Ord hashOrd() { - return ordDef(a -> { - int aHash = a.hashCode(); - return a2 -> Ordering.fromInt(Integer.valueOf(aHash).compareTo(a2.hashCode())); - }); - } - - /** - * An order instance that uses {@link Object#hashCode()} and {@link Object#equals} for computing - * the order and equality. First the hashCode is compared, if this is equal, objects are compared - * using {@link Object#equals}. - * WARNING: This ordering violate antisymmetry on hash collisions. - * - * @return An order instance that is based on {@link Object#hashCode()} and {@link Object#equals}. - * - * @deprecated As of release 4.7. - */ - @Deprecated - public static Ord hashEqualsOrd() { - return ordDef(a -> { - int aHash = a.hashCode(); - return a2 -> { - final int a2Hash = a2.hashCode(); - return aHash < a2Hash ? Ordering.LT : aHash == a2Hash && a.equals(a2) ? Ordering.EQ : Ordering.GT; - }; - }); - } - class OrdComparator implements Comparator { @Override public final int compare(A o1, A o2) { diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index 6d174ed7..587cdc9d 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -65,6 +65,13 @@ public static P1 softMemo(F0 f) { return new P1.SoftReferenceMemo<>(f); } + /** + * Convert a F0 into a P1, using weak call-by-need semantic using {@link #weakMemo(F0)}. + */ + public static P1 memo(F0 f) { + return weakMemo(f); + } + /** * Convert a F0 into a P1, using call-by-name semantic: * function f is evaluated at each call to {@link P1#_1()}. diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 420b820b..810e484d 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -39,18 +39,6 @@ public static F, A> __1() { return P1::_1; } - /** - * Promote any function to a transformation between P1s. - * - * @deprecated As of release 4.5, use {@link #map_} - * @param f A function to promote to a transformation between P1s. - * @return A function promoted to operate on P1s. - */ - @Deprecated - public static F, P1> fmap(final F f) { - return map_(f); - } - /** * Promote any function to a transformation between P1s. * @@ -243,9 +231,8 @@ public final P1 map(final F f) { } /** - * @deprecated since 4.7. Use {@link P1#weakMemo()} instead. + * Wrap the memoized value into a WeakReference. */ - @Deprecated public final P1 memo() { return weakMemo(); } @@ -267,22 +254,6 @@ public final P1 memo() { */ public P1 softMemo() { return new SoftReferenceMemo<>(this); } - /** - * @deprecated since 4.7. Use {@link P#weakMemo(F0)} instead. - */ - @Deprecated - public static P1 memo(F f) { - return P.weakMemo(() -> f.f(unit())); - } - - /** - * @deprecated since 4.7. Use {@link P#weakMemo(F0)} instead. - */ - @Deprecated - public static P1 memo(F0 f) { - return P.weakMemo(f); - } - static final class Memo extends P1 { private volatile F0 fa; private A value; diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 6fbc5fc6..1d767385 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -292,23 +292,11 @@ public static Semigroup semigroup(final F2 sum) { */ public static final Semigroup intAdditionSemigroup = intAdditionMonoid.semigroup(); - /** - * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws - */ - @Deprecated - public static final Semigroup doubleAdditionSemigroup = semigroupDef((d1, d2) -> d1 + d2); - /** * A semigroup that multiplies integers. */ public static final Semigroup intMultiplicationSemigroup = intMultiplicationMonoid.semigroup(); - /** - * @deprecated Since 4.7. Due to rounding errors, addition of doubles does not comply with monoid laws - */ - @Deprecated - public static final Semigroup doubleMultiplicationSemigroup = semigroupDef((d1, d2) -> d1 * d2); - /** * A semigroup that yields the maximum of integers. */ @@ -520,17 +508,6 @@ public NonEmptyList sum(NonEmptyList nea, F0>> neas }); } - /** - * A semigroup for optional values. - * @deprecated since 4.7. Use {@link #firstOptionSemigroup()}. - * - * @return A semigroup for optional values. - */ - @Deprecated - public static Semigroup> optionSemigroup() { - return firstOptionSemigroup(); - } - /** * A semigroup for optional values that take the first available value. * diff --git a/core/src/main/java/fj/data/Array.java b/core/src/main/java/fj/data/Array.java index 7e937200..fb245f3f 100755 --- a/core/src/main/java/fj/data/Array.java +++ b/core/src/main/java/fj/data/Array.java @@ -130,19 +130,6 @@ public Object[] array() { return copyOf(a, a.length); } - /** - * To be removed in future release: - * affectation of the result of this method to a non generic array - * will result in runtime error (ClassCastException). - * - * @deprecated As of release 4.6, use {@link #array(Class)}. - */ - @SuppressWarnings("unchecked") - @Deprecated - public A[] toJavaArray() { - return (A[]) array(); - } - /** * Returns an option projection of this array; None if empty, or the first element in * Some. diff --git a/core/src/main/java/fj/data/HashMap.java b/core/src/main/java/fj/data/HashMap.java index 400cf415..455c529c 100755 --- a/core/src/main/java/fj/data/HashMap.java +++ b/core/src/main/java/fj/data/HashMap.java @@ -325,16 +325,6 @@ public java.util.Map toMap() { return result; } - /** - * Converts the Iterable to a HashMap - * - * @deprecated As of release 4.5, use {@link #iterableHashMap(Iterable)} - */ - @Deprecated - public static HashMap from(final Iterable> entries) { - return iterableHashMap(entries); - } - public static HashMap fromMap(java.util.Map map) { return fromMap(Equal.anyEqual(), Hash.anyHash(), map); } @@ -347,16 +337,6 @@ public static HashMap fromMap(Equal eq, Hash h, java.util.Map return m; } - /** - * Converts the Iterable to a HashMap - * - * @deprecated As of release 4.5, use {@link #iterableHashMap} - */ - @Deprecated - public static HashMap from(final Iterable> entries, final Equal equal, final Hash hash) { - return iterableHashMap(equal, hash, entries); - } - /** * Converts the Iterable to a HashMap */ diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index ae7fcf6a..8691c09d 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -1414,17 +1414,6 @@ public static F, List> ArrayList_List() { // END ArrayList -> - /** - * A function that converts Java lists to lists. - * @deprecated As of 4.3, use {@link #JavaList_List} - * - * @return A function that converts Java lists to lists. - */ - @Deprecated - public static F, List> JUList_List() { - return Java::JavaList_List; - } - public static F, List> JavaList_List() { return Java::JavaList_List; } diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 5b5fff67..447f76a5 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -86,19 +86,6 @@ public final boolean isNotEmpty() { return this instanceof Cons; } - /** - * Performs a reduction on this list using the given arguments. - * @deprecated As of release 4.5, use {@link #uncons} - * - * @param nil The value to return if this list is empty. - * @param cons The function to apply to the head and tail of this list if it is not empty. - * @return A reduction on this list. - */ - @Deprecated - public final B list(final B nil, final F, B>> cons) { - return uncons(uncurryF2(cons), nil); - } - public final B uncons(final F2, B> cons, final B nil) { return isEmpty() ? nil : cons.f(head(), tail()); } @@ -123,18 +110,6 @@ public final List orTail(final F0> as) { return isEmpty() ? as.f() : tail(); } - /** - * Returns an option projection of this list; None if empty, or the first element in - * Some. Equivalent to {@link #headOption()}. - * @deprecated As of release 4.5, use {@link #headOption()} - * @return An option projection of this list. - */ - @Deprecated - public final Option toOption() { - return headOption(); - - } - /** * Returns the head of the list, if any. Equivalent to {@link #toOption()} . * @@ -185,19 +160,6 @@ public final Object[] toArrayObject() { return a; } - /** - * To be removed in future release: - * affectation of the result of this method to a non generic array - * will result in runtime error (ClassCastException). - * - * @deprecated As of release 4.6, use {@link #array(Class)}. - */ - @SuppressWarnings("unchecked") - @Deprecated - public final A[] toJavaArray() { - return (A[]) toArrayObject(); - } - /** * Returns a array projection of this list. * @@ -1529,21 +1491,6 @@ public final A mode(final Ord o) { return sort(o).group(o.equal()).maximum(intOrd.contramap(List.length_())).head(); } - /** - * Groups the elements of this list by a given keyFunction into a {@link TreeMap}. - * The ordering of the keys is determined by {@link fj.Ord#hashOrd()} (ie. Object#hasCode). - * This is not safe and therefore this method is deprecated. - * - * @param keyFunction The function to select the keys for the map. - * @return A TreeMap containing the keys with the accumulated list of matched elements. - * - * @deprecated As of release 4.7, use {@link #groupBy(F, Ord)} - */ - @Deprecated - public final TreeMap> groupBy(final F keyFunction) { - return groupBy(keyFunction, Ord.hashOrd()); - } - /** * Groups the elements of this list by a given keyFunction into a {@link TreeMap}. * @@ -1555,25 +1502,6 @@ public final TreeMap> groupBy(final F keyFunction, final Or return groupBy(keyFunction, identity(), keyOrd); } - /** - * Groups the elements of this list by a given keyFunction into a {@link TreeMap} and transforms - * the matching elements with the given valueFunction. The ordering of the keys is determined by - * {@link fj.Ord#hashOrd()} (ie. Object#hasCode). - * This is not safe and therefore this method is deprecated. - * - * @param keyFunction The function to select the keys for the map. - * @param valueFunction The function to apply on each matching value. - * @return A TreeMap containing the keys with the accumulated list of matched and mapped elements. - * - * @deprecated As of release 4.7, use {@link #groupBy(F, F, Ord)} - */ - @Deprecated - public final TreeMap> groupBy( - final F keyFunction, - final F valueFunction) { - return this.groupBy(keyFunction, valueFunction, Ord.hashOrd()); - } - /** * Groups the elements of this list by a given keyFunction into a {@link TreeMap} and transforms * the matching elements with the given valueFunction. The ordering of the keys is determined by @@ -1821,24 +1749,6 @@ public static List arrayList(final A... as) { return Array.array(as).toList(); } - /** - * Constructs a list from the given Iterable. - * @deprecated As of release 4.5, use {@link #iterableList(Iterable)} - */ - @Deprecated - public static List list(final Iterable i) { - return iterableList(i); - } - - /** - * Constructs a list from the given Iterator. - * @deprecated As of release 4.5, use {@link #iteratorList(Iterator)} - */ - @Deprecated - public static List list(final Iterator it) { - return iteratorList(it); - } - /** * Constructs a list from the given Iterator. */ diff --git a/core/src/main/java/fj/data/Seq.java b/core/src/main/java/fj/data/Seq.java index 3bcb7033..59a46df7 100644 --- a/core/src/main/java/fj/data/Seq.java +++ b/core/src/main/java/fj/data/Seq.java @@ -78,25 +78,9 @@ public static Seq single(final A a) { /** * Constructs a sequence from the given list. * - * @deprecated As of release 4.5, use {@link #listSeq(List)} - * - * @param list The list to create the sequence from. - * @return A sequence with the given elements in the list. - */ - @Deprecated - public static Seq seq(final List list) { - return iterableSeq(list); - } - - /** - * Constructs a sequence from the given list. - * - * @deprecated As of release 4.5, use {@link #iterableSeq} - * * @param list The list to create the sequence from. * @return A sequence with the elements of the list. */ - @Deprecated public static Seq listSeq(final List list) { return iterableSeq(list); } diff --git a/core/src/main/java/fj/data/Set.java b/core/src/main/java/fj/data/Set.java index 15207d83..4c0aeaa0 100644 --- a/core/src/main/java/fj/data/Set.java +++ b/core/src/main/java/fj/data/Set.java @@ -713,28 +713,4 @@ public static Set arraySet(final Ord o, final A...as) { return arraySet(o, as); } - /** - * Constructs a set from the list. - * - * @deprecated As of release 4.5, use {@link #iterableSet} - * - * @param o An order for the elements of the new set. - * @param list The elements to add to a set. - * @return A new set containing the elements of the given list. - */ - @Deprecated - public static Set set(final Ord o, List list) { - return iterableSet(o, list); - } - - /** - * Constructs a set from the list. - * - * @deprecated As of release 4.5, use {@link #iterableSet} - */ - @Deprecated - public static Set fromList(final Ord o, List list) { - return iterableSet(o, list); - } - } diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index e05e26bf..bcf87dcf 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -89,20 +89,6 @@ public final boolean isNotEmpty() { return this instanceof Cons; } - /** - * Performs a reduction on this stream using the given arguments. Equivalent to {@link #uncons}. - * - * @deprecated As of release 4.5, use {@link #uncons} - * - * @param nil The value to return if this stream is empty. - * @param cons The function to apply to the head and tail of this stream if it is not empty. - * @return A reduction on this stream. - */ - @Deprecated - public final B stream(final B nil, final F>, B>> cons) { - return uncons(nil, cons); - } - /** * Performs a reduction on this stream using the given arguments. * @@ -712,26 +698,6 @@ public static Stream range(final int from, final long to) { return arrayStream(as); } - /** - * Constructs a stream with the given elements in the Iterable. Equivalent to {@link #iterableStream(Iterable)} . - * - * @deprecated As of release 4.5, use {@link #iterableStream(Iterable)} - */ - @Deprecated - public static Stream stream(Iterable it) { - return iterableStream(it); - } - - /** - * Constructs a stream with the given elements in the Iterator. Equivalent to {@link #iteratorStream(Iterator)} . - * - * @deprecated As of release 4.5, use {@link #iteratorStream(Iterator)} - */ - @Deprecated - public static Stream stream(final Iterator it) { - return iteratorStream(it); - } - /** * Constructs a stream with the given elements in the Iterator. */ @@ -916,25 +882,6 @@ public final Option toOption() { return isEmpty() ? Option.none() : some(head()); } - /** - * To be removed in future release: - * affectation of the result of this method to a non generic array - * will result in runtime error (ClassCastException). - * - * @deprecated As of release 4.6, use {@link #array(Class)}. - */ - @Deprecated - public final A[] toJavaArray() { - @SuppressWarnings("unchecked") - final A[] array = (A[]) new Object[length()]; - int i = 0; - for (A a: this) { - array[i] = a; - i++; - } - return array; - } - /** * Returns a list projection of this stream. * diff --git a/core/src/main/java/fj/data/TreeMap.java b/core/src/main/java/fj/data/TreeMap.java index 38607dbc..e1af4d91 100644 --- a/core/src/main/java/fj/data/TreeMap.java +++ b/core/src/main/java/fj/data/TreeMap.java @@ -69,20 +69,6 @@ public String toString() { return arrayTreeMap(keyOrd, p2s); } - /** - * Constructs a tree map from the given elements. - * - * @deprecated As of release 4.5, use {@link #iterableTreeMap(Ord, Iterable)} - * - * @param keyOrd An order for the keys of the tree map. - * @param list The elements to construct the tree map with. - * @return a TreeMap with the given elements. - */ - @Deprecated - public static TreeMap treeMap(final Ord keyOrd, final List> list) { - return iterableTreeMap(keyOrd, list); - } - /** * Constructs a tree map from the given elements. * @@ -313,12 +299,12 @@ public P3, Option, Set> split(Ord ord, final K k) { } /** - * Internal construction of a TreeMap from the given set. + * Constructs a TreeMap from the given set. * @param ord An order for the keys of the tree map. * @param s The elements to construct the tree map with. * @return a TreeMap with the given elements. */ - private static TreeMap treeMap(Ord ord, Set>> s) { + public static TreeMap setTreeMap(Ord ord, Set>> s) { TreeMap empty = TreeMap.empty(ord); TreeMap tree = s.toList().foldLeft((tm, p2) -> { Option opt = p2._2(); @@ -347,7 +333,7 @@ private static TreeMap treeMap(Ord ord, Set>> s) public P3, Option, TreeMap> splitLookup(final K k) { P3>>, Option>>, Set>>> p3 = tree.split(p(k, get(k))); Ord o = tree.ord().contramap(k2 -> p(k2, Option.none())); - return p(treeMap(o, p3._1()), get(k), treeMap(o, p3._3())); + return p(setTreeMap(o, p3._1()), get(k), setTreeMap(o, p3._3())); } /** diff --git a/core/src/test/java/fj/data/ArrayTest.java b/core/src/test/java/fj/data/ArrayTest.java index 886031b3..883fc835 100644 --- a/core/src/test/java/fj/data/ArrayTest.java +++ b/core/src/test/java/fj/data/ArrayTest.java @@ -1,5 +1,6 @@ package fj.data; +import org.hamcrest.CoreMatchers; import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; From e6234b801de460ff759aafeb4674edaf3c32c503 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 5 Apr 2021 15:54:41 +1000 Subject: [PATCH 295/336] Removed deprecated methods from quickcheck --- quickcheck/src/main/java/fj/test/Gen.java | 33 ------------------ quickcheck/src/main/java/fj/test/Rand.java | 39 +++------------------- 2 files changed, 5 insertions(+), 67 deletions(-) diff --git a/quickcheck/src/main/java/fj/test/Gen.java b/quickcheck/src/main/java/fj/test/Gen.java index dabaf9a6..8fe1e6f5 100644 --- a/quickcheck/src/main/java/fj/test/Gen.java +++ b/quickcheck/src/main/java/fj/test/Gen.java @@ -536,24 +536,6 @@ public static Gen pickOne(List as) { return wordOf(1, as).map(List::head); } - /** - * Returns a generator of lists that picks the given number of elements from the given list. If - * the given number is less than zero or greater than the length of the given list, then the - * returned generator will never produce a value. - *

      - * Note: pick is synonymous with combinationOf - * - * @deprecated As of release 4.6, use {@link #combinationOf} - * - * @param n The number of elements to pick from the given list. - * @param as The list from which to pick elements. - * @return A generator of lists that picks the given number of elements from the given list. - */ - @Deprecated - public static Gen> pick(int n, List as) { - return combinationOf(n, as); - } - /** * Returns a generator of lists that picks the given number of elements from the given list. The selection is * a combination without replacement of elements from the given list, i.e. @@ -678,21 +660,6 @@ private static Gen> pick(Gen> indexesGen, Array as) indexes.foldLeft((acc, index) -> cons(as.get(index), acc), List.nil()).reverse()); } - /** - * Returns a generator of lists that produces some of the values of the given list. - *

      - * Note: someOf is synonymous with someCombinationOf - * - * @deprecated As of release 4.6, use {@link #someCombinationOf} - * - * @param as The list from which to pick values. - * @return A generator of lists that produces some of the values of the given list. - */ - @Deprecated - public static Gen> someOf(List as) { - return someCombinationOf(as); - } - /** * Returns a generator of lists that produces some of the values of the given list. The selection is * a combination without replacement of elements from the given list, i.e. diff --git a/quickcheck/src/main/java/fj/test/Rand.java b/quickcheck/src/main/java/fj/test/Rand.java index b622dfe7..e47aa8a8 100644 --- a/quickcheck/src/main/java/fj/test/Rand.java +++ b/quickcheck/src/main/java/fj/test/Rand.java @@ -5,7 +5,6 @@ import java.util.Random; -import static fj.data.Option.none; import static fj.data.Option.some; import static java.lang.Math.max; import static java.lang.Math.min; @@ -18,18 +17,16 @@ public final class Rand { private final F, F>> f; private final F, F>> g; - - // TODO Change to F when rand(f,g) is removed - private final Option> optOnReseed; + private final F onReseed; private Rand( F, F>> f, F, F>> g, - Option> optOnReseed) { + F onReseed) { this.f = f; this.g = g; - this.optOnReseed = optOnReseed; + this.onReseed = onReseed; } /** @@ -88,33 +85,7 @@ public double choose(final double from, final double to) { * @return A random generator with the given seed. */ public Rand reseed(long seed) { - return optOnReseed.option( - () -> { - throw new IllegalStateException("reseed() called on a Rand created with deprecated rand() method"); - }, - onReseed -> onReseed.f(seed)); - } - - /** - * Constructs a random generator from the given functions that supply a range to produce a - * result. - *

      - * Calling {@link #reseed(long)} on an instance returned from this method will - * result in an exception being thrown. - * - * @deprecated As of release 4.6, use {@link #rand(F, F, F)}. - * - * @param f The integer random generator. - * @param g The floating-point random generator. - * @return A random generator from the given functions that supply a range to produce a result. - */ - // TODO Change Option> optOnReseed to F onReseed when removing this method - @Deprecated - public static Rand rand( - F, F>> f, - F, F>> g) { - - return new Rand(f, g, none()); + return onReseed.f(seed); } /** @@ -131,7 +102,7 @@ public static Rand rand( F, F>> g, F onReseed) { - return new Rand(f, g, some(onReseed)); + return new Rand(f, g, onReseed); } /** From 4859b75a3837c4c772c65c46596f388e7c1627b3 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Tue, 6 Apr 2021 01:53:30 +1000 Subject: [PATCH 296/336] Added partial Either3 implementation --- core/src/main/java/fj/Equal.java | 8 + core/src/main/java/fj/Hash.java | 7 +- core/src/main/java/fj/Show.java | 10 + core/src/main/java/fj/data/Either3.java | 226 ++++++++++++++++++++ core/src/test/java/fj/data/Either3Test.java | 6 + 5 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/fj/data/Either3.java create mode 100644 core/src/test/java/fj/data/Either3Test.java diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 5cd31aeb..9179cc43 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -357,6 +357,14 @@ public static Equal> eitherEqual(final Equal ea, final Eq )); } + public static Equal> either3Equal(Equal ea, Equal eb, Equal ec) { + return equalDef((e1, e2) -> + optionEqual(ea).eq(e1.leftOption(), e2.leftOption()) && + optionEqual(eb).eq(e1.middleOption(), e2.middleOption()) && + optionEqual(ec).eq(e1.rightOption(), e2.rightOption()) + ); + } + public static Equal> resultEqual(final Equal ea, final Equal ei) { Definition eaDef = ea.def; Definition eiDef= ei.def; diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 8d0a4e4c..703d96ee 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -163,7 +163,12 @@ public static Hash> eitherHash(final Hash ha, final Hash< return hash(e -> e.isLeft() ? ha.hash(e.left().value()) : hb.hash(e.right().value())); } - /** + public static Hash> either3Hash(final Hash ha, final Hash hb, final Hash hc) { + return hash(e -> e.either(a -> ha.hash(a), b -> hb.hash(b), c -> hc.hash(c))); + } + + + /** * A hash instance for the {@link Result} type. * * @param ha Hash the Result value. diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index cd57897b..62da5273 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -256,6 +256,16 @@ public static Show> eitherShow(final Show sa, final Show< fromString("Right(").append(sb.f.f(e.right().value())).append(single(')'))); } + public static Show> eitherShow(final Show sa, final Show sb, final Show sc) { + return show(e -> + e.either( + a -> fromString("Left(").append(sa.f.f(a)).append(single(')')), + b -> fromString("Middle(").append(sb.f.f(b)).append(single(')')), + c -> fromString("Right(").append(sc.f.f(c)).append(single(')')) + ) + ); + } + /** * A show instance for the {@link Result} type. * diff --git a/core/src/main/java/fj/data/Either3.java b/core/src/main/java/fj/data/Either3.java new file mode 100644 index 00000000..8c6b7344 --- /dev/null +++ b/core/src/main/java/fj/data/Either3.java @@ -0,0 +1,226 @@ +package fj.data; + +import fj.Equal; +import fj.F; +import fj.F0; +import fj.Hash; + +import static fj.data.Option.none; +import static fj.data.Option.some; + +public abstract class Either3 { + + private Either3() {} + + private static final class Left extends Either3 { + A a; + Left(A a) { + this.a = a; + } + + @Override + public boolean isLeft() { + return true; + } + + @Override + public boolean isMiddle() { + return false; + } + + @Override + public boolean isRight() { + return false; + } + + @Override + public D either(F fa, F fb, F fc) { + return fa.f(a); + } + } + + private static final class Middle extends Either3 { + B b; + Middle(B b) { + this.b = b; + } + + @Override + public boolean isLeft() { + return false; + } + + @Override + public boolean isMiddle() { + return true; + } + + @Override + public boolean isRight() { + return false; + } + + @Override + public D either(F fa, F fb, F fc) { + return fb.f(b); + } + } + + private static final class Right extends Either3 { + C c; + Right(C c) { + this.c = c; + } + + @Override + public boolean isLeft() { + return false; + } + + @Override + public boolean isMiddle() { + return false; + } + + @Override + public boolean isRight() { + return true; + } + + @Override + public D either(F fa, F fb, F fc) { + return fc.f(c); + } + + } + + public static final class LeftProjection { + private final Either3 e; + + private LeftProjection(final Either3 e) { + this.e = e; + } + + public Either3 apply(final Either3, B, C> e) { + return e.left().bind(this::map); + } + + public boolean exists(final F f) { + return e.either(a -> f.f(a), b -> false, c -> false); + } + + public Either3 bind(F> f) { + return e.either(a -> f.f(a), b -> middle(b), c -> right(c)); + } + + public Option> filter(final F f) { + return e.either(a -> f.f(a) ? some(left(a)) : none(), b -> none(), c -> none()); + } + + + public Either3 map(final F f) { + return e.either(a -> left(f.f(a)), b -> middle(b), c -> right(c)); + } + + } + + public static final class MiddleProjection { + private final Either3 e; + + private MiddleProjection(final Either3 e) { + this.e = e; + } + + public Either3 bind(F> f) { + return e.either(a -> left(a), b -> f.f(b), c -> right(c)); + } + + } + + public static final class RightProjection { + private final Either3 e; + + private RightProjection(final Either3 e) { + this.e = e; + } + + public Either3 bind(F> f) { + return e.either(a -> left(a), b -> middle(b), c -> f.f(c)); + } + } + + public static Either3 left(A a) { + return new Left<>(a); + } + + public static Either3 middle(B b) { + return new Middle<>(b); + } + + public static Either3 right(C c) { + return new Right<>(c); + } + + public abstract boolean isLeft(); + + public abstract boolean isMiddle(); + + public abstract boolean isRight(); + + public Either3 map3(F fl, F fm, F fr) { + return either( + a -> left(fl.f(a)), + b -> middle(fm.f(b)), + c -> right(fr.f(c)) + ); + } + + public abstract D either(F fa, F fb, F fc); + + public Either3 moveLeft() { + return either(a -> right(a), b -> left(b), c -> middle(c)); + } + + public Either3 moveRight() { + return either(a -> middle(a), b -> right(b), c -> left(c)); + } + + public Either3 swap() { + return either(a -> right(a), b -> middle(b), c -> left(c)); + } + + public Option leftOption() { + return either(a -> some(a), b -> none(), c -> none()); + } + + public Option middleOption() { + return either(a -> none(), b -> some(b), c -> none()); + } + + public Option rightOption() { + return either(a -> none(), b -> none(), c -> some(c)); + } + + public final LeftProjection left() { + return new LeftProjection<>(this); + } + + public final MiddleProjection middle() { + return new MiddleProjection<>(this); + } + + public final RightProjection right() { + return new RightProjection<>(this); + } + + @Override + public final boolean equals(Object other) { + return Equal.equals0(Either3.class, this, other, () -> Equal.either3Equal(Equal.anyEqual(), Equal.anyEqual(), Equal.anyEqual())); + } + + @Override + public final int hashCode() { + return Hash.either3Hash(Hash.anyHash(), Hash.anyHash(), Hash.anyHash()).hash(this); + } + +} diff --git a/core/src/test/java/fj/data/Either3Test.java b/core/src/test/java/fj/data/Either3Test.java new file mode 100644 index 00000000..1507bf41 --- /dev/null +++ b/core/src/test/java/fj/data/Either3Test.java @@ -0,0 +1,6 @@ +package fj.data; + +public final class Either3Test { + + +} From d2f777d7ee57b48fe8dfe71317ec0790d39c76ab Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Tue, 6 Apr 2021 13:37:52 +1000 Subject: [PATCH 297/336] Fixed javadoc on headOption. --- core/src/main/java/fj/data/List.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 447f76a5..9259900f 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -111,7 +111,7 @@ public final List orTail(final F0> as) { } /** - * Returns the head of the list, if any. Equivalent to {@link #toOption()} . + * Returns the head of the list, if any. * * @return The optional head of the list. */ From d3af2373fc02278ea76a11237b0c9d3c5fb5effa Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Tue, 6 Apr 2021 13:38:50 +1000 Subject: [PATCH 298/336] Implemented isLeft, isRight, isMiddle in terms of either. Added swap methods. --- core/src/main/java/fj/data/Either3.java | 75 ++++++++----------------- 1 file changed, 23 insertions(+), 52 deletions(-) diff --git a/core/src/main/java/fj/data/Either3.java b/core/src/main/java/fj/data/Either3.java index 8c6b7344..15b1f419 100644 --- a/core/src/main/java/fj/data/Either3.java +++ b/core/src/main/java/fj/data/Either3.java @@ -2,7 +2,6 @@ import fj.Equal; import fj.F; -import fj.F0; import fj.Hash; import static fj.data.Option.none; @@ -13,53 +12,26 @@ public abstract class Either3 { private Either3() {} private static final class Left extends Either3 { - A a; + private final A a; + Left(A a) { this.a = a; } - @Override - public boolean isLeft() { - return true; - } - - @Override - public boolean isMiddle() { - return false; - } - - @Override - public boolean isRight() { - return false; - } - @Override public D either(F fa, F fb, F fc) { return fa.f(a); } + } private static final class Middle extends Either3 { - B b; + private final B b; + Middle(B b) { this.b = b; } - @Override - public boolean isLeft() { - return false; - } - - @Override - public boolean isMiddle() { - return true; - } - - @Override - public boolean isRight() { - return false; - } - @Override public D either(F fa, F fb, F fc) { return fb.f(b); @@ -67,26 +39,11 @@ public D either(F fa, F fb, F fc) { } private static final class Right extends Either3 { - C c; + private final C c; Right(C c) { this.c = c; } - @Override - public boolean isLeft() { - return false; - } - - @Override - public boolean isMiddle() { - return false; - } - - @Override - public boolean isRight() { - return true; - } - @Override public D either(F fa, F fb, F fc) { return fc.f(c); @@ -161,11 +118,17 @@ public static Either3 right(C c) { return new Right<>(c); } - public abstract boolean isLeft(); + public boolean isLeft() { + return either(a -> true, b -> false, c -> false); + } - public abstract boolean isMiddle(); + public boolean isMiddle() { + return either(a -> false, b -> true, c -> false); + } - public abstract boolean isRight(); + public boolean isRight() { + return either(a -> false, b -> false, c -> true); + } public Either3 map3(F fl, F fm, F fr) { return either( @@ -189,6 +152,14 @@ public Either3 swap() { return either(a -> right(a), b -> middle(b), c -> left(c)); } + public Either3 swapLefts() { + return either(a -> middle(a), b -> left(b), c -> right(c)); + } + + public Either3 swapRights() { + return either(a -> left(a), b -> right(b), c -> middle(c)); + } + public Option leftOption() { return either(a -> some(a), b -> none(), c -> none()); } From ef79720aa0afc1fd679198e652d8d478984dff75 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Wed, 7 Apr 2021 21:39:52 +1000 Subject: [PATCH 299/336] Updated inheritance of interfaces to Java 8 interfaces --- core/src/main/java/fj/F0.java | 8 +++++++- core/src/main/java/fj/data/IO.java | 7 ++++++- core/src/main/java/fj/function/Effect0.java | 2 ++ core/src/main/java/fj/function/Effect1.java | 20 +++++++++++++++++++- core/src/main/java/fj/function/Effect2.java | 8 +++++++- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/fj/F0.java b/core/src/main/java/fj/F0.java index 14c00ca2..c260992f 100644 --- a/core/src/main/java/fj/F0.java +++ b/core/src/main/java/fj/F0.java @@ -1,11 +1,17 @@ package fj; +import java.util.function.Supplier; + /** * Created by MarkPerry on 21/01/2015. */ @FunctionalInterface -public interface F0 { +public interface F0 extends Supplier { A f(); + default A get() { + return f(); + } + } diff --git a/core/src/main/java/fj/data/IO.java b/core/src/main/java/fj/data/IO.java index 992abaf2..e2a94a38 100644 --- a/core/src/main/java/fj/data/IO.java +++ b/core/src/main/java/fj/data/IO.java @@ -6,6 +6,7 @@ import fj.F; import fj.Unit; +import fj.function.Try0; import java.io.IOException; @@ -17,10 +18,14 @@ * @param the type of the result produced by the IO */ @FunctionalInterface -public interface IO { +public interface IO extends Try0 { A run() throws IOException; + default A f() throws IOException { + return run(); + } + default SafeIO> safe() { return IOFunctions.toSafeValidation(this); } diff --git a/core/src/main/java/fj/function/Effect0.java b/core/src/main/java/fj/function/Effect0.java index c5d4fe50..57800eb0 100644 --- a/core/src/main/java/fj/function/Effect0.java +++ b/core/src/main/java/fj/function/Effect0.java @@ -1,5 +1,7 @@ package fj.function; +import fj.F0; + /** * Created by mperry on 28/08/2014. */ diff --git a/core/src/main/java/fj/function/Effect1.java b/core/src/main/java/fj/function/Effect1.java index 8c89b715..0cc35a39 100644 --- a/core/src/main/java/fj/function/Effect1.java +++ b/core/src/main/java/fj/function/Effect1.java @@ -1,10 +1,28 @@ package fj.function; +import fj.F; +import fj.Unit; + +import java.util.function.Consumer; + +import static fj.Unit.unit; + /** * Created by mperry on 28/08/2014. */ -public interface Effect1 { +public interface Effect1 extends Consumer { void f(A a); + default void accept(A a) { + f(a); + } + + default F toF() { + return a -> { + f(a); + return unit(); + }; + } + } diff --git a/core/src/main/java/fj/function/Effect2.java b/core/src/main/java/fj/function/Effect2.java index c0735043..40d8abd8 100644 --- a/core/src/main/java/fj/function/Effect2.java +++ b/core/src/main/java/fj/function/Effect2.java @@ -1,10 +1,16 @@ package fj.function; +import java.util.function.BiConsumer; + /** * Created by mperry on 28/08/2014. */ -public interface Effect2 { +public interface Effect2 extends BiConsumer { void f(A a, B b); + default void accept(A a, B b) { + f(a, b); + } + } From 7d3f6130c4ab6cafe7fe81e5c21ceacdb8a8b375 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Wed, 7 Apr 2021 21:40:49 +1000 Subject: [PATCH 300/336] Implemented left and middle projections of Either3. --- core/src/main/java/fj/data/Either3.java | 286 +++++++++++++++++++++++- 1 file changed, 279 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/fj/data/Either3.java b/core/src/main/java/fj/data/Either3.java index 15b1f419..0c7b7371 100644 --- a/core/src/main/java/fj/data/Either3.java +++ b/core/src/main/java/fj/data/Either3.java @@ -1,9 +1,16 @@ package fj.data; -import fj.Equal; -import fj.F; -import fj.Hash; +import fj.*; +import fj.function.Effect1; +import java.util.Collection; +import java.util.Iterator; + +import static fj.Function.identity; +import static fj.P.p; +import static fj.Unit.unit; +import static fj.data.Array.mkArray; +import static fj.data.List.*; import static fj.data.Option.none; import static fj.data.Option.some; @@ -49,6 +56,8 @@ public D either(F fa, F fb, F fc) { return fc.f(c); } + + } public static final class LeftProjection { @@ -62,23 +71,121 @@ public Either3 apply(final Either3, B, C> e) { return e.left().bind(this::map); } - public boolean exists(final F f) { - return e.either(a -> f.f(a), b -> false, c -> false); - } - public Either3 bind(F> f) { return e.either(a -> f.f(a), b -> middle(b), c -> right(c)); } + public Either3 either() { + return e; + } + + public boolean exists(final F f) { + return e.either(a -> f.f(a), b -> false, c -> false); + } + public Option> filter(final F f) { return e.either(a -> f.f(a) ? some(left(a)) : none(), b -> none(), c -> none()); } + public boolean forall(final F f) { + return e.either(a -> f.f(a), b -> true, c -> true); + } + + public Unit foreach(final F f) { + return e.either(a -> f.f(a), b -> unit(), c -> unit()); + } + + public void foreachDoEffect(final Effect1 f) { + e.either(a -> f.toF().f(a), b -> unit(), c -> unit()); + } + + public Iterator iterator() { + return toList().iterator(); + } public Either3 map(final F f) { return e.either(a -> left(f.f(a)), b -> middle(b), c -> right(c)); } + public A orValue(final A value) { + return orValue(() -> value); + } + + public A orValue(final F0 f) { + return e.either(a -> a, b -> f.f(), c -> f.f()); + } + + public Either3 sequence(final Either3 e) { + return bind(Function.constant(e)); + } + + public Array toArray() { + return e.either( + a -> Array.single(a), + b -> Array.empty(), + c -> Array.empty() + ); + } + + public Collection toCollection() { + return toList().toCollection(); + } + + public List toList() { + return e.either(a -> single(a), b -> nil(), c -> nil()); + } + + public Option toOption() { + return e.either(a -> some(a), b -> none(), c -> none()); + } + + public Stream toStream() { + return e.either(a -> Stream.single(a), b -> Stream.nil(), c -> Stream.nil()); + } + + public IO> traverseIO(final F> f) { + return e.either( + a -> f.f(a).map(Either3::left), + b -> IOFunctions.unit(middle(b)), + c -> IOFunctions.unit(right(c)) + ); + } + + public List> traverseList1(final F> f) { + return e.either( + a -> f.f(a).map(Either3::left), + b -> single(middle(b)), + c -> single(right(c)) + ); + } + + public Option> traverseOption(final F> f) { + return e.either( + a -> f.f(a).map(Either3::left), + b -> some(middle(b)), + c -> some(right(c)) + ); + + } + + public P1> traverseP1(final F> f) { + return e.either( + a -> f.f(a).map(Either3::left), + b -> p(middle(b)), + c -> p(right(c)) + ); + + } + + public Stream> traverseStream(final F> f) { + return e.either( + a -> f.f(a).map(Either3::left), + b -> Stream.single(middle(b)), + c -> Stream.single(right(c)) + ); + + } + } public static final class MiddleProjection { @@ -88,10 +195,150 @@ private MiddleProjection(final Either3 e) { this.e = e; } + public Either3 apply(final Either3, C> e) { + return e.middle().bind(this::map); + } + public Either3 bind(F> f) { return e.either(a -> left(a), b -> f.f(b), c -> right(c)); } + public Either3 either() { + return e; + } + + public boolean exists(final F f) { + return e.either(a -> false, b -> f.f(b), c -> false); + } + + public Option> filter(final F f) { + return e.either(a -> none(), b -> f.f(b) ? some(middle(b)) : none(), c -> none()); + } + + public boolean forall(final F f) { + return e.either(a -> true, b -> f.f(b), c -> true); + } + + public Unit foreach(final F f) { + return e.either(a -> unit(), b -> f.f(b), c -> unit()); + } + + public void foreachDoEffect(final Effect1 f) { + e.either(a -> unit(), b -> f.toF().f(b), c -> unit()); + } + + public Iterator iterator() { + return toList().iterator(); + } + + public Either3 map(final F f) { + return e.either(a -> left(a), b -> middle(f.f(b)), c -> right(c)); + } + + public B orValue(final B value) { + return orValue(() -> value); + } + + public B orValue(final F0 f) { + return e.either(a -> f.f(), b -> b, c -> f.f()); + } + + public Either3 sequence(final Either3 e) { + return bind(Function.constant(e)); + } + + public Array toArray() { + return e.either( + a -> Array.empty(), + b -> Array.single(b), + c -> Array.empty() + ); + } + + public Collection toCollection() { + return toList().toCollection(); + } + + public List toList() { + return e.either(a -> nil(), b -> single(b), c -> nil()); + } + + public Option toOption() { + return e.either(a -> none(), b -> some(b), c -> none()); + } + + public Stream toStream() { + return e.either(a -> Stream.nil(), b -> Stream.single(b), c -> Stream.nil()); + } + + public IO> traverseIO(final F> f) { + return e.either( + a -> IOFunctions.unit(left(a)), + b -> f.f(b).map(Either3::middle), + c -> IOFunctions.unit(right(c)) + ); + } + + public List> traverseList1(final F> f) { + return e.either( + a -> single(left(a)), + b -> f.f(b).map(Either3::middle), + c -> single(right(c)) + ); + } + + public Option> traverseOption(final F> f) { + return e.either( + a -> some(left(a)), + b -> f.f(b).map(Either3::middle), + c -> some(right(c)) + ); + + } + + public P1> traverseP1(final F> f) { + return e.either( + a -> p(left(a)), + b -> f.f(b).map(Either3::middle), + c -> p(right(c)) + ); + + } + + public Stream> traverseStream(final F> f) { + return e.either( + a -> Stream.single(left(a)), + b -> f.f(b).map(Either3::middle), + c -> Stream.single(right(c)) + ); + + } + + + } + + public final Either3 leftMap(F f) { + return left().map(f); + } + + public final F, Either3> leftMap_() { + return this::leftMap; + } + + public final Either3 middleMap(F f) { + return middle().map(f); + } + + public final F, Either3> middleMap_() { + return this::middleMap; + } + + public final Either3 rightMap(F f) { + return right().map(f); + } + + public final F, Either3> rightMap_() { + return this::rightMap; } public static final class RightProjection { @@ -104,12 +351,21 @@ private RightProjection(final Either3 e) { public Either3 bind(F> f) { return e.either(a -> left(a), b -> middle(b), c -> f.f(c)); } + + public Either3 map(final F f) { + return e.either(a -> left(a), b -> middle(b), c -> right(f.f(c))); + } + } public static Either3 left(A a) { return new Left<>(a); } + public static F> left_() { + return Either3::left; + } + public static Either3 middle(B b) { return new Middle<>(b); } @@ -140,6 +396,22 @@ public Either3 map3(F fl, F fm, F fr) { public abstract D either(F fa, F fb, F fc); + public static F, D> either_(F fa, F fb, F fc) { + return e -> e.either(fa, fb, fc); + } + + public static Either3 joinLeft(final Either3, B, C> e) { + return e.left().bind(identity()); + } + + public static Either3 joinMiddle(final Either3, C> e) { + return e.middle().bind(identity()); + } + + public static Either3 joinRight(final Either3> e) { + return e.right().bind(identity()); + } + public Either3 moveLeft() { return either(a -> right(a), b -> left(b), c -> middle(c)); } From eedacf0010d8db853fd18c5ba59384d7740f9a9c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Wed, 7 Apr 2021 21:53:53 +1000 Subject: [PATCH 301/336] Implemented the right projection of Either3. --- core/src/main/java/fj/data/Either3.java | 111 ++++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/core/src/main/java/fj/data/Either3.java b/core/src/main/java/fj/data/Either3.java index 0c7b7371..9b545f7e 100644 --- a/core/src/main/java/fj/data/Either3.java +++ b/core/src/main/java/fj/data/Either3.java @@ -347,15 +347,126 @@ public static final class RightProjection { private RightProjection(final Either3 e) { this.e = e; } + public Either3 apply(final Either3> e) { + return e.right().bind(this::map); + } public Either3 bind(F> f) { return e.either(a -> left(a), b -> middle(b), c -> f.f(c)); } + public Either3 either() { + return e; + } + + public boolean exists(final F f) { + return e.either(a -> false, b -> false, c -> f.f(c)); + } + + public Option> filter(final F f) { + return e.either(a -> none(), b -> none(), c -> f.f(c) ? some(right(c)) : none()); + } + + public boolean forall(final F f) { + return e.either(a -> true, b -> true, c -> f.f(c)); + } + + public Unit foreach(final F f) { + return e.either(a -> unit(), b -> unit(), c -> f.f(c)); + } + + public void foreachDoEffect(final Effect1 f) { + e.either(a -> unit(), b -> unit(), c -> f.toF().f(c)); + } + + public Iterator iterator() { + return toList().iterator(); + } + public Either3 map(final F f) { return e.either(a -> left(a), b -> middle(b), c -> right(f.f(c))); } + public C orValue(final C value) { + return orValue(() -> value); + } + + public C orValue(final F0 f) { + return e.either(a -> f.f(), b -> f.f(), c -> c); + } + + public Either3 sequence(final Either3 e) { + return bind(Function.constant(e)); + } + + public Array toArray() { + return e.either( + a -> Array.empty(), + b -> Array.empty(), + c -> Array.single(c) + ); + } + + public Collection toCollection() { + return toList().toCollection(); + } + + public List toList() { + return e.either(a -> nil(), b -> nil(), c -> single(c)); + } + + public Option toOption() { + return e.either(a -> none(), b -> none(), c -> some(c)); + } + + public Stream toStream() { + return e.either(a -> Stream.nil(), b -> Stream.nil(), c -> Stream.single(c)); + } + + public IO> traverseIO(final F> f) { + return e.either( + a -> IOFunctions.unit(left(a)), + b -> IOFunctions.unit(middle(b)), + c -> f.f(c).map(Either3::right) + ); + } + + public List> traverseList1(final F> f) { + return e.either( + a -> single(left(a)), + b -> single(middle(b)), + c -> f.f(c).map(Either3::right) + ); + } + + public Option> traverseOption(final F> f) { + return e.either( + a -> some(left(a)), + b -> some(middle(b)), + c -> f.f(c).map(Either3::right) + ); + + } + + public P1> traverseP1(final F> f) { + return e.either( + a -> p(left(a)), + b -> p(middle(b)), + c -> f.f(c).map(Either3::right) + ); + + } + + public Stream> traverseStream(final F> f) { + return e.either( + a -> Stream.single(left(a)), + b -> Stream.single(middle(b)), + c -> f.f(c).map(Either3::right) + ); + + } + + } public static Either3 left(A a) { From 546647277325db569386141681eefc99a889ec25 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 16 Apr 2021 22:39:20 +1000 Subject: [PATCH 302/336] Speed up Gradle tests by not generating test reports and running in parallel. --- build.gradle | 10 ++++++++++ gradle.properties | 3 +++ 2 files changed, 13 insertions(+) diff --git a/build.gradle b/build.gradle index 57c36c18..8e390f9c 100644 --- a/build.gradle +++ b/build.gradle @@ -70,6 +70,7 @@ allprojects { junitRuntime = "org.junit.vintage:junit-vintage-engine:5.5.2" displayCompilerWarnings = true + generateTestReports = false } repositories { @@ -112,6 +113,15 @@ subprojects { } } + tasks.withType(Test).configureEach { + maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 + if (!generateTestReports) { + reports.html.enabled = false + reports.junitXml.enabled = false + } + } + + } task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { diff --git a/gradle.properties b/gradle.properties index d4552a30..8f904ddb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,3 +3,6 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd signingEnabled = false + +org.gradle.parallel = true + From 8cef774bf2fbd850bf0a5e13bb76d2fab8380ade Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 16 Apr 2021 22:44:17 +1000 Subject: [PATCH 303/336] Renamed show for Either3. --- core/src/main/java/fj/Show.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index 62da5273..bfb2e151 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -256,7 +256,7 @@ public static Show> eitherShow(final Show sa, final Show< fromString("Right(").append(sb.f.f(e.right().value())).append(single(')'))); } - public static Show> eitherShow(final Show sa, final Show sb, final Show sc) { + public static Show> either3Show(final Show sa, final Show sb, final Show sc) { return show(e -> e.either( a -> fromString("Left(").append(sa.f.f(a)).append(single(')')), From 250aa82edd48edca4a315ee27f89cfc1bbb88e5b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 18 Apr 2021 21:54:27 +1000 Subject: [PATCH 304/336] Make SafeIO inherit of F0. --- core/src/main/java/fj/data/SafeIO.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index 11fdc31a..0643e886 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -1,13 +1,20 @@ package fj.data; +import fj.F0; + /** * Created by MarkPerry on 3/07/2014. */ @FunctionalInterface -public interface SafeIO extends IO { +public interface SafeIO extends IO, F0 { @Override A run(); + @Override + default A f() { + return run(); + } + } From 2cad57e8c28f3f61dc929adf1387b0a48a1c354b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 18 Apr 2021 21:56:05 +1000 Subject: [PATCH 305/336] Added conversions from Effect0 to Try, TryEffect and F0. --- core/src/main/java/fj/function/Effect0.java | 29 ++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/function/Effect0.java b/core/src/main/java/fj/function/Effect0.java index 57800eb0..5e499d2d 100644 --- a/core/src/main/java/fj/function/Effect0.java +++ b/core/src/main/java/fj/function/Effect0.java @@ -1,6 +1,8 @@ package fj.function; -import fj.F0; +import fj.*; + +import static fj.Unit.unit; /** * Created by mperry on 28/08/2014. @@ -9,4 +11,29 @@ public interface Effect0 { void f(); + default F0 toF0() { + return () -> { + f(); + return unit(); + }; + } + + default TryEffect0 toTryEffect0() { + return () -> f(); + } + + default Try0 toTry0() { + return () -> { + f(); + return unit(); + }; + } + + default P1 toP1() { + return P.lazy(() -> { + f(); + return unit(); + }); + } + } From 0f4f8548635e74c4fb9582887ad15c51acb1601f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 18 Apr 2021 22:51:23 +1000 Subject: [PATCH 306/336] Implemented primary functions from F in Effect1. --- core/src/main/java/fj/function/Effect1.java | 40 +++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/core/src/main/java/fj/function/Effect1.java b/core/src/main/java/fj/function/Effect1.java index 0cc35a39..64abed44 100644 --- a/core/src/main/java/fj/function/Effect1.java +++ b/core/src/main/java/fj/function/Effect1.java @@ -1,6 +1,8 @@ package fj.function; import fj.F; +import fj.P; +import fj.P1; import fj.Unit; import java.util.function.Consumer; @@ -18,6 +20,32 @@ default void accept(A a) { f(a); } + default F bind(final F> g) { + return a -> { + return g.f(toF().f(a)).f(a); + }; + } + + default void apply(A a) { + f(a); + } + + default Effect1 contramap(F f) { + return o(f); + } + + default F map(F f) { + return a -> f.f(toF().f(a)); + } + + default F andThen(final F f) { + return map(f); + } + + default Effect1 o(final F f) { + return c -> f(f.f(c)); + } + default F toF() { return a -> { f(a); @@ -25,4 +53,16 @@ default F toF() { }; } + static Effect1 fromF(F f) { + return a -> f.f(a); + } + + default F dimap(F f, F g) { + return c -> g.f(toF().f(f.f(c))); + } + + default P1 partial(final A a) { + return P.lazy(() -> toF().f(a)); + } + } From 53ab41a58021a17a109772918c9c02f08ed32f8f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 19 Apr 2021 00:40:18 +1000 Subject: [PATCH 307/336] Added conversion functions between Effect, F, Try and TryEffect for low arities. --- core/src/main/java/fj/F0.java | 20 ++++++++ core/src/main/java/fj/data/SafeIO.java | 6 ++- core/src/main/java/fj/function/Effect1.java | 11 ++++ core/src/main/java/fj/function/Effect2.java | 12 +++++ core/src/main/java/fj/function/Try0.java | 37 ++++++++++++++ .../src/main/java/fj/function/TryEffect0.java | 50 +++++++++++++++++++ 6 files changed, 135 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/fj/F0.java b/core/src/main/java/fj/F0.java index c260992f..9354568c 100644 --- a/core/src/main/java/fj/F0.java +++ b/core/src/main/java/fj/F0.java @@ -1,5 +1,9 @@ package fj; +import fj.function.Effect0; +import fj.function.Try0; +import fj.function.TryEffect0; + import java.util.function.Supplier; /** @@ -14,4 +18,20 @@ default A get() { return f(); } + default Effect0 toEffect0() { + return () -> f(); + } + + default TryEffect0 toTryEffect0() { + return () -> f(); + } + + default Try0 toTry0() { + return () -> f(); + } + + default P1 toP1() { + return P.lazy(() -> f()); + } + } diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index 0643e886..eeef79f9 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -1,12 +1,16 @@ package fj.data; import fj.F0; +import fj.P; +import fj.P1; + +import java.io.IOException; /** * Created by MarkPerry on 3/07/2014. */ @FunctionalInterface -public interface SafeIO extends IO, F0 { +public interface SafeIO extends IO { @Override A run(); diff --git a/core/src/main/java/fj/function/Effect1.java b/core/src/main/java/fj/function/Effect1.java index 64abed44..aff85774 100644 --- a/core/src/main/java/fj/function/Effect1.java +++ b/core/src/main/java/fj/function/Effect1.java @@ -53,6 +53,15 @@ default F toF() { }; } + default TryEffect1 toTryEffect1() { + return a -> f(a); + } + + + default Try1 toTry1() { + return a -> toF().f(a); + } + static Effect1 fromF(F f) { return a -> f.f(a); } @@ -65,4 +74,6 @@ default P1 partial(final A a) { return P.lazy(() -> toF().f(a)); } + + } diff --git a/core/src/main/java/fj/function/Effect2.java b/core/src/main/java/fj/function/Effect2.java index 40d8abd8..e4d7701a 100644 --- a/core/src/main/java/fj/function/Effect2.java +++ b/core/src/main/java/fj/function/Effect2.java @@ -1,7 +1,12 @@ package fj.function; +import fj.F2; +import fj.Unit; + import java.util.function.BiConsumer; +import static fj.Unit.unit; + /** * Created by mperry on 28/08/2014. */ @@ -13,4 +18,11 @@ default void accept(A a, B b) { f(a, b); } + default F2 toF2() { + return (a, b) -> { + f(a, b); + return unit(); + }; + } + } diff --git a/core/src/main/java/fj/function/Try0.java b/core/src/main/java/fj/function/Try0.java index e218f0a7..9abfa6cd 100644 --- a/core/src/main/java/fj/function/Try0.java +++ b/core/src/main/java/fj/function/Try0.java @@ -1,5 +1,14 @@ package fj.function; +import fj.F0; +import fj.P; +import fj.P1; +import fj.data.Option; +import fj.data.Validation; + +import static fj.data.Validation.fail; +import static fj.data.Validation.success; + /** * A product of A which may throw an Exception. * @@ -13,4 +22,32 @@ public interface Try0 { A f() throws Z; + @SuppressWarnings("unchecked") + default F0> toF0() { + return () -> { + try { + return success(f()); + } catch (Exception e) { + return fail((Z) e); + } + }; + } + + default TryEffect0 toTryEffect0() { + return () -> f(); + } + + default Effect0 toEffect0() { + return () -> { + try { + f(); + } catch (Exception e) { + } + }; + } + + default P1> toP1() { + return P.lazy(() -> toF0().f()); + } + } diff --git a/core/src/main/java/fj/function/TryEffect0.java b/core/src/main/java/fj/function/TryEffect0.java index a6c9cbee..9a955c89 100644 --- a/core/src/main/java/fj/function/TryEffect0.java +++ b/core/src/main/java/fj/function/TryEffect0.java @@ -1,5 +1,15 @@ package fj.function; +import fj.F0; +import fj.P; +import fj.P1; +import fj.Unit; +import fj.data.Option; + +import static fj.Unit.unit; +import static fj.data.Option.none; +import static fj.data.Option.some; + /** * Created by mperry on 28/08/2014. */ @@ -7,4 +17,44 @@ public interface TryEffect0 { void f() throws Z; + @SuppressWarnings("unchecked") + default F0> toF0() { + return () -> { + try { + f(); + return none(); + } catch (Exception e) { + return some((Z) e); + } + }; + } + + @SuppressWarnings("unchecked") + default Try0 toTry0() { + return () -> { + try { + f(); + return unit(); + } catch (Exception e) { + throw ((Z) e); + } + }; + } + + default Effect0 toEffect0() { + return () -> { + try { + f(); + } catch (Exception e) { + } + }; + } + + default P1 toP1() { + return P.lazy(() -> { + toEffect0().f(); + return Unit.unit(); + }); + } + } From 19a70d92b43dfea29ae219a994230562d9375708 Mon Sep 17 00:00:00 2001 From: Chen Zhang <340355960@qq.com> Date: Tue, 17 Aug 2021 10:09:52 +0800 Subject: [PATCH 308/336] Improve Travis CI build Performance --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 8e7c52c9..89680bd8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ jdk: - openjdk-ea matrix: + fast_finish: true include: - jdk: openjdk12 @@ -31,3 +32,8 @@ env: global: - secure: Bun+1FZ29Q3dR9gZ/5brxcSf+zcY5tWrsqOA4GUb5bYCMyORuXQB0FYXuhKR4wB1pFrk1a9EYwRwSu3GwRJVWb+UzF0CNOWF/QG5tGPx32IOXScwlL/KonI4Vhs7Oc0fF4Wdb7euNrT27BU61jbUugjJ642b3n0VBYFYDdquprU= - secure: QAxhjqLRa+WHKIzgIJPZ/rM5a5uzqG7E5rsC0YvB25cO712oYXmzsYPia/oSp0chXlYLYMfk2UnLeQCSx2e6ogXRRRa977Q+B33Nt0Hd9SGLtduv6DBrbA2ehLU12Ib4DWe5VhF5eueAunycYcllTvqA5h+pzTtEVbd68ZHncM4= + +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ From da4cd6264e102c96d2c78eba56fa57af12655d08 Mon Sep 17 00:00:00 2001 From: YunLemon <340355960@qq.com> Date: Wed, 18 Aug 2021 08:23:20 +0800 Subject: [PATCH 309/336] Update .travis.yml --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 89680bd8..a7465305 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,6 @@ matrix: script: - ./gradlew clean test - env: global: - secure: Bun+1FZ29Q3dR9gZ/5brxcSf+zcY5tWrsqOA4GUb5bYCMyORuXQB0FYXuhKR4wB1pFrk1a9EYwRwSu3GwRJVWb+UzF0CNOWF/QG5tGPx32IOXScwlL/KonI4Vhs7Oc0fF4Wdb7euNrT27BU61jbUugjJ642b3n0VBYFYDdquprU= From 20f6248c8a7ac7a8e0cedece07aca6b6de4306e1 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Wed, 9 Feb 2022 22:28:28 +1000 Subject: [PATCH 310/336] Set the default to signing disabled as per the 5.x branch --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 07c2b60c..d4552a30 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = true +signingEnabled = false From 2387c3d3e8ff9c7899eda5e85365737477636edb Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 10 Feb 2022 20:34:40 +1000 Subject: [PATCH 311/336] Removed Java 9 options so the 5.x branch works with Java 8 --- build.gradle | 2 -- 1 file changed, 2 deletions(-) diff --git a/build.gradle b/build.gradle index 8e390f9c..81d2c1f1 100644 --- a/build.gradle +++ b/build.gradle @@ -107,7 +107,6 @@ subprojects { } tasks.withType(JavaCompile) { - options.compilerArgs.addAll(['--release', '8']) if (displayCompilerWarnings) { options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" } @@ -146,7 +145,6 @@ configure(subprojects.findAll { it.name != "props-core" }) { sourceCompatibility = "1.8" javadoc { - options.addBooleanOption('html5', true) } task javadocJar(type: Jar, dependsOn: "javadoc") { From baf69e9c359f8ee909b50fcddd0ed3b4eab438ce Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 10 Feb 2022 20:54:43 +1000 Subject: [PATCH 312/336] Template for version 5.0 release notes --- etc/release-notes/release-notes-5.0.adoc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 etc/release-notes/release-notes-5.0.adoc diff --git a/etc/release-notes/release-notes-5.0.adoc b/etc/release-notes/release-notes-5.0.adoc new file mode 100644 index 00000000..89138acd --- /dev/null +++ b/etc/release-notes/release-notes-5.0.adoc @@ -0,0 +1,22 @@ + += Release 5.0 + +Released: TODO + +== Enhancements + +== Fixes + + +== Internal + + +== Breaking Changes + + +== Documentation + + + +== Contributors + From ed841cd150b552d11234baecbbd87adf5db135ed Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 10 Feb 2022 23:26:45 +1000 Subject: [PATCH 313/336] Added FJ 5.0 doc release notes --- etc/release-notes/release-notes-5.0.adoc | 37 ++++++++++++++++++++---- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/etc/release-notes/release-notes-5.0.adoc b/etc/release-notes/release-notes-5.0.adoc index 89138acd..86cfc69e 100644 --- a/etc/release-notes/release-notes-5.0.adoc +++ b/etc/release-notes/release-notes-5.0.adoc @@ -4,19 +4,46 @@ Released: TODO == Enhancements +* The functions classes F, F2, F0, Effect1 and Effect2 extend the corresponding Java 8 function interface. Removed the corresponding classes F1W, F1Functions, F2W and F2Functions. Similarly for IO and IOW. +* Moved the function wrapper classes F1W and F2W into F and F2 as default functions. +* Added lifting a semigroup to an option monoid, using none as zero. +* Added Trampoline.suspend(F0>) +* Added sum, product and fromString to Longs. +* Added Bounded definition. +* Added toStream of Bounded in Enumerator. +* Added intersection monoid for sets. +* Added set intersection semigroup. +* Added FunctionalInterface annotations for interfaces F0, F, F2 to F8, IO and SafeIO. +* Added functions to IO. +* Added Either3. +* Updated IO and SafeIO inheritance. +* Added conversion functions for Effect, F, Try and TryEffect for low arities. == Fixes - +* Fixed BitSet properties test. == Internal - +* Upgraded to Gradle 6.8.3. +* Added Strategy, Validation, Integers, monoid, semigroup and monoid tests. +* Switch from the uptodate-gradle-plugin to gradle-versions-plugin. +* Speed up Gradle tests by running in parallel and not generating reports. == Breaking Changes - +* Removed Ord parameter from Monoid's setIntersectionMonoid function. +* Removed the classes F1W, F1Functions, F2W, F2Functions, F3W, F3Functions, F4W, F4Functions, F5W, F5Functions, F6W, F6Functions, F7W, F7Functions, F8W and F8Functions. +* Removed deprecated Monoid, Ord, P, P1, Semigroup, Array, HashMap, Java, List, Seq, Set, Stream, Gen, Rand and TreeMap functions. == Documentation - - +* Fixed the javadoc on Either's iif function. +* Fixed doc for union and intersection monoid for sets. +* Fixed semigroup docs. +* Fixed List.headOption. == Contributors +* Gabor Liptak +* Jean-Baptiste Giraudeau +* Soundharya Kamaraj +* Yaroslav Atroshenko +* Mark Perry +* Chen Zhang From f7a29a5be2df6dad22e4606a246e9b586d28f64b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 00:09:54 +1000 Subject: [PATCH 314/336] Removed build.number in the javadoc and created by Mark Perry --- build.gradle | 2 +- consume/src/test/java/fj/EmptyTest.java | 3 --- core/src/main/java/fj/Bottom.java | 2 -- core/src/main/java/fj/Class.java | 2 -- core/src/main/java/fj/Digit.java | 2 -- core/src/main/java/fj/Effect.java | 2 -- core/src/main/java/fj/Equal.java | 2 -- core/src/main/java/fj/F.java | 5 +---- core/src/main/java/fj/F0.java | 3 --- core/src/main/java/fj/F2.java | 3 --- core/src/main/java/fj/F3.java | 4 +--- core/src/main/java/fj/F4.java | 4 +--- core/src/main/java/fj/F5.java | 5 +---- core/src/main/java/fj/F6.java | 5 +---- core/src/main/java/fj/F7.java | 5 +---- core/src/main/java/fj/F8.java | 4 +--- core/src/main/java/fj/Function.java | 2 -- core/src/main/java/fj/Hash.java | 2 -- core/src/main/java/fj/LcgRng.java | 2 -- core/src/main/java/fj/Monoid.java | 2 -- core/src/main/java/fj/Ord.java | 2 -- core/src/main/java/fj/Ordering.java | 2 -- core/src/main/java/fj/P.java | 2 -- core/src/main/java/fj/P1.java | 10 +--------- core/src/main/java/fj/P2.java | 2 -- core/src/main/java/fj/P3.java | 2 -- core/src/main/java/fj/P4.java | 2 -- core/src/main/java/fj/P5.java | 2 -- core/src/main/java/fj/P6.java | 2 -- core/src/main/java/fj/P7.java | 2 -- core/src/main/java/fj/P8.java | 2 -- core/src/main/java/fj/Primitive.java | 2 -- core/src/main/java/fj/Rng.java | 3 --- core/src/main/java/fj/Semigroup.java | 2 -- core/src/main/java/fj/Show.java | 2 -- core/src/main/java/fj/Try.java | 3 --- core/src/main/java/fj/TryEffect.java | 3 --- core/src/main/java/fj/Unit.java | 2 -- core/src/main/java/fj/control/Trampoline.java | 2 +- core/src/main/java/fj/data/IO.java | 4 ---- core/src/main/java/fj/data/Iteratee.java | 3 --- core/src/main/java/fj/data/Java.java | 2 -- core/src/main/java/fj/data/Java8.java | 3 --- core/src/main/java/fj/data/List.java | 2 -- core/src/main/java/fj/data/NonEmptyList.java | 2 -- core/src/main/java/fj/data/Option.java | 2 -- core/src/main/java/fj/data/PriorityQueue.java | 2 -- core/src/main/java/fj/data/Reader.java | 1 - core/src/main/java/fj/data/SafeIO.java | 9 --------- core/src/main/java/fj/data/State.java | 3 --- core/src/main/java/fj/data/Stream.java | 2 -- core/src/main/java/fj/data/Tree.java | 2 -- core/src/main/java/fj/data/Validation.java | 2 -- core/src/main/java/fj/data/Writer.java | 3 --- core/src/main/java/fj/data/hamt/BitSet.java | 2 -- .../main/java/fj/data/hamt/HashArrayMappedTrie.java | 2 -- core/src/main/java/fj/data/hamt/Node.java | 2 -- core/src/main/java/fj/data/package-info.java | 2 -- core/src/main/java/fj/function/BigIntegers.java | 2 -- core/src/main/java/fj/function/Booleans.java | 2 -- core/src/main/java/fj/function/Doubles.java | 2 -- core/src/main/java/fj/function/Effect0.java | 3 --- core/src/main/java/fj/function/Effect1.java | 3 --- core/src/main/java/fj/function/Effect2.java | 3 --- core/src/main/java/fj/function/Effect3.java | 3 --- core/src/main/java/fj/function/Effect4.java | 3 --- core/src/main/java/fj/function/Effect5.java | 3 --- core/src/main/java/fj/function/Effect6.java | 3 --- core/src/main/java/fj/function/Effect7.java | 3 --- core/src/main/java/fj/function/Effect8.java | 3 --- core/src/main/java/fj/function/Integers.java | 2 -- core/src/main/java/fj/function/Longs.java | 2 -- core/src/main/java/fj/function/Strings.java | 2 -- core/src/main/java/fj/function/Try0.java | 1 - core/src/main/java/fj/function/Try1.java | 1 - core/src/main/java/fj/function/Try2.java | 1 - core/src/main/java/fj/function/Try3.java | 1 - core/src/main/java/fj/function/Try4.java | 1 - core/src/main/java/fj/function/Try5.java | 1 - core/src/main/java/fj/function/Try6.java | 1 - core/src/main/java/fj/function/Try7.java | 1 - core/src/main/java/fj/function/Try8.java | 1 - core/src/main/java/fj/function/TryEffect0.java | 3 --- core/src/main/java/fj/function/TryEffect1.java | 3 --- core/src/main/java/fj/function/TryEffect2.java | 3 --- core/src/main/java/fj/function/TryEffect3.java | 3 --- core/src/main/java/fj/function/TryEffect4.java | 3 --- core/src/main/java/fj/function/TryEffect5.java | 3 --- core/src/main/java/fj/function/TryEffect6.java | 3 --- core/src/main/java/fj/function/TryEffect7.java | 3 --- core/src/main/java/fj/function/TryEffect8.java | 3 --- core/src/main/java/fj/function/Visitor.java | 2 -- core/src/main/java/fj/function/package-info.java | 2 -- core/src/main/java/fj/package-info.java | 2 -- core/src/main/java/fj/parser/Parser.java | 2 -- core/src/main/java/fj/parser/Result.java | 2 -- core/src/main/java/fj/parser/package-info.java | 2 -- core/src/test/java/fj/P2Test.java | 3 --- core/src/test/java/fj/ShowTest.java | 3 --- core/src/test/java/fj/data/ArrayTest.java | 3 --- core/src/test/java/fj/data/BooleansTest.java | 3 --- core/src/test/java/fj/data/JavaTest.java | 3 --- core/src/test/java/fj/data/LazyStringTest.java | 3 --- core/src/test/java/fj/data/ListBufferTest.java | 3 --- core/src/test/java/fj/data/ListTest.java | 3 --- core/src/test/java/fj/data/List_Traverse_Tests.java | 3 --- core/src/test/java/fj/data/OptionTest.java | 3 --- core/src/test/java/fj/data/SeqTest.java | 3 --- core/src/test/java/fj/data/SetTest.java | 3 --- core/src/test/java/fj/data/StateTest.java | 3 --- core/src/test/java/fj/data/StreamTest.java | 3 --- core/src/test/java/fj/data/TreeMapTest.java | 3 --- core/src/test/java/fj/data/TreeTest.java | 6 +----- core/src/test/java/fj/data/UnitTest.java | 3 --- core/src/test/java/fj/function/TestEffect.java | 4 ---- demo/src/main/java/fj/demo/IODemo.java | 3 --- demo/src/main/java/fj/demo/StateDemo_Greeter.java | 3 --- .../main/java/fj/demo/StateDemo_VendingMachine.java | 3 --- demo/src/main/java/fj/demo/WriterDemo_Halver.java | 3 --- demo/src/main/java/fj/demo/optic/LensPerson.java | 3 --- demo/src/main/java/fj/demo/realworld/Chapter7.java | 2 -- demo/src/test/java/fj/EmptyTest.java | 3 --- java-core/src/main/java/fj/java/util/ListUtil.java | 3 --- java-core/src/test/java/fj/EmptyTest.java | 3 --- .../src/main/java/fj/data/dummy/DummyClass.java | 3 --- performance/src/test/java/fj/data/dummy/DummyTest.java | 3 --- props-core/src/test/java/fj/MemoisationTest.java | 3 --- props-core/src/test/java/fj/data/ReaderTest.java | 3 --- props-core/src/test/java/fj/data/TestRngState.java | 3 --- props-core/src/test/java/fj/data/WriterTest.java | 3 --- .../java/fj/data/fingertrees/FingerTreeProperties.java | 4 ---- .../test/java/fj/data/fingertrees/FingerTreeTest.java | 4 ---- .../src/test/java/fj/data/hamt/BitSetProperties.java | 4 ---- .../fj/data/properties/NonEmptyListProperties.java | 3 --- .../fj/data/properties/PriorityQueueProperties.java | 3 --- .../test/java/fj/data/properties/SetProperties.java | 3 --- .../java/fj/data/properties/TreeMapProperties.java | 3 --- .../java/fj/data/properties/ValidationProperties.java | 3 --- .../src/main/java/fj/data/test/PropertyAssert.java | 3 --- quickcheck/src/test/java/fj/data/test/TestNull.java | 3 --- quickcheck/src/test/java/fj/test/TestRand.java | 3 --- 141 files changed, 11 insertions(+), 374 deletions(-) diff --git a/build.gradle b/build.gradle index 81d2c1f1..1ceb4fb9 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ allprojects { snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.8.1" + fjConsumeVersion = "4.9" signModule = false diff --git a/consume/src/test/java/fj/EmptyTest.java b/consume/src/test/java/fj/EmptyTest.java index e112a97a..13675822 100644 --- a/consume/src/test/java/fj/EmptyTest.java +++ b/consume/src/test/java/fj/EmptyTest.java @@ -5,9 +5,6 @@ import org.junit.Assert; -/** - * Created by MarkPerry on 30/08/2015. - */ public class EmptyTest { @Ignore @Test diff --git a/core/src/main/java/fj/Bottom.java b/core/src/main/java/fj/Bottom.java index a70629f1..5cc7f4e4 100644 --- a/core/src/main/java/fj/Bottom.java +++ b/core/src/main/java/fj/Bottom.java @@ -2,8 +2,6 @@ /** * Represents the bottom _|_ value. - * - * @version %build.number% */ public final class Bottom { private Bottom() { diff --git a/core/src/main/java/fj/Class.java b/core/src/main/java/fj/Class.java index 56222de1..8bee1951 100644 --- a/core/src/main/java/fj/Class.java +++ b/core/src/main/java/fj/Class.java @@ -11,8 +11,6 @@ /** * A wrapper for a {@link java.lang.Class} that provides additional methods. - * - * @version %build.number% */ public final class Class { private final java.lang.Class c; diff --git a/core/src/main/java/fj/Digit.java b/core/src/main/java/fj/Digit.java index 7213e278..4fec7b0c 100644 --- a/core/src/main/java/fj/Digit.java +++ b/core/src/main/java/fj/Digit.java @@ -6,8 +6,6 @@ /** * The digits zero to nine. - * - * @version %build.number% */ public enum Digit { /** diff --git a/core/src/main/java/fj/Effect.java b/core/src/main/java/fj/Effect.java index 80680cac..2b5dcd6f 100644 --- a/core/src/main/java/fj/Effect.java +++ b/core/src/main/java/fj/Effect.java @@ -14,8 +14,6 @@ /** * Represents a side-effect. - * - * @version %build.number% */ public final class Effect { diff --git a/core/src/main/java/fj/Equal.java b/core/src/main/java/fj/Equal.java index 9179cc43..cba4a589 100644 --- a/core/src/main/java/fj/Equal.java +++ b/core/src/main/java/fj/Equal.java @@ -22,8 +22,6 @@ /** * Tests for equality between two objects. - * - * @version %build.number% */ public final class Equal { diff --git a/core/src/main/java/fj/F.java b/core/src/main/java/fj/F.java index 45cec4fe..1736f97b 100644 --- a/core/src/main/java/fj/F.java +++ b/core/src/main/java/fj/F.java @@ -16,10 +16,7 @@ import static fj.data.Zipper.fromStream; /** - * A transformation or function from A to B. This type can be represented - * using the Java 7 closure syntax. - * - * @version %build.number% + * A transformation or function from A to B. */ @FunctionalInterface public interface F extends Function { diff --git a/core/src/main/java/fj/F0.java b/core/src/main/java/fj/F0.java index 9354568c..88d60a9e 100644 --- a/core/src/main/java/fj/F0.java +++ b/core/src/main/java/fj/F0.java @@ -6,9 +6,6 @@ import java.util.function.Supplier; -/** - * Created by MarkPerry on 21/01/2015. - */ @FunctionalInterface public interface F0 extends Supplier { diff --git a/core/src/main/java/fj/F2.java b/core/src/main/java/fj/F2.java index 4f7c306d..8b1aac20 100644 --- a/core/src/main/java/fj/F2.java +++ b/core/src/main/java/fj/F2.java @@ -14,9 +14,6 @@ /** * A transformation function of arity-2 from A and B to C. - * This type can be represented using the Java 7 closure syntax. - * - * @version %build.number% */ @FunctionalInterface public interface F2 extends BiFunction { diff --git a/core/src/main/java/fj/F3.java b/core/src/main/java/fj/F3.java index b8c4dcf3..b7efeb3a 100644 --- a/core/src/main/java/fj/F3.java +++ b/core/src/main/java/fj/F3.java @@ -2,9 +2,7 @@ /** * A transformation function of arity-3 from A, B and C to - * D. This type can be represented using the Java 7 closure syntax. - * - * @version %build.number% + * D. */ @FunctionalInterface public interface F3 { diff --git a/core/src/main/java/fj/F4.java b/core/src/main/java/fj/F4.java index d63f03a7..c3c5f882 100644 --- a/core/src/main/java/fj/F4.java +++ b/core/src/main/java/fj/F4.java @@ -2,9 +2,7 @@ /** * A transformation function of arity-4 from A, B, C and - * D to E. This type can be represented using the Java 7 closure syntax. - * - * @version %build.number% + * D to E. */ @FunctionalInterface public interface F4 { diff --git a/core/src/main/java/fj/F5.java b/core/src/main/java/fj/F5.java index f63ae797..574afb15 100644 --- a/core/src/main/java/fj/F5.java +++ b/core/src/main/java/fj/F5.java @@ -2,10 +2,7 @@ /** * A transformation function of arity-5 from A, B, C, - * D and E to F$. This type can be represented using the Java - * 7 closure syntax. - * - * @version %build.number% + * D and E to F$. */ @FunctionalInterface public interface F5 { diff --git a/core/src/main/java/fj/F6.java b/core/src/main/java/fj/F6.java index 558c17fc..135e28fe 100644 --- a/core/src/main/java/fj/F6.java +++ b/core/src/main/java/fj/F6.java @@ -2,10 +2,7 @@ /** * A transformation function of arity-6 from A, B, C, - * D, E and F$ to G. This type can be - * represented using the Java 7 closure syntax. - * - * @version %build.number% + * D, E and F$ to G. */ @FunctionalInterface public interface F6 { diff --git a/core/src/main/java/fj/F7.java b/core/src/main/java/fj/F7.java index 05caefb4..a2542700 100644 --- a/core/src/main/java/fj/F7.java +++ b/core/src/main/java/fj/F7.java @@ -2,10 +2,7 @@ /** * A transformation function of arity-7 from A, B, C, - * D, E, F$ and G to H. This type - * can be represented using the Java 7 closure syntax. - * - * @version %build.number% + * D, E, F$ and G to H. */ @FunctionalInterface public interface F7 { diff --git a/core/src/main/java/fj/F8.java b/core/src/main/java/fj/F8.java index 5aa103f2..647fc14c 100644 --- a/core/src/main/java/fj/F8.java +++ b/core/src/main/java/fj/F8.java @@ -3,9 +3,7 @@ /** * A transformation function of arity-8 from A, B, C, * D, E, F$, G and H to - * I. This type can be represented using the Java 7 closure syntax. - * - * @version %build.number% + * I. */ @FunctionalInterface public interface F8 { diff --git a/core/src/main/java/fj/Function.java b/core/src/main/java/fj/Function.java index 995c179d..52819377 100644 --- a/core/src/main/java/fj/Function.java +++ b/core/src/main/java/fj/Function.java @@ -4,8 +4,6 @@ /** * Transformations on functions. - * - * @version %build.number% */ public final class Function { private Function() { diff --git a/core/src/main/java/fj/Hash.java b/core/src/main/java/fj/Hash.java index 703d96ee..241bcefb 100644 --- a/core/src/main/java/fj/Hash.java +++ b/core/src/main/java/fj/Hash.java @@ -17,8 +17,6 @@ /** * Produces a hash code for an object which should attempt uniqueness. - * - * @version %build.number% */ public final class Hash { private final F f; diff --git a/core/src/main/java/fj/LcgRng.java b/core/src/main/java/fj/LcgRng.java index 215b3572..cd918f5b 100644 --- a/core/src/main/java/fj/LcgRng.java +++ b/core/src/main/java/fj/LcgRng.java @@ -1,8 +1,6 @@ package fj; /** - * Created by MarkPerry on 7/07/2014. - * * https://en.wikipedia.org/wiki/Linear_congruential_generator */ public class LcgRng extends Rng { diff --git a/core/src/main/java/fj/Monoid.java b/core/src/main/java/fj/Monoid.java index bc09250d..bc05f33e 100644 --- a/core/src/main/java/fj/Monoid.java +++ b/core/src/main/java/fj/Monoid.java @@ -22,8 +22,6 @@ *

    1. Right Identity; forall x. sum(x, zero()) == x
    2. *
    3. Associativity; forall x y z. sum(sum(x, y), z) == sum(x, sum(y, z))
    4. * - * - * @version %build.number% */ public final class Monoid
      { diff --git a/core/src/main/java/fj/Ord.java b/core/src/main/java/fj/Ord.java index ae4d3fda..2bf90450 100644 --- a/core/src/main/java/fj/Ord.java +++ b/core/src/main/java/fj/Ord.java @@ -10,8 +10,6 @@ /** * Tests for ordering between two objects. - * - * @version %build.number% */ public final class Ord { diff --git a/core/src/main/java/fj/Ordering.java b/core/src/main/java/fj/Ordering.java index b22bcfcb..1828f69a 100644 --- a/core/src/main/java/fj/Ordering.java +++ b/core/src/main/java/fj/Ordering.java @@ -3,8 +3,6 @@ /** * The comparison of two instances of a type may have one of three orderings; less than, equal or * greater than. - * - * @version %build.number% */ public enum Ordering { /** diff --git a/core/src/main/java/fj/P.java b/core/src/main/java/fj/P.java index 587cdc9d..3e6efb74 100644 --- a/core/src/main/java/fj/P.java +++ b/core/src/main/java/fj/P.java @@ -4,8 +4,6 @@ /** * Functions across products. - * - * @version %build.number% */ public final class P { private P() { diff --git a/core/src/main/java/fj/P1.java b/core/src/main/java/fj/P1.java index 810e484d..5e575a4d 100644 --- a/core/src/main/java/fj/P1.java +++ b/core/src/main/java/fj/P1.java @@ -1,20 +1,12 @@ package fj; -import fj.data.Array; -import fj.data.Either; -import fj.data.List; -import fj.data.Option; -import fj.data.Stream; -import fj.data.Validation; +import fj.data.*; import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.lang.ref.WeakReference; import static fj.P.p; -import static fj.Unit.unit; -//import fj.data.*; - public abstract class P1 implements F0 { diff --git a/core/src/main/java/fj/P2.java b/core/src/main/java/fj/P2.java index 841b356e..b4979f03 100644 --- a/core/src/main/java/fj/P2.java +++ b/core/src/main/java/fj/P2.java @@ -9,8 +9,6 @@ /** * A product-2. - * - * @version %build.number% */ public abstract class P2 { /** diff --git a/core/src/main/java/fj/P3.java b/core/src/main/java/fj/P3.java index 6e08a0ba..fff39ed8 100644 --- a/core/src/main/java/fj/P3.java +++ b/core/src/main/java/fj/P3.java @@ -4,8 +4,6 @@ /** * A product-3. - * - * @version %build.number% */ public abstract class P3 { /** diff --git a/core/src/main/java/fj/P4.java b/core/src/main/java/fj/P4.java index 4fa2ef8c..d2dca64b 100644 --- a/core/src/main/java/fj/P4.java +++ b/core/src/main/java/fj/P4.java @@ -4,8 +4,6 @@ /** * A product-4. - * - * @version %build.number% */ public abstract class P4 { /** diff --git a/core/src/main/java/fj/P5.java b/core/src/main/java/fj/P5.java index fabc4227..07138cb3 100644 --- a/core/src/main/java/fj/P5.java +++ b/core/src/main/java/fj/P5.java @@ -4,8 +4,6 @@ /** * A product-5. - * - * @version %build.number% */ public abstract class P5 { /** diff --git a/core/src/main/java/fj/P6.java b/core/src/main/java/fj/P6.java index 670622c7..295b5427 100644 --- a/core/src/main/java/fj/P6.java +++ b/core/src/main/java/fj/P6.java @@ -4,8 +4,6 @@ /** * A product-6. - * - * @version %build.number% */ @SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P6 { diff --git a/core/src/main/java/fj/P7.java b/core/src/main/java/fj/P7.java index 6c9ac804..17161f5d 100644 --- a/core/src/main/java/fj/P7.java +++ b/core/src/main/java/fj/P7.java @@ -4,8 +4,6 @@ /** * A product-7. - * - * @version %build.number% */ @SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P7 { diff --git a/core/src/main/java/fj/P8.java b/core/src/main/java/fj/P8.java index f3902c5e..571d6a15 100644 --- a/core/src/main/java/fj/P8.java +++ b/core/src/main/java/fj/P8.java @@ -4,8 +4,6 @@ /** * A product-8. - * - * @version %build.number% */ @SuppressWarnings("UnnecessaryFullyQualifiedName") public abstract class P8 { diff --git a/core/src/main/java/fj/Primitive.java b/core/src/main/java/fj/Primitive.java index 2007c03c..6ded797e 100644 --- a/core/src/main/java/fj/Primitive.java +++ b/core/src/main/java/fj/Primitive.java @@ -2,8 +2,6 @@ /** * Functions that convert between Java primitive types. - * - * @version %build.number% */ public final class Primitive { private Primitive() { diff --git a/core/src/main/java/fj/Rng.java b/core/src/main/java/fj/Rng.java index 20b3358f..46c31b27 100644 --- a/core/src/main/java/fj/Rng.java +++ b/core/src/main/java/fj/Rng.java @@ -1,8 +1,5 @@ package fj; -/** - * Created by MarkPerry on 7/07/2014. - */ public abstract class Rng { public abstract P2 nextInt(); diff --git a/core/src/main/java/fj/Semigroup.java b/core/src/main/java/fj/Semigroup.java index 1d767385..cd31e1e3 100644 --- a/core/src/main/java/fj/Semigroup.java +++ b/core/src/main/java/fj/Semigroup.java @@ -23,8 +23,6 @@ *
        *
      • Associativity; forall x. forall y. forall z. sum(sum(x, y), z) == sum(x, sum(y, z))
      • *
      - * - * @version %build.number% */ public final class Semigroup
      { diff --git a/core/src/main/java/fj/Show.java b/core/src/main/java/fj/Show.java index bfb2e151..8a21a281 100644 --- a/core/src/main/java/fj/Show.java +++ b/core/src/main/java/fj/Show.java @@ -27,8 +27,6 @@ /** * Renders an object for display. - * - * @version %build.number% */ public final class Show { private final F> f; diff --git a/core/src/main/java/fj/Try.java b/core/src/main/java/fj/Try.java index d8a30130..8418a621 100644 --- a/core/src/main/java/fj/Try.java +++ b/core/src/main/java/fj/Try.java @@ -10,9 +10,6 @@ import static fj.data.Validation.fail; import static fj.data.Validation.success; -/** - * Created by mperry on 24/07/2014. - */ public final class Try { private Try() { diff --git a/core/src/main/java/fj/TryEffect.java b/core/src/main/java/fj/TryEffect.java index cd1f75ab..a240e638 100644 --- a/core/src/main/java/fj/TryEffect.java +++ b/core/src/main/java/fj/TryEffect.java @@ -3,9 +3,6 @@ import fj.data.Validation; import fj.function.*; -/** - * Created by mperry on 29/08/2014. - */ public final class TryEffect { private TryEffect(){} diff --git a/core/src/main/java/fj/Unit.java b/core/src/main/java/fj/Unit.java index c7471f21..76463ec1 100644 --- a/core/src/main/java/fj/Unit.java +++ b/core/src/main/java/fj/Unit.java @@ -2,8 +2,6 @@ /** * The unit type which has only one value. - * - * @version %build.number% */ public final class Unit { private static final Unit u = new Unit(); diff --git a/core/src/main/java/fj/control/Trampoline.java b/core/src/main/java/fj/control/Trampoline.java index e3b58e1c..5c787f04 100644 --- a/core/src/main/java/fj/control/Trampoline.java +++ b/core/src/main/java/fj/control/Trampoline.java @@ -9,7 +9,7 @@ /** * A Trampoline is a potentially branching computation that can be stepped through and executed in constant stack. - * It represent suspendable coroutines with subroutine calls, reified as a data structure. + * It represents suspendable coroutines with subroutine calls, reified as a data structure. */ public abstract class Trampoline { diff --git a/core/src/main/java/fj/data/IO.java b/core/src/main/java/fj/data/IO.java index e2a94a38..69434728 100644 --- a/core/src/main/java/fj/data/IO.java +++ b/core/src/main/java/fj/data/IO.java @@ -1,9 +1,5 @@ package fj.data; -/** - * Created by MarkPerry on 19/06/2014. - */ - import fj.F; import fj.Unit; import fj.function.Try0; diff --git a/core/src/main/java/fj/data/Iteratee.java b/core/src/main/java/fj/data/Iteratee.java index be68ed02..e6177068 100644 --- a/core/src/main/java/fj/data/Iteratee.java +++ b/core/src/main/java/fj/data/Iteratee.java @@ -7,9 +7,6 @@ import fj.P2; import fj.Unit; -/** - * - */ public final class Iteratee { /** The input to an iteratee. */ diff --git a/core/src/main/java/fj/data/Java.java b/core/src/main/java/fj/data/Java.java index 8691c09d..b3cb7e7f 100644 --- a/core/src/main/java/fj/data/Java.java +++ b/core/src/main/java/fj/data/Java.java @@ -35,8 +35,6 @@ /** * Functions that convert between types from the core Java API. - * - * @version %build.number% */ public final class Java { private Java() { diff --git a/core/src/main/java/fj/data/Java8.java b/core/src/main/java/fj/data/Java8.java index 46c5ca2a..184c01c5 100644 --- a/core/src/main/java/fj/data/Java8.java +++ b/core/src/main/java/fj/data/Java8.java @@ -19,9 +19,6 @@ import java.util.function.Supplier; import java.util.stream.StreamSupport; -/** - * Created by mperry on 3/06/2014. - */ public final class Java8 { private Java8() { diff --git a/core/src/main/java/fj/data/List.java b/core/src/main/java/fj/data/List.java index 9259900f..721ee9f1 100644 --- a/core/src/main/java/fj/data/List.java +++ b/core/src/main/java/fj/data/List.java @@ -28,8 +28,6 @@ /** * Provides an in-memory, immutable, singly linked list. - * - * @version %build.number% */ public abstract class List implements Iterable { private List() { diff --git a/core/src/main/java/fj/data/NonEmptyList.java b/core/src/main/java/fj/data/NonEmptyList.java index 34c8b957..96bf444a 100644 --- a/core/src/main/java/fj/data/NonEmptyList.java +++ b/core/src/main/java/fj/data/NonEmptyList.java @@ -14,8 +14,6 @@ /** * Provides an in-memory, immutable, singly linked list with total head and tail. - * - * @version %build.number% */ public final class NonEmptyList implements Iterable { /** diff --git a/core/src/main/java/fj/data/Option.java b/core/src/main/java/fj/data/Option.java index b6876c63..9831c48c 100644 --- a/core/src/main/java/fj/data/Option.java +++ b/core/src/main/java/fj/data/Option.java @@ -23,8 +23,6 @@ /** * An optional value that may be none (no value) or some (a value). This type is a replacement for * the use of null with better type checks. - * - * @version %build.number% */ public abstract class Option implements Iterable { private Option() { diff --git a/core/src/main/java/fj/data/PriorityQueue.java b/core/src/main/java/fj/data/PriorityQueue.java index 21f6ed6f..f685c36d 100644 --- a/core/src/main/java/fj/data/PriorityQueue.java +++ b/core/src/main/java/fj/data/PriorityQueue.java @@ -20,8 +20,6 @@ * annotated with type K, are combined using a monoid of K and both the * key and value are stored in the leaf. Priorities of the same value * are returned FIFO (first in, first out). - * - * Created by MarkPerry on 31 May 16. */ public final class PriorityQueue { diff --git a/core/src/main/java/fj/data/Reader.java b/core/src/main/java/fj/data/Reader.java index 9374e300..49010e31 100644 --- a/core/src/main/java/fj/data/Reader.java +++ b/core/src/main/java/fj/data/Reader.java @@ -4,7 +4,6 @@ /** * The Reader monad (also called the function monad, so equivalent to the idea of F). - * Created by MarkPerry on 7/07/2014. */ public class Reader { diff --git a/core/src/main/java/fj/data/SafeIO.java b/core/src/main/java/fj/data/SafeIO.java index eeef79f9..bcc16bf6 100644 --- a/core/src/main/java/fj/data/SafeIO.java +++ b/core/src/main/java/fj/data/SafeIO.java @@ -1,14 +1,5 @@ package fj.data; -import fj.F0; -import fj.P; -import fj.P1; - -import java.io.IOException; - -/** - * Created by MarkPerry on 3/07/2014. - */ @FunctionalInterface public interface SafeIO extends IO { diff --git a/core/src/main/java/fj/data/State.java b/core/src/main/java/fj/data/State.java index f0156b36..c5b638a3 100644 --- a/core/src/main/java/fj/data/State.java +++ b/core/src/main/java/fj/data/State.java @@ -9,9 +9,6 @@ import static fj.control.Trampoline.suspend; import static fj.data.List.cons; -/** - * Created by MarkPerry on 7/07/2014. - */ public final class State { public static State unit(F> runF) { diff --git a/core/src/main/java/fj/data/Stream.java b/core/src/main/java/fj/data/Stream.java index bcf87dcf..8afa36ee 100644 --- a/core/src/main/java/fj/data/Stream.java +++ b/core/src/main/java/fj/data/Stream.java @@ -40,8 +40,6 @@ /** * A lazy (not yet evaluated), immutable, singly linked list. - * - * @version %build.number% */ public abstract class Stream implements Iterable { private Stream() { diff --git a/core/src/main/java/fj/data/Tree.java b/core/src/main/java/fj/data/Tree.java index f430d6d2..3b12d506 100644 --- a/core/src/main/java/fj/data/Tree.java +++ b/core/src/main/java/fj/data/Tree.java @@ -10,8 +10,6 @@ /** * Provides a lazy, immutable, non-empty, multi-way tree (a rose tree). - * - * @version %build.number% */ public final class Tree implements Iterable { /** diff --git a/core/src/main/java/fj/data/Validation.java b/core/src/main/java/fj/data/Validation.java index 60d8d2b2..5c1985a4 100644 --- a/core/src/main/java/fj/data/Validation.java +++ b/core/src/main/java/fj/data/Validation.java @@ -17,8 +17,6 @@ * Isomorphic to {@link Either} but has renamed functions and represents failure on the left and success on the right. * This type also has accumulating functions that accept a {@link Semigroup} for binding computation while keeping error * values - * - * @version %build.number% */ public class Validation implements Iterable { private final Either e; diff --git a/core/src/main/java/fj/data/Writer.java b/core/src/main/java/fj/data/Writer.java index b6b4579b..ba2cded5 100644 --- a/core/src/main/java/fj/data/Writer.java +++ b/core/src/main/java/fj/data/Writer.java @@ -2,9 +2,6 @@ import fj.*; -/** - * Created by MarkPerry on 7/07/2014. - */ public final class Writer { private final A val; diff --git a/core/src/main/java/fj/data/hamt/BitSet.java b/core/src/main/java/fj/data/hamt/BitSet.java index d164642d..9efbab34 100644 --- a/core/src/main/java/fj/data/hamt/BitSet.java +++ b/core/src/main/java/fj/data/hamt/BitSet.java @@ -13,8 +13,6 @@ * For example, the BitSet("1011") represents the decimal number 11 and has * indices [3, 0] inclusive where the bit with the lowest value has the lowest * index and is the rightmost bit. - * - * Created by maperr on 31/05/2016. */ public final class BitSet { diff --git a/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java b/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java index f13ae90f..371f5435 100644 --- a/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java +++ b/core/src/main/java/fj/data/hamt/HashArrayMappedTrie.java @@ -22,8 +22,6 @@ * mapped trie. It is a refined version of the more general notion of * a hash tree. * - * @author Mark Perry - * * Based on "Ideal Hash Trees" by Phil Bagwell, available from * http://lampwww.epfl.ch/papers/idealhashtrees.pdf */ diff --git a/core/src/main/java/fj/data/hamt/Node.java b/core/src/main/java/fj/data/hamt/Node.java index f8a1ff40..af453925 100644 --- a/core/src/main/java/fj/data/hamt/Node.java +++ b/core/src/main/java/fj/data/hamt/Node.java @@ -10,8 +10,6 @@ /** * A Hash Array Mapped Trie node that is either a key-value pair or a * Hash Array Mapped Trie. - * - * Created by maperr on 31/05/2016. */ public final class Node { diff --git a/core/src/main/java/fj/data/package-info.java b/core/src/main/java/fj/data/package-info.java index 911ef492..ae9577a7 100644 --- a/core/src/main/java/fj/data/package-info.java +++ b/core/src/main/java/fj/data/package-info.java @@ -1,6 +1,4 @@ /** * Common algebraic data types. - * - * @version %build.number% */ package fj.data; diff --git a/core/src/main/java/fj/function/BigIntegers.java b/core/src/main/java/fj/function/BigIntegers.java index 30d07a10..ac6584fc 100644 --- a/core/src/main/java/fj/function/BigIntegers.java +++ b/core/src/main/java/fj/function/BigIntegers.java @@ -10,8 +10,6 @@ /** * Curried functions over Integers. - * - * @version %build.number% */ public final class BigIntegers { private BigIntegers() { diff --git a/core/src/main/java/fj/function/Booleans.java b/core/src/main/java/fj/function/Booleans.java index 6211e870..bef1b347 100644 --- a/core/src/main/java/fj/function/Booleans.java +++ b/core/src/main/java/fj/function/Booleans.java @@ -15,8 +15,6 @@ /** * Curried logical functions. - * - * @version %build.number% */ public final class Booleans { private Booleans() { diff --git a/core/src/main/java/fj/function/Doubles.java b/core/src/main/java/fj/function/Doubles.java index 6fe1b033..aefcbfdc 100644 --- a/core/src/main/java/fj/function/Doubles.java +++ b/core/src/main/java/fj/function/Doubles.java @@ -11,8 +11,6 @@ /** * Curried functions over Doubles. - * - * @version %build.number% */ public final class Doubles { private Doubles() { diff --git a/core/src/main/java/fj/function/Effect0.java b/core/src/main/java/fj/function/Effect0.java index 5e499d2d..7644d394 100644 --- a/core/src/main/java/fj/function/Effect0.java +++ b/core/src/main/java/fj/function/Effect0.java @@ -4,9 +4,6 @@ import static fj.Unit.unit; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect0 { void f(); diff --git a/core/src/main/java/fj/function/Effect1.java b/core/src/main/java/fj/function/Effect1.java index aff85774..1f3be909 100644 --- a/core/src/main/java/fj/function/Effect1.java +++ b/core/src/main/java/fj/function/Effect1.java @@ -9,9 +9,6 @@ import static fj.Unit.unit; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect1 extends Consumer { void f(A a); diff --git a/core/src/main/java/fj/function/Effect2.java b/core/src/main/java/fj/function/Effect2.java index e4d7701a..b9a5ad5a 100644 --- a/core/src/main/java/fj/function/Effect2.java +++ b/core/src/main/java/fj/function/Effect2.java @@ -7,9 +7,6 @@ import static fj.Unit.unit; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect2 extends BiConsumer { void f(A a, B b); diff --git a/core/src/main/java/fj/function/Effect3.java b/core/src/main/java/fj/function/Effect3.java index 0609584b..675d2301 100644 --- a/core/src/main/java/fj/function/Effect3.java +++ b/core/src/main/java/fj/function/Effect3.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect3 { void f(A a, B b, C c); diff --git a/core/src/main/java/fj/function/Effect4.java b/core/src/main/java/fj/function/Effect4.java index b24a7624..fdd20af8 100644 --- a/core/src/main/java/fj/function/Effect4.java +++ b/core/src/main/java/fj/function/Effect4.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect4 { void f(A a, B b, C c, D d); diff --git a/core/src/main/java/fj/function/Effect5.java b/core/src/main/java/fj/function/Effect5.java index 142be280..48634ac8 100644 --- a/core/src/main/java/fj/function/Effect5.java +++ b/core/src/main/java/fj/function/Effect5.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect5 { void f(A a, B b, C c, D d, E e); diff --git a/core/src/main/java/fj/function/Effect6.java b/core/src/main/java/fj/function/Effect6.java index fe72314b..f81cdf25 100644 --- a/core/src/main/java/fj/function/Effect6.java +++ b/core/src/main/java/fj/function/Effect6.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect6 { void f(A a, B b, C c, D d, E e, F f); diff --git a/core/src/main/java/fj/function/Effect7.java b/core/src/main/java/fj/function/Effect7.java index 944273af..4c77e4f4 100644 --- a/core/src/main/java/fj/function/Effect7.java +++ b/core/src/main/java/fj/function/Effect7.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect7 { void f(A a, B b, C c, D d, E e, F f, G g); diff --git a/core/src/main/java/fj/function/Effect8.java b/core/src/main/java/fj/function/Effect8.java index a8cfd3bb..d8b970ec 100644 --- a/core/src/main/java/fj/function/Effect8.java +++ b/core/src/main/java/fj/function/Effect8.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface Effect8 { void f(A a, B b, C c, D d, E e, F f, G g, H h); diff --git a/core/src/main/java/fj/function/Integers.java b/core/src/main/java/fj/function/Integers.java index 4b1b14b5..7f8fd0e8 100644 --- a/core/src/main/java/fj/function/Integers.java +++ b/core/src/main/java/fj/function/Integers.java @@ -16,8 +16,6 @@ /** * Curried functions over Integers. - * - * @version %build.number% */ public final class Integers { private Integers() { diff --git a/core/src/main/java/fj/function/Longs.java b/core/src/main/java/fj/function/Longs.java index 0989e8c0..2762f3e2 100644 --- a/core/src/main/java/fj/function/Longs.java +++ b/core/src/main/java/fj/function/Longs.java @@ -15,8 +15,6 @@ /** * Curried functions over Longs. - * - * @version %build.number% */ public final class Longs { private Longs() { diff --git a/core/src/main/java/fj/function/Strings.java b/core/src/main/java/fj/function/Strings.java index dadbfd22..1c239e85 100644 --- a/core/src/main/java/fj/function/Strings.java +++ b/core/src/main/java/fj/function/Strings.java @@ -12,8 +12,6 @@ /** * Curried string functions. - * - * @version %build.number% */ public final class Strings { private Strings() { diff --git a/core/src/main/java/fj/function/Try0.java b/core/src/main/java/fj/function/Try0.java index 9abfa6cd..7cdacfc1 100644 --- a/core/src/main/java/fj/function/Try0.java +++ b/core/src/main/java/fj/function/Try0.java @@ -15,7 +15,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to a P1. * * @see fj.Try#f(Try0) - * @version %build.number% */ public interface Try0 { diff --git a/core/src/main/java/fj/function/Try1.java b/core/src/main/java/fj/function/Try1.java index b626890b..53f5d048 100644 --- a/core/src/main/java/fj/function/Try1.java +++ b/core/src/main/java/fj/function/Try1.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F. * * @see fj.Try#f(Try1) - * @version %build.number% */ public interface Try1 { diff --git a/core/src/main/java/fj/function/Try2.java b/core/src/main/java/fj/function/Try2.java index 94438ccb..24e6a099 100644 --- a/core/src/main/java/fj/function/Try2.java +++ b/core/src/main/java/fj/function/Try2.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F2. * * @see fj.Try#f(Try2) - * @version %build.number% */ public interface Try2 { diff --git a/core/src/main/java/fj/function/Try3.java b/core/src/main/java/fj/function/Try3.java index 7464c013..7c0de0eb 100644 --- a/core/src/main/java/fj/function/Try3.java +++ b/core/src/main/java/fj/function/Try3.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F3. * * @see fj.Try#f(Try3) - * @version %build.number% */ public interface Try3 { diff --git a/core/src/main/java/fj/function/Try4.java b/core/src/main/java/fj/function/Try4.java index a7d969ed..d2b79d2c 100644 --- a/core/src/main/java/fj/function/Try4.java +++ b/core/src/main/java/fj/function/Try4.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F4. * * @see fj.Try#f(Try4) - * @version %build.number% */ public interface Try4 { diff --git a/core/src/main/java/fj/function/Try5.java b/core/src/main/java/fj/function/Try5.java index b9855fd7..cbc1a93d 100644 --- a/core/src/main/java/fj/function/Try5.java +++ b/core/src/main/java/fj/function/Try5.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F5. * * @see fj.Try#f(Try5) - * @version %build.number% */ public interface Try5 { diff --git a/core/src/main/java/fj/function/Try6.java b/core/src/main/java/fj/function/Try6.java index b66775c6..39bffbcb 100644 --- a/core/src/main/java/fj/function/Try6.java +++ b/core/src/main/java/fj/function/Try6.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F6. * * @see fj.Try#f(Try6) - * @version %build.number% */ public interface Try6 { diff --git a/core/src/main/java/fj/function/Try7.java b/core/src/main/java/fj/function/Try7.java index 3bc09cd9..ab56ffcd 100644 --- a/core/src/main/java/fj/function/Try7.java +++ b/core/src/main/java/fj/function/Try7.java @@ -7,7 +7,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F7. * * @see fj.Try#f(Try7) - * @version %build.number% */ public interface Try7 { diff --git a/core/src/main/java/fj/function/Try8.java b/core/src/main/java/fj/function/Try8.java index 5b2f1b55..1486de3c 100644 --- a/core/src/main/java/fj/function/Try8.java +++ b/core/src/main/java/fj/function/Try8.java @@ -6,7 +6,6 @@ * Used to instantiate a lambda that may throw an Exception before converting to an F8. * * @see fj.Try#f(Try8) - * @version %build.number% */ public interface Try8 { diff --git a/core/src/main/java/fj/function/TryEffect0.java b/core/src/main/java/fj/function/TryEffect0.java index 9a955c89..1ccaa9af 100644 --- a/core/src/main/java/fj/function/TryEffect0.java +++ b/core/src/main/java/fj/function/TryEffect0.java @@ -10,9 +10,6 @@ import static fj.data.Option.none; import static fj.data.Option.some; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect0 { void f() throws Z; diff --git a/core/src/main/java/fj/function/TryEffect1.java b/core/src/main/java/fj/function/TryEffect1.java index 40db423d..1ddaca08 100644 --- a/core/src/main/java/fj/function/TryEffect1.java +++ b/core/src/main/java/fj/function/TryEffect1.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect1 { void f(A a) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect2.java b/core/src/main/java/fj/function/TryEffect2.java index c9c13da9..c54f3fe7 100644 --- a/core/src/main/java/fj/function/TryEffect2.java +++ b/core/src/main/java/fj/function/TryEffect2.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect2 { void f(A a, B b) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect3.java b/core/src/main/java/fj/function/TryEffect3.java index c581221e..4c3f19d0 100644 --- a/core/src/main/java/fj/function/TryEffect3.java +++ b/core/src/main/java/fj/function/TryEffect3.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect3 { void f(A a, B b, C c) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect4.java b/core/src/main/java/fj/function/TryEffect4.java index f99900ca..8b04ed5f 100644 --- a/core/src/main/java/fj/function/TryEffect4.java +++ b/core/src/main/java/fj/function/TryEffect4.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect4 { void f(A a, B b, C c, D d) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect5.java b/core/src/main/java/fj/function/TryEffect5.java index d0445e3e..0bca874a 100644 --- a/core/src/main/java/fj/function/TryEffect5.java +++ b/core/src/main/java/fj/function/TryEffect5.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect5 { void f(A a, B b, C c, D d, E e) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect6.java b/core/src/main/java/fj/function/TryEffect6.java index b4d81a41..d8f1f468 100644 --- a/core/src/main/java/fj/function/TryEffect6.java +++ b/core/src/main/java/fj/function/TryEffect6.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect6 { void f(A a, B b, C c, D d, E e, F f) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect7.java b/core/src/main/java/fj/function/TryEffect7.java index 2e6004e9..133212dc 100644 --- a/core/src/main/java/fj/function/TryEffect7.java +++ b/core/src/main/java/fj/function/TryEffect7.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect7 { void f(A a, B b, C c, D d, E e, F f, G g) throws Z; diff --git a/core/src/main/java/fj/function/TryEffect8.java b/core/src/main/java/fj/function/TryEffect8.java index 4424bf00..d9c8c384 100644 --- a/core/src/main/java/fj/function/TryEffect8.java +++ b/core/src/main/java/fj/function/TryEffect8.java @@ -1,8 +1,5 @@ package fj.function; -/** - * Created by mperry on 28/08/2014. - */ public interface TryEffect8 { void f(A a, B b, C c, D d, E e, F f, G g, H h) throws Z; diff --git a/core/src/main/java/fj/function/Visitor.java b/core/src/main/java/fj/function/Visitor.java index bdca3b5e..ed0e7b53 100644 --- a/core/src/main/java/fj/function/Visitor.java +++ b/core/src/main/java/fj/function/Visitor.java @@ -15,8 +15,6 @@ /** * The essence of the visitor design pattern expressed polymorphically. - * - * @version %build.number% */ public final class Visitor { private Visitor() { diff --git a/core/src/main/java/fj/function/package-info.java b/core/src/main/java/fj/function/package-info.java index 6698bd5d..851bb534 100644 --- a/core/src/main/java/fj/function/package-info.java +++ b/core/src/main/java/fj/function/package-info.java @@ -1,6 +1,4 @@ /** * A prelude of commonly used first-class functions - * - * @version %build.number% */ package fj.function; diff --git a/core/src/main/java/fj/package-info.java b/core/src/main/java/fj/package-info.java index abeffe0f..c457d1e9 100644 --- a/core/src/main/java/fj/package-info.java +++ b/core/src/main/java/fj/package-info.java @@ -1,6 +1,4 @@ /** * Types that set the premise for the existence of Functional Java. - * - * @version %build.number% */ package fj; diff --git a/core/src/main/java/fj/parser/Parser.java b/core/src/main/java/fj/parser/Parser.java index 3ea6dd15..b5753f23 100644 --- a/core/src/main/java/fj/parser/Parser.java +++ b/core/src/main/java/fj/parser/Parser.java @@ -14,8 +14,6 @@ /** * A parser is a function that takes some input (I) and produces either an error (E) or a parse result (A) and the * remainder of the input. - * - * @version %build.number% */ public final class Parser { private final F>> f; diff --git a/core/src/main/java/fj/parser/Result.java b/core/src/main/java/fj/parser/Result.java index b8acc6c4..843dd558 100644 --- a/core/src/main/java/fj/parser/Result.java +++ b/core/src/main/java/fj/parser/Result.java @@ -12,8 +12,6 @@ /** * A parse result made up of a value (A) and the remainder of the parse input (I). - * - * @version %build.number% */ public final class Result implements Iterable { private final I i; diff --git a/core/src/main/java/fj/parser/package-info.java b/core/src/main/java/fj/parser/package-info.java index 08140f0b..8f31c204 100644 --- a/core/src/main/java/fj/parser/package-info.java +++ b/core/src/main/java/fj/parser/package-info.java @@ -1,6 +1,4 @@ /** * Parser combinators. - * - * @version %build.number% */ package fj.parser; diff --git a/core/src/test/java/fj/P2Test.java b/core/src/test/java/fj/P2Test.java index dc25a3e0..d14b6199 100644 --- a/core/src/test/java/fj/P2Test.java +++ b/core/src/test/java/fj/P2Test.java @@ -3,9 +3,6 @@ import org.junit.Assert; import org.junit.Test; -/** - * Created by MarkPerry on 22/07/2014. - */ public class P2Test { @Test diff --git a/core/src/test/java/fj/ShowTest.java b/core/src/test/java/fj/ShowTest.java index c516c0df..3d6d8354 100644 --- a/core/src/test/java/fj/ShowTest.java +++ b/core/src/test/java/fj/ShowTest.java @@ -6,9 +6,6 @@ import static fj.data.Array.array; import static org.junit.Assert.assertTrue; -/** - * Created by MarkPerry on 4/06/2015. - */ public class ShowTest { @Test public void arrayShow() { diff --git a/core/src/test/java/fj/data/ArrayTest.java b/core/src/test/java/fj/data/ArrayTest.java index 883fc835..5713e5c3 100644 --- a/core/src/test/java/fj/data/ArrayTest.java +++ b/core/src/test/java/fj/data/ArrayTest.java @@ -7,9 +7,6 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 14 Feb 16. - */ public class ArrayTest { @Test diff --git a/core/src/test/java/fj/data/BooleansTest.java b/core/src/test/java/fj/data/BooleansTest.java index b0d3f969..84f7676f 100644 --- a/core/src/test/java/fj/data/BooleansTest.java +++ b/core/src/test/java/fj/data/BooleansTest.java @@ -10,9 +10,6 @@ import static fj.function.Booleans.isnot; import static org.hamcrest.core.Is.is; -/** - * Created by amar on 28/01/15. - */ public class BooleansTest { @Test diff --git a/core/src/test/java/fj/data/JavaTest.java b/core/src/test/java/fj/data/JavaTest.java index 2a9b6bfd..b8d99510 100644 --- a/core/src/test/java/fj/data/JavaTest.java +++ b/core/src/test/java/fj/data/JavaTest.java @@ -9,9 +9,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -/** - * Created by MarkPerry on 14/07/2014. - */ public class JavaTest { @Test diff --git a/core/src/test/java/fj/data/LazyStringTest.java b/core/src/test/java/fj/data/LazyStringTest.java index 4f6325af..1adef2bd 100644 --- a/core/src/test/java/fj/data/LazyStringTest.java +++ b/core/src/test/java/fj/data/LazyStringTest.java @@ -6,9 +6,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 11/06/2015. - */ public class LazyStringTest { @Test diff --git a/core/src/test/java/fj/data/ListBufferTest.java b/core/src/test/java/fj/data/ListBufferTest.java index 1dfbbc39..f2ed8286 100644 --- a/core/src/test/java/fj/data/ListBufferTest.java +++ b/core/src/test/java/fj/data/ListBufferTest.java @@ -5,9 +5,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 17/08/2015. - */ public class ListBufferTest { @Test diff --git a/core/src/test/java/fj/data/ListTest.java b/core/src/test/java/fj/data/ListTest.java index ca7d0f22..9f09de0f 100644 --- a/core/src/test/java/fj/data/ListTest.java +++ b/core/src/test/java/fj/data/ListTest.java @@ -32,9 +32,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.*; -/** - * Created by MarkPerry on 16/01/2015. - */ public class ListTest { @Test diff --git a/core/src/test/java/fj/data/List_Traverse_Tests.java b/core/src/test/java/fj/data/List_Traverse_Tests.java index 3d964f45..5b7c0d19 100644 --- a/core/src/test/java/fj/data/List_Traverse_Tests.java +++ b/core/src/test/java/fj/data/List_Traverse_Tests.java @@ -9,9 +9,6 @@ import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -/** - * Created by amar on 28/12/14. - */ public class List_Traverse_Tests { @Test diff --git a/core/src/test/java/fj/data/OptionTest.java b/core/src/test/java/fj/data/OptionTest.java index 5a7bbdbf..e03d7aae 100644 --- a/core/src/test/java/fj/data/OptionTest.java +++ b/core/src/test/java/fj/data/OptionTest.java @@ -31,9 +31,6 @@ import static fj.data.Validation.*; import static org.junit.Assert.*; -/** - * Created by MarkPerry on 15/01/2015. - */ public final class OptionTest { @Test diff --git a/core/src/test/java/fj/data/SeqTest.java b/core/src/test/java/fj/data/SeqTest.java index 0b62db00..8a78ab31 100644 --- a/core/src/test/java/fj/data/SeqTest.java +++ b/core/src/test/java/fj/data/SeqTest.java @@ -33,9 +33,6 @@ import static org.hamcrest.core.Is.is; import static org.junit.Assert.*; -/** - * Created by MarkPerry on 16/01/2015. - */ public class SeqTest { @Test diff --git a/core/src/test/java/fj/data/SetTest.java b/core/src/test/java/fj/data/SetTest.java index cdf2519c..ae65b687 100644 --- a/core/src/test/java/fj/data/SetTest.java +++ b/core/src/test/java/fj/data/SetTest.java @@ -8,9 +8,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 18/08/2015. - */ public class SetTest { @Test diff --git a/core/src/test/java/fj/data/StateTest.java b/core/src/test/java/fj/data/StateTest.java index 37b21030..479efc38 100644 --- a/core/src/test/java/fj/data/StateTest.java +++ b/core/src/test/java/fj/data/StateTest.java @@ -5,9 +5,6 @@ import static fj.P.p; import static org.junit.Assert.assertEquals; -/** - * Created by MarkPerry on 18/12/2014. - */ public class StateTest { @Test diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index 313678aa..f320f27a 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -38,9 +38,6 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; -/** - * Created by Zheka Kozlov on 27.05.2015. - */ public class StreamTest { @Test diff --git a/core/src/test/java/fj/data/TreeMapTest.java b/core/src/test/java/fj/data/TreeMapTest.java index 96cb95b2..77352989 100644 --- a/core/src/test/java/fj/data/TreeMapTest.java +++ b/core/src/test/java/fj/data/TreeMapTest.java @@ -19,9 +19,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -/** - * Created by MarkPerry on 11/01/2015. - */ public class TreeMapTest { @Test diff --git a/core/src/test/java/fj/data/TreeTest.java b/core/src/test/java/fj/data/TreeTest.java index 811826fb..fd43c852 100644 --- a/core/src/test/java/fj/data/TreeTest.java +++ b/core/src/test/java/fj/data/TreeTest.java @@ -1,15 +1,11 @@ package fj.data; -import org.junit.Assert; import org.junit.Test; import static fj.data.Tree.leaf; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.*; +import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 29/08/2015. - */ public class TreeTest { @Test diff --git a/core/src/test/java/fj/data/UnitTest.java b/core/src/test/java/fj/data/UnitTest.java index eef15887..1fab0a7b 100644 --- a/core/src/test/java/fj/data/UnitTest.java +++ b/core/src/test/java/fj/data/UnitTest.java @@ -4,9 +4,6 @@ import org.junit.Assert; import org.junit.Test; -/** - * Created by MarkPerry on 17/01/2015. - */ public class UnitTest { @Test diff --git a/core/src/test/java/fj/function/TestEffect.java b/core/src/test/java/fj/function/TestEffect.java index 00da26f0..de2f5c5f 100644 --- a/core/src/test/java/fj/function/TestEffect.java +++ b/core/src/test/java/fj/function/TestEffect.java @@ -1,11 +1,7 @@ package fj.function; -import fj.F; import org.junit.Test; -/** - * Created by mperry on 28/08/2014. - */ public class TestEffect { @Test diff --git a/demo/src/main/java/fj/demo/IODemo.java b/demo/src/main/java/fj/demo/IODemo.java index ea313e77..aad8e41b 100644 --- a/demo/src/main/java/fj/demo/IODemo.java +++ b/demo/src/main/java/fj/demo/IODemo.java @@ -10,9 +10,6 @@ import static fj.data.LazyString.unlines_; import static java.lang.System.out; -/** - * Created by MarkPerry on 13/06/2015. - */ public class IODemo { public static void main(String[] args) { diff --git a/demo/src/main/java/fj/demo/StateDemo_Greeter.java b/demo/src/main/java/fj/demo/StateDemo_Greeter.java index 578f414e..707a1f9f 100644 --- a/demo/src/main/java/fj/demo/StateDemo_Greeter.java +++ b/demo/src/main/java/fj/demo/StateDemo_Greeter.java @@ -3,9 +3,6 @@ import fj.P; import fj.data.State; -/** - * Created by mperry on 4/08/2014. - */ public class StateDemo_Greeter { public static void main(String args[]) { diff --git a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java index ef1a09cd..75de4823 100644 --- a/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java +++ b/demo/src/main/java/fj/demo/StateDemo_VendingMachine.java @@ -6,9 +6,6 @@ import static fj.demo.StateDemo_VendingMachine.Input.COIN; import static fj.demo.StateDemo_VendingMachine.Input.TURN; -/** - * Created by MarkPerry on 20/07/2014. - */ public class StateDemo_VendingMachine { public enum Input { COIN, TURN } diff --git a/demo/src/main/java/fj/demo/WriterDemo_Halver.java b/demo/src/main/java/fj/demo/WriterDemo_Halver.java index 8473e588..9e6c6dac 100644 --- a/demo/src/main/java/fj/demo/WriterDemo_Halver.java +++ b/demo/src/main/java/fj/demo/WriterDemo_Halver.java @@ -6,9 +6,6 @@ import static fj.Monoid.stringMonoid; -/** - * Created by mperry on 4/08/2014. - */ public class WriterDemo_Halver { public static void main(String args[]) { diff --git a/demo/src/main/java/fj/demo/optic/LensPerson.java b/demo/src/main/java/fj/demo/optic/LensPerson.java index 51f5e103..641543e9 100644 --- a/demo/src/main/java/fj/demo/optic/LensPerson.java +++ b/demo/src/main/java/fj/demo/optic/LensPerson.java @@ -6,9 +6,6 @@ import static org.junit.Assert.assertTrue; -/** - * Created by MarkPerry on 23/06/2015. - */ public class LensPerson { static final class Person { diff --git a/demo/src/main/java/fj/demo/realworld/Chapter7.java b/demo/src/main/java/fj/demo/realworld/Chapter7.java index c239a5bf..bc414e4f 100644 --- a/demo/src/main/java/fj/demo/realworld/Chapter7.java +++ b/demo/src/main/java/fj/demo/realworld/Chapter7.java @@ -8,8 +8,6 @@ import static fj.data.IOFunctions.*; /** - * Created by MarkPerry on 11/06/2015. - * * Examples from Chapter 7 of Real World Haskell, http://book.realworldhaskell.org/. * * Currently just ch07/toupper-lazy4.hs. diff --git a/demo/src/test/java/fj/EmptyTest.java b/demo/src/test/java/fj/EmptyTest.java index e112a97a..13675822 100644 --- a/demo/src/test/java/fj/EmptyTest.java +++ b/demo/src/test/java/fj/EmptyTest.java @@ -5,9 +5,6 @@ import org.junit.Assert; -/** - * Created by MarkPerry on 30/08/2015. - */ public class EmptyTest { @Ignore @Test diff --git a/java-core/src/main/java/fj/java/util/ListUtil.java b/java-core/src/main/java/fj/java/util/ListUtil.java index 17fb5519..ffab7968 100644 --- a/java-core/src/main/java/fj/java/util/ListUtil.java +++ b/java-core/src/main/java/fj/java/util/ListUtil.java @@ -5,9 +5,6 @@ import java.util.List; -/** - * Created by MarkPerry on 28/08/2015. - */ public class ListUtil { public static List map(List list, F f) { diff --git a/java-core/src/test/java/fj/EmptyTest.java b/java-core/src/test/java/fj/EmptyTest.java index d1088c03..1c126bfa 100644 --- a/java-core/src/test/java/fj/EmptyTest.java +++ b/java-core/src/test/java/fj/EmptyTest.java @@ -4,9 +4,6 @@ import org.junit.Test; import org.junit.Assert; -/** - * Created by MarkPerry on 30/08/2015. - */ public class EmptyTest { @Ignore @Test diff --git a/performance/src/main/java/fj/data/dummy/DummyClass.java b/performance/src/main/java/fj/data/dummy/DummyClass.java index 72cc5c34..a94dcdde 100644 --- a/performance/src/main/java/fj/data/dummy/DummyClass.java +++ b/performance/src/main/java/fj/data/dummy/DummyClass.java @@ -1,8 +1,5 @@ package fj.data.dummy; -/** - * Created by MarkPerry on 5 Feb 16. - */ public class DummyClass { } diff --git a/performance/src/test/java/fj/data/dummy/DummyTest.java b/performance/src/test/java/fj/data/dummy/DummyTest.java index d3865433..49722bcd 100644 --- a/performance/src/test/java/fj/data/dummy/DummyTest.java +++ b/performance/src/test/java/fj/data/dummy/DummyTest.java @@ -3,9 +3,6 @@ import org.junit.Ignore; import org.junit.Test; -/** - * Created by MarkPerry on 5 Feb 16. - */ public class DummyTest { @Test diff --git a/props-core/src/test/java/fj/MemoisationTest.java b/props-core/src/test/java/fj/MemoisationTest.java index 865f76a3..605546ef 100644 --- a/props-core/src/test/java/fj/MemoisationTest.java +++ b/props-core/src/test/java/fj/MemoisationTest.java @@ -12,9 +12,6 @@ import static fj.test.Property.property; import static org.junit.Assert.assertTrue; -/** - * Created by mperry on 14/07/2014. - */ @RunWith(PropertyTestRunner.class) public class MemoisationTest { diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 044595d0..accc3394 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -13,9 +13,6 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; -/** - * Created by MarkPerry on 4/12/2014. - */ public class ReaderTest { @Test diff --git a/props-core/src/test/java/fj/data/TestRngState.java b/props-core/src/test/java/fj/data/TestRngState.java index 5f5f81bb..41143c17 100644 --- a/props-core/src/test/java/fj/data/TestRngState.java +++ b/props-core/src/test/java/fj/data/TestRngState.java @@ -17,9 +17,6 @@ import static fj.test.Property.property; import static fj.test.Variant.variant; -/** - * Created by mperry on 4/08/2014. - */ public class TestRngState { static List expected1 = List.list(4,4,2,2,2,5,3,3,1,5); diff --git a/props-core/src/test/java/fj/data/WriterTest.java b/props-core/src/test/java/fj/data/WriterTest.java index 25f99b22..50134da3 100644 --- a/props-core/src/test/java/fj/data/WriterTest.java +++ b/props-core/src/test/java/fj/data/WriterTest.java @@ -16,9 +16,6 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; -/** - * Created by MarkPerry on 17/12/2014. - */ public class WriterTest { @Test diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java index b7ed83f5..446716c2 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeProperties.java @@ -1,6 +1,5 @@ package fj.data.fingertrees; -import fj.P2; import fj.data.Stream; import fj.test.Property; import fj.test.reflect.CheckParams; @@ -12,9 +11,6 @@ import static fj.test.Property.prop; import static fj.test.Property.property; -/** - * Created by MarkPerry on 10/10/2015. - */ @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 10000) public class FingerTreeProperties { diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index b25fff51..a26fdc89 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -14,10 +14,6 @@ import static org.junit.Assert.assertThat; import static org.hamcrest.core.Is.is; - -/** - * Created by MarkPerry on 10/10/2015. - */ public class FingerTreeTest { public static final int SIZE = 10; diff --git a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java index 6c3f91a9..fbda987b 100644 --- a/props-core/src/test/java/fj/data/hamt/BitSetProperties.java +++ b/props-core/src/test/java/fj/data/hamt/BitSetProperties.java @@ -31,10 +31,6 @@ import static fj.test.Property.prop; import static fj.test.Property.property; -/** - * Created by maperr on 31/05/2016. - */ - @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 10000) public class BitSetProperties { diff --git a/props-core/src/test/java/fj/data/properties/NonEmptyListProperties.java b/props-core/src/test/java/fj/data/properties/NonEmptyListProperties.java index 256fb3a8..64ce1934 100644 --- a/props-core/src/test/java/fj/data/properties/NonEmptyListProperties.java +++ b/props-core/src/test/java/fj/data/properties/NonEmptyListProperties.java @@ -25,9 +25,6 @@ import static fj.test.Property.property; import static java.lang.Math.min; -/** - * Created by Zheka Kozlov on 02.06.2015. - */ @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 10000) public class NonEmptyListProperties { diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index 2bde7e6e..c2e46eca 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -26,9 +26,6 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertThat; -/** - * Created by MarkPerry on 18 Jun 16. - */ @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 100) public class PriorityQueueProperties { diff --git a/props-core/src/test/java/fj/data/properties/SetProperties.java b/props-core/src/test/java/fj/data/properties/SetProperties.java index 5349b650..2657b937 100644 --- a/props-core/src/test/java/fj/data/properties/SetProperties.java +++ b/props-core/src/test/java/fj/data/properties/SetProperties.java @@ -15,9 +15,6 @@ import static fj.test.Property.prop; import static fj.test.Property.property; -/** - * Created by MarkPerry on 18/08/2015. - */ @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 10000) public class SetProperties { diff --git a/props-core/src/test/java/fj/data/properties/TreeMapProperties.java b/props-core/src/test/java/fj/data/properties/TreeMapProperties.java index eb71749b..50b323ff 100644 --- a/props-core/src/test/java/fj/data/properties/TreeMapProperties.java +++ b/props-core/src/test/java/fj/data/properties/TreeMapProperties.java @@ -23,9 +23,6 @@ import static fj.test.Arbitrary.arbTreeMap; import static fj.test.Property.*; -/** - * Created by MarkPerry on 29/08/2015. - */ @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 10000) public class TreeMapProperties { diff --git a/props-core/src/test/java/fj/data/properties/ValidationProperties.java b/props-core/src/test/java/fj/data/properties/ValidationProperties.java index f5205d73..a47383ab 100644 --- a/props-core/src/test/java/fj/data/properties/ValidationProperties.java +++ b/props-core/src/test/java/fj/data/properties/ValidationProperties.java @@ -13,9 +13,6 @@ import static fj.test.Property.implies; import static fj.test.Property.prop; -/** - * Created by MarkPerry on 3/07/2015. - */ @RunWith(PropertyTestRunner.class) public class ValidationProperties { diff --git a/quickcheck/src/main/java/fj/data/test/PropertyAssert.java b/quickcheck/src/main/java/fj/data/test/PropertyAssert.java index 00187b15..d37c69a3 100644 --- a/quickcheck/src/main/java/fj/data/test/PropertyAssert.java +++ b/quickcheck/src/main/java/fj/data/test/PropertyAssert.java @@ -5,9 +5,6 @@ import fj.test.Property; import org.junit.Assert; -/** - * Created by MarkPerry on 18/12/2014. - */ public final class PropertyAssert { private PropertyAssert(){} diff --git a/quickcheck/src/test/java/fj/data/test/TestNull.java b/quickcheck/src/test/java/fj/data/test/TestNull.java index fe9dc843..0d547149 100644 --- a/quickcheck/src/test/java/fj/data/test/TestNull.java +++ b/quickcheck/src/test/java/fj/data/test/TestNull.java @@ -8,9 +8,6 @@ import static fj.test.Property.prop; import static fj.test.Property.property; -/** - * Created by MarkPerry on 3/07/2014. - */ public class TestNull { @Test diff --git a/quickcheck/src/test/java/fj/test/TestRand.java b/quickcheck/src/test/java/fj/test/TestRand.java index 1ca7c749..ea2cbce8 100644 --- a/quickcheck/src/test/java/fj/test/TestRand.java +++ b/quickcheck/src/test/java/fj/test/TestRand.java @@ -9,9 +9,6 @@ import static org.junit.Assert.assertTrue; -/** - * Created by MarkPerry on 4/06/2015. - */ public class TestRand { @Test From 8c8663a039959b07daf8c14c9a974dc5bf389960 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 18:50:17 +1000 Subject: [PATCH 315/336] Updated release process --- etc/release-process.txt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/etc/release-process.txt b/etc/release-process.txt index b22ec4e4..3bfb7bbd 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -45,12 +45,10 @@ Setup Artifact Signing ====================== The below text is a summary from https://gist.github.com/phit/bd3c6d156a2fa5f3b1bc15fa94b3256c. -As of 2021-02-12, for Windows download Gpg4win 3.1.15 at https://gpg4win.org/index.html. You need to provide 3 things: -- the public key id -- the path to the secret key ring file for your private key -- the passphrase for your private key +As of 2022-02-11, for Windows download Gpg4win 3.1.16 from https://files.gpg4win.org/. Open a command prompt and run "gpg --gen-key" and follow the prompts. + Get your key id by running: "gpg --list-key" Example output: @@ -68,9 +66,9 @@ sub rsa2048 2017-06-17 [E] [expires: 2019-06-17] In this case we only have one key, 77273D57FA5140E5A91905087A1B92B81840D019 or short* 1840D019 which is basically just the last 8 characters of the long ID. -Export the key using "gpg --export-secret-key > %UserProfile%\secring.gpg" +Export the key using "gpg --export-secret-key >%UserProfile%\secring.gpg" -In %UserProfile%\.gradle\gradle.properties, set the values below: +Create the file %UserProfile%\.gradle\gradle.properties, set the values below: signing.keyId=XXXXXXXX signing.password=mypassword @@ -90,6 +88,7 @@ sub rsa3072 2021-02-12 [E] [expires: 2023-02-12] C:\repos\functionaljava>gpg --keyserver hkp://keyserver.ubuntu.com --send-keys E86A4EC34F25A9CF6118582A7985AAE03F41B2F9 gpg: sending key 7985AAE03F41B2F9 to hkp://keyserver.ubuntu.com + gradle upload (takes about 3 mins) From 3eea643f16a7f98127f7818c900f25a5752c1781 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 20:56:10 +1000 Subject: [PATCH 316/336] Update release doc and Github readme --- README.adoc | 25 +++++++++++++------------ build.gradle | 1 - etc/release-process.txt | 10 ++++------ gradle.properties | 5 +++-- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/README.adoc b/README.adoc index cb53d003..d57b22b4 100644 --- a/README.adoc +++ b/README.adoc @@ -22,8 +22,9 @@ Important URLs for the project are: * Website, http://www.functionaljava.org * Website repository, http://github.com/functionaljava/functionaljava.github.io -* Travis continuous integration build, https://travis-ci.org/functionaljava/functionaljava -* Sonatype Repository, https://oss.sonatype.org/content/groups/public/org/functionaljava/ +* Travis continuous integration build, https://app.travis-ci.com/github/functionaljava/functionaljava +* Sonatype repository, https://oss.sonatype.org/content/groups/public/org/functionaljava/ +* Maven Central repository, https://mvnrepository.com/artifact/org.functionaljava/functionaljava == Downloading @@ -35,12 +36,12 @@ The Functional Java artifact is published to Maven Central using the group `org. * Java 8 specific support (`functionaljava-java8`) * property based testing (`functionaljava-quickcheck` or `functionaljava-quickcheck_1.8` if you use Java 8+) -The latest stable version is `4.8.1`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `4.9`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.8.1" -compile "org.functionaljava:functionaljava-java8:4.8.1" -compile "org.functionaljava:functionaljava-quickcheck:4.8.1" -compile "org.functionaljava:functionaljava-java-core:4.8.1" +compile "org.functionaljava:functionaljava:4.9" +compile "org.functionaljava:functionaljava-java8:4.9" +compile "org.functionaljava:functionaljava-quickcheck:4.9" +compile "org.functionaljava:functionaljava-java-core:4.9" ---- and in Maven: @@ -48,22 +49,22 @@ and in Maven: org.functionaljava functionaljava - 4.8.1 + 4.9 org.functionaljava functionaljava-java8 - 4.8.1 + 4.9 org.functionaljava functionaljava-quickcheck - 4.8.1 + 4.9 org.functionaljava functionaljava-java-core - 4.8.1 + 4.9 ---- @@ -71,7 +72,7 @@ and in Maven: FunctionalJava uses the Retro Lambda project to backport Java 8 lambdas to Java 6 bytecode. This requires access to both JDK 6 and 8. The build system requires the environment variables `JAVA6_HOME` and `JAVA8_HOME` to refer to the appropriate directories. -Building is done using Gradle 2.13. In the root directory run: +Building is done using Gradle 6.8.3. In the root directory run: ---- ./gradlew ---- diff --git a/build.gradle b/build.gradle index 1ceb4fb9..cc2e265c 100644 --- a/build.gradle +++ b/build.gradle @@ -41,7 +41,6 @@ allprojects { defaultTasks "build" ext { - isSnapshot = true fjBaseVersion = "5.0" snapshotAppendix = "-SNAPSHOT" diff --git a/etc/release-process.txt b/etc/release-process.txt index 3bfb7bbd..e4b35e2d 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -4,13 +4,11 @@ Current Release Process Go through the issues and pull requests and set the Label and Milestone field. Add information to /etc/release-notes/release-notes-.adoc. -Update build.gradle: -* set isSnapshot to false -* set useRetroLambda to true - Update gradle.properties: +* set isSnapshot to false * Set signingEnabled to true + Run the build command: gradlew clean build upload @@ -24,8 +22,8 @@ Login to Sonatype and verify the release: Commit changes Increase the version: -* Edit build.gradle: update isSnapshot to true, increase fjBaseVersion, update fjConsumeVersion, update useRetroLambda. -* Edit gradle.properties: set signingEnabled to false +* Edit build.gradle: increase fjBaseVersion, update fjConsumeVersion. +* Edit gradle.properties: set signingEnabled to false, set isSnapshot to true Commit changes and push. Notes that CI builds using Travis and Jenkins will fail with the release due to lack of configured signing. diff --git a/gradle.properties b/gradle.properties index 1f1f4ed9..1171b13a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,8 @@ +signingEnabled = false +isSnapshot = true + sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signingEnabled = false - org.gradle.parallel = true From ce361b4466565cd4b074c7a11937f804b470bcba Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 20:56:42 +1000 Subject: [PATCH 317/336] Re-added openjdk8 for FJ 5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a7465305..fa0798a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ sudo: false language: java jdk: - - openjdk10 + - openjdk8 - openjdk11 - openjdk-ea From ba209425860e146c95386e9de314698c71e8e3cf Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 21:05:36 +1000 Subject: [PATCH 318/336] Updated Travis CI link at the top of the readme --- README.adoc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.adoc b/README.adoc index d57b22b4..4ede16b7 100644 --- a/README.adoc +++ b/README.adoc @@ -1,6 +1,6 @@ = Functional Java -image:https://travis-ci.org/functionaljava/functionaljava.svg?branch=master["Build Status", link="https://travis-ci.org/functionaljava/functionaljava"] +image:https://travis-ci.org/functionaljava/functionaljava.svg?branch=master["Build Status", link="https://app.travis-ci.com/github/functionaljava/functionaljava"] image:https://codecov.io/gh/functionaljava/functionaljava/branch/master/graph/badge.svg["Code Coverage", link="https://codecov.io/gh/functionaljava/functionaljava"] image:https://badges.gitter.im/functionaljava/functionaljava.svg[link="https://gitter.im/functionaljava/functionaljava?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"] @@ -8,7 +8,7 @@ image::http://www.functionaljava.org/img/logo-600x144.png[] Functional Java is an open source library facilitating functional programming in Java. The library implements numerous basic and advanced programming abstractions that assist composition oriented development. Functional Java also serves as a platform for learning functional programming concepts by introducing these concepts using a familiar language. -The library is intended for use in production applications and is thoroughly tested using the technique of automated specification-based testing with ScalaCheck and Functional Java's quickcheck module. Functional Java is compiled with Java 8 targeting Java 7 bytecode. The use of lambdas within the project are backported with the Retro Lambda library, supporting Java versions 6 to 8. +The library is intended for use in production applications and is thoroughly tested using the technique of automated specification-based testing with ScalaCheck and Functional Java's quickcheck module. Functional Java is compiled with Java 8 targeting Java 7 bytecode. The use of lambdas within the project are back ported with the Retro Lambda library, supporting Java versions 6 to 8. Functional Java provides abstractions for the following types: From 80862115da1e0d065b95e394bd517851b314d821 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 21:47:41 +1000 Subject: [PATCH 319/336] Prep for 5.0 release --- build.gradle | 1 + gradle.properties | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index cc2e265c..1e7bf98c 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,7 @@ allprojects { defaultTasks "build" ext { + isSnapshot = false fjBaseVersion = "5.0" snapshotAppendix = "-SNAPSHOT" diff --git a/gradle.properties b/gradle.properties index 1171b13a..d18e6a6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,5 @@ -signingEnabled = false -isSnapshot = true +signingEnabled = true sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd From a4ff75ed351c2e0996399d2b059a76fa158317fc Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 11 Feb 2022 22:11:47 +1000 Subject: [PATCH 320/336] Prep for FJ 5.1 --- build.gradle | 4 ++-- gradle.properties | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/build.gradle b/build.gradle index 1e7bf98c..70485ec9 100644 --- a/build.gradle +++ b/build.gradle @@ -41,8 +41,8 @@ allprojects { defaultTasks "build" ext { - isSnapshot = false - fjBaseVersion = "5.0" + isSnapshot = true + fjBaseVersion = "5.1" snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") diff --git a/gradle.properties b/gradle.properties index d18e6a6f..50202eda 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -signingEnabled = true +signingEnabled = false sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd From 56a9a51594e1a4030ff27f4db345e7b736489c8d Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sun, 13 Feb 2022 23:14:27 +1000 Subject: [PATCH 321/336] Added signing parameters to the properties file --- gradle.properties | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gradle.properties b/gradle.properties index 50202eda..dde4512b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,8 @@ signingEnabled = false sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd +signing.keyId= +signing.password= +signing.secretKeyRingFile= + org.gradle.parallel = true From 3c254bb3b6840512f896bb3348e3e5401837929e Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 14 Feb 2022 20:46:29 +1000 Subject: [PATCH 322/336] Fix series/5.x build. Removed extra jdk's for series 5.x. --- .travis.yml | 11 ----------- gradle.properties | 6 +++--- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/.travis.yml b/.travis.yml index fa0798a4..bc3fc57f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,24 +5,13 @@ language: java jdk: - openjdk8 - - openjdk11 - - openjdk-ea matrix: fast_finish: true include: - - jdk: openjdk12 - script: - - ./gradlew build coverage -s -i - after_success: - - bash <(curl -s https://codecov.io/bash) - - '[ "$TRAVIS_BRANCH" = "series/5.x" -a "$TRAVIS_PULL_REQUEST" = "false" -a -z "$TRAVIS_TAG" ] - && ./gradlew uploadArchives' allow_failures: - - jdk: openjdk10 - - jdk: openjdk-ea script: - ./gradlew clean test diff --git a/gradle.properties b/gradle.properties index dde4512b..6ee9a768 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ signingEnabled = false sonatypeUsername = incorrectUser sonatypePassword = incorrectPwd -signing.keyId= -signing.password= -signing.secretKeyRingFile= +#signing.keyId= +#signing.password= +#signing.secretKeyRingFile= org.gradle.parallel = true From 474a49ca5b7760cd79243ca4b428ea7ddef0b72e Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 14 Feb 2022 22:18:36 +1000 Subject: [PATCH 323/336] Upgrade Junit to 4.13.2, fixed deprecations. Update gradle-versions-plugin, junit-vintage-engine --- build.gradle | 8 ++++---- core/src/test/java/fj/ClassTest.java | 2 +- core/src/test/java/fj/DigitTest.java | 2 +- core/src/test/java/fj/MonoidTest.java | 2 +- core/src/test/java/fj/TryTest.java | 2 +- core/src/test/java/fj/control/db/TestDbState.java | 2 +- core/src/test/java/fj/data/ArrayTest.java | 2 +- core/src/test/java/fj/data/DListTest.java | 2 +- core/src/test/java/fj/data/LazyStringTest.java | 2 +- core/src/test/java/fj/data/ListBufferTest.java | 2 +- core/src/test/java/fj/data/SetTest.java | 2 +- core/src/test/java/fj/data/StreamTest.java | 2 +- core/src/test/java/fj/data/TreeMapTest.java | 2 +- core/src/test/java/fj/data/TreeTest.java | 2 +- core/src/test/java/fj/data/TreeZipperTest.java | 2 +- core/src/test/java/fj/data/ValidationTest.java | 2 +- core/src/test/java/fj/data/ZipperTest.java | 2 +- core/src/test/java/fj/data/hamt/HamtTest.java | 2 +- core/src/test/java/fj/data/optic/IsoTest.java | 2 +- core/src/test/java/fj/data/optic/LensTest.java | 2 +- core/src/test/java/fj/data/optic/OptionalTest.java | 2 +- core/src/test/java/fj/data/optic/PrismTest.java | 2 +- core/src/test/java/fj/data/optic/TraversalTest.java | 2 +- core/src/test/java/fj/data/vector/VTest.java | 2 +- core/src/test/java/fj/function/VisitorTest.java | 2 +- props-core/src/test/java/fj/data/ReaderTest.java | 2 +- .../src/test/java/fj/data/fingertrees/FingerTreeTest.java | 3 +-- .../java/fj/data/properties/PriorityQueueProperties.java | 2 +- 28 files changed, 31 insertions(+), 32 deletions(-) diff --git a/build.gradle b/build.gradle index 70485ec9..93dafa67 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath "com.github.ben-manes:gradle-versions-plugin:0.27.0" + classpath "com.github.ben-manes:gradle-versions-plugin:0.36.0" classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:5.3.0" } @@ -46,7 +46,7 @@ allprojects { snapshotAppendix = "-SNAPSHOT" fjVersion = fjBaseVersion + (isSnapshot ? snapshotAppendix : "") - fjConsumeVersion = "4.9" + fjConsumeVersion = "5.0" signModule = false @@ -66,8 +66,8 @@ allprojects { sonatypeUploadUrl = isSnapshot ? sonatypeSnapshotUrl : sonatypeReleaseUrl primaryEmail = "functionaljava@googlegroups.com" - junitCompile = "junit:junit:4.12" - junitRuntime = "org.junit.vintage:junit-vintage-engine:5.5.2" + junitCompile = "junit:junit:4.13.2" + junitRuntime = "org.junit.vintage:junit-vintage-engine:5.8.2" displayCompilerWarnings = true generateTestReports = false diff --git a/core/src/test/java/fj/ClassTest.java b/core/src/test/java/fj/ClassTest.java index 2959e351..dfbc7f00 100644 --- a/core/src/test/java/fj/ClassTest.java +++ b/core/src/test/java/fj/ClassTest.java @@ -11,7 +11,7 @@ import java.util.Iterator; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ClassTest { @Test diff --git a/core/src/test/java/fj/DigitTest.java b/core/src/test/java/fj/DigitTest.java index 9fc98d4c..13169aca 100644 --- a/core/src/test/java/fj/DigitTest.java +++ b/core/src/test/java/fj/DigitTest.java @@ -5,7 +5,7 @@ import static fj.data.Array.range; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class DigitTest { @Test diff --git a/core/src/test/java/fj/MonoidTest.java b/core/src/test/java/fj/MonoidTest.java index 1156e729..68457f09 100644 --- a/core/src/test/java/fj/MonoidTest.java +++ b/core/src/test/java/fj/MonoidTest.java @@ -8,7 +8,7 @@ import static fj.data.Option.some; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class MonoidTest { diff --git a/core/src/test/java/fj/TryTest.java b/core/src/test/java/fj/TryTest.java index bd94e986..46fb2dd3 100644 --- a/core/src/test/java/fj/TryTest.java +++ b/core/src/test/java/fj/TryTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TryTest { diff --git a/core/src/test/java/fj/control/db/TestDbState.java b/core/src/test/java/fj/control/db/TestDbState.java index 188eae3d..2a942e1a 100644 --- a/core/src/test/java/fj/control/db/TestDbState.java +++ b/core/src/test/java/fj/control/db/TestDbState.java @@ -9,7 +9,7 @@ import java.sql.*; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TestDbState { @Test diff --git a/core/src/test/java/fj/data/ArrayTest.java b/core/src/test/java/fj/data/ArrayTest.java index 5713e5c3..e686a02b 100644 --- a/core/src/test/java/fj/data/ArrayTest.java +++ b/core/src/test/java/fj/data/ArrayTest.java @@ -5,7 +5,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.instanceOf; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ArrayTest { diff --git a/core/src/test/java/fj/data/DListTest.java b/core/src/test/java/fj/data/DListTest.java index 6846ca2d..48c0c2fe 100644 --- a/core/src/test/java/fj/data/DListTest.java +++ b/core/src/test/java/fj/data/DListTest.java @@ -4,7 +4,7 @@ import static fj.data.DList.*; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class DListTest { @Test diff --git a/core/src/test/java/fj/data/LazyStringTest.java b/core/src/test/java/fj/data/LazyStringTest.java index 1adef2bd..14a88c14 100644 --- a/core/src/test/java/fj/data/LazyStringTest.java +++ b/core/src/test/java/fj/data/LazyStringTest.java @@ -4,7 +4,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class LazyStringTest { diff --git a/core/src/test/java/fj/data/ListBufferTest.java b/core/src/test/java/fj/data/ListBufferTest.java index f2ed8286..6b16f1ca 100644 --- a/core/src/test/java/fj/data/ListBufferTest.java +++ b/core/src/test/java/fj/data/ListBufferTest.java @@ -3,7 +3,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ListBufferTest { diff --git a/core/src/test/java/fj/data/SetTest.java b/core/src/test/java/fj/data/SetTest.java index ae65b687..e30d166a 100644 --- a/core/src/test/java/fj/data/SetTest.java +++ b/core/src/test/java/fj/data/SetTest.java @@ -6,7 +6,7 @@ import static fj.data.Option.some; import static fj.Ord.intOrd; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class SetTest { diff --git a/core/src/test/java/fj/data/StreamTest.java b/core/src/test/java/fj/data/StreamTest.java index f320f27a..febd4567 100644 --- a/core/src/test/java/fj/data/StreamTest.java +++ b/core/src/test/java/fj/data/StreamTest.java @@ -36,7 +36,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class StreamTest { diff --git a/core/src/test/java/fj/data/TreeMapTest.java b/core/src/test/java/fj/data/TreeMapTest.java index 77352989..051f0773 100644 --- a/core/src/test/java/fj/data/TreeMapTest.java +++ b/core/src/test/java/fj/data/TreeMapTest.java @@ -16,7 +16,7 @@ import static fj.data.TreeMap.iterableTreeMap; import static org.hamcrest.CoreMatchers.equalTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; public class TreeMapTest { diff --git a/core/src/test/java/fj/data/TreeTest.java b/core/src/test/java/fj/data/TreeTest.java index fd43c852..a6028f37 100644 --- a/core/src/test/java/fj/data/TreeTest.java +++ b/core/src/test/java/fj/data/TreeTest.java @@ -4,7 +4,7 @@ import static fj.data.Tree.leaf; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TreeTest { diff --git a/core/src/test/java/fj/data/TreeZipperTest.java b/core/src/test/java/fj/data/TreeZipperTest.java index c52f4111..c2549963 100644 --- a/core/src/test/java/fj/data/TreeZipperTest.java +++ b/core/src/test/java/fj/data/TreeZipperTest.java @@ -4,7 +4,7 @@ import static fj.data.Option.none; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TreeZipperTest { @Test diff --git a/core/src/test/java/fj/data/ValidationTest.java b/core/src/test/java/fj/data/ValidationTest.java index 37a51bcc..4505499c 100644 --- a/core/src/test/java/fj/data/ValidationTest.java +++ b/core/src/test/java/fj/data/ValidationTest.java @@ -37,7 +37,7 @@ import static fj.data.Validation.*; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ValidationTest { diff --git a/core/src/test/java/fj/data/ZipperTest.java b/core/src/test/java/fj/data/ZipperTest.java index 51c7b4ea..78d837aa 100644 --- a/core/src/test/java/fj/data/ZipperTest.java +++ b/core/src/test/java/fj/data/ZipperTest.java @@ -3,7 +3,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class ZipperTest { @Test diff --git a/core/src/test/java/fj/data/hamt/HamtTest.java b/core/src/test/java/fj/data/hamt/HamtTest.java index 1e601f24..19a22411 100644 --- a/core/src/test/java/fj/data/hamt/HamtTest.java +++ b/core/src/test/java/fj/data/hamt/HamtTest.java @@ -12,7 +12,7 @@ import static fj.P.p; import static fj.data.List.list; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; /** * @author Mark Perry diff --git a/core/src/test/java/fj/data/optic/IsoTest.java b/core/src/test/java/fj/data/optic/IsoTest.java index 6cace533..7aace4d8 100644 --- a/core/src/test/java/fj/data/optic/IsoTest.java +++ b/core/src/test/java/fj/data/optic/IsoTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class IsoTest { @Test diff --git a/core/src/test/java/fj/data/optic/LensTest.java b/core/src/test/java/fj/data/optic/LensTest.java index d78fa0d0..60513651 100644 --- a/core/src/test/java/fj/data/optic/LensTest.java +++ b/core/src/test/java/fj/data/optic/LensTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class LensTest { @Test diff --git a/core/src/test/java/fj/data/optic/OptionalTest.java b/core/src/test/java/fj/data/optic/OptionalTest.java index 07c3f79a..5bea2864 100644 --- a/core/src/test/java/fj/data/optic/OptionalTest.java +++ b/core/src/test/java/fj/data/optic/OptionalTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class OptionalTest { @Test diff --git a/core/src/test/java/fj/data/optic/PrismTest.java b/core/src/test/java/fj/data/optic/PrismTest.java index da128d72..ce6dddb4 100644 --- a/core/src/test/java/fj/data/optic/PrismTest.java +++ b/core/src/test/java/fj/data/optic/PrismTest.java @@ -4,7 +4,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class PrismTest { @Test diff --git a/core/src/test/java/fj/data/optic/TraversalTest.java b/core/src/test/java/fj/data/optic/TraversalTest.java index cadd6ccf..9cfc25cc 100644 --- a/core/src/test/java/fj/data/optic/TraversalTest.java +++ b/core/src/test/java/fj/data/optic/TraversalTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class TraversalTest { @Test diff --git a/core/src/test/java/fj/data/vector/VTest.java b/core/src/test/java/fj/data/vector/VTest.java index 9a3709ac..8dabd66e 100644 --- a/core/src/test/java/fj/data/vector/VTest.java +++ b/core/src/test/java/fj/data/vector/VTest.java @@ -5,7 +5,7 @@ import org.junit.Test; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class VTest { @Test diff --git a/core/src/test/java/fj/function/VisitorTest.java b/core/src/test/java/fj/function/VisitorTest.java index 54efcf24..da92a4bb 100644 --- a/core/src/test/java/fj/function/VisitorTest.java +++ b/core/src/test/java/fj/function/VisitorTest.java @@ -11,7 +11,7 @@ import static fj.data.Option.some; import static fj.function.Visitor.*; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class VisitorTest { @Test diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index accc3394..4817e41c 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -10,7 +10,7 @@ import static fj.test.Property.prop; import static fj.test.Property.property; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; public class ReaderTest { diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index a26fdc89..7f02288c 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -8,10 +8,9 @@ import org.junit.Test; import static fj.Monoid.intAdditionMonoid; -import static fj.Monoid.intMinMonoid; import static fj.data.fingertrees.FingerTree.measured; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; public class FingerTreeTest { diff --git a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java index c2e46eca..5460bfdf 100644 --- a/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java +++ b/props-core/src/test/java/fj/data/properties/PriorityQueueProperties.java @@ -24,7 +24,7 @@ import static fj.test.Property.prop; import static fj.test.Property.property; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; @RunWith(PropertyTestRunner.class) @CheckParams(maxSize = 100) From c4ebbb541a40bcbf8a17e6ef1f1cae7a3a463ff4 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 14 Feb 2022 22:22:45 +1000 Subject: [PATCH 324/336] Updated bnd to 6.1.0 --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 93dafa67..3b627e85 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { dependencies { classpath "com.github.ben-manes:gradle-versions-plugin:0.36.0" - classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:5.3.0" + classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0" } wrapper { From df6e6f8ea2fee836794c365f93fc8839388fd02b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 14 Feb 2022 22:49:54 +1000 Subject: [PATCH 325/336] Updated H2 lib to 2.1.210. Updated deprecated Assert.assertThat to MatcherAssert.assertThat --- core/build.gradle | 2 +- core/src/test/java/fj/FFunctionsTest.java | 2 +- core/src/test/java/fj/OrderingTest.java | 2 +- core/src/test/java/fj/PTest.java | 2 +- core/src/test/java/fj/TryEffectTest.java | 2 +- .../test/java/fj/control/parallel/StrategyTest.java | 3 ++- core/src/test/java/fj/data/BooleansTest.java | 3 ++- core/src/test/java/fj/data/IOFunctionsTest.java | 11 ++++++----- core/src/test/java/fj/data/ListTest.java | 5 ++++- core/src/test/java/fj/data/List_Traverse_Tests.java | 2 +- core/src/test/java/fj/function/DoublesTest.java | 5 ++++- core/src/test/java/fj/function/IntegersTest.java | 5 ++++- core/src/test/java/fj/function/LongsTest.java | 5 ++++- core/src/test/java/fj/function/StringsTest.java | 2 +- core/src/test/java/fj/parser/ParserTest.java | 2 +- 15 files changed, 34 insertions(+), 19 deletions(-) diff --git a/core/build.gradle b/core/build.gradle index cbdad60b..9ee293a9 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -8,7 +8,7 @@ archivesBaseName = project.projectName dependencies { testCompile junitCompile testRuntime junitRuntime - testCompile 'com.h2database:h2:1.4.199' + testCompile 'com.h2database:h2:2.1.210' testCompile 'commons-dbutils:commons-dbutils:1.7' } diff --git a/core/src/test/java/fj/FFunctionsTest.java b/core/src/test/java/fj/FFunctionsTest.java index b235ff67..4f01a0db 100644 --- a/core/src/test/java/fj/FFunctionsTest.java +++ b/core/src/test/java/fj/FFunctionsTest.java @@ -4,7 +4,7 @@ import fj.data.TreeZipper; import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; public class FFunctionsTest { diff --git a/core/src/test/java/fj/OrderingTest.java b/core/src/test/java/fj/OrderingTest.java index 9b980e67..640bc1d3 100644 --- a/core/src/test/java/fj/OrderingTest.java +++ b/core/src/test/java/fj/OrderingTest.java @@ -8,7 +8,7 @@ import static fj.Ordering.GT; import static fj.Ordering.LT; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; public class OrderingTest { diff --git a/core/src/test/java/fj/PTest.java b/core/src/test/java/fj/PTest.java index 2a97303f..00220f9d 100644 --- a/core/src/test/java/fj/PTest.java +++ b/core/src/test/java/fj/PTest.java @@ -4,7 +4,7 @@ import static fj.Function.identity; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class PTest { @Test diff --git a/core/src/test/java/fj/TryEffectTest.java b/core/src/test/java/fj/TryEffectTest.java index ea92b8f2..6fd46fd1 100644 --- a/core/src/test/java/fj/TryEffectTest.java +++ b/core/src/test/java/fj/TryEffectTest.java @@ -5,7 +5,7 @@ import fj.function.TryEffect1; import org.junit.Test; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; public class TryEffectTest { diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java index 0c605829..b4d21320 100644 --- a/core/src/test/java/fj/control/parallel/StrategyTest.java +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -16,7 +16,8 @@ import static fj.control.parallel.Strategy.*; import static fj.data.Stream.range; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; + public class StrategyTest { diff --git a/core/src/test/java/fj/data/BooleansTest.java b/core/src/test/java/fj/data/BooleansTest.java index 84f7676f..61325df0 100644 --- a/core/src/test/java/fj/data/BooleansTest.java +++ b/core/src/test/java/fj/data/BooleansTest.java @@ -9,6 +9,7 @@ import static fj.data.List.list; import static fj.function.Booleans.isnot; import static org.hamcrest.core.Is.is; +import static org.hamcrest.MatcherAssert.assertThat; public class BooleansTest { @@ -70,7 +71,7 @@ public void testIsNot(){ F f1 = a -> a == 4; List result = list("some", "come", "done!").filter(isnot(String::length, f1)); - Assert.assertThat(result.length(), is(1)); + assertThat(result.length(), is(1)); Assert.assertEquals(result, list("done!")); } diff --git a/core/src/test/java/fj/data/IOFunctionsTest.java b/core/src/test/java/fj/data/IOFunctionsTest.java index adad0d11..8ae18b1a 100644 --- a/core/src/test/java/fj/data/IOFunctionsTest.java +++ b/core/src/test/java/fj/data/IOFunctionsTest.java @@ -12,7 +12,8 @@ import static fj.data.Stream.cons; import static fj.data.Stream.nil_; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; public class IOFunctionsTest { @@ -33,8 +34,8 @@ public void close() { r -> () -> new BufferedReader(r).readLine() ); - Assert.assertThat(bracketed.run(), is("Read OK")); - Assert.assertThat(closed.get(), is(true)); + assertThat(bracketed.run(), is("Read OK")); + assertThat(closed.get(), is(true)); } @Test @@ -59,9 +60,9 @@ public void close() { bracketed.run(); fail("Exception expected"); } catch (IllegalArgumentException e) { - Assert.assertThat(e.getMessage(), is("OoO")); + assertThat(e.getMessage(), is("OoO")); } - Assert.assertThat(closed.get(), is(true)); + assertThat(closed.get(), is(true)); } @Test diff --git a/core/src/test/java/fj/data/ListTest.java b/core/src/test/java/fj/data/ListTest.java index 9f09de0f..720157e8 100644 --- a/core/src/test/java/fj/data/ListTest.java +++ b/core/src/test/java/fj/data/ListTest.java @@ -30,7 +30,10 @@ import static fj.data.Validation.fail; import static fj.data.Validation.*; import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; public class ListTest { diff --git a/core/src/test/java/fj/data/List_Traverse_Tests.java b/core/src/test/java/fj/data/List_Traverse_Tests.java index 5b7c0d19..ad925847 100644 --- a/core/src/test/java/fj/data/List_Traverse_Tests.java +++ b/core/src/test/java/fj/data/List_Traverse_Tests.java @@ -7,7 +7,7 @@ import static fj.data.List.list; import static fj.data.Option.some; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; public class List_Traverse_Tests { diff --git a/core/src/test/java/fj/function/DoublesTest.java b/core/src/test/java/fj/function/DoublesTest.java index 6ba98fa2..09ca4bbe 100644 --- a/core/src/test/java/fj/function/DoublesTest.java +++ b/core/src/test/java/fj/function/DoublesTest.java @@ -1,6 +1,9 @@ package fj.function; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import fj.F; import org.junit.Test; diff --git a/core/src/test/java/fj/function/IntegersTest.java b/core/src/test/java/fj/function/IntegersTest.java index 985afba9..c07197af 100644 --- a/core/src/test/java/fj/function/IntegersTest.java +++ b/core/src/test/java/fj/function/IntegersTest.java @@ -8,7 +8,10 @@ import static fj.data.List.list; import static fj.data.Option.none; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertTrue; public class IntegersTest { diff --git a/core/src/test/java/fj/function/LongsTest.java b/core/src/test/java/fj/function/LongsTest.java index d59fc07c..196da20f 100644 --- a/core/src/test/java/fj/function/LongsTest.java +++ b/core/src/test/java/fj/function/LongsTest.java @@ -8,7 +8,10 @@ import static fj.data.List.list; import static fj.data.Option.none; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + public class LongsTest { diff --git a/core/src/test/java/fj/function/StringsTest.java b/core/src/test/java/fj/function/StringsTest.java index c13e1b81..79cb8a3d 100644 --- a/core/src/test/java/fj/function/StringsTest.java +++ b/core/src/test/java/fj/function/StringsTest.java @@ -5,7 +5,7 @@ import static fj.Function.compose; import static fj.function.Strings.*; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; public class StringsTest { diff --git a/core/src/test/java/fj/parser/ParserTest.java b/core/src/test/java/fj/parser/ParserTest.java index a3f623f5..f2664a1f 100644 --- a/core/src/test/java/fj/parser/ParserTest.java +++ b/core/src/test/java/fj/parser/ParserTest.java @@ -8,7 +8,7 @@ import static fj.parser.Result.result; import static org.hamcrest.core.Is.is; -import static org.junit.Assert.*; +import static org.hamcrest.MatcherAssert.assertThat; public class ParserTest { @Test From 5ecd37c0b30b383ed8788b62190b4efce6b0feab Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 14 Feb 2022 23:54:44 +1000 Subject: [PATCH 326/336] Upgrade Gradle to 7.3, jacoco to 0.8.7. Upgrade plugin from java to java-library, maven to maven-publish --- build.gradle | 19 ++- consume/build.gradle | 6 +- core/build.gradle | 14 +- .../fj/control/parallel/StrategyTest.java | 1 - core/src/test/java/fj/data/ArrayTest.java | 1 + core/src/test/java/fj/data/BooleansTest.java | 1 + core/src/test/java/fj/data/DListTest.java | 1 + .../src/test/java/fj/data/LazyStringTest.java | 1 + .../src/test/java/fj/data/ListBufferTest.java | 1 + .../java/fj/data/List_Traverse_Tests.java | 1 + core/src/test/java/fj/data/hamt/HamtTest.java | 1 + core/src/test/java/fj/data/optic/IsoTest.java | 1 + .../src/test/java/fj/data/optic/LensTest.java | 1 + .../test/java/fj/data/optic/OptionalTest.java | 1 + core/src/test/java/fj/data/vector/VTest.java | 1 + .../test/java/fj/function/DoublesTest.java | 2 +- .../test/java/fj/function/StringsTest.java | 4 +- demo/build.gradle | 8 +- gradle/wrapper/gradle-wrapper.properties | 2 +- java-core/build.gradle | 11 +- lib.gradle | 138 +++++++++++++----- performance/build.gradle | 6 +- props-core-scalacheck/build.gradle | 12 +- props-core/build.gradle | 6 +- .../src/test/java/fj/data/ReaderTest.java | 1 + .../fj/data/fingertrees/FingerTreeTest.java | 3 +- quickcheck/build.gradle | 9 +- 27 files changed, 173 insertions(+), 80 deletions(-) diff --git a/build.gradle b/build.gradle index 3b627e85..9556b473 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { } wrapper { - gradleVersion = "6.8.3" + gradleVersion = "7.3" distributionType = Wrapper.DistributionType.ALL } } @@ -35,7 +35,7 @@ allprojects { apply plugin: "jacoco" jacoco { - toolVersion = "0.8.2" + toolVersion = "0.8.7" } defaultTasks "build" @@ -49,6 +49,7 @@ allprojects { fjConsumeVersion = "5.0" signModule = false + uploadModule = false projectTitle = "Functional Java" projectName = "functionaljava" @@ -58,12 +59,20 @@ allprojects { projectUrl = "http://functionaljava.org/" scmUrl = "git://github.com/functionaljava/functionaljava.git" scmGitFile = "scm:git@github.com:functionaljava/functionaljava.git" + scmSshGitFile = "scm:git:ssh://git@github.com/functionaljava/functionaljava.git" + licenseUrl = "https://github.com/functionaljava/functionaljava/blob/master/etc/LICENCE" + licenseName = "The BSD3 License" + + issueUrl = "https://github.com/functionaljava/functionaljava/issues" + githubUrl = "https://github.com/functionaljava/functionaljava" sonatypeBaseUrl = "https://oss.sonatype.org" sonatypeSnapshotUrl = "$sonatypeBaseUrl/content/repositories/snapshots/" sonatypeRepositoryUrl = "$sonatypeBaseUrl/content/groups/public" sonatypeReleaseUrl = "$sonatypeBaseUrl/service/local/staging/deploy/maven2/" + sonatypeUploadUrl = isSnapshot ? sonatypeSnapshotUrl : sonatypeReleaseUrl + primaryEmail = "functionaljava@googlegroups.com" junitCompile = "junit:junit:4.13.2" @@ -94,7 +103,7 @@ subprojects { } apply from: "$rootDir/lib.gradle" - apply plugin: "java" + apply plugin: "java-library" apply plugin: "eclipse" repositories { @@ -139,7 +148,7 @@ task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { configure(subprojects.findAll { it.name != "props-core" }) { - apply plugin: "maven" + apply plugin: "maven-publish" apply plugin: "signing" apply plugin: "biz.aQute.bnd.builder" sourceCompatibility = "1.8" @@ -164,7 +173,7 @@ configure(subprojects.findAll { it.name != "props-core" }) { } jar { - version project.fjVersion + archiveVersion = project.fjVersion bnd ( 'Bundle-Name': 'Functional Java', 'Signature-Version': project.fjVersion, diff --git a/consume/build.gradle b/consume/build.gradle index 370ebfbf..45dadefb 100644 --- a/consume/build.gradle +++ b/consume/build.gradle @@ -2,8 +2,8 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { - compile("$group:$projectName:$fjConsumeVersion") + api "$group:$projectName:$fjConsumeVersion" - testCompile junitCompile - testRuntime junitRuntime + testImplementation junitCompile + testRuntimeOnly junitRuntime } diff --git a/core/build.gradle b/core/build.gradle index 9ee293a9..282ec191 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,18 +1,18 @@ ext { signModule = true + uploadModule = true + } archivesBaseName = project.projectName dependencies { - testCompile junitCompile - testRuntime junitRuntime - testCompile 'com.h2database:h2:2.1.210' - testCompile 'commons-dbutils:commons-dbutils:1.7' + testImplementation junitCompile + testRuntimeOnly junitRuntime + testImplementation 'com.h2database:h2:2.1.210' + testImplementation 'commons-dbutils:commons-dbutils:1.7' } performSigning(signingEnabled, signModule) -configureUpload(signingEnabled, signModule) - -uploadArchives.enabled = true +configureUpload(signingEnabled, signModule, uploadModule) diff --git a/core/src/test/java/fj/control/parallel/StrategyTest.java b/core/src/test/java/fj/control/parallel/StrategyTest.java index b4d21320..1f5e7bba 100644 --- a/core/src/test/java/fj/control/parallel/StrategyTest.java +++ b/core/src/test/java/fj/control/parallel/StrategyTest.java @@ -18,7 +18,6 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; - public class StrategyTest { @Test diff --git a/core/src/test/java/fj/data/ArrayTest.java b/core/src/test/java/fj/data/ArrayTest.java index e686a02b..11683fbf 100644 --- a/core/src/test/java/fj/data/ArrayTest.java +++ b/core/src/test/java/fj/data/ArrayTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.MatcherAssert.assertThat; + public class ArrayTest { @Test diff --git a/core/src/test/java/fj/data/BooleansTest.java b/core/src/test/java/fj/data/BooleansTest.java index 61325df0..e5dbeb12 100644 --- a/core/src/test/java/fj/data/BooleansTest.java +++ b/core/src/test/java/fj/data/BooleansTest.java @@ -11,6 +11,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; + public class BooleansTest { @Test diff --git a/core/src/test/java/fj/data/DListTest.java b/core/src/test/java/fj/data/DListTest.java index 48c0c2fe..77f4db6c 100644 --- a/core/src/test/java/fj/data/DListTest.java +++ b/core/src/test/java/fj/data/DListTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; + public class DListTest { @Test public void testConsSnoc() { diff --git a/core/src/test/java/fj/data/LazyStringTest.java b/core/src/test/java/fj/data/LazyStringTest.java index 14a88c14..060c5394 100644 --- a/core/src/test/java/fj/data/LazyStringTest.java +++ b/core/src/test/java/fj/data/LazyStringTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; + public class LazyStringTest { @Test diff --git a/core/src/test/java/fj/data/ListBufferTest.java b/core/src/test/java/fj/data/ListBufferTest.java index 6b16f1ca..784b9510 100644 --- a/core/src/test/java/fj/data/ListBufferTest.java +++ b/core/src/test/java/fj/data/ListBufferTest.java @@ -5,6 +5,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; + public class ListBufferTest { @Test diff --git a/core/src/test/java/fj/data/List_Traverse_Tests.java b/core/src/test/java/fj/data/List_Traverse_Tests.java index ad925847..eee5752d 100644 --- a/core/src/test/java/fj/data/List_Traverse_Tests.java +++ b/core/src/test/java/fj/data/List_Traverse_Tests.java @@ -9,6 +9,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; + public class List_Traverse_Tests { @Test diff --git a/core/src/test/java/fj/data/hamt/HamtTest.java b/core/src/test/java/fj/data/hamt/HamtTest.java index 19a22411..ce901e6e 100644 --- a/core/src/test/java/fj/data/hamt/HamtTest.java +++ b/core/src/test/java/fj/data/hamt/HamtTest.java @@ -14,6 +14,7 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; + /** * @author Mark Perry */ diff --git a/core/src/test/java/fj/data/optic/IsoTest.java b/core/src/test/java/fj/data/optic/IsoTest.java index 7aace4d8..f9559d3f 100644 --- a/core/src/test/java/fj/data/optic/IsoTest.java +++ b/core/src/test/java/fj/data/optic/IsoTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; + public class IsoTest { @Test public void testIso() { diff --git a/core/src/test/java/fj/data/optic/LensTest.java b/core/src/test/java/fj/data/optic/LensTest.java index 60513651..98be7fca 100644 --- a/core/src/test/java/fj/data/optic/LensTest.java +++ b/core/src/test/java/fj/data/optic/LensTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; + public class LensTest { @Test public void testLensPersonGet() { diff --git a/core/src/test/java/fj/data/optic/OptionalTest.java b/core/src/test/java/fj/data/optic/OptionalTest.java index 5bea2864..7fddb31b 100644 --- a/core/src/test/java/fj/data/optic/OptionalTest.java +++ b/core/src/test/java/fj/data/optic/OptionalTest.java @@ -6,6 +6,7 @@ import static org.hamcrest.core.Is.is; import static org.hamcrest.MatcherAssert.assertThat; + public class OptionalTest { @Test public void testOptionalSome() { diff --git a/core/src/test/java/fj/data/vector/VTest.java b/core/src/test/java/fj/data/vector/VTest.java index 8dabd66e..34f8686c 100644 --- a/core/src/test/java/fj/data/vector/VTest.java +++ b/core/src/test/java/fj/data/vector/VTest.java @@ -7,6 +7,7 @@ import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; + public class VTest { @Test public void testVectorUp(){ diff --git a/core/src/test/java/fj/function/DoublesTest.java b/core/src/test/java/fj/function/DoublesTest.java index 09ca4bbe..53b74e52 100644 --- a/core/src/test/java/fj/function/DoublesTest.java +++ b/core/src/test/java/fj/function/DoublesTest.java @@ -1,7 +1,6 @@ package fj.function; import static org.hamcrest.MatcherAssert.assertThat; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -12,6 +11,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import static org.junit.Assert.assertTrue; import static org.hamcrest.core.Is.is; import static fj.data.List.list; diff --git a/core/src/test/java/fj/function/StringsTest.java b/core/src/test/java/fj/function/StringsTest.java index 79cb8a3d..db20fd68 100644 --- a/core/src/test/java/fj/function/StringsTest.java +++ b/core/src/test/java/fj/function/StringsTest.java @@ -5,8 +5,10 @@ import static fj.Function.compose; import static fj.function.Strings.*; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.*; import static org.hamcrest.core.Is.is; +import static org.hamcrest.MatcherAssert.assertThat; + public class StringsTest { @Test diff --git a/demo/build.gradle b/demo/build.gradle index f19e765f..87bf7a5c 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -6,10 +6,10 @@ mainClassName = "fj.demo.euler.Problem2" archivesBaseName = "${project.projectName}-${project.name}" dependencies { - compile project(":core") - compile project(":quickcheck") - testCompile junitCompile - testRuntime junitRuntime + api project(":core") + api project(":quickcheck") + testImplementation junitCompile + testImplementation junitRuntime } test { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8cf6eb5a..fbce071a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/java-core/build.gradle b/java-core/build.gradle index e7b40bb9..f6a6146a 100644 --- a/java-core/build.gradle +++ b/java-core/build.gradle @@ -3,16 +3,15 @@ archivesBaseName = "${project.projectName}-${project.name}" ext { signModule = true + uploadModule = true } dependencies { - compile project(":core") - testCompile junitCompile - testRuntime junitRuntime + api project(":core") + testImplementation junitCompile + testRuntimeOnly junitRuntime } performSigning(signingEnabled, signModule) -configureUpload(signingEnabled, signModule) +configureUpload(signingEnabled, signModule, uploadModule) - -uploadArchives.enabled = true diff --git a/lib.gradle b/lib.gradle index 39ce7a7e..5ff91f01 100644 --- a/lib.gradle +++ b/lib.gradle @@ -20,7 +20,7 @@ String findJavaCommand(String command) { Boolean doSigning(String signingAllowed, Boolean doModule) { def b = signingAllowed.trim() == "true" && doModule -// println("signModule: ${project.name} signingEnabled: $signingAllowed module: $doModule") +// println("signModule: ${project.name} signingAllowed: $signingAllowed doModule: $doModule") b } @@ -31,50 +31,122 @@ void performSigning(String signingAllowed, Boolean doModule) { } } -void configureUpload(String signingEnabled, Boolean signModule) { +def customisePom(pom, gradleProject) { + pom.withXml { + def root = asNode() - uploadArchives { - enabled = false - repositories { - mavenDeployer { - if (doSigning(signingEnabled, signModule)) { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - } + // add all items necessary for maven central publication + root.children().last() + { + resolveStrategy = Closure.DELEGATE_FIRST - repository(url: sonatypeUploadUrl) { - authentication(userName: sonatypeUsername, password: sonatypePassword) + name project.pomProjectName + description project.projectDescription + url project.projectUrl + organization { + name project.pomOrganisation + url project.projectUrl + } + issueManagement { + system 'GitHub' + url project.issueUrl + } + licenses { + license { + name project.licenseName + url project.licenseUrl + distribution 'repo' } - pom { - groupId = project.group - project { - name pomProjectName - packaging 'jar' - description projectDescription - url projectUrl - organization { - name pomOrganisation - url projectUrl - } - scm { - url scmUrl - } - licenses { - license { - name "The BSD3 License" - url "https://github.com/functionaljava/functionaljava/blob/master/etc/LICENCE" - distribution 'repo' + } + scm { + url project.githubUrl + connection project.scmGitFile + developerConnection project.scmSshGitFile + } + } + } +} + + +void configureUpload(String signingEnabled, Boolean signModule, Boolean uploadModule) { + + if (uploadModule) { + + publishing { + + publications { + + mavenJava(MavenPublication) { + groupId project.group + artifactId project.name + version project.version + + from components.java + + customisePom(pom, rootProject) + + artifact sourcesJar + artifact javadocJar + + if (doSigning(signingEnabled, signModule)) { + // sign the pom + pom.withXml { + def pomFile = file("${project.buildDir}/generated-pom.xml.asc") + writeTo(pomFile) + def pomAscFile = signing.sign(pomFile).signatureFiles[0] + artifact(pomAscFile) { + classifier = null + extension = 'pom.asc' } + pomFile.delete() } - developers { - developer { - email primaryEmail + + // sign the artifacts + project.tasks.signArchives.signatureFiles.each { + artifact(it) { + def matcher = it.file =~ /-(sources|javadoc|jre8|jre9)\.jar\.asc$/ + if (matcher.find()) { + classifier = matcher.group(1) + } else { + classifier = null + } + extension = 'jar.asc' } } } + + } + + } + + repositories { + maven { + url project.sonatypeUploadUrl + credentials { + username sonatypeUsername + password sonatypePassword + } } } + + } + + model { + tasks.publishMavenJavaPublicationToMavenLocal { + dependsOn(project.tasks.signArchives) + } + tasks.publishMavenJavaPublicationToMavenRepository { + dependsOn(project.tasks.signArchives) + } + tasks.publish { + dependsOn(project.tasks.build) + } +// tasks.install { +// dependsOn(project.tasks.build) +// } } + } + } ext { diff --git a/performance/build.gradle b/performance/build.gradle index c6f4c8a6..7efbde2e 100644 --- a/performance/build.gradle +++ b/performance/build.gradle @@ -1,6 +1,6 @@ dependencies { - compile project(":core") - testCompile junitCompile - testRuntime junitRuntime + api project(":core") + testImplementation junitCompile + testRuntimeOnly junitRuntime } diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index f26b5425..358b365b 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -11,12 +11,12 @@ ext { } dependencies { - compile project(":core") - compile "org.scala-lang:scala-library:$scalaVersion" - compile "org.scalacheck:scalacheck_$scalacheckScalaVersion:$scalacheckVersion" + api project(":core") + api "org.scala-lang:scala-library:$scalaVersion" + api "org.scalacheck:scalacheck_$scalacheckScalaVersion:$scalacheckVersion" - testCompile junitCompile - testRuntime junitRuntime + testImplementation junitCompile + testRuntimeOnly junitRuntime } tasks.withType(ScalaCompile) { @@ -24,4 +24,4 @@ tasks.withType(ScalaCompile) { } performSigning(signingEnabled, signModule) -configureUpload(signingEnabled, signModule) +configureUpload(signingEnabled, signModule, project.uploadModule) diff --git a/props-core/build.gradle b/props-core/build.gradle index b991bd47..534a051b 100644 --- a/props-core/build.gradle +++ b/props-core/build.gradle @@ -2,7 +2,7 @@ archivesBaseName = "${project.projectName}-${project.name}" dependencies { - compile project(":quickcheck") - testCompile junitCompile - testRuntime junitRuntime + api project(":quickcheck") + testImplementation junitCompile + testRuntimeOnly junitRuntime } diff --git a/props-core/src/test/java/fj/data/ReaderTest.java b/props-core/src/test/java/fj/data/ReaderTest.java index 4817e41c..48352620 100644 --- a/props-core/src/test/java/fj/data/ReaderTest.java +++ b/props-core/src/test/java/fj/data/ReaderTest.java @@ -13,6 +13,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertTrue; + public class ReaderTest { @Test diff --git a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java index 7f02288c..8cc94825 100644 --- a/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java +++ b/props-core/src/test/java/fj/data/fingertrees/FingerTreeTest.java @@ -8,10 +8,11 @@ import org.junit.Test; import static fj.Monoid.intAdditionMonoid; +import static fj.Monoid.intMinMonoid; import static fj.data.fingertrees.FingerTree.measured; import static org.hamcrest.CoreMatchers.equalTo; -import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.Is.is; +import static org.hamcrest.MatcherAssert.assertThat; public class FingerTreeTest { diff --git a/quickcheck/build.gradle b/quickcheck/build.gradle index 2e5dbe4c..c9851596 100644 --- a/quickcheck/build.gradle +++ b/quickcheck/build.gradle @@ -1,16 +1,15 @@ ext { signModule = true + uploadModule = true } archivesBaseName = "${project.projectName}-${project.name}" dependencies { - compile project(":core") - compile junitCompile + api project(":core") + api junitCompile } performSigning(signingEnabled, signModule) -configureUpload(signingEnabled, signModule) - -uploadArchives.enabled = true +configureUpload(signingEnabled, signModule, uploadModule) From 93c0403576becdffce91fdd9382b831725f6d795 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 17 Feb 2022 23:25:47 +1000 Subject: [PATCH 327/336] Removed deprecated jcenter. Added mavenLocal before mavenCentral in some missing cases. Fixed deprecated reports html enabled to required. --- build.gradle | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index 9556b473..43e7ae5b 100644 --- a/build.gradle +++ b/build.gradle @@ -6,8 +6,8 @@ apply plugin: "com.github.ben-manes.versions" buildscript { repositories { mavenLocal() - jcenter() mavenCentral() + gradlePluginPortal() } dependencies { @@ -83,9 +83,8 @@ allprojects { } repositories { - jcenter() - mavenCentral() mavenLocal() + mavenCentral() } version = fjVersion @@ -98,6 +97,7 @@ subprojects { buildscript { repositories { + mavenLocal() mavenCentral() } } @@ -108,7 +108,6 @@ subprojects { repositories { mavenLocal() - jcenter() mavenCentral() maven { url sonatypeRepositoryUrl @@ -124,8 +123,8 @@ subprojects { tasks.withType(Test).configureEach { maxParallelForks = Runtime.runtime.availableProcessors().intdiv(2) ?: 1 if (!generateTestReports) { - reports.html.enabled = false - reports.junitXml.enabled = false + reports.html.required = false + reports.junitXml.required = false } } @@ -141,8 +140,8 @@ task coverage(type: org.gradle.testing.jacoco.tasks.JacocoReport) { getSourceDirectories().from(files(subprojects.findAll {subproject -> subproject.name in projectForFoverage} .sourceSets.main.allSource.srcDirs)) reports { - html.enabled = true - xml.enabled = true + html.required = true + xml.required = true } } From 0c7f70139917f46c1f855a7258678e6c1377bf0b Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Thu, 17 Feb 2022 23:39:00 +1000 Subject: [PATCH 328/336] Upgrade from Gradle 7.3 t o7.4 --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 43e7ae5b..08204ba9 100644 --- a/build.gradle +++ b/build.gradle @@ -16,7 +16,7 @@ buildscript { } wrapper { - gradleVersion = "7.3" + gradleVersion = "7.4" distributionType = Wrapper.DistributionType.ALL } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index fbce071a..b1159fc5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 2ad5cd9f098b574f4e72d4f1924f6c0962621397 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 18 Feb 2022 00:25:11 +1000 Subject: [PATCH 329/336] Do some Travis optimisation --- .travis.yml | 6 +++++- gradle.properties | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index bc3fc57f..2fb30bf7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,13 +14,17 @@ matrix: allow_failures: script: - - ./gradlew clean test + - ./gradlew build --no-daemon env: global: - secure: Bun+1FZ29Q3dR9gZ/5brxcSf+zcY5tWrsqOA4GUb5bYCMyORuXQB0FYXuhKR4wB1pFrk1a9EYwRwSu3GwRJVWb+UzF0CNOWF/QG5tGPx32IOXScwlL/KonI4Vhs7Oc0fF4Wdb7euNrT27BU61jbUugjJ642b3n0VBYFYDdquprU= - secure: QAxhjqLRa+WHKIzgIJPZ/rM5a5uzqG7E5rsC0YvB25cO712oYXmzsYPia/oSp0chXlYLYMfk2UnLeQCSx2e6ogXRRRa977Q+B33Nt0Hd9SGLtduv6DBrbA2ehLU12Ib4DWe5VhF5eueAunycYcllTvqA5h+pzTtEVbd68ZHncM4= +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock + - rm -fr $HOME/.gradle/caches/*/plugin-resolution/ + cache: directories: - $HOME/.gradle/caches/ diff --git a/gradle.properties b/gradle.properties index 6ee9a768..e96743fd 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,3 +9,4 @@ sonatypePassword = incorrectPwd #signing.secretKeyRingFile= org.gradle.parallel = true +org.gradle.caching = true From 1dd3b3e8aa84df1d7788d74bcc17457efbc2511f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 18 Feb 2022 00:49:23 +1000 Subject: [PATCH 330/336] Update readme for FJ 5.0 --- README.adoc | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/README.adoc b/README.adoc index 4ede16b7..e24b3e6f 100644 --- a/README.adoc +++ b/README.adoc @@ -8,7 +8,7 @@ image::http://www.functionaljava.org/img/logo-600x144.png[] Functional Java is an open source library facilitating functional programming in Java. The library implements numerous basic and advanced programming abstractions that assist composition oriented development. Functional Java also serves as a platform for learning functional programming concepts by introducing these concepts using a familiar language. -The library is intended for use in production applications and is thoroughly tested using the technique of automated specification-based testing with ScalaCheck and Functional Java's quickcheck module. Functional Java is compiled with Java 8 targeting Java 7 bytecode. The use of lambdas within the project are back ported with the Retro Lambda library, supporting Java versions 6 to 8. +The library is intended for use in production applications and is thoroughly tested using the technique of automated specification-based testing with ScalaCheck and Functional Java's quickcheck module. Functional Java provides abstractions for the following types: @@ -32,16 +32,13 @@ The recommended way to download and use the project is through your build tool. The Functional Java artifact is published to Maven Central using the group `org.functionaljava` with three published artifacts: -* the core library (`functionaljava` or `functionaljava_1.8` if you use Java 8+) -* Java 8 specific support (`functionaljava-java8`) -* property based testing (`functionaljava-quickcheck` or `functionaljava-quickcheck_1.8` if you use Java 8+) +* the core library (`functionaljava`) +* property based testing (`functionaljava-quickcheck`) -The latest stable version is `4.9`. This can be added to your Gradle project by adding the dependencies: +The latest stable version is `5.0`. This can be added to your Gradle project by adding the dependencies: ---- -compile "org.functionaljava:functionaljava:4.9" -compile "org.functionaljava:functionaljava-java8:4.9" -compile "org.functionaljava:functionaljava-quickcheck:4.9" -compile "org.functionaljava:functionaljava-java-core:4.9" +compile "org.functionaljava:functionaljava:5.0" +compile "org.functionaljava:functionaljava-quickcheck:5.0" ---- and in Maven: @@ -49,34 +46,22 @@ and in Maven: org.functionaljava functionaljava - 4.9 - - - org.functionaljava - functionaljava-java8 - 4.9 + 5.0 org.functionaljava functionaljava-quickcheck - 4.9 - - - org.functionaljava - functionaljava-java-core - 4.9 + 5.0 ---- == Building -FunctionalJava uses the Retro Lambda project to backport Java 8 lambdas to Java 6 bytecode. This requires access to both JDK 6 and 8. The build system requires the environment variables `JAVA6_HOME` and `JAVA8_HOME` to refer to the appropriate directories. - -Building is done using Gradle 6.8.3. In the root directory run: +Building is done using Gradle 7.4. In the root directory run: ---- ./gradlew ---- -This requires access to Java and will download the Gradle build tool and necessary dependencies and build FunctionalJava. +This requires access to Java 8 and will download the Gradle build tool and necessary dependencies and build FunctionalJava. == Features @@ -126,4 +111,4 @@ link:etc/LICENCE[The Functional Java license] uses the BSD 3 license (3-clause l == Release Notes -For release notes for each version, see the directory etc/release-notes. \ No newline at end of file +For release notes for each version, see the directory etc/release-notes. From 1bcfaa1cb1e4a2e1db710984dc3a1ebd374a09c1 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 18 Feb 2022 23:48:22 +1000 Subject: [PATCH 331/336] Updated gradle versions plugin to 0.42.0. Added arb values for ParModule to help with upgrading Scala and Scalacheck --- build.gradle | 2 +- .../src/main/java/fj/test/Arbitrary.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 08204ba9..c89c9536 100644 --- a/build.gradle +++ b/build.gradle @@ -11,7 +11,7 @@ buildscript { } dependencies { - classpath "com.github.ben-manes:gradle-versions-plugin:0.36.0" + classpath "com.github.ben-manes:gradle-versions-plugin:0.42.0" classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:6.1.0" } diff --git a/quickcheck/src/main/java/fj/test/Arbitrary.java b/quickcheck/src/main/java/fj/test/Arbitrary.java index 146d0a9b..04f1e20b 100644 --- a/quickcheck/src/main/java/fj/test/Arbitrary.java +++ b/quickcheck/src/main/java/fj/test/Arbitrary.java @@ -23,6 +23,9 @@ import fj.P6; import fj.P7; import fj.P8; +import fj.Unit; +import fj.control.parallel.ParModule; +import fj.control.parallel.Strategy; import fj.data.*; import fj.LcgRng; import fj.Ord; @@ -65,9 +68,12 @@ import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.DelayQueue; import java.util.concurrent.Delayed; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.SynchronousQueue; +import java.util.concurrent.ThreadFactory; /** * Common Gen helper functions. @@ -98,6 +104,24 @@ public static Gen> arbState(Gen as, Cogen cs, Gen aa return arbF(cs, arbP2(as, aa)).map(State::unit); } + public static Gen arbParModule() { + return Arbitrary.arbStrategy().map(s -> ParModule.parModule(s)); + } + + public static Gen> arbStrategy() { + Strategy s = Strategy.executorStrategy(fixedThreadsExecutorService(2)); + return Gen.elements(s); + } + + private static ExecutorService fixedThreadsExecutorService(int n) { + return Executors.newFixedThreadPool(n, r -> { + ThreadFactory tf = Executors.defaultThreadFactory(); + Thread t = tf.newThread(r); + t.setDaemon(true); + return t; + }); + } + /** * An arbitrary for the LcgRng. */ From aad325739af7dae57c921506a66ee8e4f6ddd026 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 18 Feb 2022 23:50:55 +1000 Subject: [PATCH 332/336] Added problematic upgrade tests from CheckParModule.scala to CheckParModuleTest.java --- .../control/parallel/CheckParModuleTest.java | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java diff --git a/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java b/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java new file mode 100644 index 00000000..dfbbdda5 --- /dev/null +++ b/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java @@ -0,0 +1,48 @@ +package fj.control.parallel; + +import fj.Equal; +import fj.F; +import fj.Monoid; +import fj.P; +import fj.P1; +import fj.P2; +import fj.data.Stream; +import fj.test.Arbitrary; +import fj.test.Property; +import fj.test.runner.PropertyTestRunner; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static fj.Equal.stringEqual; +import static fj.Monoid.stringMonoid; +import static fj.test.Arbitrary.arbInteger; +import static fj.test.Arbitrary.arbP1; +import static fj.test.Arbitrary.arbParModule; +import static fj.test.Arbitrary.arbStream; +import static fj.test.Arbitrary.arbString; +import static fj.test.Property.prop; +import static fj.test.Property.property; + +@RunWith(PropertyTestRunner.class) +public class CheckParModuleTest { + + public Property parFlatMap() { + return property(arbStream(arbString), arbParModule(), (str, pm) -> { + F> f = s3 -> Stream.stream(s3, reverse().f(s3)); + return prop(Equal.streamEqual(stringEqual).eq(str.bind(f), pm.parFlatMap(str, f).claim())); + }); + } + + private F reverse() { + return s2 -> new StringBuilder(s2).reverse().toString(); + } + + public Property parFoldMap() { + return property(arbStream(arbString), arbParModule(), (str, pm) -> { + F, P2, Stream>> chunk = x -> P.p(Stream.stream(x.head()), x.tail()._1()); + return prop(stringEqual.eq(stringMonoid.sumLeft(str.map(reverse())), pm.parFoldMap(str, reverse(), stringMonoid, chunk).claim())); + }); + } + + +} From 3bced817e36f54c1191f378d9fc9380fb477b567 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Fri, 18 Feb 2022 23:59:51 +1000 Subject: [PATCH 333/336] Removed problematic properties for Scala 2.12 that were moved to Java. --- .../test/scala/fj/control/parallel/CheckParModule.scala | 7 ------- 1 file changed, 7 deletions(-) diff --git a/props-core-scalacheck/src/test/scala/fj/control/parallel/CheckParModule.scala b/props-core-scalacheck/src/test/scala/fj/control/parallel/CheckParModule.scala index 8e13eb1b..bba1feff 100644 --- a/props-core-scalacheck/src/test/scala/fj/control/parallel/CheckParModule.scala +++ b/props-core-scalacheck/src/test/scala/fj/control/parallel/CheckParModule.scala @@ -46,11 +46,4 @@ object CheckParModule extends Properties("ParModule") { property("parMapArray") = forAll((s: Array[String], p: ParModule) => arrayEqual(stringEqual).eq(s.map(rev), p.parMap(s, rev).claim)) - property("parFlatMap") = forAll((s: Stream[String], p: ParModule) => { - val f = (x: String) => Stream.stream(x, rev(x)) : Stream[String] - streamEqual(stringEqual).eq(s.bind(f), p.parFlatMap(s, f).claim)}) - - property("parFoldMap") = forAll((s: Stream[String], p: ParModule) => { - val chunk = (x: Stream[String]) => P.p(Stream.stream(x.head), x.tail._1) - stringEqual.eq(stringMonoid.sumLeft(s.map(rev)), p.parFoldMap(s, rev, stringMonoid, chunk).claim)}) } From 835ca0fb9ae5278aa3371dfdf73562002747c72c Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 19 Feb 2022 01:02:47 +1000 Subject: [PATCH 334/336] Upgrade to Gradle 2.12. Removed CheckHashMap no null values test as the semantics changed with Scala 2.12 so that null.asInstanceOf[Int] returns 0 instead of null --- core/src/main/java/fj/function/Strings.java | 4 ++++ props-core-scalacheck/build.gradle | 12 ++++++++++-- .../src/test/scala/fj/data/CheckArray.scala | 4 ++-- .../src/test/scala/fj/data/CheckHashMap.scala | 11 ----------- .../java/fj/control/parallel/CheckParModuleTest.java | 12 ++++++------ 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/fj/function/Strings.java b/core/src/main/java/fj/function/Strings.java index 1c239e85..d9815248 100644 --- a/core/src/main/java/fj/function/Strings.java +++ b/core/src/main/java/fj/function/Strings.java @@ -96,4 +96,8 @@ public static F, String> unlines() { return Strings::unlines; } + public static F reverse() { + return s -> new StringBuilder(s).reverse().toString(); + } + } diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index 358b365b..faa7d737 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -4,9 +4,17 @@ archivesBaseName = "${project.projectName}-${project.name}" apply plugin: 'scala' ext { - scalaVersion = "2.11.12" - scalacheckScalaVersion = "2.11" +// scalaVersion = "2.11.12" +// scalacheckScalaVersion = "2.11" + scalaVersion = "2.12.15" + scalacheckScalaVersion = "2.12" +// scalaVersion = "2.13.8" +// scalacheckScalaVersion = "2.13" + scalacheckVersion = "1.12.6" +// scalacheckVersion = "1.13.5" +// scalacheckVersion = "1.15.2" + signModule = true } diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckArray.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckArray.scala index f8cce111..b116a6a9 100755 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckArray.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckArray.scala @@ -63,7 +63,7 @@ object CheckArray extends Properties("Array") { a.reverse.foldRight((a: String, b: Array[String]) => array[String](scala.Array(a): _*).append(b), empty[String]))) property("scans") = forAll((a: Array[Int], z: Int) => { - val add = (x: Int, y: Int) => x + y + val add: F2[Int, Int, Int] = (x: Int, y: Int) => x + y val left = a.scanLeft(add, z) val right = a.reverse().scanRight(add, z).reverse() @@ -72,7 +72,7 @@ object CheckArray extends Properties("Array") { property("scans1") = forAll((a: Array[Int]) => (a.length() > 0) ==> { - val add = (x: Int, y: Int) => x + y + val add: F2[Int, Int, Int] = (x: Int, y: Int) => x + y val left = a.scanLeft1(add) val right = a.reverse().scanRight1(add).reverse() diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala index dfde81e3..6ebd060d 100755 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala @@ -105,15 +105,4 @@ object CheckHashMap extends Properties("HashMap") { keysAreEqual && valuesAreEqual }) - property("No null values") = forAll((list: List[Int]) => { - val m = HashMap.hashMap[Int, Int]() - list.foreachDoEffect(new Effect1[Int] { - def f(a: Int) { - m.set(a, null.asInstanceOf[Int]) - } - }) - list.forall(new F[Int, java.lang.Boolean]() { - def f(a: Int) = m.contains(a) == false - }) - }) } \ No newline at end of file diff --git a/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java b/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java index dfbbdda5..0c4f418f 100644 --- a/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java +++ b/props-core/src/test/java/fj/control/parallel/CheckParModuleTest.java @@ -7,6 +7,7 @@ import fj.P1; import fj.P2; import fj.data.Stream; +import fj.function.Strings; import fj.test.Arbitrary; import fj.test.Property; import fj.test.runner.PropertyTestRunner; @@ -28,19 +29,18 @@ public class CheckParModuleTest { public Property parFlatMap() { return property(arbStream(arbString), arbParModule(), (str, pm) -> { - F> f = s3 -> Stream.stream(s3, reverse().f(s3)); + F> f = s3 -> Stream.stream(s3, Strings.reverse().f(s3)); return prop(Equal.streamEqual(stringEqual).eq(str.bind(f), pm.parFlatMap(str, f).claim())); }); } - private F reverse() { - return s2 -> new StringBuilder(s2).reverse().toString(); - } - public Property parFoldMap() { return property(arbStream(arbString), arbParModule(), (str, pm) -> { F, P2, Stream>> chunk = x -> P.p(Stream.stream(x.head()), x.tail()._1()); - return prop(stringEqual.eq(stringMonoid.sumLeft(str.map(reverse())), pm.parFoldMap(str, reverse(), stringMonoid, chunk).claim())); + return prop(stringEqual.eq( + stringMonoid.sumLeft(str.map(Strings.reverse())), + pm.parFoldMap(str, Strings.reverse(), stringMonoid, chunk).claim() + )); }); } From 4671564744bd18e6d9c77ff03f47d8e3900cf28f Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Sat, 19 Feb 2022 01:22:40 +1000 Subject: [PATCH 335/336] Prep for next Scala version --- props-core-scalacheck/build.gradle | 1 + props-core-scalacheck/src/test/scala/fj/Tests.scala | 2 +- props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/props-core-scalacheck/build.gradle b/props-core-scalacheck/build.gradle index faa7d737..396d19d4 100644 --- a/props-core-scalacheck/build.gradle +++ b/props-core-scalacheck/build.gradle @@ -13,6 +13,7 @@ ext { scalacheckVersion = "1.12.6" // scalacheckVersion = "1.13.5" +// scalacheckVersion = "1.14.0" // scalacheckVersion = "1.15.2" signModule = true diff --git a/props-core-scalacheck/src/test/scala/fj/Tests.scala b/props-core-scalacheck/src/test/scala/fj/Tests.scala index d94661f9..c5ec3977 100644 --- a/props-core-scalacheck/src/test/scala/fj/Tests.scala +++ b/props-core-scalacheck/src/test/scala/fj/Tests.scala @@ -18,7 +18,7 @@ object Tests { fj.control.parallel.CheckParModule.properties ).flatten - def main(args: Array[String]) { + def main(args: Array[String]): scala.Unit = { run(tests) // System.exit(0) } diff --git a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala index 6ebd060d..c629a10f 100755 --- a/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala +++ b/props-core-scalacheck/src/test/scala/fj/data/CheckHashMap.scala @@ -9,6 +9,8 @@ import Hash._ import Ord._ import fj.data.Option._ import scala.collection.JavaConversions._ +//import scala.collection.JavaConverters._ + import org.scalacheck.{Arbitrary, Properties} import data.ArbitraryList._ import org.scalacheck.Arbitrary._ From a2f7ebe5ef319df492f547e0be4cc965af667e35 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Mon, 7 Mar 2022 18:38:31 +1000 Subject: [PATCH 336/336] Updated doc when releasing FJ 5.0 --- README.adoc | 11 ++++++++-- etc/release-notes/release-notes-5.1.adoc | 28 ++++++++++++++++++++++++ etc/release-process.txt | 24 ++++++++++++++++---- 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 etc/release-notes/release-notes-5.1.adoc diff --git a/README.adoc b/README.adoc index e24b3e6f..ecf403e2 100644 --- a/README.adoc +++ b/README.adoc @@ -34,11 +34,13 @@ The Functional Java artifact is published to Maven Central using the group `org. * the core library (`functionaljava`) * property based testing (`functionaljava-quickcheck`) +* a small amount of Java 8 support (`functionaljava-java-core`) The latest stable version is `5.0`. This can be added to your Gradle project by adding the dependencies: ---- compile "org.functionaljava:functionaljava:5.0" compile "org.functionaljava:functionaljava-quickcheck:5.0" +compile "org.functionaljava:functionaljava-java-core:5.0" ---- and in Maven: @@ -53,11 +55,16 @@ and in Maven: functionaljava-quickcheck 5.0 + + org.functionaljava + functionaljava-java-core + 5.0 + ---- == Building -Building is done using Gradle 7.4. In the root directory run: +Building is done using Java 8 and Gradle 7.4. In the root directory run: ---- ./gradlew ---- @@ -111,4 +118,4 @@ link:etc/LICENCE[The Functional Java license] uses the BSD 3 license (3-clause l == Release Notes -For release notes for each version, see the directory etc/release-notes. +For release notes for each version, see the directory link:etc/release-notes. diff --git a/etc/release-notes/release-notes-5.1.adoc b/etc/release-notes/release-notes-5.1.adoc new file mode 100644 index 00000000..22dbc552 --- /dev/null +++ b/etc/release-notes/release-notes-5.1.adoc @@ -0,0 +1,28 @@ + += Release + +Proposed release: + +== Enhancements + +* TODO. + +== Fixes + +* TODO. + +== Internal + +* TODO. + +== Breaking Changes + +* TODO. + +== Documentation + +* TODO. + +== Contributors + +* TODO. diff --git a/etc/release-process.txt b/etc/release-process.txt index e4b35e2d..f5699a5b 100644 --- a/etc/release-process.txt +++ b/etc/release-process.txt @@ -1,6 +1,6 @@ -Current Release Process -======================= +Release Process +=============== Go through the issues and pull requests and set the Label and Milestone field. Add information to /etc/release-notes/release-notes-.adoc. @@ -10,7 +10,7 @@ Update gradle.properties: Run the build command: -gradlew clean build upload +gradlew clean build publishAllPublicationsToMavenRepository Login to Sonatype and verify the release: * Login to https://oss.sonatype.org @@ -18,6 +18,7 @@ Login to Sonatype and verify the release: * Tick the release and click Close * Wait until closed * Tick the release and click Release +* It takes ~24 hours for Sonatype to sync to Maven Central where it should appear Commit changes @@ -33,12 +34,27 @@ Create tag: Create the next version of the release notes with empty fields using the template. -Copy the generated javadoc for each component to the website repositories' master branch under /javadoc/. Commit the javadoc and push. +Copy the generated javadoc for each component to the website repositories' master branch, see https://github.com/functionaljava/functionaljava.github.io, under /javadoc/. Copy: +- core to functionaljava +- java-core to functionaljava-java-core +- quickcheck to functionaljava-quickcheck + +Commit the javadoc and push. Update the website and Github README.adoc. This includes adding any features to the home page and features page. Updating the doc page with javadoc links. Update the download page with a link to the latest release notes. Send a message to the group and social media about the release, TODO. +Setup Sonatype +====================== +You need to be able to login to https://oss.sonatype.org. Register or check your login details. + +Create/edit the file %UserProfile%\.gradle\gradle.properties, set the values below: + +sonatypeUsername = +sonatypePassword = + + Setup Artifact Signing ====================== The below text is a summary from https://gist.github.com/phit/bd3c6d156a2fa5f3b1bc15fa94b3256c.