Created
July 22, 2014 15:04
-
-
Save orangy/e3beb9646b996ce48dc4 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
package x | |
fun fn(items: List<String?>) { | |
items.foreach(filter.notNull) { value -> | |
println("$value") | |
} | |
items.foreach(map.indexed) { (index,value) -> | |
println("$index $value") | |
} | |
} | |
object map { | |
object indexed | |
} | |
object filter { | |
object notNull | |
} | |
inline fun <T> Iterable<T>.foreach(_: map.indexed, body: (Int, T) -> Unit) { | |
var index = 0 | |
for (element in this) { | |
body(index++, element) | |
} | |
} | |
inline fun <T : Any> Iterable<T?>.foreach(_: filter.notNull, body: (T) -> Unit) { | |
for (element in this) { | |
if (element != null) | |
body(element) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment