concept Gen in category functional programming

appears as: Gen, Gen
Functional Programming with Kotlin

This is an excerpt from Manning's book Functional Programming with Kotlin.

We determined earlier that a Gen<A> was something that knows how to generate values of type A. How could it go about doing this? Well, it could randomly generate these values. Considering that we devoted all of chapter 6 to this topic, it would seem like we’re missing a trick if we don’t use what we learned in that chapter! Thinking back to our example, we provided an interface for a purely functional random number generator, RNG. We then showed how to make it convenient to combine computations that make use of it. If we recall the definition of State, we can simply make Gen a type that wraps a State transition over a random number generator.

Listing 8.5. Define Gen by wrapping a state transition over a random number generator
interface RNG {
    fun nextInt(): Pair<Int, RNG>
}

data class State<S, out A>(val run: (S) -> Pair<A, S>)

data class Gen<A>(val sample: State<RNG, A>)