The Encodian population engine provides features to perform common manipulations on a collection (Iterable). These features mimic the extension methods provided by IEnumerable<T>, thus, you can group, sort, and perform other sequential data manipulations in template expressions in a common way.
In the below examples, the term persons refers to the data collection (array, list, or enumerable) that the method operates on. It’s simply a placeholder for any collection you might have in your JSON data.
Extension Method | Example |
All(Predicate) |
Check if all elements in a collection satisfy a specified condition. persons.All(p => p.Age < 50) |
Any() |
Persons.Any() |
Any(Predicate) |
Checks if any element in a collection satisfies a specified condition. It returns persons.Any(p => p.Name == "John Smith") Example: <<if [persons.Any(p => p.Age > 30)]>>There is someone older than 30.<</if>> |
Average(Selector) |
Calculate the mean value of a numeric property across all items in. a collection. persons.Average(p => p.Age) |
Concat(IEnumerable) |
persons.Concat(otherPersons) |
Contains(Object) |
Check if a key value or collection contains an item that matches a specified condition. persons.Contains(otherPersons.First()) ------------- Example template syntax <<foreach [person in persons]>> Example JSON: { Word document result: John Smith Expanding on the example above you can change the syntax slightly to find everything that doesn't match the condition. <<foreach [person in persons]>> Word document result: Alice Williams |
Count() |
persons.Count() |
Count(Predicate) |
persons.Count(p => p.Age > 30) |
Distinct() |
persons.Distinct() |
First() |
persons.First() |
First(Predicate) |
persons.First(p => p.Age > 30) |
FirstOrDefault() |
persons.FirstOrDefault() |
FirstOrDefault(Predicate) |
persons.FirstOrDefault(p => p.Age > 30) |
GroupBy(Selector) |
Group items in a collection based on a specified property or key. persons.GroupBy(p => p.Age) or persons.GroupBy( p => new { Age = p.Age, Count = p.Children.Count() }) ------------- Example template syntax: <<foreach [group in persons.GroupBy(p => p.City)]>> Example JSON: { Word document result: City: London |
Last() |
persons.Last() |
Last(Predicate) |
persons.Last(p => p.Age > 100) |
LastOrDefault() |
persons.LastOrDefault() |
LastOrDefault(Predicate) |
persons.LastOrDefault(p => p.Age > 100) |
Max(ComparableSelector) |
persons.Max(p => p.Age) |
Min(ComparableSelector) |
persons.Min(p => p.Age) |
OrderBy(ComparableSelector) |
persons.OrderBy(p => p.Age) Or persons.OrderBy(p => p.Age).ThenByDescending(p => p.Name) |
OrderByDescending(ComparableSelector) |
persons.OrderByDescending(p => p.Age) Or persons.OrderByDescending(p => p.Age).ThenByDescending(p => p.Name) |
Select(Selector) |
persons.Select(p => p.Name) |
SelectMany(EnumerationSelector) |
persons.SelectMany(p => p.Children) |
Single() |
persons.Single() |
Single(Predicate) |
persons.Single(p => p.Name == "John Smith") |
SingleOrDefault() |
persons.SingleOrDefault() |
SingleOrDefault(Predicate) |
persons.SingleOrDefault(p => p.Name == "John Smith") |
Skip(int) |
persons.Skip(10) |
SkipWhile(Predicate) |
persons.SkipWhile(p => p.Age < 21) |
Sum(Selector) |
persons.Sum(p => p.Children.Count()) |
Take(int) |
persons.Take(5) |
TakeWhile(Predicate) |
persons.TakeWhile(p => p.Age < 50) |
Union(IEnumerable) |
persons.Union(otherPersons) |
Where(Predicate) |
persons.Where(p => p.Age > 18) |
0 Comments