Skip to content

Instantly share code, notes, and snippets.

@ersin-ertan
Created October 9, 2017 02:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ersin-ertan/d29b3fcf9b9923a60a7abb7263bac810 to your computer and use it in GitHub Desktop.
Save ersin-ertan/d29b3fcf9b9923a60a7abb7263bac810 to your computer and use it in GitHub Desktop.
package function
var Function = { function:Function<*> -> val function = function.javaClass.newInstance() as Function<*> }
fun Function(Function:Function<*>):(Function<*>) -> Function<*> = { Function ->
fun Function<*>.Function(Function:Function<*>):Function<*> = (function.Function.javaClass.newInstance() as ((Function<*>) -> Function<*>)?)!!
(Function(Function = function.Function(Function)).Function(Function = function.Function(Function = function.Function(Function = function.Function)(Function))) as Function<*>).Function(Function)
}
@ersin-ertan
Copy link
Author

var Function is a lambda which takes in a function with star projection type, within the the lambdas local scope there is a declaration of a value called function which is a new instance of the input function cast to a Function as star projection(thus this part is redundant)

Within the fun call Function, it takes in a Function call Function of star projection type, thus the same as the lambda. and returns a fun that takes in a arg of type Function star projection and returns a type Function star projection. The input of the fun is captured in the closure. You may start to discover the recursively nested definitions. The fun equates to a lambda which now has the input arg captured, and accepts a Function star projection called Function. Within local scope of the lambda, there is a extension function of type Function star projection on the class Function which takes in a function of type star projection and returns the Function of star projection which equates to the package function.Function variable from defined in the class above on line 1, but we are getting an instance of the class and casting it to a fun of type Function star projection which returns a Function star projection which may be null, but the instance will not be null.

The last line is calling the function(with a named parameter of Function which is the package.Function variable which takes in the Function variable defined in the lambda scope. We call the local fun Function on it, to which we have the named variable Function defined as the same function package.Function variable from before which takes in the same parameter as the two function calls before it, but the difference being that this time we are currying the lambdas local function called Function, to which all of that is cast as a Function of star projection to which we call the local fun Function with the lambdas Function variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment