コード例 #1
0
        public void TestPush()
        {
            int value = Generator.GetInt32();

            var stack = ImmutableTreeStack.Create <int>();

            Assert.Empty(stack);

            // Push doesn't change the original stack
            stack.Push(value);
            Assert.Empty(stack);

            stack = stack.Push(value);
            Assert.Single(stack);
            Assert.Equal(value, stack.Peek());
            int[] expected = { value };
            int[] actual   = stack.ToArray();
            Assert.Equal(expected, actual);

            // Test through the IImmutableStack<T> interface
            IImmutableStack <int> immutableStack = stack;

            immutableStack.Push(Generator.GetInt32());
            Assert.Equal(expected, immutableStack);

            int nextValue = Generator.GetInt32();

            immutableStack = immutableStack.Push(nextValue);
            Assert.Equal(new[] { nextValue, value }, immutableStack);
        }
コード例 #2
0
ファイル: MayBe.cs プロジェクト: sk8tz/DevExpress.Mvvm.Free
        static IImmutableStack <T> GetNextElementInHierarchyCore <T>(IImmutableStack <T> rootStack, Func <T, IList <T> > getChildren, Func <IList <T>, T, int> indedOf, bool skipChildren) where T : class
        {
            var currentElement = rootStack.Peek();
            var children       = getChildren(currentElement);

            if (!skipChildren && children.Any())
            {
                return(rootStack.Push(children.First()));
            }

            var parents = rootStack.Pop();
            var parent  = parents.FirstOrDefault();

            if (parent == null)
            {
                return(rootStack);
            }

            var neighbors = getChildren(parent);
            var index     = indedOf(neighbors, currentElement);

            if (index < neighbors.Count - 1)
            {
                return(parents.Push(neighbors[index + 1]));
            }

            return(GetNextElementInHierarchyCore(parents, getChildren, indedOf, skipChildren: true));
        }
コード例 #3
0
        /// <summary>
        /// A test for Empty
        /// </summary>
        /// <typeparam name="T">The type of elements held in the stack.</typeparam>
        private void EmptyTestHelper <T>() where T : new()
        {
            IImmutableStack <T> actual = ImmutableStack <T> .Empty;

            Assert.NotNull(actual);
            Assert.True(actual.IsEmpty);
            AssertAreSame(ImmutableStack <T> .Empty, actual.Clear());
            AssertAreSame(ImmutableStack <T> .Empty, actual.Push(new T()).Clear());
        }
コード例 #4
0
        internal sealed override HarshProvisionerContextBase PushStateCore(Object state)
        {
            if (state == null)
            {
                throw Logger.Fatal.ArgumentNull(nameof(state));
            }

            return(this.With(c => c._stateStack, _stateStack.Push(state)));
        }
コード例 #5
0
        private static IImmutableStack <object> GetLogicalOperationStack()
        {
            IImmutableStack <object> empty = (IImmutableStack <object>)CallContext.LogicalGetData(LogicalOperation.CallContextDataSlotName);

            if (empty == null)
            {
                empty = ImmutableLogicalOperationStack <object> .Empty;
                if (LogicalOperation.IsRunningInAdapter)
                {
                    empty = empty.Push(new object());
                }
                LogicalOperation.UpdateImmutableStack(empty);
            }
            return(empty);
        }
コード例 #6
0
        private DocumentNode CreateDelegationQuery(
            OperationType operation,
            IImmutableStack <SelectionPathComponent> path,
            FieldNode requestedField)
        {
            if (!path.Any())
            {
                path = path.Push(new SelectionPathComponent(
                                     requestedField.Name,
                                     Array.Empty <ArgumentNode>()));
            }

            FieldNode current = CreateRequestedField(requestedField, ref path);

            while (path.Any())
            {
                path    = path.Pop(out SelectionPathComponent component);
                current = CreateSelection(current, component);
            }

            var usedVariables = new HashSet <string>();

            _usedVariables.CollectUsedVariables(current, usedVariables);
            _usedVariables.CollectUsedVariables(_fragments, usedVariables);

            var definitions = new List <IDefinitionNode>();

            definitions.Add(CreateOperation(
                                _operationName,
                                operation,
                                new List <FieldNode> {
                current
            },
                                _variables.Where(t =>
                                                 usedVariables.Contains(t.Variable.Name.Value))
                                .ToList()));
            definitions.AddRange(_fragments);

            return(new DocumentNode(null, definitions));
        }
コード例 #7
0
 public static IImmutableStack <T> push <T>(IImmutableStack <T> stack, T value) =>
 stack.Push(value);
コード例 #8
0
ファイル: ImmutableQueue.cs プロジェクト: oflores/confsamples
 public IImmutableQueue <T> Enqueue(T value)
 {
     return(new ImmutableQueue <T>(forwards, backwards.Push(value)));
 }
コード例 #9
0
 public ParserContext AddVariable(ParameterExpression variable)
 {
     return(new ParserContext(ExpectedType, TypeResolver, nameTable.Add(variable.Name, variable), variables.Push(variable)));
 }
コード例 #10
0
        public GameState Do(Covers covers)
        {
            var moves = _moves.Push(covers);

            return(new GameState(moves, CursorPosition));
        }
コード例 #11
0
 public IImmutableStack <Step> AddStep <TStep>(IImmutableStack <Step> steps, TStep step, IGremlinQueryEnvironment environment) where TStep : Step
 {
     return(TryGetAddHandler(typeof(TStep), step.GetType()) is Func <IImmutableStack <Step>, TStep, IGremlinQueryEnvironment, IAddStepHandler, IImmutableStack <Step> > del
         ? del(steps, step, environment, this)
         : steps.Push(step));
 }
コード例 #12
0
 public override IImmutableStack <Step> AddStep <TStep>(IImmutableStack <Step> steps, TStep step, IGremlinQueryEnvironment environment) => steps.Push(step);