Last active
August 29, 2015 13:57
-
-
Save taitruong/9786928 to your computer and use it in GitHub Desktop.
String, list operation, map, toList
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
object ScalaHackSession { | |
//map and toList | |
val message = "Hello, Scala" //> message : String = Hello, Scala | |
message.map(_ + "-") //> res0: scala.collection.immutable.IndexedSeq[String] = Vector(H-, e-, l-, l-, | |
//| o-, ,-, " -", S-, c-, a-, l-, a-) | |
message.toList //> res1: List[Char] = List(H, e, l, l, o, ,, , S, c, a, l, a) | |
//palindrome: head, reverse, and splitAt | |
val palindrome = "Never odd or even" //> palindrome : String = Never odd or even | |
palindrome.head //> res2: Char = N | |
palindrome.reverse //> res3: String = neve ro ddo reveN | |
palindrome.splitAt(11)._2.reverse //> res4: String = neve r | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment