cacti is a collection of object-oriented Kotlin primitives.
Principles. These are the design principles behind cacti.
Currently, the only way to use the library is to clone the repository. This is not going to be published until 0.0.1 release.
The library only works with Numeric
objects. So you will
have to wrap a number (Int, Double, Float etc) with Number
which is
Numeric
.
val number: Numeric = Number(256)
To sum two numbers
val result: Numeric = Sum(
Number(5),
Number(10)
) // 15
To multiply two numbers
val result: Numeric = Product(
Number(50),
Number(2)
) // 100
To subtract one number from another
val result: Numeric = Difference(
Number(5),
Number(2)
) // 3
To divide one number by another
val result: Numeric = Quotient(
Number(10),
Number(2)
) // 5
All these accept Numeric
objects in their constructors,
so they are strongly composable
val result: Numeric = Product(
Difference(
Quotient(
Number(100),
Number(2)
),
Difference(
Number(30),
Number(5)
)
),
Number(2)
) // equivalent of (100 / 2 - (30 - 5)) * 2
To get the lowest number of two
val result: Numeric = Minimum(
Number(5),
Number(2)
) // 2
To get the highest number of two
val result: Numeric = Maximum(
Number(5),
Number(2)
) // 5
Ask your questions related to cacti library on Stackoverflow with kotlin-cacti
tag.
Just fork the repo and send us a pull request.