this has moved to https://web.archive.org/web/20150321014734/https://wiki.scala-lang.org/display/SW/IRC+vs.+Twitter+vs.+Real+Life+name+conversion+chart
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
package test; | |
import java.lang.{reflect => jreflect} | |
import scala.reflect.mirror._ | |
/** | |
* Scala counterpart of java.lang.reflect.InvocationHandler | |
*/ | |
trait InvocationHandler { | |
def invoke(proxy: AnyRef, method: Symbol, args: Array[AnyRef]): AnyRef |
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> def f[A[_] <: Seq[_]](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[_] <: Seq[t] forSome { type t }](f: A[Int]) = f.head | |
f: [A[_] <: Seq[_]](f: A[Int])A | |
scala> def f[A[t] <: Seq[_] forSome { type t}](f: A[Int]) = f.head | |
f: [A[t] <: Seq[_] forSome { type t }](f: A[Int])A |
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> val l = List(10, 100, 1000, 10000) | |
l: List[Int] = List(10, 100, 1000, 10000) | |
scala> l.orElse[Int, Int]{ case i: Int => 34 } | |
res14: PartialFunction[Int,Int] = <function1> | |
scala> res14(0) | |
res15: Int = 10 | |
scala> res14(10) |
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
object Tapper { | |
implicit def anyToTapper[A](obj: A) = new Tapper(obj) | |
} | |
class Tapper[A](obj: A) { | |
def tap(code: A => Unit): A = { | |
code(obj) | |
obj | |
} | |
} |
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> trait YouCantMatchMe | |
defined trait YouCantMatchMe | |
scala> object YesICan extends Traitor[YouCantMatchMe] | |
defined module YesICan | |
scala> def uncatchable_?(any: Any) = any match { | |
| case YesICan(uncatchable) => Some(uncatchable) | |
| case _ => None | |
| } |
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 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 |
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 DateParsers extends RegexParsers { | |
def dateTime(pattern: String): Parser[DateTime] = new Parser[DateTime] { | |
val dateFormat = DateTimeFormat.forPattern(pattern) | |
val dateParser = dateFormat.getParser | |
def jodaParse(text: CharSequence, offset: Int) = { | |
val mutableDateTime = new MutableDateTime | |
val newPos = dateFormat.parseInto(mutableDateTime, text, offset); | |
(mutableDateTime.toDateTime, newPos) | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<scheme name="OxbowSolarizedDark" version="1" parent_scheme="Default"> | |
<option name="LINE_SPACING" value="1.2" /> | |
<option name="EDITOR_FONT_SIZE" value="13" /> | |
<option name="EDITOR_FONT_NAME" value="Consolas" /> | |
<colors> | |
<option name="ADDED_LINES_COLOR" value="" /> | |
<option name="ANNOTATIONS_COLOR" value="2b36" /> | |
<option name="ANNOTATIONS_MERGED_COLOR" value="" /> | |
<option name="CARET_COLOR" value="dc322f" /> |
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
object Tuples { | |
import HLists._ | |
implicit def tuple1ToHList[A](t : Product1[A]) = new { def hlisted : A :: HNil = t._1 :: HNil } | |
implicit def tuple2ToHList[A, B](t : Product2[A, B]) = new { def hlisted : A :: B :: HNil = t._1 :: t._2 :: HNil } | |
implicit def tuple3ToHList[A, B, C](t : Product3[A, B, C]) = new { def hlisted : A :: B :: C :: HNil = t._1 :: t._2 :: t._3 :: HNil } | |
implicit def hListToTuple1[A](h : A :: HNil) = new { def tupled : Tuple1[A] = Tuple1(h.head) } | |
implicit def hListToTuple2[A, B](h : A :: B :: HNil) = new { def tupled : (A, B) = (h.head, h.tail.head) } | |
implicit def hListToTuple3[A, B, C](h : A :: B :: C :: HNil) = new { def tupled : (A, B, C) = (h.head, h.tail.head, h.tail.tail.head) } |