drop* and take* only for specific element values

Jonathan M Davis via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Aug 13 08:01:04 PDT 2014


On Wed, 13 Aug 2014 07:45:17 -0700
Jonathan M Davis via Digitalmars-d-learn
<digitalmars-d-learn at puremagic.com> wrote:

> On Wed, 13 Aug 2014 14:28:29 +0000
> Meta via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
> wrote:
>
> > On Wednesday, 13 August 2014 at 12:37:34 UTC, Nordlöw wrote:
> > > Are there variants of drop* and take* that only drop element if
> > > its equal to a value kind of like strip does?
> > >
> > > If not I believe they should be added.
> >
> > No, but it'd probably be useful. Maybe call them dropIf/takeIf,
> > or just add an overload that takes a predicate... I'll look into
> > making a pull request sometime this week. How do you envision
> > these working?
>
> They're called find and until. You just have to give them the opposite
> predicate that you'd give a function called dropIf or takeIf.

I should probably pointed out that we attempted to put dropWhile and takeWhile
into Phobos quite some time ago (which would basically be dropIf and takeIf),
but Andrei refused to let them in, because all they did was reverse the
predicate, so arguments that they should be added based on the fact that find
and until take the opposite predicate aren't going to fly.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list