Skip to Content
Clojure Applied
book

Clojure Applied

by Ben Vandgrift, Alex Miller
August 2015
Intermediate to advanced
220 pages
5h 53m
English
Pragmatic Bookshelf
Content preview from Clojure Applied

Reducing to a Value

The reduce function reduces a collection to a value by repeatedly applying a function to an accumulated value and the next element in the collection, using an optional initial value. The into function is a special case that reduces a collection to another collection instead of a simple value.

For example, in our space simulation, consider computing the total number of moons across all planets in the solar system. We need to first extract the number of moons for each planet (a mapping transformation), then reduce those to a single value (the total) by using the + function. The reduce function is often used to combine a collection transformation with a reduction step.

We can compute the total for a collection of planets using ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Clojure Programming

Clojure Programming

Chas Emerick, Brian Carper, Christophe Grand
Living Clojure

Living Clojure

Carin Meier
Clojure Cookbook

Clojure Cookbook

Ryan Neufeld, Luke VanderHart

Publisher Resources

ISBN: 9781680501476Errata Page