Skip to content

Instantly share code, notes, and snippets.

@rubythonode
Forked from debop/package.scala
Created February 5, 2017 13:01
Show Gist options
  • Save rubythonode/206072aab74820d9cd8a44b9e2d00d4c to your computer and use it in GitHub Desktop.
Save rubythonode/206072aab74820d9cd8a44b9e2d00d4c to your computer and use it in GitHub Desktop.
Port apply, let method in Kotlin Standard library to Scala
/** 모든 수형에 대해 builder 패턴을 제공하기 위해 사용 : Kotlin 의 apply method 와 같다 */
implicit class AnyRefExtension[T <: AnyRef](underlying: T) {
def build(builder: T => T): T = builder(underlying)
def let(procedure: T => Unit): Unit = procedure(underlying)
}
/** 모든 Option 에 대해 Kotlin 의 let 과 같은 기능을 제공한다 */
implicit class OptionExteions[T](underlying: Option[T]) {
def let(procedure: T => Unit): Unit = underlying foreach { procedure }
}
@sankemax
Copy link

doesn't let has the signature of: let[T, U](f: T => U): U?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment