Video: ID – FP in Kotlin with Arrow
Welcome to the series of videos about functional programming in Kotlin with Arrow. Arrow is a library pack with data types and type classes that empower pure functional programming in Kotlin. In this video, we are going to talk about the Id data type. Id is a data type used in Arrow to model pure values. The identity monad can be seen as the ambient monad that encodes the effect of having no effect. It's ambient in the sense that plain pure values are values of Id.
That is to say, that the type Id[A] is just a synonym for A. We can consider values of type A as values of type Id[A] and vice-versa. As we can see in this example, Id is useful when interpreting a polymorphic program, and we want as a result, a value in the current context. Id comes with a lot of combinators and methods such as map, fold, flatMap and many more. Map allows us to transform the inner value of an Id from one value to another. When we have multiple Id values and we want to compute where the possibility that they will be fulfilled, we can use flatMap. flatMap allows us to combine two Id values and with their result, produces a new result. Monad comprehensions delegate to "flatMap()", let us comprehend over the potential value inside the Id, but, they do so in a very Imperative style, where you can have on instruction at a time, in sequence stating what is happening. Monad comprehensions are implemented in Arrow at the top coroutines.
Here the function bind() bind into the left value once flatMap completes. We can use the applicative builder to compute our different values of Id. That are independent from each other. With the applicative builder, we can map or convert into tuples, a set of operations preserving the type information and preserving their type and arity. In the next series of videos, we'll learn about more data types, type classes, and the unified programming model that Arrow proposes. .