[Issue 18121] New: Needleless findSplit* methods

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 24 21:40:33 UTC 2017


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

          Issue ID: 18121
           Summary: Needleless findSplit* methods
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: phobos
          Assignee: nobody at puremagic.com
          Reporter: the.mail.of.mi2 at gmail.com

I'd like to suggest enriching findSplit* method family with the "needleless"
predicate option.

Motivation:

Let's have a range of string tokens that - after cutting of the initial brace -
looks like this:

    auto range = ["23", "42", "14.3", "-323", "}"]

Now I want to map all the numbers to the array:

    auto array = range.findSplitBefore(x => !x.isNumeric).map(to!double).array;

As you can see, I do not need the second parameter of prediate, as I am not
comparing the subsequent haystack elements with any needle - I check the
condition on the haystack elements alone instead. Unfortunately, It's not that
simple, because I have only this prototype:

     auto findSplitBefore(alias pred, R1, R2)(R1 haystack, R2 needle) //[...]

That's why I need to add a dummy parameter to achieve what I want to:

    auto array = range.findSplitBefore(x =>
!x.isNumeric)([""]).map(to!double).array;

So what I suggest is to add this prototype as well for convenience:

     auto findSplitBefore(alias pred, R)(R haystack) //[...]

and the similar ones for findSplit and findSplitAfter.

--


More information about the Digitalmars-d-bugs mailing list