Skip to content

C#/F# - friendly extensions for building sequence-based composite data processing solutions.

License

Notifications You must be signed in to change notification settings

vkamiansky/composite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

composite

Build status Latest Nuget version

A sequence is a logical series of elements all of one type. The definition of a sequence has no stipulation of how its elements are stored, or linked, or whether they are stored at all. In C# sequences are called enumerable collections, they implement IEnumerable<T>. In F# they are represented by the seq<T> type.

The main purpose of Project Composite is to provide extensions or functions that allow building sequence-based data processing solutions in C#/F# with more convenience and practical sense.

It also introduces Composite<T>, a brand of sequence with a native support for nesting. Each node of a Composite<T> is either a Value containing a payload object or a Composite comprising a sequence of child nodes.

The functions are listed below grouped by their C#-friendly representations followed by their F#-friendly signatures.

Sequence Extensions

IEnumerable<T>[] EnumerableExtensions.AsPartitioned<T>(IEnumerable<T> source, int numberPartitions)

F#: Seq.partition: (numParts: int) -> (source: seq<'T>) -> seq<'T> []

Splits the source sequence into an array of sequences.

The function uses deferred execution. The resulting sequences will not be generated until they are enumerated as shown in the diagram below.

AsPartitioned diagram

IEnumerable<T[]> EnumerableExtensions.AsPaged<T>(IEnumerable<T> source, int pageSize)

F# (available in standard FSharp.Core since version 4.4.0.0): Seq.chunkBySize: (chunkSize: int) -> (source: seq<'T>) -> seq<'T[]>

Divides the input sequence into a sequence of pages each containing at most the given number of elements.

The function uses deferred execution. The resulting sequence will not be generated until it is enumerated as shown in the diagram below.

AsPaged diagram

IEnumerable<T[]> EnumerableExtensions.AsBatched<T>(IEnumerable<T> source, int batchSize, Func<T, int> getElementSize)

F#: Seq.chunkByWeight: (chunkWeight: int) -> (weigh: 'T -> int) -> (source: seq<'T>) -> seq<'T[]>

Divides the input sequence into a sequence of batches of either one element or as many elements as possible if their total size does not exceed the given number. The size of each element is obtained through the use of the given function.

The function uses deferred execution. The resulting sequence will not be generated until it is enumerated as shown in the diagram below.

AsBatched diagram

IEnumerable<TResult> EnumerableExtensions.AccumulateSelectMany<TSource>(IEnumerable<TSource> source, AccumulateTransformRule<TSource, TResult>[] rules)

F#: Seq.accumulateCollect (rules: (('TIn -> bool)[] * ('TIn[] -> seq<'TOut>))[]) -> (source: seq<'TIn>) -> seq<'TOut>

Finds elements in the input sequence to accumulate them in arrays, applies the respective transform functions to populated arrays, and concatenates the results. The accumulation and transformation of objects found in the source sequence is performed according to the given rules.

AccumulateTransformRulehas the following constructor signature:

public AccumulateTransformRule(Func<TSource, bool>[] findPredicates, Func<TSource[], IEnumerable<TResult>> transformFunction)

The findPredicates are used to find objects to be put in the accumulator cells with the respective indices.

The transformFunction is used to transform the array of accumulated objects into an enumerable result.

The function uses deferred execution. The resulting sequence will not be generated until it is enumerated as shown in the diagram below if we assume the rules are defined as in the following listing.

var rules = new[] { new AccumulateTransformRule<int, int>(
                        new Func<int, bool>[] { 
                            x => x > 2, 
                            x => x > 3 },
                        x => new[] { x[0] + x[1] + 1, 2 * x[0] + x[1] / 2 } ),
                    new AccumulateTransformRule<int, int>(
                        new Func<int, bool>[] { 
                            x => x > 1, 
                            x => x > 2 },
                        x => new[] { 2 * x[0] + x[1], 3 * x[0] + x[1] } )
                   };

AccumulateSelectMany diagram

Composite Extensions

Composite<T> CompositeExtensions.Fork<T>(Composite<T> source, Func<T, bool> predicate, Func<T, T[]> mapping)

F#: Comp.fork (predicate: 'T -> bool) -> (mapping: 'T -> seq<'T>) -> (source: 'T Composite) -> 'T Composite

Builds a new sequence composite based on the source in which the values containing objects for which the given predicate returns true are substituted for sequence composites wrapping the sequences produced from them through the use of the mapping function.

The function uses deferred execution. The resulting sequence composite will not be generated until it is enumerated as shown in the diagram below.

Fork diagram

Composite<TOut> CompositeExtensions.Select<TIn,TOut>(Composite<TIn> source, Func<TIn, TOut> mapping)

F#: Comp.map (mapping: 'TIn -> 'TOut) -> (source: 'TIn Composite) -> 'TOut Composite

Builds a new sequence composite based on the source in which the values contain objects substituted through the use of the given function.

The function uses deferred execution. The resulting sequence composite will not be generated until it is enumerated as shown in the diagram below.

Select diagram

IEnumerable<Composite<T>> CompositeExtensions.ToComponents<T>(Composite<T> source)

F#: Comp.components (source: 'T Composite) -> seq<'T Composite>

Returns the sequence of components of the input sequence composite.

The function uses deferred execution. The resulting sequence will not be generated until it is enumerated as shown in the diagram below.

ToComponents diagram

IEnumerable<T> CompositeExtensions.AsEnumerable<T>(Composite<T> source)

F#: Seq.ofComp (source: 'T Composite) -> seq<'T>

Views the given sequence composite as a sequence.

The function uses deferred execution. The resulting sequence will not be generated until it is enumerated as shown in the diagram below.

AsEnumerable diagram

About

C#/F# - friendly extensions for building sequence-based composite data processing solutions.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published