This Gist was automatically created by Carbide, a free online programming environment.
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
name := "demoProject" | |
version := "1.0" | |
scalaVersion := "2.11.8" |
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
sealed trait Animal | |
case class Dog(name: String) extends Animal | |
case class Cat(name: String) extends Animal | |
val dogs = List(Dog("pochi"), Dog("gon")) | |
val cats = List(Cat("tama"), Cat("kuro")) | |
val animals: List[Animal] = List(dogs, cats).flatten |
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 com.aerospike.client.policy.ClientPolicy | |
import com.aerospike.client.{AerospikeClient, Bin, Key} | |
object AerospikeIntLongSpec extends App { | |
val policy = new ClientPolicy | |
policy.user = ""; policy.password = "" | |
val client = new AerospikeClient(policy, "127.0.0.1", 3000) | |
val (keyName, binName) = ("budget", "spend") |
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 State { | |
import State._ | |
val seq: Seq[(Double, State)] | |
def next: State = | |
(seq sortWith { (s1, s2) => | |
(s1._1 * randValue) > (s2._1 * randValue) | |
}).head._2 |
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
// stackable trait pattern | |
// http://www.artima.com/scalazine/articles/stackable_trait_pattern.html | |
abstract class IntQueue { | |
def get: Int | |
def put(x: Int) | |
} | |
import scala.collection.mutable.ArrayBuffer |
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
scala> class A[M[_]] | |
warning: there was one feature warning; re-run with -feature for details | |
defined class A | |
scala> class B[M[+_]] | |
warning: there was one feature warning; re-run with -feature for details | |
defined class B | |
scala> class C[M[-_]] | |
warning: there was one feature warning; re-run with -feature for details |
- Main.scala
import scala.annotation.tailrec
object Main extends App {
def f(a: Int): Int = {
a match {
case x if x <= 1 => 1
case x => x * f(x - 1)
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
scala> val a: Option[String] = Some("msg") | |
a: Option[String] = Some(msg) | |
scala> <msg content={a orNull} /> | |
warning: there was one feature warning; re-run with -feature for details | |
res3: scala.xml.Elem = <msg content="msg"/> | |
scala> val a: Option[String] = None | |
a: Option[String] = None |
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 Greeter { | |
val s: String | |
def greet(): String = s"greet! $s" | |
} | |
object Greeter { | |
implicit def convertInt(i: Int): Greeter = new Greeter { val s = i.toString } | |
} | |
import Greeter._ |
NewerOlder