This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.higherKinds | |
def sequence[A, M[X] <: TraversableOnce[X]](in: M[Monad[A]])(implicit cbf: CanBuildFrom[M[Monad[A]], A, M[A]]): Monad[M[A]] = { | |
val unit = Monad(cbf(in)) | |
in.foldLeft(unit){ | |
(mba, ma) => for (ba <- mba; a <- ma) yield ba += a | |
}.map(_.result()) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def square[Element, IT[_] <: Iterable[Element], That](it: IT[Element]) | |
(implicit bf: CanBuildFrom[IT[Element], Element, That], | |
num: Numeric[Element]): That = { | |
val b = bf.apply(it) | |
b.sizeHint(it) | |
it.foreach(elem => b += num.times(elem,elem) ) | |
b.result() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\setenv LESS '-iMSx4FXRe' | |
\pset pager always | |
\pset null ¤ | |
\pset linestyle unicode | |
\pset border 2 | |
-- Returns query time cost with each order | |
\timing | |
-- Returns more information on errors |
NewerOlder