This happens when you define mapan overly restrictive signature map[B](f: Pat[A] => Pat[B]). Recall that it is usually assumed that it accepts functions with an arbitrary type of result B, that is, it should be something like:
map[B](f: A => B): <stuff>
Now your understanding for the intermediate helper variable brown
val xs = for {
len <- lPat.bubble
brown = Pat(4, 40, 3)
cantus <- brown.grouped(len)
} yield {
cantus ++ Pat(-1)
}
rewritten using mapin
val xs = lPat.bubble.map(((len) => {
val brown = Pat(4, 40, 3);
scala.Tuple2(len, brown)
})).flatMap(((x$1) => x$1: @scala.unchecked match {
case scala.Tuple2((len @ _), (brown @ _)) =>
brown.
grouped(len).
map(((cantus) => cantus.$plus$plus(Pat(-1))))
}))
.
, map (Pat[A], Pat[Int]) ( (len, brown)) Pat[B] .
. , map map[B](f: Pat[A] => Pat[B]), . map. Pat[X] map f: X => Y Pat[Y] X Y, map.
: ...
, , - - CanPatFrom:
trait CanPatFrom[X, A] extends (X => Pat[A])
...
def map[X, B](f: Pat[A] => X)(implicit cpf: CanPatFrom[X, B]) = {
val pb: Pat[B] = cpf(f(...))
/* do your stuff here with `Pat[B]` instead of
* generic `X`
*/
...
}
, Pat - - ,
CanPatFrom[Pat[A], Pat[A]],CanPatFrom[(Pat[A], Pat[B]), Pat[(A, B)]],CanPatFrom[(Pat[A], Pat[B], Pat[C]), Pat[(A, B, C)]],- ...
map, , , , .