anchor.diff:  
   	def isDefined: Boolean
   
  -	def map[B](f: A=>B): Option[B] = flatMap(x => Some(f(x)))
  +	def map[B](f: A=>B): Option[B] =
  +    flatMap(x => Some(f(x)))
   
  -	def flatMap[B](f: A=>Option[B]): Option[B] = if(isDefined) f(value) else None
  -}
  +	def flatMap[B](f: A=>Option[B]): Option[B] =	
  +    if(isDefined) f(value) else None
  +    }
   
   ----
   As you may have already guessed, the scala library already implements this function, but lets analyse it any way: `flatMap` is very similar to our last definition to `map`, but since the provided effectful function `f` is already giving us an `Option` then we do not need to wrap it. Also notice that we redefined `map` in terms of our new `flatMap`, clever right?
   
   Now this new mechanism will allow us to combine effectful functions! (functions that return a functor instead of a pure value).
  -
   [source,scala]
   ----
  -val f: Int => Int = x => x + 5
  -val filter10: Int => Option[Int] = x => if (x > 10) Some(x) else None
  -val sumIfMoreThan10: Int => Option[Int] = x => filter10(x).map(f)
  -val sumIfPositive: Int => Option[Int] = x => if (x > 0) Some(f(x)) else None
  -val total: Int => Option[Int] = x => sumIfPositive(x).flatMap(sumIfMoreThan10)
  +val f: Int => Int = 
  +x => x + 5
  +val filter10: Int => Option[Int] =
  +x => if (x > 10) Some(x) else None
  +val sumIfMoreThan10: Int => Option[Int] =
  +x => filter10(x).map(f)
  +val sumIfPositive: Int => Option[Int] =
  +x => if (x > 0) Some(f(x)) else None
  +val total: Int => Option[Int] =
  +x => sumIfPositive(x).flatMap(sumIfMoreThan10)
   total(6)
   > Option[Int] = Some(16)
   total(-1)
  
positive.code: = Side Effects and How To Deal With Them The Cool Way, Part 2: Monads Introduction
  
  :published_at: 2016-10-31
  :hp-tags: monad
  
  :hp-image: https://prismic-io.s3.amazonaws.com/lunatech%2F63f8716c-161c-4613-b1bd-004ec8af96e0_laptop-op-schoot-veroorzaakt-tijdelijke-onvruchtbaarheid.jpg
  
  In http://www.lunatech.com/blog/WASQJiQAANmjwKxf/side-effects-and-how-to-deal-with-them-the-cool-way-part-1-pure-fonctions-and-functors[part 1] of this series we learnt how to decouple the code that deals with side effects from our pure functions by using functors (Any type constructor which implements the map function). Now lets see how we can extend our functors so that we can sequence computations that each fall under the indeterminism of side effects.
  
  == Function Composition And a Slight Issue
  
  Remember that we mentioned that the `Option[A]` type in the standard library of scala is a functor, that actually handles the side effect of possible missing values. Now lets create two pure functions to compute integers:
  
  [source,scala]
  ----
  val f: Int => Int = 
  
negative.code: found   : Int => Option[Int] required: ? => Int 
  f compose filter
  ----
  On this case our `map` function from our functor can help us:
  [source,scala]
  ----
  val sumIfMoreThan10: Int => Option[Int] =	x => filter10(x).map(f)
  