Given a list of {x,y} datapoints, return a pure function f (from the reals to the reals) such that f[x]==y for every {x,y} in the data. If x is not one of the x-values then return the y-value for the previous point (the one with x-value less than x). If the function gets a value less than that of the first x-value in the data -- i.e., there is no previous point -- then return 0.
For example, given data {{1,20}, {2,10}}, return a pure function that looks like this:
Graph of the function given {{1,20},{2,10}} http://yootles.com/outbox/so/piecewise.png
I wrote something using Function
and Piecewise
that I'll include as an answer but it seems like it might be inefficient, especially for a large list of points.
[UPDATE: My answer may actually be decent now. I'll probably go with it if no one has better ideas.]
To be clear, we're looking for function that takes a single argument -- a list of pairs of numbers -- and returns a pure function. That pure function should take a number and return a number.