concept sequence in category kotlin

appears as: sequence, sequences, sequence, The sequences, The sequence
Functional Programming with Kotlin

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

Functional programming is an alternative style to the imperative that addresses the problems mentioned above. In this chapter we will be looking at a simple example where a piece of imperative code with side effects (we’ll understand what that means shortly) is transformed into the functional style by a sequence of refactoring steps. The eradication of these side effects is one of the core concepts behind functional programming, and so is one of the highlights of this chapter. We will understand the dangers these effects pose and see how to extract them from our code, bringing us back to the safe place of simplicity where we departed from when we initially set out on our journey.

The sequence and traverse combinators should be pretty familiar to you by now, and your implementations of them from previous chapters are probably all very similar. Implement them once and for all on Monad<F>.

The Joy of Kotlin

This is an excerpt from Manning's book The Joy of Kotlin.

The constants function produces the set of limit values (such as Int.MIN_VALUE, 0 and INT.MAX_VALUE for integers). Most often, you’ll make it return an empty list. The random function returns a sequence of randomly created instances.

Write a package-level function called sequence that combines a List<Option<A>> into an Option<List<A>>. It’ll be a Some<List<A>> if all values in the original list are Some instances, or a None<List<A>> if there is at least one None in the list. Here’s its signature: