diff options
author | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-01 12:49:53 +1000 |
---|---|---|
committer | Carlo Zancanaro <carlo@zancanaro.id.au> | 2015-06-01 12:49:53 +1000 |
commit | a0d8c8066faadaf609e151ed0b71235a9615584a (patch) | |
tree | b9e07a2d5e32158991c8c40b6ede95c864d4056d /src | |
parent | fef70631f4d1be56d772816af22778efebcc8391 (diff) |
Rename fmap -> map (apparently that's what Java's going with, see java.util.Optional)
Diffstat (limited to 'src')
4 files changed, 15 insertions, 19 deletions
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<T> { }; } - default <R> Generator<R> fmap(Function<T, R> f) { - return (random, size) -> this.generate(random, size).fmap(f); + default <R> Generator<R> map(Function<T, R> f) { + return (random, size) -> this.generate(random, size).map(f); } default <R> Generator<R> flatMap(Function<T, Generator<R>> 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 <T> Generator<T> elements(List<T> elements) { - return integer(0, elements.size()).fmap(elements::get); + return integer(0, elements.size()).map(elements::get); } public static Generator<Boolean> bool() { @@ -89,24 +89,24 @@ public final class Generators { } public static Generator<Character> character() { - return integer(0, 256).fmap(i -> (char) i.intValue()); + return integer(0, 256).map(i -> (char) i.intValue()); } public static Generator<Character> asciiCharacter() { - return integer(32, 127).fmap(i -> (char) i.intValue()); + return integer(32, 127).map(i -> (char) i.intValue()); } public static Generator<Character> 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<Character> 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<String> stringOf(Generator<Character> 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<T> { RoseTree.removeEach(trees))); } - public <R> RoseTree<R> fmap(Function<T, R> f) { + public <R> RoseTree<R> map(Function<T, R> 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 <R> RoseTree<R> flatmap(Function<T, RoseTree<R>> f) { - return RoseTree.join(this.fmap(f)); + public <R> RoseTree<R> flatMap(Function<T, RoseTree<R>> f) { + return RoseTree.join(this.map(f)); } public RoseTree<T> filter(Predicate<T> 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<Object[]> generator = Generator.tuple((Generator<Object>[]) generators).fmap(List::toArray); + Generator<Object[]> generator = Generator.tuple((Generator<Object>[]) generators).map(List::toArray); long seed = getSeed(method); Random random = new Random(seed); |