From 097a33bc2ecaa64a664550ddd62ccd8de47c51d0 Mon Sep 17 00:00:00 2001 From: Ben Culkin Date: Tue, 1 Dec 2020 20:20:27 -0500 Subject: An assortment of changes --- .../java/bjc/functypes/FixpointExample.java | 37 ++++++++++++++-------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'src/example/java') diff --git a/src/example/java/bjc/functypes/FixpointExample.java b/src/example/java/bjc/functypes/FixpointExample.java index 8d3e658..71dab4a 100644 --- a/src/example/java/bjc/functypes/FixpointExample.java +++ b/src/example/java/bjc/functypes/FixpointExample.java @@ -1,17 +1,28 @@ package bjc.functypes; +import static bjc.functypes.Combinators.*; + import java.util.function.*; -public class FixpointExample { - public static void main(String[] args) { - BiFunction, Integer> func - = (input, self) -> { - if (input <= 1) return 1; - else return input * self.apply(input - 1); - }; - - Function factorial = Fixpoints.fix(func); - - for (int i = 0; i < 10; i++) System.out.println(factorial.apply(i)); - } -} +/** + * Examples about how fixpoints work. + * + * @author Ben Culkin + * + */ +public class FixpointExample +{ + /** + * Main method. + * + * @param args Unused CLI args. + */ + public static void main(String[] args) { + Function factorial = Fixpoints.fix((input, self) -> { + if (input <= 1) return 1; + else return input * self.apply(input - 1); + }); + + times(10, andThen(factorial::apply, System.out::println)); + } +} \ No newline at end of file -- cgit v1.2.3