Last active
April 20, 2017 09:40
-
-
Save mihirk/bbaf5dd73abc6b545f4d20cdcd015257 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import java.util.function.Function; | |
public class WeirdLinkedList { | |
public static Function<Boolean, Object> cons(Object head, Object tail) { | |
return (Boolean cond) -> cond ? head : tail; | |
} | |
public static Object nth(Function<Boolean, Object> list, Integer n) { | |
return n == 0 ? list.apply(true) : nth((Function<Boolean, Object>) list.apply(false), n - 1); | |
} | |
public static void printList(Function<Boolean, Object> list) { | |
if (list != null) { | |
System.out.print(list.apply(true)); | |
if (list.apply(false) != null) { | |
System.out.print(","); | |
} | |
printList((Function<Boolean, Object>) list.apply(false)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment