Question: I have a function in a context, (in a Maybe / Option) and I want to pass it a value and get back the return value, directly out of the context.

Let's take an example in Scala :

```
scala> Some((x:Int) => x * x)
res0: Some[Int => Int] = Some(<function1>)

```

Of course, I can do

```
res0.map(_(5))

```

to execute the function, but the result is wrapped in the context.

Ok, I could do :

```
res0.map(_(5)).getOrElse(...)

```

but I'm copy/pasting this everywhere in my code (I have a lot of functions wrapped in Option, or worst, in Either...).

I need a better form, something like :

```
res0.applyOrElse(5, ...)

```

Does this concept of 'applying a function in a concept to a value and immediatly returning the result out of the context' exists in FP with a specific name (I'm lost in all those Functor, Monad and Applicatives...) ?

Answer: 
You can use `andThen` to move the default from the place where you call the function to the place where you define it:

```
val foo: String => Option[Int] = s => Some(s.size)
val bar: String => Int = foo.andThen(_.getOrElse(100))

```

This only works for `Function1`, but if you want a more generic version, Scalaz provides functor instances for `FunctionN`:

```
import scalaz._, Scalaz._

val foo: (String, Int) => Option[Int] = (s, i) => Some(s.size + i)
val bar: (String, Int) => Int = foo.map(_.getOrElse(100))

```

This also works for `Function1`—just replace `andThen` above with `map`.

More generally, as I mention above, this looks a little like `unliftId` on `Kleisli`, which takes a wrapped function `A => F[B]` and collapses the `F` using a comonad instance for `F`. If you wanted something that worked generically for `Option`, `Either[E, ?]`, etc., you could write something similar that would take a `Optional` instance for `F` and a default value.
The getOrElse is most logical way to do it. In regards to copy/pasting it all over the place - you might not be dividing your logic up on the best way. Generally, you want to defer resolving your Options (or Futures/etc) in your code until the point you need to have it unwrapped. In this case, it seems more sensible that your function takes in an an Int and returns an Int, and you map your option where you need the result of that function.