public static < I , O > Set < O > map ( final Set < ? extends I > input , final FunctorEx < I , O > functor ) { return new AbstractSet < O > ( ) { @ Override public Iterator < O > iterator ( ) { return new MapIterator < I , O > ( input . iterator ( ) , functor ) ; } @ Override public boolean contains ( Object o ) { I element = functor . deapply ( o ) ; return element == null ? false : input . contains ( element ) ; } @ Override public int size ( ) { return input . size ( ) ; } } ; }
A simple second - order map function for sets