Skip to content

Instantly share code, notes, and snippets.

@SethTisue
Last active November 27, 2018 21:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SethTisue/8977033 to your computer and use it in GitHub Desktop.
Save SethTisue/8977033 to your computer and use it in GitHub Desktop.
Example of `lazy val` inside `implicit class`
// `lazy val` inside `implicit class`
implicit class RichStream[T](s: Stream[T]) {
lazy val circular: Stream[T] =
s #::: circular
}
// in order to make this work with `extends AnyVal`, you have to make the
// lazy val local, as follows:
implicit class RichStream[T](private val s: Stream[T]) extends AnyVal {
def circular: Stream[T] = {
lazy val result: Stream[T] = s #::: result
result
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment