def user = User.find( "admin" ) //this might be null if 'admin' does not exist def streetName = user?.address?.street //streetName will be null if user or user.address is null // no NPE thrown Eiffel : Contracts Nice : Null type (?String vs String) ?String name = null; int len = name.length(); //Compile error int len = (name == null) ? 0 : name.length(); String name = "Some non-null string"; int len = name.length(); //Compiles
fmap(final F<A, B> f) { return new F<Either<E, A>, Either<E, B>>() { public Either<E, B> f(final Either<E, A> a) { if (a.isLeft()) { return Either.left(a.leftValue); } return Either.right(f.f(a.rightValue)); } }; } B A B A
_1(); Strategy with the Identity Monad public static class Strategy<A> { private final F<P1<A>, P1<A>> parallelStrategy; private Strategy(final F<P1<A>, P1<A>> f) { this.parallelStrategy = f; } ... … public <B> P1<List<A>> parMap(final F<B, A> f, final List<B> bs) ... }