Add basic support for functional style programming.

Refactored intrusive and non-intrusive versions of functions and test.