Created
February 5, 2017 09:34
-
-
Save debop/b27fa426590e098ce04b570f40822771 to your computer and use it in GitHub Desktop.
Port apply, let method in Kotlin Standard library to Scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 모든 수형에 대해 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 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
def build(builder: T => T): T = builder(underlying)
를
def build(builder: T => Unit):T = { builder(underlying); underlying }
로 변경하는 것이 더 정확합니다.