Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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