Click or drag to resize

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.

Namespace:  MoreLinq
Assembly:  MoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntax
public static IEnumerable<TResult> Choose<T, TResult>(
	this IEnumerable<T> source,
	Func<T, (bool IsSome, TResult , )> chooser
)

Parameters

source
Type: System.Collections.GenericIEnumerableT
The source sequence.
chooser
Type: SystemFuncT, 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

Type: 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.
Examples
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