Provides additional methods specific to a LinqIterable<XElement> such as ancestors, attributes, descendants, elements, and remove.

Hierarchy

Constructors

Properties

create: ((source: Iterable<XElement>) => LinqElements)

Type declaration

source: Iterable<XElement>

Methods

  • [iterator](): Iterator<XElement, any, undefined>
  • Returns the sequence of elements represented by this LinqIterable<T>.

    Returns

    The sequence of elements represented by this LinqIterable<T>.

    Returns Iterator<XElement, any, undefined>

  • all(predicate: PredicateWithIndex<XElement>): boolean
  • Returns true if the predicate is true for every element in the sequence or if the sequence is empty.

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    Returns boolean

  • For the elements contained in this sequence, returns the concatenated sequences of ancestors of such elements in reverse document order. If a name is provided, the resulting sequence contains only those ancestors having a matching name.

    Returns

    A flat sequence of ancestors in reverse document order.

    Parameters

    • Optional name: null | XName

      The optional name used to filter the sequence of ancestors.

    Returns LinqElements

  • For the elements contained in this sequence, returns the concatenated sequences of ancestors of such elements, including the elements themselves, in reverse document order. If a name is provided, the resulting sequence contains only those ancestors having a matching name.

    Returns

    A flat sequence of ancestors, including the elements, in reverse document order.

    Parameters

    • Optional name: null | XName

      The optional name used to filter the sequence of ancestors.

    Returns LinqElements

  • any(predicate?: PredicateWithIndex<XElement>): boolean
  • 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.

    Parameters

    • Optional predicate: PredicateWithIndex<XElement>

      The optional predicate.

    Returns boolean

  • For the elements contained in this sequence, returns the concatenated sequences of attributes of such elements. If a name is provided, the resulting sequence contains only those attributes having a matching name.

    Returns

    A function that will return a flat sequence of attributes.

    Parameters

    • Optional name: null | XName

      The optional name used to filter the sequence of attributes.

    Returns LinqAttributes

  • count(predicate?: PredicateWithIndex<XElement>): number
  • Returns the number of elements in the sequence. If a predicate is provided, filters the sequence based on the predicate.

    Returns

    The number of elements in the sequence.

    Parameters

    • Optional predicate: PredicateWithIndex<XElement>

      The optional predicate.

    Returns number

  • Returns the elements of the specified sequence or the default value if the sequence is empty.

    Returns

    The elements of the specified sequence or the default value if the sequence is empty.

    Parameters

    • defaultValue: XElement

      The default value to be returned if this sequence is empty.

    Returns LinqElements

  • For the elements contained in this sequence, returns the concatenated sequences of descendant nodes of such elements in document order.

    Returns

    The concatenated, flat sequence of descendant nodes in document order.

    Returns LinqNodes

  • For the elements contained in this sequence, returns the concatenated sequences of descendant nodes of such elements, including the elements themselves, in document order.

    Returns

    The concatenated, flat sequence of descendant nodes, including the source elements, in document order.

    Returns LinqNodes

  • For the elements contained in this sequence, returns the concatenated sequences of descendants of such elements in document order. If a name is provided, the resulting sequence contains only those descendants having a matching name.

    Returns

    The concatenated, flat sequence of descendant nodes in document order.

    Parameters

    • Optional name: null | XName

    Returns LinqElements

  • For the elements contained in this sequence, returns the concatenated sequences of descendants of such elements, including the elements themselves, in document order. If a name is provided, the resulting sequence contains only those elements and descendants having a matching name.

    Returns

    The concatenated, flat sequence of descendants, including the source elements, in document order.

    Parameters

    • Optional name: null | XName

    Returns LinqElements

  • For the elements contained in this sequence, returns the concatenated sequences of child elements of such elements in document order.

    If a name is provided, the resulting sequence contains only those child elements having a matching name.

    Returns

    The concatenated, flat sequence of child elements in document order.

    Parameters

    • Optional name: null | XName

    Returns LinqElements

  • Filters this sequence, using zero or more filters.

    Returns

    A filtered sequence.

    Parameters

    • Rest ...filters: IterableFilter<XElement>[]

      The filters to use.

    Returns LinqElements

  • Returns the first element of this sequence. If a predicate is provided, filters the sequence based on the predicate.

    Returns

    The first element.

    Throws

    If the (optionally filtered) sequence is empty.

    See

    last and single

    Parameters

    • Optional predicate: PredicateWithIndex<XElement>

      The optional predicate.

    Returns XElement

  • 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:

    • nullable (e.g., string?) and non-nullable (e.g.,string) reference types: null
    • nullable value types (e.g., int?, bool?): null
    • non-nullable value types (e.g., 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:

    • in C#, the default values are 0 and false, respectively; and
    • in TypeScript, the default value is undefined 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;

    Returns

    The first element of this sequence or undefined, if this sequence is empty.

    See

    lastOrDefault and singleOrDefault

    Returns undefined | XElement

  • Returns either (1) the first element of this sequence for which the predicate returns true or (2) undefined, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Example

    const sequence = linqIterable([1, 2, 3, 4, 5]);
    const nonNullValue = sequence.firstOrDefault((n) => n > 3); // 4
    const defaultValue = sequence.firstOrDefault((n) => n > 5); // undefined

    Returns

    Either (1) the first element of this sequence for which the predicate returns true or (2) undefined.

    See

    lastOrDefault and singleOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    Returns undefined | XElement

  • Returns the first element of this sequence or the given default value, if this sequence is empty.

    Remarks

    Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.

    Example

    const sequence = linqIterable<number>([]);
    const defaultValue = sequence.firstOrDefault(0); // 0

    Returns

    The first element of this sequence or the given default value, if this sequence is empty.

    See

    lastOrDefault and singleOrDefault

    Parameters

    • defaultValue: XElement

      The default value to be returned if this sequence is empty.

    Returns XElement

  • Returns either (1) the first element of this sequence for which the predicate returns true or (2) the given default value, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Example

    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

    Returns

    Either (1) the first element of this sequence for which the predicate returns true or (2) the given default value.

    See

    lastOrDefault and singleOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    • defaultValue: XElement

      The default value.

    Returns XElement

  • Returns the last element of the sequence. If a predicate is provided, filters the sequence based on the predicate.

    Returns

    The last element.

    Throws

    If the (optionally filtered) sequence is empty.

    See

    first and single

    Parameters

    • Optional predicate: PredicateWithIndex<XElement>

      The optional predicate.

    Returns XElement

  • 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:

    • nullable (e.g., string?) and non-nullable (e.g.,string) reference types: null
    • nullable value types (e.g., int?, bool?): null
    • non-nullable value types (e.g., 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:

    • in C#, the default values are 0 and false, respectively; and
    • in TypeScript, the default value is undefined 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;

    Returns

    The last element of this sequence or undefined, if this sequence is empty.

    See

    firstOrDefault and singleOrDefault

    Returns undefined | XElement

  • Returns either (1) the last element of this sequence for which the predicate returns true or (2) undefined, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Example

    const sequence = linqIterable([1, 2, 3, 4, 5]);
    const nonNullValue = sequence.lastOrDefault((n) => n > 3); // 4
    const defaultValue = sequence.lastOrDefault((n) => n > 5); // undefined

    Returns

    Either (1) the last element of this sequence for which the predicate returns true or (2) undefined.

    See

    firstOrDefault and singleOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    Returns undefined | XElement

  • Returns the last element of this sequence or the given default value, if this sequence is empty.

    Remarks

    Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.

    Example

    const sequence = linqIterable<number>([]);
    const defaultValue = sequence.lastOrDefault(0); // 0

    Returns

    The last element of this sequence or the given default value, if this sequence is empty.

    See

    firstOrDefault and singleOrDefault

    Parameters

    • defaultValue: XElement

      The default value to be returned if this sequence is empty.

    Returns XElement

  • Returns either (1) the last element of this sequence for which the predicate returns true or (2) the given default value, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Example

    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

    Returns

    Either (1) the last element of this sequence for which the predicate returns true or (2) the given default value.

    See

    firstOrDefault and singleOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    • defaultValue: XElement

      The default value.

    Returns XElement

  • For the elements contained in this sequence, returns the concatenated sequences of child nodes of such elements in document order.

    Returns

    The concatenated, flat sequence of child nodes in document order.

    Returns LinqNodes

  • remove(): void
  • Removes each element contained in this sequence from its parent XContainer.

    Returns void

  • resolve<TResult>(resolution: IterableTransform<XElement, TResult>): TResult
  • Applies the given resolution to this sequence.

    Returns

    The resolved value.

    Type Parameters

    • TResult

      The type of the result of the resolution.

    Parameters

    • resolution: IterableTransform<XElement, TResult>

      The resolution to use.

    Returns TResult

  • Projects, or maps, each element of a sequence into a new form.

    Returns

    The projected, or mapped, sequence.

    Type Parameters

    • TResult

      The type of the elements of the projected, or mapped, sequence.

    Parameters

    • selector: SelectorWithIndex<XElement, TResult>

      The selector used to project, or map, the elements.

    Returns LinqIterable<TResult>

  • selectMany<TResult>(selector: SelectorWithIndex<XElement, Iterable<TResult>>): LinqIterable<TResult>
  • Merges the selected sequences into one flat sequence.

    Returns

    The merged, flat sequence.

    Type Parameters

    • TResult

      The type of the elements of the flat sequence.

    Parameters

    • selector: SelectorWithIndex<XElement, Iterable<TResult>>

      The selector.

    Returns LinqIterable<TResult>

  • Returns the single element of the sequence. If a predicate is provided, filters the sequence based on the predicate.

    Returns

    The single element.

    Throws

    If the (optionally filtered) sequence does not contain exactly one element.

    See

    first and last

    Parameters

    • Optional predicate: PredicateWithIndex<XElement>

      The optional predicate.

    Returns XElement

  • 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:

    • nullable (e.g., string?) and non-nullable (e.g.,string) reference types: null
    • nullable value types (e.g., int?, bool?): null
    • non-nullable value types (e.g., 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:

    • in C#, the default values are 0 and false, respectively; and
    • in TypeScript, the default value is undefined 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;

    Returns

    The single element or undefined, if this sequence is empty.

    Throws

    If this sequence contains more than one element.

    See

    firstOrDefault and lastOrDefault

    Returns undefined | XElement

  • Returns either (1) the single element of this sequence for which the predicate returns true or (2) undefined, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Returns

    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.

    Throws

    If there is more than one element for which the predicate returns true.

    See

    firstOrDefault and lastOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    Returns undefined | XElement

  • Returns the single element of this sequence or the given default value, if this sequence is empty.

    Remarks

    Do not use this overload in case the elements of this sequence are functions. See the section on overloads for details.

    Returns

    The single element of this sequence or the given default value, if this sequence is empty.

    Throws

    If this sequence contains more than one element.

    See

    firstOrDefault and lastOrDefault

    Parameters

    • defaultValue: XElement

      The default value to be returned if this sequence is empty.

    Returns XElement

  • Returns either (1) the single element of this sequence for which the predicate returns true or (2) the given default value, if:

    • this sequence is empty or
    • the predicate returns false for all elements of this sequence.

    Returns

    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.

    Throws

    If there is more than one element for which the predicate returns true.

    See

    firstOrDefault and lastOrDefault

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The predicate.

    • defaultValue: XElement

      The default value to be returned if this sequence is empty or the predicate returns false for all elements.

    Returns XElement

  • Returns a new sequence that contains the elements from this sequence with the first count elements omitted.

    Returns

    A new sequence that contains the elements from this sequence with the first count elements omitted.

    Parameters

    • count: number

      The number of elements to be omitted.

    Returns LinqElements

  • Returns a new sequence that contains the elements from this sequence with the last count elements omitted.

    Returns

    A new sequence that contains the elements from this sequence with the first count elements omitted.

    Parameters

    • count: number

      The number of elements to be omitted.

    Returns LinqElements

  • Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.

    Returns

    A new sequence with the remaining elements.

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The specified condition.

    Returns LinqElements

  • Returns a new sequence that contains the specified number of contiguous elements from the start of this sequence.

    Returns

    a new sequence that contains the specified number of contiguous elements from the start of this sequence.

    Parameters

    • count: number

      The number of elements to take.

    Returns LinqElements

  • Returns a new sequence that contains the specified number of contiguous elements from the end of this sequence.

    Returns

    A new sequence that contains the specified number of contiguous elements from the end of this sequence.

    Parameters

    • count: number

      The number of elements to take.

    Returns LinqElements

  • Returns a new sequence that contains elements from this sequence that occur before the element at which the specified condition is false.

    Returns

    A new sequence that contains elements from this sequence that occur before the element at which the specified condition is false.

    Parameters

    • predicate: PredicateWithIndex<XElement>

      The specified condition.

    Returns LinqElements

  • transform<TResult>(transformation: IterableValueTransform<XElement, TResult>): LinqIterable<TResult>
  • Transforms this sequence, using the given transformation.

    Transform

    TResult The type of the elements of the transformed sequence.

    Returns

    A transformed sequence.

    Type Parameters

    • TResult

    Parameters

    • transformation: IterableValueTransform<XElement, TResult>

      The transformation to use.

    Returns LinqIterable<TResult>

Generated using TypeDoc