Using Swifts KeyPaths in Higher-Order Functions

How KeyPaths improve map, compactMap, flatMap, and filter

David Piper
Better Programming
Published in
6 min readFeb 2, 2020

--

Photo by Aleksandra Boguslawska on Unsplash

When working with collections like arrays or sets, we can use so-called higher-order functions like map to transform each element of the collection or filter to get a subset of the collection’s elements.

--

--