Try Konad. Monads composition API that just works. For OOP developers

Hey guys I would like to invite you to try out this library named Konad.
Leave a star :star: if you find it helpful :grinning:

It aims to provide a simple and OOP-oriented API to compose Monads and Monads-like data structures. Kotlin nullables can be easily composed with it.

Complete usage example in the documentation.
Other use-cases in these articles:

Example of composing nullables:

val foo: Int? = 1
val bar: String? = "2"
val baz: Float? = 3.0f

fun useThem(x: Int, y: String, z: Float): Int = x + y.toInt() + z.toInt()

val result: Int? = ::useThem.curry() 

// or even 

val result: Result<Int> = ::useThem.curry() 
   .on(foo.ifNull("Foo should not be null")) 
   .on(bar.ifNull("Bar should not be null")) 
   .on(baz.ifNull("Baz should not be null"))

It also has a composable Result class that can be in Ok or Error states.

Result example:

val userResult: Result<User> = ...

    is Result.Ok -> userResult.toString()
    is Result.Errors -> userResult.toList().joinToString(" - ")

// or

   .map{ user -> user.toString() }
   .ifError { errors -> errors.description(errorDescriptionsSeparator = " - ") }

Thank you for your attention. Any feedback would be much appreciated.

1 Like