Created
May 31, 2017 13:53
-
-
Save fgoinai/21b4088a7f9883c22097f33abe08a5b8 to your computer and use it in GitHub Desktop.
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
fun <T: Comparable<T>> eWhen(target: T, tester: Tester<T>.() -> Unit) { | |
val test = Tester(target) | |
test.tester() | |
test.funFiltered?.invoke() ?: return | |
} | |
class Tester<T: Comparable<T>>(val it: T) { | |
var funFiltered: (() -> Unit)? = null | |
infix fun Boolean.then(block: () -> Unit) { | |
if (this && funFiltered == null) | |
funFiltered = block | |
} | |
fun lt(arg: T) = it < arg | |
fun gt(arg: T) = it > arg | |
fun ge(arg: T) = it >= arg | |
fun le(arg: T) = it <= arg | |
fun eq(arg: T) = it == arg | |
fun ne(arg: T) = it != arg | |
fun ct(arg: Collection<T>) = it in arg | |
fun ct(arg: String) = it as String in arg | |
fun nc(arg: Collection<T>) = it !in arg | |
fun nc(arg: String) = it as String !in arg | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment