Initializes a new instance with the given source sequence.
The source sequence.
Protected
Readonly
createProtected
Readonly
sourceReturns the sequence of elements represented by this LinqIterable<T>
.
The sequence of elements represented by this LinqIterable<T>
.
Returns true if the predicate is true for every element in the sequence or if the sequence is empty.
The predicate.
If a predicate is provided, returns true if the predicate is true for any element in the sequence. If no predicate is provided, returns true if the sequence has any entries.
Optional
predicate: PredicateWithIndex<XAttribute>The optional predicate.
Filters this sequence, using the given filters.
A filtered sequence.
The filters to use.
Returns the number of elements in the sequence. If a predicate is provided, filters the sequence based on the predicate.
The number of elements in the sequence.
Optional
predicate: PredicateWithIndex<XAttribute>The optional predicate.
Returns the elements of the specified sequence or the default value if the sequence is empty.
The elements of the specified sequence or the default value if the sequence is empty.
The default value to be returned if this sequence is empty.
Filters this sequence, using zero or more filters.
A filtered sequence.
Rest
...filters: IterableFilter<XAttribute>[]The filters to use.
Returns the first element of this sequence. If a predicate is provided, filters the sequence based on the predicate.
The first element.
If the (optionally filtered) sequence is empty.
Optional
predicate: PredicateWithIndex<XAttribute>The optional predicate.
Returns the first element of this sequence or undefined
, if the sequence is empty.
When using this API, you should appreciate the differences between C# vs. JavaScript
and TypeScript regarding the default values used for different types, e.g., as
assigned by using the default
keyword in C# or when not explicitly initializing
fields or variables in JavaScript.
In C#, the default values are as follows:
string?
) and non-nullable (e.g.,string
) reference types: null
int?
, bool?
): null
int
, bool
): 0
and false
In JavaScript, the default value for uninitialized fields or variables is undefined
in all cases. In TypeScript, you must either explicitly allow undefined
in the
declaration or use the non-null assertion operator (!
) to assign undefined
.
Now, let's look at the signature of the well-known FirstOrDefault()
extension method
in C# (based on the .NET 6 documentation, which uses TSource
instead of T
):
public static T? FirstOrDefault<T>(this IEnumerable<T> source);
Based on our understanding of the default values, the most natural signature in TypeScript is the following:
firstOrDefault(): T | undefined;
On an abstract level, the C# and TypeScript counterparts behave in the same way.
For empty sequences, they both return the respective default values. On a concrete
level, however, the language-specific difference between the default values for
non-nullable value types in C# (e.g., int
, bool
) and the correspnding types
in TypeScript (e.g., number
, boolean
) is that:
0
and false
, respectively; andundefined
in all cases.Should you want to receive a value other than undefined
in case the sequence
is empty, you can use one of the overloads that allows you to specify a default
value:
firstOrDefault(defaultValue: T): T;
firstOrDefault(predicate: PredicateWithIndex<T>, defaultValue: T): T;
The first element of this sequence or undefined
, if this sequence is empty.
Returns either (1) the first element of this sequence for which the predicate
returns true
or (2) undefined
, if:
false
for all elements of this sequence.const sequence = linqIterable([1, 2, 3, 4, 5]);
const nonNullValue = sequence.firstOrDefault((n) => n > 3); // 4
const defaultValue = sequence.firstOrDefault((n) => n > 5); // undefined
Either (1) the first element of this sequence for which the predicate
returns true
or (2) undefined
.
The predicate.
Returns the first element of this sequence or the given default value, if this sequence is empty.
Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.
const sequence = linqIterable<number>([]);
const defaultValue = sequence.firstOrDefault(0); // 0
The first element of this sequence or the given default value, if this sequence is empty.
The default value to be returned if this sequence is empty.
Returns either (1) the first element of this sequence for which the predicate
returns true
or (2) the given default value, if:
false
for all elements of this sequence.const sequence = linqIterable([1, 2, 3, 4, 5]);
const nonNullValue = sequence.firstOrDefault((n) => n > 3, 0); // 4
const defaultValue = sequence.firstOrDefault((n) => n > 5, 0); // 0
Either (1) the first element of this sequence for which the predicate
returns true
or (2) the given default value.
The predicate.
The default value.
Groups elements by selected key.
The grouped elements.
The type of the grouping keys.
Selects the grouping keys.
Returns the last element of the sequence. If a predicate is provided, filters the sequence based on the predicate.
The last element.
If the (optionally filtered) sequence is empty.
Optional
predicate: PredicateWithIndex<XAttribute>The optional predicate.
Returns the last element of this sequence or undefined
, if the sequence is empty.
When using this API, you should appreciate the differences between C# vs. JavaScript
and TypeScript regarding the default values used for different types, e.g., as
assigned by using the default
keyword in C# or when not explicitly initializing
fields or variables in JavaScript.
In C#, the default values are as follows:
string?
) and non-nullable (e.g.,string
) reference types: null
int?
, bool?
): null
int
, bool
): 0
and false
In JavaScript, the default value for uninitialized fields or variables is undefined
in all cases. In TypeScript, you must either explicitly allow undefined
in the
declaration or use the non-null assertion operator (!
) to assign undefined
.
Now, let's look at the signature of the well-known LastOrDefault()
extension method
in C# (based on the .NET 6 documentation, which uses TSource
instead of T
):
public static T? LastOrDefault<T>(this IEnumerable<T> source);
Based on our understanding of the default values, the most natural signature in TypeScript is the following:
lastOrDefault(): T | undefined;
On an abstract level, the C# and TypeScript counterparts behave in the same way.
For empty sequences, they both return the respective default values. On a concrete
level, however, the language-specific difference between the default values for
non-nullable value types in C# (e.g., int
, bool
) and the correspnding types
in TypeScript (e.g., number
, boolean
) is that:
0
and false
, respectively; andundefined
in all cases.Should you want to receive a value other than undefined
in case the sequence
is empty, you can use one of the overloads that allows you to specify a default
value:
lastOrDefault(defaultValue: T): T;
lastOrDefault(predicate: PredicateWithIndex<T>, defaultValue: T): T;
The last element of this sequence or undefined
, if this sequence is empty.
Returns either (1) the last element of this sequence for which the predicate
returns true
or (2) undefined
, if:
false
for all elements of this sequence.const sequence = linqIterable([1, 2, 3, 4, 5]);
const nonNullValue = sequence.lastOrDefault((n) => n > 3); // 4
const defaultValue = sequence.lastOrDefault((n) => n > 5); // undefined
Either (1) the last element of this sequence for which the predicate
returns true
or (2) undefined
.
The predicate.
Returns the last element of this sequence or the given default value, if this sequence is empty.
Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.
const sequence = linqIterable<number>([]);
const defaultValue = sequence.lastOrDefault(0); // 0
The last element of this sequence or the given default value, if this sequence is empty.
The default value to be returned if this sequence is empty.
Returns either (1) the last element of this sequence for which the predicate
returns true
or (2) the given default value, if:
false
for all elements of this sequence.const sequence = linqIterable([1, 2, 3, 4, 5]);
const nonNullValue = sequence.lastOrDefault((n) => n > 3, 0); // 4
const defaultValue = sequence.lastOrDefault((n) => n > 5, 0); // 0
Either (1) the last element of this sequence for which the predicate
returns true
or (2) the given default value.
The predicate.
The default value.
Removes each XAttribute
represented in this sequence from its parent
XElement
.
Applies the given resolution to this sequence.
The resolved value.
The type of the result of the resolution.
The resolution to use.
Projects, or maps, each element of a sequence into a new form.
The projected, or mapped, sequence.
The type of the elements of the projected, or mapped, sequence.
The selector used to project, or map, the elements.
Merges the selected sequences into one flat sequence.
The merged, flat sequence.
The type of the elements of the flat sequence.
The selector.
Returns the single element of the sequence. If a predicate is provided, filters the sequence based on the predicate.
The single element.
If the (optionally filtered) sequence does not contain exactly one element.
Optional
predicate: PredicateWithIndex<XAttribute>The optional predicate.
Returns the single element of this sequence or undefined
, if the sequence is empty.
When using this API, you should appreciate the differences between C# vs. JavaScript
and TypeScript regarding the default values used for different types, e.g., as
assigned by using the default
keyword in C# or when not explicitly initializing
fields or variables in JavaScript.
In C#, the default values are as follows:
string?
) and non-nullable (e.g.,string
) reference types: null
int?
, bool?
): null
int
, bool
): 0
and false
In JavaScript, the default value for uninitialized fields or variables is undefined
in all cases. In TypeScript, you must either explicitly allow undefined
in the
declaration or use the non-null assertion operator (!
) to assign undefined
.
Now, let's look at the signature of the well-known SingleOrDefault()
extension method
in C# (based on the .NET 6 documentation, which uses TSource
instead of T
):
public static T? SingleOrDefault<T>(this IEnumerable<T> source);
Based on our understanding of the default values, the most natural signature in TypeScript is the following:
singleOrDefault(): T | undefined;
On an abstract level, the C# and TypeScript counterparts behave in the same way.
For empty sequences, they both return the respective default values. On a concrete
level, however, the language-specific difference between the default values for
non-nullable value types in C# (e.g., int
, bool
) and the correspnding types
in TypeScript (e.g., number
, boolean
) is that:
0
and false
, respectively; andundefined
in all cases.Should you want to receive a value other than undefined
in case the sequence
is empty, you can use one of the overloads that allows you to specify a default
value:
singleOrDefault(defaultValue: T): T;
singleOrDefault(predicate: PredicateWithIndex<T>, defaultValue: T): T;
The single element or undefined
, if this sequence is empty.
If this sequence contains more than one element.
Returns either (1) the single element of this sequence for which the predicate
returns true
or (2) undefined
, if:
false
for all elements of this sequence.Either (1) the single element of this sequence for which the predicate
returns true
or (2) undefined
, if the predicate returns false
for all
elements.
If there is more than one element for which the predicate returns true
.
The predicate.
Returns the single element of this sequence or the given default value, if this sequence is empty.
Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.
The single element of this sequence or the given default value, if this sequence is empty.
If this sequence contains more than one element.
The default value to be returned if this sequence is empty.
Returns either (1) the single element of this sequence for which the predicate
returns true
or (2) the given default value, if:
false
for all elements of this sequence.Either (1) the single element of this sequence for which the predicate
returns true
or (2) the given default value, if the predicate returns
false
for all elements.
If there is more than one element for which the predicate returns true
.
The predicate.
The default value to be returned if this sequence is empty or the predicate returns false for all elements.
Returns a new sequence that contains the elements from this sequence with
the first count
elements omitted.
A new sequence that contains the elements from this sequence with
the first count
elements omitted.
The number of elements to be omitted.
Returns a new sequence that contains the elements from this sequence with
the last count
elements omitted.
A new sequence that contains the elements from this sequence with
the first count
elements omitted.
The number of elements to be omitted.
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
A new sequence with the remaining elements.
The specified condition.
Returns a new sequence that contains the specified number of contiguous elements from the start of this sequence.
a new sequence that contains the specified number of contiguous elements from the start of this sequence.
The number of elements to take.
Returns a new sequence that contains the specified number of contiguous elements from the end of this sequence.
A new sequence that contains the specified number of contiguous elements from the end of this sequence.
The number of elements to take.
Returns a new sequence that contains elements from this sequence that occur before the element at which the specified condition is false.
A new sequence that contains elements from this sequence that occur before the element at which the specified condition is false.
The specified condition.
Returns all the elements in the sequence as an array.
Transforms this sequence, using the given transformation.
TResult The type of the elements of the transformed sequence.
A transformed sequence.
The transformation to use.
Filters the sequence using the given predicate.
The filtered sequence.
The predicate.
Generated using TypeDoc
Provides additional methods specific to a
LinqIterable<XAttribute>
.