
Offers Scala's PartialFunction, enabling partial application of functions with chaining capabilities for complex logic, and supports operations with arrays, results, or nullable types.
This library provides Scala's PartialFunction and a set of functions that take it as an argument in Kotlin.
Partial functions are those that might not provide an answer for every possible input, unlike total functions which offer a result for each input.
Add the dependency to your project:
dependencies {
implementation("com.jsoizo:partial-function-kt:0.1.1")
}To define a PartialFunction
val devide = partialFunction<Int, Int>(
{ it != 0 }, // idDefinedAt: Checks if a value is contained in the function's domain
{ 42 / it } // apply: Apply the body of this function to the argument
)To chain PartialFunctions for complex logic
val add100 = partialFunction<Int, Int>(
{ it >= 0 },
{ it + 100 }
)
val devide42AndAdd100 = devide42 andThen add100
val devide42OrAdd100 = devide42 orElse add100To use the defined PartialFunction with Array, Result, or Nullable operations
val numbers = listOf(1, 2, 0, -4, -3)
val collected = numbers.collect(devide42AndAdd100)
// listOf(142, 121, -10, -14)This project is licensed under the MIT License.
This library provides Scala's PartialFunction and a set of functions that take it as an argument in Kotlin.
Partial functions are those that might not provide an answer for every possible input, unlike total functions which offer a result for each input.
Add the dependency to your project:
dependencies {
implementation("com.jsoizo:partial-function-kt:0.1.1")
}To define a PartialFunction
val devide = partialFunction<Int, Int>(
{ it != 0 }, // idDefinedAt: Checks if a value is contained in the function's domain
{ 42 / it } // apply: Apply the body of this function to the argument
)To chain PartialFunctions for complex logic
val add100 = partialFunction<Int, Int>(
{ it >= 0 },
{ it + 100 }
)
val devide42AndAdd100 = devide42 andThen add100
val devide42OrAdd100 = devide42 orElse add100To use the defined PartialFunction with Array, Result, or Nullable operations
val numbers = listOf(1, 2, 0, -4, -3)
val collected = numbers.collect(devide42AndAdd100)
// listOf(142, 121, -10, -14)This project is licensed under the MIT License.