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
| var com = com || {}; | |
| com.MTVClass1 = function (videoID) { | |
| "use strict"; | |
| var self = {}; | |
| function bar() { | |
| return "bar" + videoID; | |
| } | |
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
| function _extend(object, source) { | |
| for (var key in source) { | |
| if (source.hasOwnProperty(key)) { | |
| object[key] = source[key]; | |
| } | |
| } | |
| return object; | |
| } | |
| var mtv = (function (mtv) { |
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
| def pattern(value: String, consToMatch: String): String = { | |
| val a = "1" | |
| val b = "2" | |
| value match { | |
| case `a` => "one" | |
| case `b` => "two" | |
| case `consToMatch` => "!!!" | |
| case _ => "???" | |
| } | |
| } |
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 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" |
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
| 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) |
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
| 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 ...) |
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
| val a = Some(2) | |
| val b = Some(3) | |
| for { | |
| v1 <- a | |
| v2 <- b //v2 is Int | |
| } yield v1 + v2 | |
| for { | |
| v1 <- 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
| 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" } |
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
| 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) |
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
| case class User(name: String, age: Int) | |
| User(name = "Bob", age = 10).copy(age = 40) // User(Bob, 40) |