Theoretical appliance for reflection may produce ...
# language-proposals
i
Theoretical appliance for reflection may produce cleaner code
Copy code
fun main(args: Array<String>) {

	fun length(s: String) = s.length
	fun isOdd(x: Int) = x % 2 != 0
	
	//Now
	val oddLength = compose(::isOdd, ::length)

	// Pipeline operator
	// no parenthesis and no need to define complicated compose fun
	val oddLength == ::length |> ::isOdd

	val strings = listOf("a", "ab", "abc")
	println(strings.filter(oddLength)) // Prints "[a, abc]"
}

fun <A, B, C> compose(f: (B) -> C, g: (A) -> B): (A) -> C {
	return { x -> f(g(x)) }
}