Skip to content

Instantly share code, notes, and snippets.

@csoma
Last active January 1, 2016 07:59
Show Gist options
  • Save csoma/8115672 to your computer and use it in GitHub Desktop.
Save csoma/8115672 to your computer and use it in GitHub Desktop.
Scala example of lightweight data modelling - based on https://gist.github.com/amontalenti/8114383
object Main extends App {
val some_items = List(1, 2, 3, 4)
for (item <- some_items)
println(item)
val some_mapping = Map("ST"->"started", "IP"->"in progress", "DN"->"done")
for ((key, value) <- some_mapping)
println(key + "=>" + value)
}
// See it here: http://ideone.com/V9PEEp
// Idiomatic Scala will not use "for" in this case.
// Alternatives:
// some_items.map( println _ )
// some_mapping.map( println _ )
// Other:
// some_mapping.foreach { case(key, value) => println(key + "=>" + value) }
// some_mapping.foreach {item => println(item._1 + "=>" + item._2)}
// some_mapping.keys.foreach( key => println( key + "=>" + some_mapping(key) ))
@jpfuentes2
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment