Skip to content

Instantly share code, notes, and snippets.

@tabdulradi
Last active April 19, 2018 12:48
Show Gist options
  • Save tabdulradi/81105786ef62345855276962d9d45316 to your computer and use it in GitHub Desktop.
Save tabdulradi/81105786ef62345855276962d9d45316 to your computer and use it in GitHub Desktop.
Function that allows values to be discarded in a visible way. Combined with Scalac flags: `-Ywarn-value-discard` (and maybe `-Xfatal-warnings`).
scala> ValueDiscard[Int](5)
scala> ValueDiscard(5)
<console>:12: error: ValueDiscard.type does not take parameters
ValueDiscard(5)
^
object ValueDiscard {
/**
* Function that allows values to be discarded in a visible way.
*
* @tparam T type of the value that will be computed (it won't be inferred,
* must be specified)
* @return function accepting value expression that needs to be computed and
* whose value will be discarded
*/
def apply[T]: (=> T) => Unit = { value =>
val _ = value
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment