MoreEnumerableChooseT, TResult Method

Applies a function to each element of the source sequence and returns a new sequence of result elements for source elements where the function returns a couple (2-tuple) having a true as its first element and result as the second.

Definition

Namespace: MoreLinq
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<TResult> Choose<T, TResult>(
	this IEnumerable<T> source,
	Func<T, (bool , TResult )> chooser
)

Parameters

source  IEnumerableT
The source sequence.
chooser  FuncT, ValueTupleBoolean, TResult
The function that is applied to each source element.

Type Parameters

T
The type of the elements in source.
TResult
The type of the elements in the returned sequence.

Return Value

IEnumerableTResult
A sequence TResult elements.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This method uses deferred execution semantics and streams its results.

Example

C#
var str = "O,l,2,3,4,S,6,7,B,9";
var xs = str.Split(',').Choose(s => (int.TryParse(s, out var n), n));
The xs variable will be a sequence of the integers 2, 3, 4, 6, 7 and 9.

See Also