title: How to make your own for-comprehension compliant scala monad?
body: <p>I want to implement my own for-comprehension compatible monads and functors in Scala.</p>
  
  <p>Let's take two stupid monads as an example. One monad is a state monad that contains an "Int" that you can map or flatmap over. </p>
  
  <pre><code>val maybe = IntMonad(5)
  maybe flatMap( a =&gt; 3 * ( a map ( () =&gt; 2 * a ) ) )
  // returns IntMonad(30)
  </code></pre>
  
  <p>Another monad takes does function composition like so...</p>
  
  <pre><code>val func = FunctionMonad( () =&gt; println("foo") )
  val fooBar = func map ( () =&gt; println("bar") )
  fooBar()
  // foo
  // bar
  // returns Unit
  </code></pre>
  
  <p>The example may have some mistakes, but you get the idea.</p>
  
  <p>I want to be able to use these two different types of made up Monads inside a for-comprehension in Scala. Like this:</p>
  
  <pre><code>val myMonad = IntMonad(5)
  for {
      a &lt;- myMonad
      b &lt;- a*2
      c &lt;- IntMonad(b*2)
  } yield c    
  // returns IntMonad(20)
  </code></pre>
  
  <p>I am not a Scala master, but you get the idea</p>