Last active
December 15, 2015 02:09
-
-
Save ryoppy/5185306 to your computer and use it in GitHub Desktop.
いろんなスニペット置き場
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
// SeqをMapに | |
// Seq(1,2,3) => Map(1 -> 2, 2 -> 3, 3 -> 4) | |
Seq(1, 2, 3).flatMap { i => | |
Map(i -> (i + 1)) | |
}.toMap | |
// SomeにnullいれてもNoneにはならない | |
Some(null) == None // false | |
Option(null) == None // true | |
// 簡単な正規表現マッチ | |
val urlPattern = """^([0-9]*?)@.*$""".r | |
val urlPattern(num) = "123@345" // num = 123 | |
// ListBufferのメモ | |
val lb = scala.collection.mutable.ListBuffer.empty[Int] | |
lb += 1 | |
println(lb) | |
lb.clear | |
println(lb, lb.isEmpty) | |
// 何か詰めるだけのList管理object | |
object FooIds { | |
var ids = List.empty[Int] | |
def add(id: Int): Unit = ids = id :: ids | |
def contains(id: Int): Boolean = ids.contains(id) | |
def replace(newIds: List[Int]): Unit = ids = newIds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment