Hidden in koan("Map values can be iterated") is a comment which piqued my interest:
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
// NOTE that the following will not compile, as iterators do not implement "contains" | |
// mapValues.contains("Illinois") should be (true) |
I cracked out the SBT console to have a better look:
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> val myMap = Map("MI" -> "Michigan", "OH" -> "Ohio", "WI" -> "Wisconsin", "MI" -> "Michigan") | |
myMap: scala.collection.immutable.Map[java.lang.String,java.lang.String] = Map(MI -> Michigan, OH -> Ohio, WI -> Wisconsin) | |
scala> val mapValues = myMap.values | |
mapValues: Iterable[java.lang.String] = MapLike(Michigan, Ohio, Wisconsin) |
It seems the comment is a little incorrect (myValues is an Iterable rather than an Iterator) but I get the idea.
No comments:
Post a Comment