These are chat archives for ThoughtWorksInc/Binding.scala

6th
Dec 2017
But in general the issue with using for/yield is that it turns into a map operation, when you really want a flatMap for what you're doing. So an alternative way would be to do:
models flatMap { model =>
        <h3>
          {model.name}
        </h3>
        <ul>
          {for (i <- model.contents) yield {
          <li>
            {i.toString}
          </li>
        }}
        </ul>
      }
This is only an issue when you're returning a sequence of xml elements from each element in a Vars or some other collection.
Basim Khajwal
@basimkhajwal
Dec 06 2017 17:24
@kahliburke Thanks a lot, I didn't realise the for comprehension was actually using a map operation. In my mind I thought that if it worked for a regular Binding it would also work for a BindingSeq.
Kahli Burke
@kahliburke
Dec 06 2017 18:23
@basimkhajwal In scala a for comprehension is syntactic sugar for chaining flatMap, map -> https://docs.scala-lang.org/tutorials/FAQ/yield.html#translating-for-comprehensions