Pick
Applies the given chooser
function to successive elements, returning the first result where function returns an option value that IsSome
.
It works similar to Choose
function, but in this case only the first value is returned.
Parameters
Returns
Func<T, Option<T2>> chooser
IEnumerable<T> source
T2
Exceptions
Type
When
InvalidOperationException
The chooser function returns options with IsNone for all elements.
Usage
Getting the double of first odd number in a collection
//IEnumerable<int> source = { 2, 2, 4, 4, 6, 6, 7, 8, 9 }
int result = source.Pick(value =>
{
if(value % 2 == 1)
return value * 2;
else
return Option<int>.None();
});
//result = 14
Last updated
Was this helpful?