mirror of
https://github.com/DanilaFe/abacus
synced 2024-12-22 07:20:09 -08:00
Create the NumberRangeBuilder utility class.
This commit is contained in:
parent
ba63dd7874
commit
4c94abb18b
|
@ -0,0 +1,24 @@
|
|||
package org.nwapw.abacus.number
|
||||
|
||||
import org.nwapw.abacus.Abacus
|
||||
|
||||
/**
|
||||
* A utility class for creating [NumberRange] instances.
|
||||
*
|
||||
* Unlike a regular [ClosedRange], a NumberRange must have a third parameter,
|
||||
* which is the [Abacus] instance that is used for promotion. However, the ".." operator
|
||||
* is infix, and can only take two parameters. The solution is, instead of returning instances
|
||||
* of NumberRange directly, to return a builder, which then provides a [with] infix function
|
||||
* to attach it to an instance of Abacus.
|
||||
* @property start the beginning of the range.
|
||||
* @property endInclusive the end of the range.
|
||||
*/
|
||||
class NumberRangeBuilder(private val start: NumberInterface, private val endInclusive: NumberInterface) {
|
||||
|
||||
/**
|
||||
* Generate a [NumberRange] with the given instance of [abacus].
|
||||
* @return a new range with the given instance of Abacus.
|
||||
*/
|
||||
infix fun with(abacus: Abacus) = NumberRange(abacus, start, endInclusive)
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user