azavea/geotrellis — pull request #210 by joshmarcus (2012-10-10 14:54:22+00:00)
Title: Add new simple syntax for creating operations. 

This pull request adds a new syntax for transforming a function into an operation. It includes op function(s) in the geotrellis package and plus tests. It also moves some test packages around to empty out the now abandoned geotrellis.op namespace, which is being reused as the set of overloaded functions geotrellis.op().

The new syntax:

If you define a function that returns a literal value, an operation to be executed, or a StepResult (indicating success or failure) the function can be turned into an operation by passing it to the op function.

For example,

1) A literal value, e.g.

val plusOne = op { (i:Int) => i + 1 }

2) An operation to be executed next:

val localPlusOne ( (r:Raster, i:Int) => local.Add(r,i + 1) )

3) Or a StepResult (which indicates success or failure)
val plusOne = op { (i:Int) => Result(i + 1) }

This works for methods with up to 4 arguments, but we can extend as far as we want. Example:

val sumOp = op { (a:Int, b:Int, c:Int) => a + b + c }