Last active
March 17, 2023 13:26
-
-
Save s1monw1/e9d052e3d33ce7ee6b2a84f8bd58d057 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class PrintingScope( | |
val separator: String = "________________" | |
) | |
context(PrintingScope) | |
fun <K, V> Map<K, V>.customPrint() { | |
forEach { (k, v) -> | |
println("K: $k") | |
println("V: $v") | |
println(separator) | |
} | |
} | |
// usage | |
val mapping = mapOf("a" to 1, "b" to 2, "c" to 3) | |
val scope = PrintingScope() | |
with(scope) { | |
mapping.customPrint() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment