davezych / shience

A .NET port(ish) of Github's Scientist library. (https://github.com/github/scientist)
MIT License
9 stars 1 forks source link

.Where() should be chainable #19

Closed MovGP0 closed 8 years ago

MovGP0 commented 8 years ago

It should be possible to chain multiple .Where() clauses on a single Science object. To do so, the Skip property should be refactored to an IList<Func<bool>> rather than an bool:

internal IList<Func<bool>> Skip { get; } = new List<Func<bool>>();
public static Science<TResult> Where<TResult>(this Science<TResult> science, Func<bool> predicate)
{
    science.Skip.Add(predicate);
    return science;
}

The predicate should not be executed immediately, but at the time the Science object gets executed. The .Execute() and .ExecuteAsync() methods should check all conditions and break using

if(science.Skip.Any(reason => reason())) return;
MovGP0 commented 8 years ago

see also #4

davezych commented 8 years ago

Agreed.