-
-
Save rubythonode/206072aab74820d9cd8a44b9e2d00d4c 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
doesn't let has the signature of:
let[T, U](f: T => U): U
?