A list can be iterated as follows:
scala> val thrill = "Will" :: "fill" :: "until" :: Nil val thrill: List[String] = List(Will, fill, until) scala> thrill.map(s => s + "y") val res14: List[String] = List(Willy, filly, untily) The above code first creates a list and then the second command creates a map with an iterable called as 's', the map creates a new string from 's' by appending the char 'y'.
However, I do not understand the following iteration process:
scala> thrill.sortWith((s,t) => s.charAt(0).toLower < t.charAt(0).toLower) val res19: List[String] = List(fill, until, Will) Does the tuple (s,t) take two elements of thrill at once and compares them? How is sorting performed exactly using this syntax/function?
没有评论:
发表评论