Skip to content

Instantly share code, notes, and snippets.

View leedm777's full-sized avatar

David M. Lee leedm777

View GitHub Profile
@leedm777
leedm777 / traits.scala
Created March 13, 2012 13:42 — forked from jbrechtel/traits.scala
Traits in Scala
trait Searchable {
def search(query: SearchQuery): Seq[SearchResults]
}
trait PaginationWithNominalType {
this: Searchable =>
def page(query: SearchQuery, pageSize: Int, pageNum: Int) = {
search(query).grouped(pageSize).toList(pageNum)
}
}
@leedm777
leedm777 / maps.scala
Created March 13, 2012 14:23 — forked from jbrechtel/maps.scala
Scala maps
//create a map
val cars = Map("james" -> "BMW", "ike" -> "Infiniti", "stephen" -> "Buick")
//create a map from an Array
//Scala does not provide a convenience method to do this... :(
val carArray = Array("james", "BMW", "ike", "Infiniti", "stephen", "Buick")
val cars = carArray.grouped(2).toList.map(c => (c.head,c.last)).toMap
//mapping over a map
//transform all string keys to symbols (interned strings)