Moved general-purpose functional programming code out of the api2 package

Once this stabilizes it might be worth putting it in a seperate module but
for the time being it's convenient to be able to fiddle with.