public void EnumeratorLengthTest1() { var list1 = new ImmutableList<int>(new int[] { 0, 1, 2 }); var list2 = new ImmutableList<int>(new int[] { 3, 4, 5 }); var list = list1.Concat(list2); Assert.True(list.Length == 6); list = list.Tail(); Assert.True(list.Length == 5); list = list.Tail(); list = list.Tail(); list = list.Tail(); list = list.Tail(); Assert.True(list.Length == 1); Assert.True(list.IsAlmostEmpty); list = list.Tail(); Assert.True(list.IsEmpty); Assert.Throws<ParserException>(() => list.Tail()); }
public ListData AddRow(IDictionary <string, object> values, out ListItemId newItemId) { if (_ids.Count == 0) { newItemId = new ListItemId(1); } else { newItemId = new ListItemId(_ids[_ids.Count - 1].IntValue + 1); } var newIds = ImmutableList.ValueOf(_ids.Concat(new[] { newItemId })); return(ChangeProp(ImClone(this), im => { var newColumns = new List <ColumnData>(); for (int iCol = 0; iCol < ListDef.Properties.Count; iCol++) { object value; values.TryGetValue(ListDef.Properties[iCol].Name, out value); newColumns.Add(Columns[iCol].AddRow(value)); } im.Columns = ImmutableList.ValueOf(newColumns); im._ids = newIds; im.RebuildIndex(); })); }
public void EnumeratorLengthTest1() { var list1 = new ImmutableList <int>(new int[] { 0, 1, 2 }); var list2 = new ImmutableList <int>(new int[] { 3, 4, 5 }); var list = list1.Concat(list2); Assert.True(list.Length == 6); list = list.Tail(); Assert.True(list.Length == 5); list = list.Tail(); list = list.Tail(); list = list.Tail(); list = list.Tail(); Assert.True(list.Length == 1); Assert.True(list.IsAlmostEmpty); list = list.Tail(); Assert.True(list.IsEmpty); Assert.Throws <ParserException>(() => list.Tail()); }
private static ISet <string> BuildExcludePatternsForGlobs(ImmutableHashSet <string> globsToIgnore, ImmutableList <string> .Builder excludePatterns) { var anyExcludes = excludePatterns.Count > 0; var anyGlobsToIgnore = globsToIgnore.Count > 0; if (anyGlobsToIgnore && anyExcludes) { return(excludePatterns.Concat(globsToIgnore).ToImmutableHashSet()); } return(anyExcludes ? excludePatterns.ToImmutableHashSet() : globsToIgnore); }
public void EnumeratorTest3() { var list1 = new ImmutableList<int>(new int[] { 1, 2, 3 }); var list2 = new ImmutableList<int>(new int[] { 4, 5, 6 }); var list = 0.Cons( list1.Concat(list2) ); int index = 0; foreach (var item in list) { Assert.True(item == index); index++; } Assert.True(index == 7); }
public void EnumeratorTest2() { var list1 = new ImmutableList<int>(new int[] { 0, 1, 2 }); var list2 = new ImmutableList<int>(new int[] { 3, 4, 5 }); var list = list1.Concat(list2); int index = 0; foreach (var item in list) { Assert.True(item == index); index++; } Assert.True(index == 6); }
public void EnumeratorTest3() { var list1 = new ImmutableList <int>(new int[] { 1, 2, 3 }); var list2 = new ImmutableList <int>(new int[] { 4, 5, 6 }); var list = 0.Cons(list1.Concat(list2)); int index = 0; foreach (var item in list) { Assert.True(item == index); index++; } Assert.True(index == 7); }
public void EnumeratorTest2() { var list1 = new ImmutableList <int>(new int[] { 0, 1, 2 }); var list2 = new ImmutableList <int>(new int[] { 3, 4, 5 }); var list = list1.Concat(list2); int index = 0; foreach (var item in list) { Assert.True(item == index); index++; } Assert.True(index == 6); }
public IndexedPropertyDescriptor MakePropertyDescriptor(int index, ImmutableList <object> columnHeaderKey, PropertyDescriptor originalPropertyDescriptor, IColumnCaption caption, AggregateOperation aggregateOperation) { IColumnCaption qualifiedCaption; if (columnHeaderKey.Count == 0) { qualifiedCaption = caption; } else { qualifiedCaption = new CaptionComponentList(columnHeaderKey.Concat(new[] { caption }) .Select(CaptionComponentList.MakeCaptionComponent)); } var attributes = DataSchema.GetAggregateAttributes(originalPropertyDescriptor, aggregateOperation).ToArray(); return(new IndexedPropertyDescriptor(DataSchema, index, aggregateOperation.GetPropertyType(originalPropertyDescriptor.PropertyType), qualifiedCaption, attributes)); }
public ImmutableList <T> Modify(ImmutableList <T> source) { if (source.Count >= _count) { return(source); } if (_isBefore) { var range = Enumerable.Range(0, _count - source.Count); var items = range.Select(_factory); return(items.Concat(source).ToImmutableList()); } else { var range = Enumerable.Range(source.Count, _count - source.Count); var items = range.Select(_factory); return(source.Concat(items).ToImmutableList()); } }
public override async Task ExecuteAsync(SmtpSession smtpSession, CancellationToken token) { ImmutableList <string> encryptedExtensions = ImmutableList.CreateRange( new[] { "AUTH " + String.Join(" ", smtpSession.ImplementationFactory.Authentication.GetSupported()), }); smtpSession.ConnectedHost = Arguments; ImmutableList <string> plainTextExtensions = PlainTextExtensions; var extensions = GeneralExtensions.Concat(smtpSession.Connection.IsEncrypted ? encryptedExtensions : plainTextExtensions); if (smtpSession.Connection.Certificate != null && !smtpSession.Connection.IsEncrypted) { extensions = extensions.Concat(new[] { "STARTTLS" }); } await smtpSession.SendReplyAsync(ReplyCode.Okay, true, $"{smtpSession.Settings.DomainName} greets {Arguments}", token); await smtpSession.SendReplyAsync(ReplyCode.Okay, extensions, token); }
public static ICharParser <TDict> BuildDictionaryParser <TKey, TValue, TDict> ( ICharParser <TKey> keyParser, ICharParser <TValue> valueParser, TDict empty, Func <TDict, TKey, TValue, TDict> addItem ) { ICharParser <Tuple <TKey, TValue> > kvp = ParseConvert ( ParseSequence ( keyParser.ResultToObject(), Token("=>"), valueParser.ResultToObject() ), objs => new Tuple <TKey, TValue>((TKey)objs[0], (TValue)objs[2]), null ); var dict = ParseSequence ( Token("{"), ParseOptRep ( ParseConvert ( ParseSequence ( kvp.ResultToObject(), Token(",") ), lst => (Tuple <TKey, TValue>)lst[0], null ), true, true ) .ResultToObject(), ParseOptRep ( kvp, true, false ) .ResultToObject(), Token("}") ); return(ParseConvert ( dict, objs => { ImmutableList <Tuple <TKey, TValue> > l1 = (ImmutableList <Tuple <TKey, TValue> >)objs[1]; ImmutableList <Tuple <TKey, TValue> > l2 = (ImmutableList <Tuple <TKey, TValue> >)objs[2]; TDict v = empty; foreach (Tuple <TKey, TValue> kvp0 in l1.Concat(l2)) { v = addItem(v, kvp0.Item1, kvp0.Item2); } return v; }, null )); }
public override ColumnData AddRow(object value) { return(ReplaceValues(ImmutableList.ValueOf(_values.Concat(new[] { ConvertValue(value) })))); }
protected override ICollection <I> SelectItems(ImmutableList <ItemData> .Builder listBuilder, ImmutableHashSet <string> globsToIgnore) { List <I> itemsToAdd = new List <I>(); Lazy <Func <string, bool> > excludeTester = null; ImmutableList <string> .Builder excludePatterns = ImmutableList.CreateBuilder <string>(); if (_excludes != null) { // STEP 4: Evaluate, split, expand and subtract any Exclude foreach (string exclude in _excludes) { string excludeExpanded = _expander.ExpandIntoStringLeaveEscaped(exclude, ExpanderOptions.ExpandPropertiesAndItems, _itemElement.ExcludeLocation); IList <string> excludeSplits = ExpressionShredder.SplitSemiColonSeparatedList(excludeExpanded); excludePatterns.AddRange(excludeSplits); } if (excludePatterns.Any()) { excludeTester = new Lazy <Func <string, bool> >(() => EngineFileUtilities.GetMatchTester(excludePatterns)); } } foreach (var fragment in _itemSpec.Fragments) { if (fragment is ItemExpressionFragment <P, I> ) { // STEP 3: If expression is "@(x)" copy specified list with its metadata, otherwise just treat as string bool throwaway; var itemsFromExpression = _expander.ExpandExpressionCaptureIntoItems( ((ItemExpressionFragment <P, I>)fragment).Capture, _evaluatorData, _itemFactory, ExpanderOptions.ExpandItems, false /* do not include null expansion results */, out throwaway, _itemElement.IncludeLocation); if (excludeTester != null) { itemsToAdd.AddRange(itemsFromExpression.Where(item => !excludeTester.Value(item.EvaluatedInclude))); } else { itemsToAdd.AddRange(itemsFromExpression); } } else if (fragment is ValueFragment) { string value = ((ValueFragment)fragment).ItemSpecFragment; if (excludeTester == null || !excludeTester.Value(value)) { var item = _itemFactory.CreateItem(value, value, _itemElement.ContainingProject.FullPath); itemsToAdd.Add(item); } } else if (fragment is GlobFragment) { string glob = ((GlobFragment)fragment).ItemSpecFragment; string[] includeSplitFilesEscaped = EngineFileUtilities.GetFileListEscaped(_rootDirectory, glob, excludePatterns.Count > 0 ? (IEnumerable <string>)excludePatterns.Concat(globsToIgnore) : globsToIgnore); foreach (string includeSplitFileEscaped in includeSplitFilesEscaped) { itemsToAdd.Add(_itemFactory.CreateItem(includeSplitFileEscaped, glob, _itemElement.ContainingProject.FullPath)); } } else { throw new InvalidOperationException(fragment.GetType().ToString()); } } return(itemsToAdd); }
public ClassDeclarationBuilder With(params MethodDeclarationBuilder[] methodDeclarationBuilders) { return(new ClassDeclarationBuilder(_name, _methods.Concat(methodDeclarationBuilders), _namespaceName)); }
public override IEnumerator <T> GetEnumerator() { return(_head.Concat(_tail).GetEnumerator()); }