title: Why does a Try work here when the parameter does not expect a Try?
body: <p>I'm reading <a href="http://danielwestheide.com/blog/2013/01/09/the-neophytes-guide-to-scala-part-8-welcome-to-the-future.html" rel="nofollow">The Neophyte's Guide to Scala Part 8: Welcome to the Future</a> and one part of code I'm confused about is this:</p>
  
  <pre><code>import scala.util.Try
  
  object CoffeeSync extends App {
  
    // Some type aliases, just for getting more meaningful method signatures:
    type CoffeeBeans = String
    type GroundCoffee = String
    case class Water(temperature: Int)
    type Milk = String
    type FrothedMilk = String
    type Espresso = String
    type Cappuccino = String
  
    // dummy implementations of the individual steps:
    def grind(beans: CoffeeBeans): GroundCoffee = s"ground coffee of $beans"
    def heatWater(water: Water): Water = water.copy(temperature = 85)
    def frothMilk(milk: Milk): FrothedMilk = s"frothed $milk"
    def brew(coffee: GroundCoffee, heatedWater: Water): Espresso = "espresso"
    def combine(espresso: Espresso, frothedMilk: FrothedMilk): Cappuccino = "cappuccino"
  
    // going through these steps sequentially:
    def prepareCappuccino(): Try[Cappuccino] = for {
      ground &lt;- Try(grind("arabica beans"))
      water &lt;- Try(heatWater(Water(25)))
      espresso &lt;- Try(brew(ground, water))
      foam &lt;- Try(frothMilk("milk"))
    } yield {
      combine(espresso, foam)
    }
  </code></pre>
  
  <p>All of this works fine, but what I'm confused about is why <code>Try</code> works in the For Fomprehension?</p>
  
  <p><code>grind("arabica beans")</code> is supposed to return a value of type <code>GroundCoffee</code> which is a type alias for <code>String</code>.   I get that For Comprehensions are iterating through a Collection and that this gets assigned to one value, and that <code>Try(grind(...))</code> is viewed as a Collection of 1 element so that <code>ground</code> represents the element "unwrapped".</p>
  
  <p>But if that explanation were complete, then I wouldn't get a compile error when I do the following:</p>
  
  <pre><code>// going through these steps sequentially:
    def prepareCappuccino(): Try[Cappuccino] = for {
      // Replaced Try with Seq
      ground &lt;- Seq(grind("arabica beans"))
      water &lt;- Try(heatWater(Water(25)))
      espresso &lt;- Try(brew(ground, water))
      foam &lt;- Try(frothMilk("milk"))
    } yield {
      combine(espresso, foam)
    }
  </code></pre>
  
  <p>This gives me the following:</p>
  
  <pre><code>    &lt;console&gt;:41: error: type mismatch;
   found   : scala.util.Try[CoffeeSync.Cappuccino]
      (which expands to)  scala.util.Try[String]
   required: scala.collection.GenTraversableOnce[?]
             water &lt;- Try(heatWater(Water(25)))
                   ^
  &lt;console&gt;:40: error: type mismatch;
   found   : Seq[Nothing]
   required: scala.util.Try[CoffeeSync.Cappuccino]
      (which expands to)  scala.util.Try[String]
             ground &lt;- Seq(grind("arabica beans"))
                    ^
  </code></pre>
  
  <p>So I guess what I'm really asking is <strong>Why does my <code>Seq[GroundCoffee]</code> get converted into a <code>Seq[Nothing]</code>?</strong>  Thanks for your help.</p>