Skip to content

Instantly share code, notes, and snippets.

View efleming969's full-sized avatar

Erick Fleming efleming969

  • Fleming Services, LLC
  • Frankfort, KY
View GitHub Profile
@kings13y
kings13y / BowlingKataRunner.scala
Created March 23, 2011 16:35
Sample solution to standard bowling kata (http://codingdojo.org/cgi-bin/wiki.pl?KataBowling) using Scala pattern matching and extractors
// Idiomatic solution using extrators
// Extractors allow us to bind parameters to an object and are usable in pattern matches to see if a pattern can apply to the params submitted.
// Note this is simialr to case classes, but works against an Object (which are like 'static' classes in Java). Also it incurs some performance penalties
// as opposed to using case classes
class BowlingForExtractors() {
def score(bowls:List[Int]) = scoreFrames(bowls).slice(0,10).sum // take the first 10 elements from the List and sum them..any additional elements are the result of additional strikes
def scoreFrames(bowls:List[Int]) : List[Int] = bowls match {
case Nil => List(0)