Every programming language can represent values that change over time. If you update a counter on each iteration of a loop or each time the user clicks, that’s a variable that changes over time. But from the language’s point of view, that variable just happens to change over time. The language doesn’t know that; only you know that.
With Elm, we can have our cake and eat it too. Just as fold (aka reduce) lets us turn a pure function (like addition) into a quasi-stateful operation (like adding up a list of numbers), we can use fold on signals to manage state over time while keeping the rest of our logic pure. And because the Signal abstraction is so well chosen and well implemented, the code to make that all work is both elegant and familiar.
David Crespo uses live coding and a tour of Elm to guide you to Elm’s aha moment: folding time.
David Crespo is a frontend engineer working on commerce at Braintree.
Comments on this page are now closed.
©2016, O'Reilly Media, Inc. • (800) 889-8969 or (707) 827-7019 • Monday-Friday 7:30am-5pm PT • All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. • email@example.com