From a0d8c8066faadaf609e151ed0b71235a9615584a Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Mon, 1 Jun 2015 12:49:53 +1000 Subject: Rename fmap -> map (apparently that's what Java's going with, see java.util.Optional) --- src/main/java/au/id/zancanaro/javacheck/Generator.java | 7 +++---- src/main/java/au/id/zancanaro/javacheck/Generators.java | 12 ++++++------ src/main/java/au/id/zancanaro/javacheck/RoseTree.java | 13 +++++-------- .../java/au/id/zancanaro/javacheck/junit/Properties.java | 2 +- 4 files changed, 15 insertions(+), 19 deletions(-) (limited to 'src/main/java/au/id/zancanaro') diff --git a/src/main/java/au/id/zancanaro/javacheck/Generator.java b/src/main/java/au/id/zancanaro/javacheck/Generator.java index 55d06f8..076f7c2 100644 --- a/src/main/java/au/id/zancanaro/javacheck/Generator.java +++ b/src/main/java/au/id/zancanaro/javacheck/Generator.java @@ -1,6 +1,5 @@ package au.id.zancanaro.javacheck; -import java.util.Arrays; import java.util.List; import java.util.Random; import java.util.function.Function; @@ -36,13 +35,13 @@ public interface Generator { }; } - default Generator fmap(Function f) { - return (random, size) -> this.generate(random, size).fmap(f); + default Generator map(Function f) { + return (random, size) -> this.generate(random, size).map(f); } default Generator flatMap(Function> action) { return (random, size) -> { - return RoseTree.join(this.generate(random, size).fmap(action).fmap(g -> g.generate(random, size))); + return RoseTree.join(this.generate(random, size).map(action).map(g -> g.generate(random, size))); }; } } diff --git a/src/main/java/au/id/zancanaro/javacheck/Generators.java b/src/main/java/au/id/zancanaro/javacheck/Generators.java index 9ced818..08b9989 100644 --- a/src/main/java/au/id/zancanaro/javacheck/Generators.java +++ b/src/main/java/au/id/zancanaro/javacheck/Generators.java @@ -36,7 +36,7 @@ public final class Generators { } public static Generator elements(List elements) { - return integer(0, elements.size()).fmap(elements::get); + return integer(0, elements.size()).map(elements::get); } public static Generator bool() { @@ -89,24 +89,24 @@ public final class Generators { } public static Generator character() { - return integer(0, 256).fmap(i -> (char) i.intValue()); + return integer(0, 256).map(i -> (char) i.intValue()); } public static Generator asciiCharacter() { - return integer(32, 127).fmap(i -> (char) i.intValue()); + return integer(32, 127).map(i -> (char) i.intValue()); } public static Generator alphaNumericCharacter() { return oneOf( integer(48, 58), integer(65, 91), - integer(97, 123)).fmap(i -> (char) i.intValue()); + integer(97, 123)).map(i -> (char) i.intValue()); } public static Generator alphaCharacter() { return oneOf( integer(65, 91), - integer(97, 123)).fmap(i -> (char) i.intValue()); + integer(97, 123)).map(i -> (char) i.intValue()); } private static String makeString(Character[] arr) { @@ -122,7 +122,7 @@ public final class Generators { } public static Generator stringOf(Generator charGen) { - return listOf(charGen).fmap(list -> { + return listOf(charGen).map(list -> { char[] chars = new char[list.size()]; int i = 0; for (Character c : list) { diff --git a/src/main/java/au/id/zancanaro/javacheck/RoseTree.java b/src/main/java/au/id/zancanaro/javacheck/RoseTree.java index 4d7b770..86952da 100644 --- a/src/main/java/au/id/zancanaro/javacheck/RoseTree.java +++ b/src/main/java/au/id/zancanaro/javacheck/RoseTree.java @@ -2,10 +2,7 @@ package au.id.zancanaro.javacheck; import java.io.IOException; import java.io.Writer; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; +import java.util.*; import java.util.function.Function; import java.util.function.Predicate; @@ -90,14 +87,14 @@ public class RoseTree { RoseTree.removeEach(trees))); } - public RoseTree fmap(Function f) { + public RoseTree map(Function f) { return new RoseTree<>( f.apply(this.value), - () -> Iterators.mappingIterator(tree -> tree.fmap(f), this.children.iterator())); + () -> Iterators.mappingIterator(tree -> tree.map(f), this.children.iterator())); } - public RoseTree flatmap(Function> f) { - return RoseTree.join(this.fmap(f)); + public RoseTree flatMap(Function> f) { + return RoseTree.join(this.map(f)); } public RoseTree filter(Predicate predicate) { diff --git a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java index 5ec0c36..0507413 100644 --- a/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java +++ b/src/main/java/au/id/zancanaro/javacheck/junit/Properties.java @@ -193,7 +193,7 @@ public class Properties extends BlockJUnit4ClassRunner { generators[index++] = this.generators.get(type); } @SuppressWarnings("unchecked") - Generator generator = Generator.tuple((Generator[]) generators).fmap(List::toArray); + Generator generator = Generator.tuple((Generator[]) generators).map(List::toArray); long seed = getSeed(method); Random random = new Random(seed); -- cgit v1.2.3