/// <summary> /// Add a delegate/method as a handler /// </summary> /// <typeparam name="TData">Type of data</typeparam> /// <param name="handle">Handle delegate/method</param> /// <returns>A new Executor</returns> public Executor <TDataImplements> AddHandler <TData>(Action <TData> handle) where TData : class, TDataImplements { return(new Executor <TDataImplements>( _allHandlers.Add(Handler <TDataImplements> .From(handle)) )); }
static IEnumerable <Segment> GetGraphKeyImpl(ISymbol symbol, IImmutableList <Segment> acc) { if (symbol == null) { return(acc.Reverse()); } if (symbol is ITypeSymbol) { return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "+")))); } if (symbol is INamespaceSymbol) { if (((INamespaceSymbol)symbol).IsGlobalNamespace) { return(GetGraphKeyImpl(symbol.ContainingSymbol, acc)); } return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, ".")))); } if (symbol is IModuleSymbol) { return(GetGraphKeyImpl(symbol.ContainingSymbol, acc)); } if (symbol is IAssemblySymbol) { return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "|")))); } return(GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "!")))); }
void IScopeManager <T> .EnableScope(T domain) { lock (_sync) { Entry dm; if (_scopeByNames.TryGetValue(domain.Name, out dm)) { dm.Enabled = true; if (!(domain is ISchema)) { Interlocked.Exchange(ref _scopes, _scopes.Add(domain)); } } } }
//BLOCKING IO READ private IImmutableList <ByteString> ReadAhead(int maxChunks, IImmutableList <ByteString> chunks) { if (chunks.Count <= maxChunks && IsActive) { try { var readBytes = _chan.Read(_buffer, 0, _chunkSize); if (readBytes == 0) { //EOF _eofReachedAtOffset = _chan.Position; _log.Debug($"No more bytes available to read (got 0 from read), marking final bytes of file @ {_eofReachedAtOffset}"); return(chunks); } _readBytesTotal += readBytes; var newChunks = chunks.Add(ByteString.Create(_buffer, 0, readBytes)); return(ReadAhead(maxChunks, newChunks)); } catch (Exception ex) { OnErrorThenStop(ex); //read failed, we're done here return(ImmutableList <ByteString> .Empty); } } return(chunks); }
public void Replace(int index, byte opcode) { var original = this[index]; this[index] = opcode; mutations = mutations.Add(new Mutation(index, original, opcode)); }
/// <summary> /// Adds the specified <paramref name="indexer"/> to the <see cref="Indexers"/> list /// </summary> /// <param name="indexer">An <see cref="Indexer"/> to add</param> /// <returns>Returns a reference to the same <paramref name="indexer"/>, allowing other operations to be chained</returns> /// <exception cref="ArgumentException"> /// Throw when this set already contains an indexer with the same <see cref="Indexer.Source"/> /// property value as the <paramref name="indexer"/> being added /// </exception> public Indexer Add([NotNull] Indexer indexer) { if (indexer == null) { throw new ArgumentNullException("indexer"); } if (ContainsSource(indexer.Source)) { throw new ArgumentException("Source is already included in this IndexerSet", "indexer"); } lock (lockObject) indexers = indexers.Add(indexer); return(indexer); }
public async Task <IImmutableList <PackageResult> > Package(IImmutableList <PackageResource> resources, string version) { var packageResources = resources .Add(new PackageResource("main.tf", await File.ReadAllBytesAsync(_file.FullName))); return(ImmutableList.Create(await PackageResult.FromResources($"{Name}.{version}.zip", packageResources))); }
public GradientColorBuilder Add(GradientColorByValue gradientColor) { if (_gradientColorList.Any(item => item.Value == gradientColor.Value)) { throw new InvalidOperationException($"Gradient color value ({gradientColor.Value}) is already defined"); } return(ShallowClone(_gradientColorList.Add(gradientColor))); }
IImmutableList <RowModel> UpdateRows( IImmutableList <RowModel> visibleRows, Dictionary <ILiveElement, Action <RowModel> > updates) { //while (visibleRows.Count < 30) // visibleRows = visibleRows.Add(new RowModel(_tree)); // First update all rows currently attached to an element Queue <RowModel> freeRows = new Queue <RowModel>(); foreach (var rowModel in visibleRows) { var rowModelLocal = rowModel; // Shouldn't be necesarry in C# 5 or higher, doing it just to be safe. rowModel.Element.Do( el => { Action <RowModel> update; if (updates.TryGetValue(el, out update)) { update(rowModelLocal); updates.Remove(el); } else { freeRows.Enqueue(rowModelLocal); } }, () => { freeRows.Enqueue(rowModelLocal); }); } // Now update all remaining elements foreach (var update in updates.Values) { RowModel rowModel; if (freeRows.Count > 0) { rowModel = freeRows.Dequeue(); } else { rowModel = new RowModel(_tree); visibleRows = visibleRows.Add(rowModel); } update(rowModel); } // And then detach any leftover rows // (we don't free row templates if tree is resized smaller) while (freeRows.Count > 0) { freeRows.Dequeue().Detach(); } return(visibleRows); }
public void RemoveTest() { ImmutableList <int> list = ImmutableList <int> .Empty; for (int i = 1; i <= 10; i++) { list = list.Add(i * 10); } list = list.Remove(30); Assert.Equal(9, list.Count); Assert.False(list.Contains(30)); list = list.Remove(100); Assert.Equal(8, list.Count); Assert.False(list.Contains(100)); list = list.Remove(10); Assert.Equal(7, list.Count); Assert.False(list.Contains(10)); var removeList = new int[] { 20, 70 }; list = list.RemoveAll(removeList.Contains); Assert.Equal(5, list.Count); Assert.False(list.Contains(20)); Assert.False(list.Contains(70)); IImmutableList <int> list2 = ImmutableList <int> .Empty; for (int i = 1; i <= 10; i++) { list2 = list2.Add(i * 10); } list2 = list2.Remove(30); Assert.Equal(9, list2.Count); Assert.False(list2.Contains(30)); list2 = list2.Remove(100); Assert.Equal(8, list2.Count); Assert.False(list2.Contains(100)); list2 = list2.Remove(10); Assert.Equal(7, list2.Count); Assert.False(list2.Contains(10)); list2 = list2.RemoveAll(removeList.Contains); Assert.Equal(5, list2.Count); Assert.False(list2.Contains(20)); Assert.False(list2.Contains(70)); }
/// <summary> /// Sets the item in the given index. /// </summary> /// <param name="index">The index in which the item would be replaced.</param> /// <param name="item">The item to replace with item in the given index.</param> /// <returns>New list with the item in the given index replaced with the given one.</returns> public IImmutableList <T> SetItem(int index, T item) { if (index < 0 || index >= this.Count) { throw new ArgumentOutOfRangeException("index"); } ImmutableList <T> notToCopy = ListAt(index + 1) as ImmutableList <T>; IImmutableList <T> newList = notToCopy.ListAt(index - 1); newList = newList.Add(item); return(CopyDifferntial(newList, this, notToCopy)); }
static IEnumerable<Segment> GetGraphKeyImpl(ISymbol symbol, IImmutableList<Segment> acc) { if (symbol == null) return acc.Reverse(); if (symbol is ITypeSymbol) return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "+"))); if (symbol is INamespaceSymbol) { if (((INamespaceSymbol)symbol).IsGlobalNamespace) return GetGraphKeyImpl(symbol.ContainingSymbol, acc); return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "."))); } if (symbol is IModuleSymbol) return GetGraphKeyImpl(symbol.ContainingSymbol, acc); if (symbol is IAssemblySymbol) return GetGraphKeyImpl(symbol.ContainingSymbol, acc); return GetGraphKeyImpl(symbol.ContainingSymbol, acc.Add(Segment.From(symbol, "!"))); }
private void AddSubjectUnderCategory(ISubject subject) { subjects = subjects.Add(subject); foreach (string keyword in subject.Keywords) { if (map.TryGetValue(keyword, out var keywordSet)) { map = map.SetItem(keyword, keywordSet.Add(subject)); } else { map = map.SetItem(keyword, ImmutableHashSet <ISubject> .Empty.Add(subject)); } } }
public Logic(SeqStage <T> stage, TaskCompletionSource <IImmutableList <T> > promise) : base(stage.Shape) { _stage = stage; SetHandler(stage._in, onPush: () => { _buf = _buf.Add(Grab(stage._in)); Pull(stage._in); }, onUpstreamFinish: () => { promise.TrySetResult(_buf); CompleteStage(); }, onUpstreamFailure: ex => { promise.TrySetException(ex); FailStage(ex); }); }
protected override bool Receive(object message) { return(message.Match() .With <int>(i => { if (_buffer.Count == 0 && TotalDemand > 0) { OnNext(i); } else { _buffer = _buffer.Add(i); DeliverBuffer(); } }) .With <Request>(DeliverBuffer) .With <Cancel>(() => Context.Stop(Self)) .WasHandled); }
public InferenceState Unify(out IImmutableList <InferenceState> states) { var state = this; states = ImmutableList.Create(state); while (state.Context.Any(e => e is IConstraint)) { var prefix = state.Context.TakeWhile(e => !(e is IConstraint)); var eqAndSuffix = state.Context.SkipWhile(e => !(e is IConstraint)); if (eqAndSuffix.First() is IConstraint constraint) { state = constraint.Solve(state.Fresh, prefix.ToImmutableList(), eqAndSuffix.Skip(1).ToImmutableList()); } else { throw new Exception("Should never get here: said there was a constraint, but then didn't find it."); } states = states.Add(state); } return(state); }
/// <inheritdoc /> protected override bool Receive(object message) { switch (message) { case int wordCount: _results = _results.Add(wordCount); if (_results.Count == _expectedResults) { var meanWordLength = _results.Sum() * 1.0 / _results.Count; _replyTo.Tell(new StatsResult(meanWordLength)); Context.Stop(Self); } return(true); case ReceiveTimeout _: _replyTo.Tell(new JobFailed("Service unavailable, try again later")); Context.Stop(Self); return(true); } return(false); }
private static IEnumerable <CircularReferenceError> Analyse(string assemblyName, IImmutableList <string> parent, IDictionary <string, AssemblyCheck> context) { var hasCycle = parent.Contains(assemblyName); var currentPath = parent.Add(assemblyName); if (hasCycle) { yield return(new CircularReferenceError(currentPath)); yield break; } var assembly = context[assemblyName]; foreach (var child in assembly.AssembliesReferenced) { foreach (var result in Analyse(child, currentPath, context).ToList()) { yield return(result); } } }
private void OnSpawnpointDiscovered(Spawnpoint s) { s.IsDiscovered = true; _discoveredSpawnpoints = _discoveredSpawnpoints.Add(s.Id); _fileWriterScheduler.Schedule(_discoveredSpawnpoints, SerializeDiscoveredSpawnpoints); var spawnpointsDiscovered = 0; for (int i = 0; i < _spawnpoints.Count; i++) { var spawnpoint = _spawnpoints[i]; if (spawnpoint.IsDiscovered) { spawnpointsDiscovered++; } } _coroutineScheduler.Run(_announcerUi.Introduce( "Spawnpoint discovered:", _challengeColor, s.Name, spawnpointsDiscovered + "/" + _spawnpoints.Count + " spawnpoints discovered")); }
private static IEnumerable <KeyValuePair <string, string?> > VisitArray(IImmutableList <string> keys, JArray array) { return(Enumerable.Range(0, array.Count) .SelectMany(i => VisitToken(keys.Add(i.ToString(CultureInfo.InvariantCulture)), array[i]))); }
public IProcessBuilder AddArgument(string argument) => ShallowClone(arguments: Option.Some(_arguments.Add(argument)));
internal Builder AddQuery(IWittyerSimpleVariant variant) { _query = _query.Add(variant); return this; }
public override void OnPush() { _buf = _buf.Add(Grab(_stage.In)); Pull(_stage.In); }
private IEither <ParsingException, IPartialParse <IImmutableList <OutputType> > > RepeatParse ( int currentCount, string remainingInput, IImmutableList <OutputType> outputs ) { if (currentCount <= 0) { return(Either.Create <ParsingException> .Right(new PartialParse <IImmutableList <OutputType> >(outputs, remainingInput))); } return(m_outer.Parse(remainingInput) .Match( error => Either.Create <IPartialParse <IImmutableList <OutputType> > > .Left(ParsingFailure(remainingInput, error)), success => RepeatParse(currentCount - 1, success.RemainingInput, outputs.Add(success.Output)) )); }
public GlobalJsonModificationBuilder AddMsBuildSdk(MsBuildSdk sdk) => ShallowClone(sdksToAdd: Option.Some(_msBuildSdksToAdd.Add(sdk)));
private static IEnumerable <KeyValuePair <string, string?> > VisitJObject(IImmutableList <string> keys, JObject jObject) { return(jObject.Properties() .SelectMany(property => VisitToken(keys.Add(property.Name), property.Value))); }
public Graph Add(Statement statement) { return(new Graph(graphKind, name, statements.Add(statement))); }
public static IImmutableList <T> add <T>(IImmutableList <T> list, T value) => list.Add(value);
public void AddCondition(ICondition <TValue> condition) { conditions = conditions.Add(condition); }
public State AddParameter(object?parameter) { return(new State(parameters.Add(parameter), argumentExtractor, postValidations, assignmentOperators)); }
internal Builder AddNonSupported(IVcfVariant variant) { _notSupported = _notSupported.Add(variant); return this; }