All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.IntervalTypeOperations.kt Maven / Gradle / Ivy

The newest version!
package io.github.whathecode.kotlinx.interval


/**
 * Provides generic access to the predefined set of type operators of interval values of type [T] ([valueOperations])
 * and distances between values of type [TSize] ([sizeOperations]).
 */
class IntervalTypeOperations, TSize : Comparable>(
    /**
     * Provide access to the predefined set of operators of [T].
     */
    val valueOperations: TypeOperations,
    /**
     * Provide access to the predefined set of operators of [TSize].
     */
    val sizeOperations: TypeOperations,
    /**
     * Return the distance from a specified value [T] to the additive identity (usually "zero") of [T].
     */
    val getDistanceTo: (T) -> TSize
)


/**
 * Create [IntervalTypeOperations] for intervals with values of type [T] and distances between values of type [TSize].
 *
 * @throws UnsupportedOperationException if [valueOperations] or [sizeOperations] needs to be specified
 * since no default is supported.
 */
inline fun , reified TSize : Comparable> createIntervalTypeOperations(
    /**
     * Specify how to access predefined operators of type [T].
     * For basic Kotlin types, this parameter is initialized with a matching default.
     */
    valueOperations: TypeOperations = getBasicTypeOperationsFor(),
    /**
     * Specify how to access predefined operators of type [TSize].
     * For basic Kotlin types, this parameter is initialized with a matching default.
     */
    sizeOperations: TypeOperations = getBasicTypeOperationsFor(),
    /**
     * A function returning the distance from a specified value [T] to the additive identity (usually "zero") of [T].
     */
    noinline getDistanceTo: (T) -> TSize
) = IntervalTypeOperations( valueOperations, sizeOperations, getDistanceTo )




© 2015 - 2024 Weber Informatics LLC | Privacy Policy