Created
September 25, 2012 11:40
-
-
Save mads-hartmann/3781263 to your computer and use it in GitHub Desktop.
Shopping Cart use-case
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
object ShoppingCart { | |
/* | |
* Data has been taken from http://www.freebase.com/view/book/book_edition | |
*/ | |
implicit val mergeableItem = new Mergeable[Book] {} | |
case class Book(name: String, | |
creditedTo: Option[String], | |
publisher: Option[String], | |
publicationYear: Option[Int], | |
binding: Option[String]) | |
def main(args: Array[String]) { | |
var shoppingCart = MergeableListMultiset() | |
shoppingCart = shoppingCart + Book("Brave New Words: The Oxford Dictionary of Science Fiction", Some("Jeff Prucher"), Some("Oxford University Press"), Some(2007), Some("Hardcover")) | |
shoppingCart = shoppingCart + Book("On Lisp", None, Some("Prentice Hall"), Some(1993), Some("Paperback")) | |
shoppingCart = shoppingCart + Book("The Logic of Failure: Why Things Go Wrong and What We Can Do to Make Them Right", None, Some("Perseus Books Group"), Some(1996), Some("Paperback")) | |
shoppingCart = shoppingCart + Book("The Immaculate Conception", None, Some("House of Anansi Press"), Some(2006), None) | |
shoppingCart = shoppingCart + Book("Bluebeard", Some("Kurt Vonnegut, Jr."), Some("Delacorte Press"), Some(1987), Some("Hardcover")) | |
shoppingCart = shoppingCart + Book("On Lisp", None, Some("Prentice Hall"), Some(1993), Some("Paperback")) | |
println("Shopping cart contents") | |
println(shoppingCart.map( (a: Tuple2[Book, Int]) => { | |
val (book, count) = a | |
"item: , count: ".format(book.name, count) | |
})) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment