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
bundle:install mvn:org.scala-ide/scala-library/2.9.2.v20120330-163119-949a4804e4-vfinal | |
bundle:install mvn:org.scalaz/scalaz-core_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-effect_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-iteratee_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-concurrent_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-typelevel_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-iterv_2.9.2/7.0.0-M3 | |
bundle:install mvn:org.scalaz/scalaz-xml_2.9.2/7.0.0-M3 |
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
scala> def fanOut[A, B, C](f: Lens[A, B], g: Lens[A, C]): Lens[A, (B, C)] = Lens.lensu[A, (B, C)]({ case (a, (b, c)) => f.set(g.set(a, c), b) }, a => (f.get(a), g.get(a))) | |
fanOut: [A, B, C](f: scalaz.package.Lens[A,B], g: scalaz.package.Lens[A,C])scalaz.package.Lens[A,(B, C)] | |
scala> case class Foo(x: Int, y: Int) | |
defined class Foo | |
scala> val XL = Lens.lensu[Foo, Int]((f, x) => f.copy(x = x), _.x) | |
XL: scalaz.package.Lens[Foo,Int] = scalaz.LensTFunctions$$anon$5@3dfc8f84 | |
scala> val YL = Lens.lensu[Foo, Int]((f, y) => f.copy(y = y), _.y) |
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 scalaz._ | |
/** | |
* Provides type aliases and utilities for working with state disjunctions. | |
* | |
* A state disjunction is a function `S => F[(S, L \/ R)]` wrapped in the StateT and EitherT monad | |
* transformers. | |
* | |
* See `StateDisjunctionT` and `StateDisjunction` for more information. |
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
<plugin> | |
<groupId>net.alchim31.maven</groupId> | |
<artifactId>scala-maven-plugin</artifactId> | |
<version>${scala.plugin.version}</version> | |
<configuration> | |
<recompileMode>incremental</recompileMode> | |
<useZincServer>true</useZincServer> | |
<args> | |
<arg>-target:jvm-1.5</arg> | |
<arg>-deprecation</arg> |
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
scala> val s = MSet() ++ (1 to 20) | |
s: scala.collection.mutable.Set[Int] = Set(5, 9, 15, 16, 18, 14, 19, 2, 20, 6, 1, 13, 4, 12, 7, 3, 8, 17, 11, 10) | |
scala> s.size | |
res16: Int = 20 | |
scala> s foreach { n => if (n % 2 == 0) s -= n } | |
scala> s.size | |
res18: Int = 11 |
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.concurrent.duration._ | |
trait Foo { implicit val timeout = 1 second } | |
trait Bar extends Foo { implicit override val timeout = 2 seconds } |
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
class Age private (val v: Short) extends AnyVal { | |
def isInfant = v < 2 | |
def isToddler = v >= 2 && v <= 4 | |
def isSenior = v >= 50 | |
} | |
object Age { | |
def apply(v: Short): Age = { | |
require(v >= 0 && v < 200, "Must be between 0 and 200") | |
new Age(v) |
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 scalaz._ | |
import Scalaz._ | |
object Fib { | |
type Memo = Map[Int, Int] | |
def stFib(n: Int): State[Memo, Int] = n match { | |
case 0 => State.state(0) | |
case 1 => State.state(1) | |
case n => |
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
trait State[S, A] { | |
val run: S => (S, A) | |
def apply(s: S): (S, A) = | |
run(s) | |
def eval(s: S): A = | |
apply(s)._2 |