Range golf challenge: apply predicate to a subrange, returning the original range modified.

Ali Çehreli acehreli at yahoo.com
Fri Oct 7 20:19:07 UTC 2022


On 10/7/22 12:19, FeepingCreature wrote:
 > On Friday, 7 October 2022 at 16:49:33 UTC, rassoc 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?
 >
 > Y'all are missing the point a bit. :)

It's because of your example! :)

 > The type spec of the selector is "takes a range, returns a subrange." A
 > subrange here being "a range like the original but with some amount of
 > elements missing."

Your example does not miss the "missing" elements (the odd ones):

   assert(result.equal([0, 1, 4, 3, 8, 5, 12, 7, 16, 9]));

Maybe you mean selectSubrange is already written and does miss some 
elements and the goal is to merge those back into where they were 
missing from.

Ali




More information about the Digitalmars-d mailing list