This re-styles your sublime text sidebar to be dark, it fits default Monokai theme.
Save the Default.sublime-theme file into packages/Theme - Default, make a backup of your original if you want to be able to go back easily.
Based on:
implicit class JsonOps(json: Seq[_]){ | |
def /(label: String): Seq[_] = json flatMap { | |
case s: Seq[_] => s / label | |
case m: Map[String@unchecked,_] => m.get(label).toSeq | |
case other => Nil | |
} | |
def as[T] = json.headOption.map(_.asInstanceOf[T]) | |
} | |
// value-level pattern matching | |
(1,"test", Person("Chris")) match { | |
case (x, s: String, t: Person) => doSomething(x) | |
} | |
//--------------------- | |
// type-level pattern matching |
case class Person(name: String, livesAt: Int, isRich: Boolean ) | |
case class Address(city: String) | |
// main | |
println( showPerson(1) ) | |
println( showPerson(2) ) | |
// Blocking | |
object DAO{ | |
// Sample data coming from Database |
type -> [L, R] = ( L, R ) | |
object -> { | |
def apply[L, R]( l: L, r: R ) = ( l, r ) | |
def unapply[L, R]( t: ( L, R ) ) = Option( t ) | |
} | |
// usage | |
def foo(t: Int -> String -> Double) = t match { case i -> s -> d => … } | |
foo( 1 -> "x" -> 1.1 ) |
// error message not helpful | |
scala> class SomeTypeClass[T] | |
scala> case class Foo(s: String) | |
scala> implicit def fooTC(implicit ev: SomeTypeClass[String]) = new SomeTypeClass[Foo] | |
scala> implicitly[SomeTypeClass[Foo]] | |
<console>:15: error: could not find implicit value for parameter e: SomeTypeClass[Foo] | |
implicitly[SomeTypeClass[Foo]] | |
^ |
sealed trait AnnotatedString { | |
def ++( other: AnnotatedString ) = Concat( this, other ) | |
def mkString( codes: Vector[String] = Vector() ): String = this match { | |
case Plain( s ) => s | |
case Concat( left, right ) => left.mkString( codes ) ++ right.mkString( codes ) | |
case Modify( s, f ) => f( s.mkString( codes ) ) // FIXME: this probably messes with the ansi codes | |
case Colored( code, s ) => code ++ s.mkString( codes :+ code ) ++ Console.RESET ++ codes.mkString | |
} | |
def map( f: String => String ) = Modify( this, f ) | |
} |
// usage example | |
import ai.x.generic.BoundLens.ImplicitBoundLens | |
case class Outer( inner: Inner, s: String ) | |
case class Inner( i: Int ) | |
val o = Outer(Inner(5), "foo") | |
o.lens(_.s).set("bar") | |
.lens(_.inner.i).modify(_+1) // .lens calls can be chained nicely | |
// implementation |
addCommandAlias("git", "; sh git") | |
commands ++= Seq( | |
Command.args("sh", "<shell command>") { (state, args) => | |
// using script -q here to maintain ansi colors, see http://stackoverflow.com/a/13587964/467390 | |
val ret = ("script -q /dev/null " ++ args.mkString(" ")) ! | |
state | |
} | |
) |
import scalaz._ | |
import Scalaz._ | |
def monadic[T]( scope: Identity[Unit] => Identity[T] ) = | |
scope( Monad[Identity].point( () ) ).value | |
val z = monadic{ | |
for{ _ <- _ | |
x = 5 | |
y = 6 |
This re-styles your sublime text sidebar to be dark, it fits default Monokai theme.
Save the Default.sublime-theme file into packages/Theme - Default, make a backup of your original if you want to be able to go back easily.
Based on: