ChooseExtensionChooseT, 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.Extensions
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
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