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
case class Part1(i1: Int, i2: String) | |
case class Part2(i1: String, i2: Int) | |
case class Whole(p1: Part1, p2: Part2) | |
class Tuple2Mapper[Entity,Component1,Tuple1,Component2,Tuple2]( | |
entityFactory: (Component1,Component2) => Entity, | |
entityExtractor: Entity => Option[(Component1,Component2)], | |
component1factory: Tuple1 => Component1, | |
component1extractor: Component1 => Option[Tuple1], | |
component2factory: Tuple2 => Component2, | |
component2extractor: Component2 => Option[Tuple2] |
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 Monoid[M] { | |
def zero: M | |
def add(m1: M, m2: M): M | |
} | |
trait Foldable[F[_]] { | |
def foldl[A, B](as: F[A], z: B, f: (B, A) => B): B | |
} | |
def mapReduce[F[_], A, B](as: F[A], m: Monoid[A]) |
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
package slick | |
/** | |
* This is some code extracted from TimeOut codebase, demonstrating: | |
* - Use of tag typed to avoid mixing session of different DB | |
* - The use of the Reader Monad to compose Actions together and defer the choice of async/sync computation | |
* | |
* I remove the part where we can say if our operation are read only or not (to use different connection), in order to | |
* make things easier. | |
**/ |
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
brew update | |
brew versions FORMULA | |
cd `brew --prefix` | |
git checkout HASH Library/Formula/FORMULA.rb # use output of "brew versions" | |
brew install FORMULA | |
brew switch FORMULA VERSION | |
git checkout -- Library/Formula/FORMULA.rb # reset formula | |
## Example: Using Subversion 1.6.17 | |
# |
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
pbpaste | highlight --src-lang=Scala -O rtf --style molokai --font-size 18 --font Consolas | pbcopy |
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
package com.sport195.api | |
import play.api.libs.json._ | |
import scala.language.experimental.macros | |
object ImplicitConversions { | |
import java.sql.Timestamp | |
import java.sql.Date | |
implicit val x = scala.language.implicitConversions |
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
implicit def MapReader[V,B <: BSONValue](implicit vr: BSONReader[B,V]) = new BSONDocumentReader[Seq[(String, V)]] { | |
def read(bson: BSONDocument): Seq[(String, V)] = { | |
val elements = bson.elements.map { tuple => | |
tuple._1 -> tuple._2.seeAsTry(vr).get | |
} | |
elements | |
} | |
} | |
implicit def MapWriter[V,B <: BSONValue](implicit vw: BSONWriter[V,B]) = new BSONDocumentWriter[Seq[(String, 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 MyApp extends App{ | |
type Scott[V] = EitherT[Option,String,V] | |
type ScottI = Scott[Int] | |
def myf: Int => ScottI = _.point[Scott] | |
def lar: ScottI = for{ | |
x <- myf(4) |
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
// ideal world, where every library has a tmap enabled monadic interface: | |
object Dep1Lib{ | |
def doSomeThing = for{ | |
dep1context <- Implicit[Dep1Context] | |
dep3context <- Implicit[Dep3Context] | |
} yield /* ... do something ... */ | |
} | |
object Dep3Lib{ | |
def doSomeThingElse = for{ |
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
Type-indexed maps (TMap) are data structures that support type-safe, | |
constant time lookups of elements by their type. They are unordered, | |
allow structural typing and can be used as composable records. Unlike | |
HList-based implementations as in Shapeless, TMaps are implemented | |
using subtyping, which leads to pretty readable types and error messages. | |
TMap types can easily be written by hand. | |
TMaps are a perfect fit for monadic dependency injection. They enable | |
the Reader monad to be used for multiple dependencies with zero boiler | |
plate. The combination can be viewed as a partial implementation of |
OlderNewer