reimplemented apply optional to use functor.