ChooseExtension.Choose<T, 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.ExtensionsAssembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
public static IEnumerable<TResult> Choose<T, TResult>(
this IEnumerable<T> source,
Func<T, (bool , TResult )> chooser
)
<ExtensionAttribute>
Public Shared Function Choose(Of T, TResult) (
source As IEnumerable(Of T),
chooser As Func(Of T, ( As Boolean, As TResult))
) As IEnumerable(Of TResult)
public:
[ExtensionAttribute]
generic<typename T, typename TResult>
static IEnumerable<TResult>^ Choose(
IEnumerable<T>^ source,
Func<T, ValueTuple<bool, TResult>>^ chooser
)
[<ExtensionAttribute>]
static member Choose :
source : IEnumerable<'T> *
chooser : Func<'T, ValueTuple<bool, 'TResult>> -> IEnumerable<'TResult>
- source IEnumerable<T>
- The source sequence.
- chooser Func<T, ValueTuple<Boolean, TResult>>
- The function that is applied to each source
element.
- T
-
The type of the elements in source.
- TResult
-
The type of the elements in the returned sequence.
IEnumerable<TResult>A sequence
TResult elements.In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerable<T>. 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).
This method uses deferred execution semantics and streams its
results.
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.