interface Function { R apply(T t); } interface Functor> { F map(Function f); } class Identity implements Functor> { private final T value; public Identity(T value) { this.value = value; } @Override public Identity map(Function f) { final R result = f.apply(this.value); return new Identity<>(result); } } class Incr implements Immutator { @Override public Integer invoke(Integer param) { return param + 1; } } class Length implements Immutator { @Override public Integer invoke(String param) { return param.length(); } } class Print implements Action { @Override public void call(Object item) { System.out.println(item); } } class MyTest { public static void main(String[] args) { Probably maybeInt = Probably.just(10); maybeInt.act(new Print()); System.out.println(Probably.just(2030).check(new IsModEq(0, 2))); Identity idString = new Identity<>("abc"); Identity idInt = idString.map(String::length); } }