| Pattern 2 | Replacing State-Carrying Functional Interface |
Intent
To encapsulate a bit of state along with program logic so it can be passed around, stored in data structures, and generally treated like any other first-class construct
Overview
In Pattern 1, Replacing Functional Interface, we saw how to replace Functional Interface with higher-order functions, but the instances we looked at didn’t carry around any program state. In this pattern, we’ll take a look at how we can replace Functional Interface implementations that need state using a powerful construct called a closure.
Also Known As
Function Object Functoid Functor
Functional Replacement
Functions in the functional world are part of a powerful construct called a closure. A closure wraps ...
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