Skip to content

Instantly share code, notes, and snippets.

@priort
Created December 30, 2018 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save priort/87eb24afc9532479e682d1c8e5434547 to your computer and use it in GitHub Desktop.
Save priort/87eb24afc9532479e682d1c8e5434547 to your computer and use it in GitHub Desktop.
class JazzBandSpec extends FlatSpec with Matchers{
"Jazz band closure " should " create a musician closure with access to band set list" in {
val setList = List("Donna Lee", "Dig")
val jazzBandFunctionThatCreatesMusician: List[String] => () => List[String]
= JazzBand.jazzBandThatCreatesMusician
val musicianFunctionThatCanGetBandSetList: () => List[String]
= jazzBandFunctionThatCreatesMusician(setList)
musicianFunctionThatCanGetBandSetList() should be (setList)
//Re-writing the above in a more idiomatic and simplified way
JazzBand.jazzBandThatCreatesMusician(setList)() should be (setList)
}
}
package object JazzBand {
def jazzBandThatCreatesMusician(setList: List[String])
= () => setList
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment