Skip to content

Instantly share code, notes, and snippets.

Created December 19, 2012 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4333322 to your computer and use it in GitHub Desktop.
Save anonymous/4333322 to your computer and use it in GitHub Desktop.
Mapping symbols in Ruby, and two ways in Scala.
[ :bradley, :ryan, :sam, :scott ].map { |x| x.to_s.upcase }
// 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment