This file contains hidden or 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 onTrades[T](trades: List[Trade])(fn: Trade => T) = | |
Future.traverse(trades) {trade => | |
Future { fn(trade) } | |
} |
This file contains hidden or 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._ | |
type G[A] = Forall[({type f[B] = ((A, B) => B, B) => B})#f] | |
val cons: Forall[({type f[A] = (A, Stream[A]) => Stream[A]})#f] = | |
new Forall[({type f[A] = (A, Stream[A]) => Stream[A]})#f] { | |
def apply[A] = (x, xs) => { println("called cons"); x #:: xs } | |
} |
This file contains hidden or 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._ | |
type List[A] = Forall[({type f[B] = ((A, B) => B, B) => B})#f] | |
val nil: Forall[List] = new Forall[List] { | |
def apply[A] = new List[A] { | |
def apply[B] = (c, n) => n | |
} | |
} |
This file contains hidden or 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
http://twitter.com/#!/dgiffone/status/116857796024213504 | |
http://twitter.com/#!/zeit_geist/status/116847468192333825 | |
http://twitter.com/#!/aloyer/status/116858699934470144 | |
http://twitter.com/#!/mich_ham/status/116878614460514305 | |
http://twitter.com/#!/graven/status/116890930707050496 |
This file contains hidden or 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
/** | |
* |@| is a helper function that helps you accumulate applicative functors. It gives you an ApplicativeBuilder (it's part of | |
* the implementation though) through which you accumulate your applicatives just as you would using the Builder pattern of | |
* the GoF in the OO world. Once you have all the applicatives you can pass it a function that will be applied to all the | |
* values that you have accumulated so far. e.g. | |
*/ | |
scala> (1.some |@| 2.some) apply {_ + _} | |
res1: Option[Int] = Some(3) |
This file contains hidden or 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
val m1 = Map(1 -> Map(1 -> "a", 2 -> "b", 3 -> "c")) | |
val m2 = Map(1 -> Map(2 -> "x"), 2 -> Map(3 -> "d", 5 -> "e")) | |
tojson(m1) |+| tojson(m2) should equal(tojson(m1 |+| m2)) |
This file contains hidden or 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 Cake { | |
type Config | |
def config: Config | |
} | |
trait FooConfig { | |
// ... | |
} | |
trait FooComponent extends Cake { |
This file contains hidden or 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> state[Int, Int](10) | |
res9: scalaz.State[Int,Int] = scalaz.package$State$$anon$1@3bbe242c | |
scala> res9.run(0) | |
res10: (Int, Int) = (0,10) | |
scala> res9 map (_ * 2) | |
res11: scalaz.StateT[scalaz.Id.Id,Int,Int] = scalaz.StateT$$anon$7@31a9253 | |
scala> res11.run(0) |
This file contains hidden or 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
Welcome to Scala version 2.10.0-M7 (Java HotSpot(TM) Client VM, Java 1.7.0_01). | |
Type in expressions to have them evaluated. | |
Type :help for more information. | |
scala> import scalaz._ | |
import scalaz._ | |
scala> import Scalaz._ | |
import Scalaz._ |
This file contains hidden or 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 validAge(age: Int): \/[String, Int] = //.. | |
def validName(name: String): \/[String, String] = //.. | |
(validAge(10).validation.toValidationNEL |@| validName("xxx").validation.toValidationNEL) { (a, n) => //.. } | |
/** | |
I am using the above snippet to accumulate errors using scalaz.Either and Validation. Is there any way to do the above without using Validation, just using Either. I don't like the conversion to Validation which I have to do just to lift the errors into a List for accumulation. | |
**/ |