Skip to content

Instantly share code, notes, and snippets.

var com = com || {};
com.MTVClass1 = function (videoID) {
"use strict";
var self = {};
function bar() {
return "bar" + videoID;
}
function _extend(object, source) {
for (var key in source) {
if (source.hasOwnProperty(key)) {
object[key] = source[key];
}
}
return object;
}
var mtv = (function (mtv) {
def pattern(value: String, consToMatch: String): String = {
val a = "1"
val b = "2"
value match {
case `a` => "one"
case `b` => "two"
case `consToMatch` => "!!!"
case _ => "???"
}
}
trait A {
def m: String
}
trait B extends A {
override def m: String = "b"
def b = "b"
}
trait C extends A {
override def m: String = "c"
def c = "c"
var ll = List(List(1, 2, 3), List(2, 3), List(1), List(9), List(11, 1))
for {
l <- ll
e <- l if l.contains(1)
} yield e // List(1, 2, 3, 1, 11, 1)
import scala.util.Try
val s = Try("100".toInt) // Success(100)
val f = Try("michal".toInt) // Failure(java.lang.NumberFormatException ...)
s.map(_ + 200) // Success(300)
f.map(_ + 200) // Failure(java.lang.NumberFormatException ...)
val a = Some(2)
val b = Some(3)
for {
v1 <- a
v2 <- b //v2 is Int
} yield v1 + v2
for {
v1 <- a
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def ageNextYear(currentAge: Int): Future[Int] = {
Future { currentAge + 1 }
}
def welcome(name: String, age: Int): Future[String] = {
Future { s"$name $age" }
val s = Array(1 ,2, 3) // s: Array[Int] = Array(1, 2, 3)
def testCase(s: Seq[Int]) = s // testCase: TestCase[](val s: Seq[Int]) => Seq[Int]
testCase(s) // res0: Seq[Int] = WrappedArray(1, 2, 3)
s(0) = 7 // res1: Unit = ()
testCase(s) // res2: Seq[Int] = WrappedArray(7, 2, 3)
case class User(name: String, age: Int)
User(name = "Bob", age = 10).copy(age = 40) // User(Bob, 40)