clipperhouse/gen — pull request #50 by BiggerNoise (2014-06-13 21:21:34+00:00)
Title: Added predicate and predicate operations

- Added a type definition for a predicate which takes the item being generated and defines a TypePredicate func(item Type) bool
- Added member functions on the predicate for And, Or, and Not

I was hand rolling something like what gen makes automatically for a project I was recently working on. By treating the predicate functions as a defined type and defining the And,Or, etc. I was able to produce some very clean looking code:

```` go
if !member.Claims.Any(YearsWindowSelector(endMonth, 1).And(acoEncounter)) {
return *NewRuleResultClinicallyExcluded(ExNoEncounter)
}
if member.Claims.Any(YearsWindowSelector(endMonth, 2).And(examPerformed)) {
return *NewRuleResultIndicated(1)
}

````
Here, YearsWindowSelector() is a function that returns a predicate that filters claims by date. acoEncounter and examPerformed are predicates that are looking at the services rendered for a given claim.

The syntax for Not() is a bit clunky; unfortunately since there's no overloading, the receiver is the only way to differentiate the different predicate methods.

Logistics:
- I wrote tests for 'thing', but not 'other' (they would pretty much be the same). I can add those if you like.
- I did not make the predicate stuff optional. I will take a stab at that if you are otherwise willing to pull this in.
- Locally, I had to change gen/typewriters/genwriter/test/setup.go to reference biggernoise/gen and not clipperhouse/gen. I don't think that you will need (or want) that change if you're evaluating this P/R
- If you accept this, it would probably make sense to change the templates for the other methods so they take predicates. I did not do that with this P/R to avoid gunking it up. I would be happy to do so if you want to pull this in.

Hope that this can make it into your library.