Replies: 1 comment
-
mmm.... I'd probably prefer public static IEnumerable<T> TransformIf(
this IEnumerable<T> source,
bool condition,
Func<IEnumerable<T>, IEnumerable<T>> transformer); I probably won't take the time to implement, because I've never found a need for it; but I can see the value of it, so if you want to submit a PR for it, I'll take it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was coding a feature today, and i came across one specific usecase.
I have optional arguments given at run time. in my case it was Skip and Take.
so if provided i needed to update my IEnumerable to match the provided settings.
for the Skip it was easy:
foreach( var i in Enumerator.Skip(maybeSkip ?? 0) )
but for the take, there's no default, so it would be
foreach( var i in Enumerator.Skip(maybeSkip ?? 0) .Take(maybeTake ?? Enumerator.Count))
or i could do something like:
if(maybeSkip.hasvalue) then update Iterator
if(maybeTake.Hasvalue) then update iterator
BUT
it would be nice to be able to chain conditionnal LinqMethods like:
var iterator
.TakeIf(count, ApplyTakePredicateFunc
.SkipIf(count, ApplySkipPredicateFunc)
.OrderByIf(x => Name, ApplyOrderByPredidateFunc)
you see the picture.
or just having an IF extension like :
public static IEnumerable If(
this IEnumerable source,
bool condition,
Func<IEnumerable, IEnumerable> branch)
{
return condition ? branch(source) : source;
}
Beta Was this translation helpful? Give feedback.
All reactions