summaryrefslogtreecommitdiff
path: root/src/main/java/au/id/zancanaro/Generator.java
diff options
context:
space:
mode:
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)));
+ };
}
}