Skip to content

Instantly share code, notes, and snippets.

@mihirk
Last active April 20, 2017 09:40
Show Gist options
  • Save mihirk/bbaf5dd73abc6b545f4d20cdcd015257 to your computer and use it in GitHub Desktop.
Save mihirk/bbaf5dd73abc6b545f4d20cdcd015257 to your computer and use it in GitHub Desktop.
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