Skip to content

Instantly share code, notes, and snippets.

@debop
Created February 5, 2017 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save debop/b27fa426590e098ce04b570f40822771 to your computer and use it in GitHub Desktop.
Save debop/b27fa426590e098ce04b570f40822771 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 }
}
@debop
Copy link
Author

debop commented Feb 5, 2017

def build(builder: T => T): T = builder(underlying)

def build(builder: T => Unit):T = { builder(underlying); underlying }
로 변경하는 것이 더 정확합니다.

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