(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
class A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
trait Enum { //DIY enum type | |
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia | |
type EnumVal <: Value //This is a type that needs to be found in the implementing class | |
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values | |
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal | |
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS} | |
val oldVec = get |
// See https://github.com/dadrox/scala.enum for examples in the unit test | |
trait Enum { | |
import java.util.concurrent.atomic.AtomicReference | |
type EnumVal <: Value //This is a type that needs to be found in the implementing class | |
def withName(name: String): Option[EnumVal] = values.find(_.name == name) | |
def withNameIgnoringCase(name: String): Option[EnumVal] = values.find(_.name.equalsIgnoreCase(name)) |
#!/usr/bin/env bash | |
# This is very hacky remedy to following error people using sbt | |
# and 2.10.0-M1 release of Scala are going to see: | |
# | |
# API.scala:261: error: type mismatch; | |
# found : API.this.global.tpnme.NameType | |
# (which expands to) API.this.global.TypeName | |
# required: String | |
# sym.isLocalClass || sym.isAnonymousClass || sym.fullName.endsWith(LocalChild) | |
# |
import scala.reflect.api._ | |
import scala.reflect.runtime._ | |
import scala.reflect.runtime.Mirror._ | |
object Pimps{ | |
implicit def pimp(str:String) = new { | |
def test = println("hello") | |
} | |
} |
class Skeleton(val name:String) { | |
val joints = new ArrayBuffer[Joint]() | |
val jointsByName = new HashMap[String, Joint]() // convenience only | |
var rootJoint:Option[Joint] = None | |
} | |
class Joint { | |
var name:String = "unnamed joint :-(" | |
val relativeTranslation = new Vector3d() // relative to parent |
// flatMap | |
// This code is equivalent to: | |
// option.flatMap(foo(_)) | |
option match { | |
case None => None | |
case Some(x) => foo(x) | |
} | |
// flatten | |
// This code is equivalent to: |
package spray.testkit | |
import spray.util._ | |
import akka.actor.ActorSystem | |
trait JUnitInterface extends TestFrameworkInterface { | |
def failTest(msg: String) = throw new AssertionError(msg) | |
} | |
trait JUnitRouteTest extends RouteTest with JUnitInterface { |
# | |
# Working with branches | |
# | |
# Get the current branch name (not so useful in itself, but used in | |
# other aliases) | |
branch-name = "!git rev-parse --abbrev-ref HEAD" | |
# Push the current branch to the remote "origin", and set it to track | |
# the upstream branch | |
publish = "!git push -u origin $(git branch-name)" |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.