Example #1
0
        // Transforms an IEnumerable into another by specific rules.

        public static IEnumerable <TOut> Transform <TIn, TOut> (this IEnumerable <TIn> input, params EmitterFunc <TIn, TOut> [] rules)
        {
            CloneableEnumerator <TIn> enumerator = new CloneableEnumerator <TIn> (input, 0);

            while (enumerator.MoveNext())
            {
                InputData <TIn> inputData = new InputData <TIn> (input, enumerator);

                foreach (var rule in rules)
                {
                    TOut output;
                    if (rule(inputData.NewContext(), out output) == RuleResult.MatchEmit)
                    {
                        yield return(output);
                    }
                }
            }
        }
Example #2
0
 public InputData(IEnumerable <TIn> input, CloneableEnumerator <TIn> enumerator)
 {
     this.AllValues    = input;
     this.Enumerator   = enumerator;
     this.MatchedRules = new List <IRule <TIn> > ();
 }