Skip to content

Instantly share code, notes, and snippets.

@NonCoderF
Last active January 1, 2023 11:01
Show Gist options
  • Save NonCoderF/ff064d11b4e31c4743a0a33631f24837 to your computer and use it in GitHub Desktop.
Save NonCoderF/ff064d11b4e31c4743a0a33631f24837 to your computer and use it in GitHub Desktop.
fun main() {
val fun1: (Int) -> Int = { x -> x + 1 }
val fun2: (String) -> String = { x -> x.reversed() }
val fun3: (List<Int>) -> Int = { x -> x.sum() }
val fun4: (Double) -> Double = { x -> x * x }
val result1: (Int) -> Any = ::fun4::fun3::fun2::fun1
val result2: (Int) -> Any = fun4::fun3::fun2::fun1
val fun5: (Any) -> String = { x -> x.toString() }
val fun6: (String) -> String = { x -> x.capitalize() }
val fun7: (String) -> String = { x -> x.repeat(2) }
val fun8: (String) -> String = { x -> x.substring(1) }
val result3: (Int) -> String = fun8::fun7::fun6::fun5::result1
val result4: (Int) -> String = ::fun8::fun7::fun6::fun5::result2
println(result3(10)) // prints "100.0"
println(result4(10)) // prints "100.0"
}
@NonCoderF
Copy link
Author

It is not a good practice....Just for fun!

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