(PUP-1799) add new function api - FOR REVIEW ONLY

This is the first cut of the new Function API - it is for review only at this point even if it is functional, passes its own tests etc. There are a number of TODOs in the logic and some refactoring where constructs grew in complexity and should be made easier to follow (and more performant).

Submitting to get a travis run as well as more eyes on this.