Skip to content

Instantly share code, notes, and snippets.

@dabd
Created February 13, 2016 09:22
Show Gist options
  • Save dabd/673ad89c0185ad0c7085 to your computer and use it in GitHub Desktop.
Save dabd/673ad89c0185ad0c7085 to your computer and use it in GitHub Desktop.
class Foo {
val quux = "quux"
def bar(baz: () => Unit): Foo = {
baz()
this
}
}
// I would like to write in fluent style like this but I can't reference the
// previous object in the chain
val qux = (new Foo).bar(() => println(s"${<how to reference new Foo here?>.quux}"))
// So I have to break it into two vals which is ugly
val qux = (new Foo)
val corge = qux.bar(() => println(s"${qux.quux}"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment