-
-
Save sam/4333325 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[ :bradley, :ryan, :sam, :scott ].map { |x| x.to_s.upcase } |
This file contains hidden or 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
// Symbols converted to Strings in Scala retain their literal notation | |
// with the leading apostraphe, so we have to drop dat to get the same | |
// output as Ruby. | |
Seq('bradley, 'ryan, 'sam, 'scott).map(_.toString.drop(1).toUpperCase) | |
// Here's a for-comprehension, which doesn't look as nice in the trivial | |
// example, but if you're going to nest maps/filters/etc, can be much | |
// more readable in the complex/compound operations: | |
for(name <- Seq('bradley, 'ryan, 'sam, 'scott)) yield name.toString.drop(1).toUpperCase | |
// Here's an example printing each name to STDOUT with a parallel collection, | |
// using ALL THE CORES! | |
Seq('sam, 'bradley, 'ryan, 'scott).par.foreach { name => println(name.toString.drop(1).toUpperCase) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment