Skip to content

Instantly share code, notes, and snippets.

@cowlike
Created January 5, 2018 21:32
Show Gist options
  • Save cowlike/aae7fbf3fc4f960a8736e0884fe63b8f to your computer and use it in GitHub Desktop.
Save cowlike/aae7fbf3fc4f960a8736e0884fe63b8f to your computer and use it in GitHub Desktop.
Random Kotlin stuff
fun <K> HashMap<K,String>.build() {
for (i in this.keys) {
val x = i.toString()
this.put(i, x)
}
}
/*
fun HashMap<Int,String>.build() {
this.put(0, "0")
for (i in 1..10) {
this.put(i, "$i")
}
}
*/
fun StringBuilder.build(nums: Int): StringBuilder {
append("1..").append(nums)
return this
}
/*
customers = ['c1':[1,2,3], 'c2':[1,2,4], 'c3':[2]]
moreEvens = customers.findAll { c ->
c.value.findAll { it % 2 == 0 }.size > c.value.size / 2 }
*/
val customers = hashMapOf(
"c1" to listOf(1,2,3),
"c2" to listOf(1,2,4),
"c3" to listOf(2))
val moreEvens = customers.filter { c ->
c.value.filter { it % 2 == 0 }.size > c.value.size / 2 }
fun main(args: Array<String>) {
println(StringBuilder().build(5).append("!"))
val moreEvens = customers.filter {
c -> c.value.filter { it % 2 == 0 }.size > c.value.size / 2 }
println(moreEvens)
}
/*
var map = HashMap<Int,String>()
map.put(0, "foo")
map.put(1, "1")
map.build()
println(map)
}*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment