![]() |
|
[Java] Playing With Java 8 Lambdas and Closures. - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Java] Playing With Java 8 Lambdas and Closures. (/showthread.php?tid=5510818) |
Playing With Java 8 Lambdas and Closures. - g4143 - Jan 1, 2017 I decided to see if I could port a simple program which uses lambdas and closures to create a dictionary(it really turns out to be a linked list of anonymous functions and closures) with Java 8. It turns out I'm not a Java pro so it took me a few minutes to figure out a solution and it may not be the best solution. Java 8 solution Code import java.util.Optional;Just for comparison here's the 'almost' same solution but in Chicken Scheme. Code (use srfi-1)Here's two solutions in OCaml. The first is without type annotations and the second has type annotations. OCaml without type annotations. Note this solution is very concise but you still have to juggle the types but its all in your head. Code let empty k = NoneCode type ('a, 'b) dict = 'a -> 'b option |