Range golf challenge: apply predicate to a subrange, returning the original range modified.
H. S. Teoh
hsteoh at qfbox.info
Fri Oct 7 17:09:10 UTC 2022
On Fri, Oct 07, 2022 at 04:49:33PM +0000, rassoc via Digitalmars-d wrote:
> On 10/7/22 16:00, FeepingCreature via Digitalmars-d wrote:
> > Thoughts?
>
> How about your selector func wraps the elements, similar to Nullable
> or via SumType, and your modifier func operates on the marked ones
> during iteration while returning the others as is? Poor man's monads?
Another way is if you convert .select into a predicate, then:
auto r = myrange.map!(e => pred(e) ? modify(e) : e);
But that depends on how easy it is to convert .select into a predicate.
T
--
If lightning were to ever strike an orchestra, it'd always hit the conductor first.
More information about the Digitalmars-d
mailing list