Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Last active November 25, 2016 14:36
Show Gist options
  • Select an option

  • Save sliskiCode/9d2ac4fcee5d1a43d028a009eaa835c1 to your computer and use it in GitHub Desktop.

Select an option

Save sliskiCode/9d2ac4fcee5d1a43d028a009eaa835c1 to your computer and use it in GitHub Desktop.
7 things you probably don’t know about Kotlin #9
val prices = listOf(21.8, 232.5, 231.3)
val taxedDiscountedRounded = compose(::taxed, ::discounted, ::rounded)
prices.map(taxedDiscountedRounded)
fun <A, B> compose(f: (A) -> A,
g: (A) -> A,
h: (A) -> B): (A) -> B = { x -> h(g(f(x))) }
fun taxed(value: Double): Double = value * 1.4
fun discounted(value: Double): Double = value * 0.9
fun rounded(value: Double): Double = Math.round(value).toDouble()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment