digitalmars.D - Suggestion: needleless findSplit* methods
- Piotr Mitana (23/23) Dec 12 2017 Hello,
- bauss (4/8) Dec 12 2017 Either do it yourself and create a pull-request or go here
- bauss (2/14) Dec 12 2017 Oops, the link was meant to be: https://issues.dlang.org
- Seb (5/9) Dec 12 2017 ... or you simply use `until`:
- Jonathan M Davis (6/17) Dec 12 2017 You can, but you end up with a different range type that way, whereas wi...
Hello, I'd like to make a little suggestion for phobos: enrich 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 I suggest adding this prototype as well for convenience: auto findSplitBefore(alias pred, R)(R haystack) //[...]
Dec 12 2017
On Tuesday, 12 December 2017 at 08:19:39 UTC, Piotr Mitana wrote:Hello, I'd like to make a little suggestion for phobos: enrich findSplit* method family with the "needleless" predicate option. [...]Either do it yourself and create a pull-request or go here instead of posting in the forums: https://dlang.org/bugstats.php
Dec 12 2017
On Tuesday, 12 December 2017 at 09:17:21 UTC, bauss wrote:On Tuesday, 12 December 2017 at 08:19:39 UTC, Piotr Mitana wrote:Oops, the link was meant to be: https://issues.dlang.orgHello, I'd like to make a little suggestion for phobos: enrich findSplit* method family with the "needleless" predicate option. [...]Either do it yourself and create a pull-request or go here instead of posting in the forums: https://dlang.org/bugstats.php
Dec 12 2017
On Tuesday, 12 December 2017 at 08:19:39 UTC, Piotr Mitana wrote:Hello, I'd like to make a little suggestion for phobos: enrich findSplit* method family with the "needleless" predicate option. [...]... or you simply use `until`: auto r = ["23", "42", "14.3", "-323", "}"]; r.until!(x => !x.isNumeric).map!(to!double).writeln; Runnable example: https://run.dlang.io/is/zNRzpI
Dec 12 2017
On Tuesday, December 12, 2017 09:25:57 Seb via Digitalmars-d wrote:On Tuesday, 12 December 2017 at 08:19:39 UTC, Piotr Mitana wrote:You can, but you end up with a different range type that way, whereas with findSplit*, you can retain the original range type with at least some ranges. So, improving findSplit* is a perfectly valid enhancement request. But for some use cases, until will certainly do the job. - Jonathan M DavisHello, I'd like to make a little suggestion for phobos: enrich findSplit* method family with the "needleless" predicate option. [...]... or you simply use `until`: auto r = ["23", "42", "14.3", "-323", "}"]; r.until!(x => !x.isNumeric).map!(to!double).writeln; Runnable example: https://run.dlang.io/is/zNRzpI
Dec 12 2017