1
0
mirror of https://github.com/DanilaFe/abacus synced 2025-07-14 13:31:56 -07:00
Abacus/core/src/main/kotlin/org/nwapw/abacus/number/NumberUtils.kt
2017-09-01 18:32:41 -07:00

16 lines
584 B
Kotlin

@file:JvmName("NumberUtils")
package org.nwapw.abacus.number
typealias PromotionFunction = java.util.function.Function<NumberInterface, NumberInterface>
typealias PromotionPath = List<PromotionFunction>
typealias NumberClass = Class<NumberInterface>
/**
* Promote a number through this path. The functions in this path
* are applied in order to the number, and the final result is returned.
*
* @param from the number to start from.
*/
fun PromotionPath.promote(from: NumberInterface): NumberInterface {
return fold(from, { current, function -> function.apply(current) })
}