From c25450f6288748782ad60cc7c4b8e0e0bdc52c1c Mon Sep 17 00:00:00 2001 From: Carlo Zancanaro Date: Sun, 31 May 2015 13:53:08 +1000 Subject: Better code, based off ParentRunner among other things --- src/main/java/au/id/zancanaro/Generator.java | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'src/main/java/au/id/zancanaro/Generator.java') 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 { return (random, size) -> RoseTree.pure(value); } - default Generator genFlatmap(Function, Generator> f) { - return (random, size) -> { - RoseTree inner = this.generate(random, size); - Generator generator = f.apply(inner); - return generator.generate(random, size); - }; - } - - default Generator genFmap(Function, RoseTree> f) { - return (random, size) -> f.apply(this.generate(random, size)); - } - @SafeVarargs static Generator tuple(Generator... generators) { return (random, size) -> { @@ -42,10 +28,8 @@ public interface Generator { } default Generator flatMap(Function> action) { - return this.genFlatmap(rose -> { - Generator> generator = (random, size) -> - rose.fmap(action).fmap(g -> g.generate(random, size)); - return generator.genFmap(RoseTree::join); - }); + return (random, size) -> { + return RoseTree.join(this.generate(random, size).fmap(action).fmap(g -> g.generate(random, size))); + }; } } -- cgit v1.2.3