IronRuby.Builtins.IListOps.CombinationEnumerator.Each C# (CSharp) Method

Each() public method

public Each ( IronRuby.Runtime.RubyScope scope, BlockParam block ) : object
scope IronRuby.Runtime.RubyScope
block IronRuby.Runtime.BlockParam
return object
            public object Each(RubyScope/*!*/ scope, BlockParam/*!*/ block) {
                int size = _size ?? _list.Count;
                if (size < 0 || size > _list.Count) {
                    return _list;
                }
                var result = new object[size];
                var values = new object[_list.Count];
                _list.CopyTo(values, 0);
                var stack = new Stack<State>();
                stack.Push(new State(0, 0, true));

                while (stack.Count > 0) {
                    var entry = stack.Pop();
                    int i = entry.i;
                    int j = entry.j;

                    if (entry.init && j == result.Length) {
                        object blockResult;
                        if (block.Yield(RubyOps.MakeArrayN(result), out blockResult)) {
                            return blockResult;
                        }
                    } else {
                        if (!entry.init) {
                            i++;
                        }
                        if (i <= values.Length - result.Length + j) {
                            result[j] = values[i];
                            stack.Push(new State(i, j, false));
                            stack.Push(new State(i + 1, j + 1, true));
                        }
                    }
                }
                return _list;
            }
        }
IListOps.CombinationEnumerator