Why can it be written like this?
Why should it be written like this?
fun log(tag: String)
= fun(target: OutputStream)
= fun(message: Any?)
= target.write("[$tag] $message\n".toByteArray())
fun log(tag: String)
= fun(target: OutputStream)
= fun(message: Any?)
= target.write("[$tag] $message\n".toByteArray())
since you labeled this question currying
, I wonder why you don't know that this is the general Corey way of writing.
log
function takes a tag
parameter and returns an anonymous function that receives the target
parameter, which in turn returns an anonymous function that receives message
. Finally, this function uses the three parameters received earlier to complete the write
operation.
this function needs to be tuned when called, like this:
log(aTag)(aTarget)(aMessage);