Last active
December 24, 2015 06:59
-
-
Save f81/6760622 to your computer and use it in GitHub Desktop.
第11章:ScalaのSeqリファレンス ref: http://qiita.com/f81@github/items/75c616a527cf5c039676
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> Seq(1, 2, 3)(2) | |
res0: Int = 3 |
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> Seq(1, 2, 3) isDefinedAt (3) | |
res1: Boolean = false | |
scala> Seq(1, 2, 3) isDefinedAt (2) | |
res2: Boolean = true |
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> Seq(1, 2, 3, 2) prefixLength (_ != 3) | |
res15: Int = 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
scala> 4 +: Seq(1, 2, 3) | |
res16: Seq[Int] = List(4, 1, 2, 3) |
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> Seq(1, 2, 3) :+ 4 | |
res17: Seq[Int] = List(1, 2, 3, 4) |
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> Seq(1, 2, 3) padTo (10, 4) | |
res18: Seq[Int] = List(1, 2, 3, 4, 4, 4, 4, 4, 4, 4) |
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> Seq(1, 2, 3) patch (1, Seq(4, 5, 6), 2) | |
res19: Seq[Int] = List(1, 4, 5, 6) |
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> Seq(1, 2, 3) updated (2, 4) | |
res20: Seq[Int] = List(1, 2, 4) |
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> Seq(4, 1, 5, 2, 3, 7, 8) sorted | |
res21: Seq[Int] = List(1, 2, 3, 4, 5, 7, 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
scala> Seq(1, 2, 3) reverse | |
res22: Seq[Int] = List(3, 2, 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> Seq(1, 2, 3) startsWith Seq(1, 2) | |
res23: Boolean = true | |
scala> Seq(1, 2, 3) startsWith Seq(2, 3) | |
res24: Boolean = false |
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> Seq(1, 2, 3) endsWith Seq(2, 3) | |
res25: Boolean = true | |
scala> Seq(1, 2, 3) endsWith Seq(1, 2) | |
res26: Boolean = false |
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> Seq(1, 2, 3) length | |
res3: Int = 3 |
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> Seq(1, 2, 3) contains (3) | |
res27: Boolean = true | |
scala> Seq(1, 2, 3) contains (4) | |
res28: Boolean = false |
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> Seq(1, 2, 3, 4, 5) containsSlice Seq(3, 4) | |
res29: Boolean = true | |
scala> Seq(1, 2, 3, 4, 5) containsSlice Seq(4, 4) | |
res30: Boolean = false |
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> Seq(1, 2, 3) intersect Seq(2, 3, 4, 5, 6) | |
res28: Seq[Int] = List(2, 3) |
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> Seq(2, 3, 4, 5, 6) diff Seq(1, 2, 3) | |
res30: Seq[Int] = List(4, 5, 6) |
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> Seq(2, 3, 4, 5, 6) union Seq(1, 2, 3) | |
res31: Seq[Int] = List(2, 3, 4, 5, 6, 1, 2, 3) |
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> Seq(2, 3, 4, 5, 6, 2, 3) distinct | |
res32: Seq[Int] = List(2, 3, 4, 5, 6) |
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> Seq(1, 2, 3) lengthCompare (2) | |
res4: Int = 1 | |
scala> Seq(1, 2, 3) lengthCompare(3) | |
res5: Int = 0 | |
scala> Seq(1, 2, 3) lengthCompare (4) | |
res6: Int = -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> Seq(1, 2, 3) indices | |
res7: scala.collection.immutable.Range = Range(0, 1, 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
scala> Seq(1, 2, 3, 2) indexOf (2) | |
res8: Int = 1 | |
scala> Seq(1, 2, 3, 2) indexOf (4) | |
res9: Int = -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> Seq(1, 2, 3, 2) lastIndexOf (2) | |
res10: Int = 3 |
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> Seq(1, 2, 3, 2, 3) indexOfSlice Seq(2, 3) | |
res11: Int = 1 | |
scala> Seq(1, 2, 3, 2, 3) indexOfSlice Seq(2, 2) | |
res12: Int = -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> Seq(1, 2, 3, 2, 3) lastIndexOfSlice Seq(2, 3) | |
res13: Int = 3 |
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> Seq(1, 2, 3, 2, 3) indexWhere (_ == 2) | |
res14: Int = 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment