summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/Generator.java
diff options
context:
space:
mode:
authorCarlo Zancanaro <carlo@zancanaro.id.au>2015-05-31 13:53:08 +1000
committerCarlo Zancanaro <carlo@zancanaro.id.au>2015-05-31 13:53:08 +1000
commitc25450f6288748782ad60cc7c4b8e0e0bdc52c1c (patch)
treed25bd7a6bac5535cdff87fac5cbe0146a59f7b75 /src/main/java/au/id/zancanaro/Generator.java
parentd29e1d49116c66adab72b1c1bb49c1fa3d4f8140 (diff)
Better code, based off ParentRunner among other things
Diffstat (limited to 'src/main/java/au/id/zancanaro/Generator.java')
-rw-r--r--src/main/java/au/id/zancanaro/Generator.java22
1 files changed, 3 insertions, 19 deletions
diff --git a/src/main/java/au/id/zancanaro/Generator.java b/src/main/java/au/id/zancanaro/Generator.java
index 4b80e51..1c948af 100644
--- a/src/main/java/au/id/zancanaro/Generator.java
+++ b/src/main/java/au/id/zancanaro/Generator.java
@@ -1,7 +1,5 @@
package au.id.zancanaro;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Random;
import java.util.function.Function;
@@ -12,18 +10,6 @@ public interface Generator<T> {
return (random, size) -> RoseTree.pure(value);
}
- default <R> Generator<R> genFlatmap(Function<RoseTree<T>, Generator<R>> f) {
- return (random, size) -> {
- RoseTree<T> inner = this.generate(random, size);
- Generator<R> generator = f.apply(inner);
- return generator.generate(random, size);
- };
- }
-
- default <R> Generator<R> genFmap(Function<RoseTree<T>, RoseTree<R>> f) {
- return (random, size) -> f.apply(this.generate(random, size));
- }
-
@SafeVarargs
static <T> Generator<T[]> tuple(Generator<T>... generators) {
return (random, size) -> {
@@ -42,10 +28,8 @@ public interface Generator<T> {
}
default <R> Generator<R> flatMap(Function<T, Generator<R>> action) {
- return this.genFlatmap(rose -> {
- Generator<RoseTree<R>> generator = (random, size) ->
- rose.fmap(action).fmap(g -> g.generate(random, size));
- return generator.<R>genFmap(RoseTree::join);
- });
+ return (random, size) -> {
+ return RoseTree.join(this.generate(random, size).fmap(action).fmap(g -> g.generate(random, size)));
+ };
}
}