NanoByte.Common  2.6.1
NanoByte.Common.Dispatch.Bucketizer< TElement, TValue > Class Template Reference

Splits collections into multiple buckets based on predicate matching. The first matching predicate wins. Create with Bucketizer.Bucketize<T>. More...

Inheritance diagram for NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >:

Public Member Functions

Bucketizer< T > Add (Predicate< T > predicate, ICollection< T > bucket)
 Adds a new bucket rule. More...
 
void Run ()
 Adds each element to the first bucket with a matching predicate (if any). Set up with Add first. More...
 
IEnumerator< BucketRule< T > > GetEnumerator ()
 
Bucketizer< TElement, TValue > Add (TValue value, ICollection< TElement > bucket)
 Adds a new bucket rule. More...
 
void Run ()
 Adds each element to the first bucket with a matching value (if any). Set up with Add first. More...
 
IEnumerator< BucketRule< TElement, TValue > > GetEnumerator ()
 

Static Public Member Functions

static Bucketizer< T > Bucketize< T > (this IEnumerable< T > elements)
 Creates a new predicate-matching bucketizer. More...
 
static Bucketizer< TElement, TValue > Bucketize< TElement, TValue > (this IEnumerable< TElement > elements, Func< TElement, TValue > valueRetriever)
 Creates a new value-mapping bucketizer. More...
 

Package Functions

 Bucketizer (IEnumerable< T > elements)
 Creates a new predicate-matching bucketizer. More...
 
 Bucketizer (IEnumerable< TElement > elements, Func< TElement, TValue > valueRetriever)
 Creates a new value-mapping bucketizer. More...
 

Detailed Description

Splits collections into multiple buckets based on predicate matching. The first matching predicate wins. Create with Bucketizer.Bucketize<T>.

Splits collections into multiple buckets based on value-mapping. Create with Bucketizer.Bucketize<TElement,TValue>.

Contains extension methods for creating bucketizers.

Template Parameters
TThe common base type of all objects to be bucketized.
Template Parameters
TElementThe common base type of all objects to be bucketized.
TValueThe type of the values to be matched.

Constructor & Destructor Documentation

◆ Bucketizer() [1/2]

NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Bucketizer ( IEnumerable< T >  elements)
inlinepackage

Creates a new predicate-matching bucketizer.

Parameters
elementsThe elements to be bucketized.

◆ Bucketizer() [2/2]

NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Bucketizer ( IEnumerable< TElement >  elements,
Func< TElement, TValue >  valueRetriever 
)
inlinepackage

Creates a new value-mapping bucketizer.

Parameters
elementsThe elements to be bucketized.
valueRetrieverA function to map elements to their according values used for bucketization.

Member Function Documentation

◆ Add() [1/2]

Bucketizer<T> NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Add ( Predicate< T >  predicate,
ICollection< T >  bucket 
)
inline

Adds a new bucket rule.

Parameters
predicateA condition to check elements against.
bucketThe collection elements are added to if they match the predicate .
Returns
The "this" pointer for use in a "Fluent API" style.

◆ Add() [2/2]

Bucketizer<TElement, TValue> NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Add ( TValue  value,
ICollection< TElement >  bucket 
)
inline

Adds a new bucket rule.

Parameters
valueA value to compare with the result of the value retriever using object.Equals(object,object).
bucketThe collection elements are added to if they match the value .
Returns
The "this" pointer for use in a "Fluent API" style.

◆ Bucketize< T >()

static Bucketizer<T> NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Bucketize< T > ( this IEnumerable< T >  elements)
static

Creates a new predicate-matching bucketizer.

Parameters
elementsThe elements to be bucketized.

◆ Bucketize< TElement, TValue >()

static Bucketizer<TElement, TValue> NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Bucketize< TElement, TValue > ( this IEnumerable< TElement >  elements,
Func< TElement, TValue >  valueRetriever 
)
static

Creates a new value-mapping bucketizer.

Parameters
elementsThe elements to be bucketized.
valueRetrieverA function to map elements to their according values used for bucketization.

◆ Run() [1/2]

void NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Run ( )
inline

Adds each element to the first bucket with a matching predicate (if any). Set up with Add first.

◆ Run() [2/2]

void NanoByte.Common.Dispatch.Bucketizer< TElement, TValue >.Run ( )
inline

Adds each element to the first bucket with a matching value (if any). Set up with Add first.


The documentation for this class was generated from the following files: