Lean  $LEAN_TAG$
QuantConnect.Util.LinqExtensions Class Reference

Provides more extension methods for the enumerable types More...

Static Public Member Functions

static Dictionary< K, V > ToDictionary< K, V > (this IEnumerable< KeyValuePair< K, V >> enumerable)
 Creates a dictionary enumerable of key value pairs More...
 
static IReadOnlyDictionary< K, V > ToReadOnlyDictionary< K, V > (this IEnumerable< KeyValuePair< K, V >> enumerable)
 Creates a new read-only dictionary from the key value pairs More...
 
static HashSet< TResult > ToHashSet< T, TResult > (this IEnumerable< T > enumerable, Func< T, TResult > selector)
 Creates a new HashSet<T> from the elements in the specified enumerable More...
 
static List< TResult > ToList< T, TResult > (this IEnumerable< T > enumerable, Func< T, TResult > selector)
 Creates a new IList<T> from the projected elements in the specified enumerable More...
 
static TResult[] ToArray< T, TResult > (this IEnumerable< T > enumerable, Func< T, TResult > selector)
 Creates a new array from the projected elements in the specified enumerable More...
 
static ImmutableArray< TResult > ToImmutableArray< T, TResult > (this IEnumerable< T > enumerable, Func< T, TResult > selector)
 Creates a new immutable array from the projected elements in the specified enumerable More...
 
static bool IsNullOrEmpty< T > (this IEnumerable< T > enumerable)
 Returns true if the specified enumerable is null or has no elements More...
 
static T Median< T > (this IEnumerable< T > enumerable)
 Gets the median value in the collection More...
 
static TProperty Median< T, TProperty > (this IEnumerable< T > collection, Func< T, TProperty > selector)
 Gets the median value in the collection More...
 
static int BinarySearch< TItem, TSearch > (this IList< TItem > list, TSearch value, Func< TSearch, TItem, int > comparer)
 Performs a binary search on the specified collection. More...
 
static int BinarySearch< TItem > (this IList< TItem > list, TItem value)
 Performs a binary search on the specified collection. More...
 
static int BinarySearch< TItem > (this IList< TItem > list, TItem value, IComparer< TItem > comparer)
 Performs a binary search on the specified collection. More...
 
static IEnumerable< T > Memoize< T > (this IEnumerable< T > enumerable)
 Wraps the specified enumerable such that it will only be enumerated once More...
 
static IEnumerable< T > Range< T > (T start, T end, Func< T, T > incrementer, bool includeEndPoint=false)
 Produces the an enumerable of the range of values between start and end using the specified incrementing function More...
 
static IEnumerable< IEnumerable< T > > GroupAdjacentBy< T > (this IEnumerable< T > enumerable, Func< T, T, bool > grouper)
 Groups adjacent elements of the enumerale using the specified grouper function More...
 
static bool AreDifferent< T > (this ISet< T > left, ISet< T > right)
 Determines if there are any differences between the left and right collections. This method uses sets to improve performance and also uses lazy evaluation so if a difference is found, true is immediately returned and evaluation is halted. More...
 
static IEnumerable< T > AsEnumerable< T > (this IEnumerator< T > enumerator)
 Converts an IEnumerator<T> to an IEnumerable<T> More...
 
static V GetValueOrDefault< K, V > (this IDictionary< K, V > dictionary, K key, V defaultValue=default(V))
 Gets the value associated with the specified key or provided default value if key is not found. More...
 
static void DoForEach< T > (this IEnumerable< T > source, Action< T > action)
 Performs an action for each element in collection source More...
 

Detailed Description

Provides more extension methods for the enumerable types

Definition at line 27 of file LinqExtensions.cs.

Member Function Documentation

◆ ToDictionary< K, V >()

static Dictionary<K, V> QuantConnect.Util.LinqExtensions.ToDictionary< K, V > ( this IEnumerable< KeyValuePair< K, V >>  enumerable)
static

Creates a dictionary enumerable of key value pairs

Template Parameters
KThe key type
VThe value type
Parameters
enumerableThe IEnumerable of KeyValuePair instances to convert to a dictionary
Returns
A dictionary holding the same data as the enumerable

Definition at line 36 of file LinqExtensions.cs.

◆ ToReadOnlyDictionary< K, V >()

static IReadOnlyDictionary<K, V> QuantConnect.Util.LinqExtensions.ToReadOnlyDictionary< K, V > ( this IEnumerable< KeyValuePair< K, V >>  enumerable)
static

Creates a new read-only dictionary from the key value pairs

Template Parameters
KThe key type
VThe value type
Parameters
enumerableThe IEnumerable of KeyValuePair instances to convert to a dictionary
Returns
A read-only dictionary holding the same data as the enumerable

Definition at line 48 of file LinqExtensions.cs.

◆ ToHashSet< T, TResult >()

static HashSet<TResult> QuantConnect.Util.LinqExtensions.ToHashSet< T, TResult > ( this IEnumerable< T >  enumerable,
Func< T, TResult >  selector 
)
static

Creates a new HashSet<T> from the elements in the specified enumerable

Template Parameters
TThe item type of the source enumerable
TResultThe type of the items in the output HashSet<T>
Parameters
enumerableThe items to be placed into the enumerable
selectorSelects items from the enumerable to be placed into the HashSet<T>
Returns
A new HashSet<T> containing the items in the enumerable

Definition at line 61 of file LinqExtensions.cs.

◆ ToList< T, TResult >()

static List<TResult> QuantConnect.Util.LinqExtensions.ToList< T, TResult > ( this IEnumerable< T >  enumerable,
Func< T, TResult >  selector 
)
static

Creates a new IList<T> from the projected elements in the specified enumerable

Template Parameters
TThe item type of the source enumerable
TResultThe type of the items in the output List<T>
Parameters
enumerableThe items to be placed into the list
selectorSelects items from the enumerable to be placed into the List<T>
Returns
A new List<T> containing the items in the enumerable

Definition at line 74 of file LinqExtensions.cs.

◆ ToArray< T, TResult >()

static TResult [] QuantConnect.Util.LinqExtensions.ToArray< T, TResult > ( this IEnumerable< T >  enumerable,
Func< T, TResult >  selector 
)
static

Creates a new array from the projected elements in the specified enumerable

Template Parameters
TThe item type of the source enumerable
TResultThe type of the items in the output array
Parameters
enumerableThe items to be placed into the array
selectorSelects items from the enumerable to be placed into the array
Returns
A new array containing the items in the enumerable

Definition at line 87 of file LinqExtensions.cs.

◆ ToImmutableArray< T, TResult >()

static ImmutableArray<TResult> QuantConnect.Util.LinqExtensions.ToImmutableArray< T, TResult > ( this IEnumerable< T >  enumerable,
Func< T, TResult >  selector 
)
static

Creates a new immutable array from the projected elements in the specified enumerable

Template Parameters
TThe item type of the source enumerable
TResultThe type of the items in the output array
Parameters
enumerableThe items to be placed into the array
selectorSelects items from the enumerable to be placed into the array
Returns
A new array containing the items in the enumerable

Definition at line 100 of file LinqExtensions.cs.

◆ IsNullOrEmpty< T >()

static bool QuantConnect.Util.LinqExtensions.IsNullOrEmpty< T > ( this IEnumerable< T >  enumerable)
static

Returns true if the specified enumerable is null or has no elements

Template Parameters
TThe enumerable's item type
Parameters
enumerableThe enumerable to check for a value
Returns
True if the enumerable has elements, false otherwise

Definition at line 111 of file LinqExtensions.cs.

◆ Median< T >()

static T QuantConnect.Util.LinqExtensions.Median< T > ( this IEnumerable< T >  enumerable)
static

Gets the median value in the collection

Template Parameters
TThe item type in the collection
Parameters
enumerableThe enumerable of items to search
Returns
The median value, throws InvalidOperationException if no items are present

Definition at line 122 of file LinqExtensions.cs.

◆ Median< T, TProperty >()

static TProperty QuantConnect.Util.LinqExtensions.Median< T, TProperty > ( this IEnumerable< T >  collection,
Func< T, TProperty >  selector 
)
static

Gets the median value in the collection

Template Parameters
TThe item type in the collection
TPropertyThe type of the value selected
Parameters
collectionThe collection of items to search
selectorFunction used to select a value from collection items
Returns
The median value, throws InvalidOperationException if no items are present

Definition at line 136 of file LinqExtensions.cs.

◆ BinarySearch< TItem, TSearch >()

static int QuantConnect.Util.LinqExtensions.BinarySearch< TItem, TSearch > ( this IList< TItem >  list,
TSearch  value,
Func< TSearch, TItem, int >  comparer 
)
static

Performs a binary search on the specified collection.

Template Parameters
TItemThe type of the item.
TSearchThe type of the searched item.
Parameters
listThe list to be searched.
valueThe value to search for.
comparerThe comparer that is used to compare the value with the list items.
Returns
The index of the item if found, otherwise the bitwise complement where the value should be per MSDN specs

Definition at line 150 of file LinqExtensions.cs.

◆ BinarySearch< TItem >() [1/2]

static int QuantConnect.Util.LinqExtensions.BinarySearch< TItem > ( this IList< TItem >  list,
TItem  value 
)
static

Performs a binary search on the specified collection.

Template Parameters
TItemThe type of the item.
Parameters
listThe list to be searched.
valueThe value to search for.
Returns
The index of the item if found, otherwise the bitwise complement where the value should be per MSDN specs

Definition at line 192 of file LinqExtensions.cs.

◆ BinarySearch< TItem >() [2/2]

static int QuantConnect.Util.LinqExtensions.BinarySearch< TItem > ( this IList< TItem >  list,
TItem  value,
IComparer< TItem >  comparer 
)
static

Performs a binary search on the specified collection.

Template Parameters
TItemThe type of the item.
Parameters
listThe list to be searched.
valueThe value to search for.
comparerThe comparer that is used to compare the value with the list items.
Returns
The index of the item if found, otherwise the bitwise complement where the value should be per MSDN specs

Definition at line 205 of file LinqExtensions.cs.

◆ Memoize< T >()

static IEnumerable<T> QuantConnect.Util.LinqExtensions.Memoize< T > ( this IEnumerable< T >  enumerable)
static

Wraps the specified enumerable such that it will only be enumerated once

Template Parameters
TThe enumerable's element type
Parameters
enumerableThe source enumerable to be wrapped
Returns
A new enumerable that can be enumerated multiple times without re-enumerating the source enumerable

Definition at line 216 of file LinqExtensions.cs.

◆ Range< T >()

static IEnumerable<T> QuantConnect.Util.LinqExtensions.Range< T > ( start,
end,
Func< T, T >  incrementer,
bool  includeEndPoint = false 
)
static

Produces the an enumerable of the range of values between start and end using the specified incrementing function

Template Parameters
TThe enumerable item type
Parameters
startThe start of the range
endThe end of the range, non-inclusive by default
incrementerThe incrementing function, with argument of the current item
includeEndPointTrue to emit the end point, false otherwise
Returns
An enumerable of the range of items between start and end
Type Constraints
T :IComparable 

Definition at line 232 of file LinqExtensions.cs.

◆ GroupAdjacentBy< T >()

static IEnumerable<IEnumerable<T> > QuantConnect.Util.LinqExtensions.GroupAdjacentBy< T > ( this IEnumerable< T >  enumerable,
Func< T, T, bool >  grouper 
)
static

Groups adjacent elements of the enumerale using the specified grouper function

Template Parameters
TThe enumerable item type
Parameters
enumerableThe source enumerable to be grouped
grouperA function that accepts the previous value and the next value and returns true if the next value belongs in the same group as the previous value, otherwise returns false
Returns
A new enumerable of the groups defined by grouper. These groups don't have a key and are only grouped by being emitted separately from this enumerable

Definition at line 263 of file LinqExtensions.cs.

◆ AreDifferent< T >()

static bool QuantConnect.Util.LinqExtensions.AreDifferent< T > ( this ISet< T >  left,
ISet< T >  right 
)
static

Determines if there are any differences between the left and right collections. This method uses sets to improve performance and also uses lazy evaluation so if a difference is found, true is immediately returned and evaluation is halted.

Template Parameters
TThe item type
Parameters
leftThe left set
rightThe right set
Returns
True if there are any differences between the two sets, false otherwise

Definition at line 298 of file LinqExtensions.cs.

◆ AsEnumerable< T >()

static IEnumerable<T> QuantConnect.Util.LinqExtensions.AsEnumerable< T > ( this IEnumerator< T >  enumerator)
static

Converts an IEnumerator<T> to an IEnumerable<T>

Template Parameters
TCollection element type
Parameters
enumeratorThe enumerator to convert to an enumerable
Returns
An enumerable wrapping the specified enumerator

Definition at line 313 of file LinqExtensions.cs.

◆ GetValueOrDefault< K, V >()

static V QuantConnect.Util.LinqExtensions.GetValueOrDefault< K, V > ( this IDictionary< K, V >  dictionary,
key,
defaultValue = default(V) 
)
static

Gets the value associated with the specified key or provided default value if key is not found.

Template Parameters
KThe key type
VThe value type
Parameters
dictionaryThe dictionary instance
keyLookup key
defaultValueDefault value
Returns
Value associated with the specified key or default value

Definition at line 333 of file LinqExtensions.cs.

◆ DoForEach< T >()

static void QuantConnect.Util.LinqExtensions.DoForEach< T > ( this IEnumerable< T >  source,
Action< T >  action 
)
static

Performs an action for each element in collection source

Template Parameters
T
Parameters
sourceCollection source
actionAn action to perform

Definition at line 345 of file LinqExtensions.cs.


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