| Pattern 16 | Function Builder |
Intent
To create a function that itself creates functions, allowing us to synthesize behaviors on the fly
Overview
Sometimes we’ve got a function that performs a useful action, and we need a function that performs some other, related action. We might have a vowel? predicate that returns true when a vowel is passed in and need a consonant? that does the same for consonants.
Other times, we’ve got some data that we need to turn into an action. We might have a discount percentage and need a function that can apply that discount to a set of items.
With Function Builder, we write a function that takes our data or function (though, as we’ve seen, the distinction between functions and data is blurry) and uses it to create ...
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.
Read now
Unlock full access