RETRACTION ALERT: See the very end for the good news
I might be jumping the gun on this one (I was, see the “Retraction” at the end of this post) but I think I’ve come across my first Scala niggle. Having range support build into a language is really nice, and fair play to Scala for having it. I’m not sure I like the syntax however (and this might be where I’m missing something – please comment if I have). What I mean is this:
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
val someNumbers = Range(0, 10) // gives me a scala.collection.immmutable.Range object which contains every Int from 0 to 9 |
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
val someNumbers = Range(2, 10, 3) // gives me a scala.collection.immmutable.Range object which contains the Ints 2, 5, and 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
someRubyNumbers = (1..5) // gives me a Ruby Range object which contains the Ints 1, 2, 3, 4 and 5 |
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
someRubyNumbers = (1…5) // gives me a Ruby Range object which contains the Ints 1, 2, 3, and 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
val someNumbers = Range(0, 10).inclusive // gives me a scala.collection.immmutable.Range object which contains every Int from 0 to 10 |
Retraction
I just got to the AboutLists Koan. Hidden away in koan("You can create a list from a range") is a sweet little Range literal:
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
val a = (1 to 5).toList |
No comments:
Post a Comment