Unlock This Episode
Our Free plan includes 1 subscriber-only episode of your choice, plus weekly updates from our newsletter.
Introduction
And just like that our views now take a smaller subset of state than the full AppState
, which means the stores that power the views are starting to look a lot more like the reducers that power them.
It’s also worth noting how simple these changes were, and how quick we made them. We merely changed the state that the views operated on to focus in on just what they needed, and then we made sure that the stores we passed to those views were transformed in order to pluck out these values.
Subscribe to Point-Free
Access this episode, plus all past and future episodes when you become a subscriber.
Already a subscriber? Log in
Exercises
It can be useful to produce “read-only” stores that cannot send any actions. Write a
view
that transforms a store that can perform actions into a store that cannot perform actions. What is the appropriate data type to describe theAction
of such a store?In our second episode on algebraic data types, we explored such a transformation.
In our first episode on algebraic data types, we introduced the
Either
type, which is the most generic, non-trivial enum one could make:enum Either<A, B> { case left(A) case right(B) }
In this episode we create a wrapper enum called
CounterViewAction
to limit the counter view’s ability to send any app action. Instead of introducing an ad hoc enum, refactor things to utilize theEither
type.How does this compare to utilizing structs and tuples for intermediate state?
References
Contravariance
Brandon Williams & Stephen Celis • Monday Apr 30, 2018We first explored the concept of the pullback
in our episode on “contravariance”, although back then we used a different name for the operation. The pullback
is an instrumental form of composition that arises in certain situations, and can often be counter-intuitive at first sight.
Let’s explore a type of composition that defies our intuitions. It appears to go in the opposite direction than we are used to. We’ll show that this composition is completely natural, hiding right in plain sight, and in fact related to the Liskov Substitution Principle.
Why Functional Programming Matters
John Hughes • Saturday Apr 1, 1989A classic paper exploring what makes functional programming special. It focuses on two positive aspects that set it apart from the rest: laziness and modularity.
Access Control
AppleThis chapter of the Swift Programming Language book explains access control in depth and how it affects module imports.
Elm: A delightful language for reliable webapps
Elm is both a pure functional language and framework for creating web applications in a declarative fashion. It was instrumental in pushing functional programming ideas into the mainstream, and demonstrating how an application could be represented by a simple pure function from state and actions to state.
Redux: A predictable state container for JavaScript apps.
The idea of modeling an application’s architecture on simple reducer functions was popularized by Redux, a state management library for React, which in turn took a lot of inspiration from Elm.
Composable Reducers
Brandon Williams • Tuesday Oct 10, 2017A talk that Brandon gave at the 2017 Functional Swift conference in Berlin. The talk contains a brief account of many of the ideas covered in our series of episodes on “Composable State Management”.