Skip to content

Instantly share code, notes, and snippets.

@taitruong
Last active August 29, 2015 13:57
Show Gist options
  • Save taitruong/9786928 to your computer and use it in GitHub Desktop.
Save taitruong/9786928 to your computer and use it in GitHub Desktop.
String, list operation, map, toList
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