Came onto this usual situation where I need to run quite a large number of time the same method on different data set, with some common parameters. An elegant way of doing that, rather than re-specifying the same parameters over and over again, is a method factory (not to be confused with factory method).

Method factory is based on closure so most languages supporting closure should support it.

In C# it goes this way:

private static Func<Spaghetti[], bool> CreateSpaggethiFinder(
ISpagghetiComparer compare, Spaghetti referenceSpaghetti)
{
return ((checkTheseSpaghetti, lookForThisComparisonResult) =>
{
return checkTheseSpaghetti.Any(spaghetti => compare(referenceSpaghetti, spaghetti)) == lookForThisComparisonResult;
});
}


and then you use it that way:

var spaghettiFinder = CreateSpaghettiFinder(new DefaultSpaghettiComparer(), someSpaghettiYouFoundSomewhere);

if (spaghettiFinder(someFormOfSpaghettiBowl, 0))
yeahTheSpaghettiIsTheeeeere();


Cool!