Last active
August 29, 2015 14:25
-
-
Save javipacheco/08270f5b402f32044987 to your computer and use it in GitHub Desktop.
Paranoia
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List<String> list = Arrays.asList("a", "b", "c", "d"); | |
match(list) | |
.when(nil()).then(() -> System.out.println("Empty List")) | |
.when(headNil(eq("b"))).then(() -> System.out.println("Singleton List of 'b'")) | |
.when(headNil(any())).then(head -> System.out.println("Singleton List of " + head)) | |
.when(headTail(any(), any())).then( | |
(head, tail) -> System.out.println("head: " + head + " Remaining: " + tail)) | |
.doMatch(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val list = List("a", "b", "c", "d") | |
list match { | |
case Nil => println("Empty List") | |
case List("b") => println("Singleton List of 'b'") | |
case List(head) => println("Singleton List of " + head) | |
case head :: tail => println("head: " + head + " Remaining: " + tail) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment