[Issue 4535] std.range could have a takeWhile!pred(range) function

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Jul 14 16:36:06 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=4535

--- Comment #13 from KnightMare <black80 at bk.ru> ---
(In reply to KnightMare from comment #12)

my version of wrapping "until" to "takeWhile":
auto takeWhile( alias F, R )( R r ) {
    struct NR {
        bool isEmpty = false;
        this( bool e ) { isEmpty = e; }

        bool empty() { return isEmpty; }
        auto front() { return r.front; }
        void popFront() { 
            if (isEmpty) return;
            r.popFront;
            isEmpty = isEmpty || !F( r.front);
        }
    }
    return NR( r.empty );
}

I was hinted at IRC channel that it can be simpler:
> auto takeWhile( alias pred, A...)( A a) { return until!( not!pred)( a); }

and no string version yet like .takeWhile!"n<7".

do u see that how many code for not familiar users with metaprogramming in D?
u should understand that most of programmers don't know every aspect in D, they
try to use same things that they are used before same way as before, they have
some expectations, they want more clearness without new strong headache that
exists in learning of non-trivail programming language.
so, adding known aliases and simpler versions of algos to Phobos u make simpler
life for other non-meta-gurus.

imo nobody will search "until" for enumerating ranges when they are look at 4
"take..." and don't see "take with predicate".. yes, they have some thoughts
that should exists something with predicate - it is so expected.. but it new
research for nothing when they are researching cure for cancer for example.

--


More information about the Digitalmars-d-bugs mailing list