You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
val plus = runc<Int, Runction<Int,Int,Any,Any>, Any, Any> { a ->
runc { b ->
a+b
}
}
println( plus(2)(7) ) // 2 + 7 = 9val plusTen = plus(10)
println( plusTen(4) ) // 10 + 4 = 14
decoration
val plus = runc<Int, Runction<Int,Int,Int,Int>, Any, Any> { a ->
runc { b ->
decoration( a+b )
}
}
// decoration(it) = it * it val plusFourThenPow = plus(4) decorateLeft { it * it }
println( plusFourThenPow(5) ) // { it * it }( 4 + 5 ) = 81
bind & composite
val plusTwo = { x:Int-> x +2 }
val plusTen = { x:Int-> x +10 }
//val plusTwelve = { x -> plusTen( plusTwo( x ) ) }val plusTwelve = plusTwo composite plusTen //<=> plusTen compositeLeft plusTwo// { x -> println( plusTwelve( x ) ) }.invoke( 6 )
plusTwelve composite ::println bind 6// output: 18
bindOn & compositeOn
val modulo = runc<Int,Runction<Int,Boolean,Boolean,Boolean>,Int,Int> { b ->
runc { a ->
a % b ==0
}
}
val isOdd = modulo(2) compositeOn { not() }
0..9 bindOn
{ toList() } bindOn
{ this::filter bind isOdd } bind ::println
//output: [1, 3, 5, 7, 9]