Summary

This was an intense chapter. We learned about the concept of working with effects in a way that the knowledge of the effects' structure is outsourced to another abstraction. We looked at three such abstractions.

The Functor allows us to apply a function of one argument to each element stored in the container.

The Applicative (or applicative functor) extends the Functor in a way that it is possible to apply a function of two arguments (and by induction, functions of any number of arguments). We’ve seen that it is possible to choose one of three equally valid sets of primitives that define applicative and derive all of the other methods from these primitives.

We said that this approach of defining a minimal set of primitive functions and the rest of functionality in terms of these primitives is a common approach in functional programming.

The last abstraction we saw was the Traversable (or traversable functor), which allows us to iterate over effects, thus changing their content, but preserving the underlying structure.

We paid special attention to combining applications and later to combining traversable. Having implemented the general methods that allow us to build stacks of arbitrary functors and use these stacks to go straight to the heart, we were able to reuse existing functions that were defined in terms of plain effect-free types.

What we haven't demonstrated, though, is the way that data from one applicative can influence functions that are called deeper in the stack—we just used constant parameters in our examples. The reason we did this is that applications do not support sequencing computations.

In the next chapter, we'll learn about another abstraction that is capable of truly chaining computations—a monad.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.140.197.136