Thread overview |
---|
October 18, 2015 std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
How do you call startsWith with only a predicate --- import std.algorithm; import std.ascii; bool iden(string str) { return str.startsWith!(a => a.isAlpha || a == '_'); } --- |
October 18, 2015 Re: std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | On Sunday, 18 October 2015 at 17:48:20 UTC, Freddy wrote:
> How do you call startsWith with only a predicate
> ---
> import std.algorithm;
> import std.ascii;
>
> bool iden(string str)
> {
> return str.startsWith!(a => a.isAlpha || a == '_');
> }
> ---
Is this a simplified use case of some actual code you have? Otherwise, you can just do:
bool iden(string str)
{
auto f = str.front;
return f.isAlpha || f == '_';
}
|
October 18, 2015 Re: std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Meta | On Sunday, 18 October 2015 at 17:58:30 UTC, Meta wrote:
> Is this a simplified use case of some actual code you have? Otherwise, you can just do:
>
>
> bool iden(string str)
> {
> auto f = str.front;
> return f.isAlpha || f == '_';
> }
It's simplified, i wanted to check for empty
|
October 18, 2015 Re: std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Freddy | On Sunday, October 18, 2015 17:48:18 Freddy via Digitalmars-d-learn wrote:
> How do you call startsWith with only a predicate
> ---
> import std.algorithm;
> import std.ascii;
>
> bool iden(string str)
> {
> return str.startsWith!(a => a.isAlpha || a == '_');
> }
> ---
startsWith doesn't have an overload that takes only a predicate. The existing overloads all require at least one "needle" to search for in the "haystack." An overload that doesn't require a needle could certainly be added, but there isn't one right now.
- Jonathan M Davis
|
October 19, 2015 Re: std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jonathan M Davis | On Sunday, 18 October 2015 at 21:44:57 UTC, Jonathan M Davis wrote: > startsWith doesn't have an overload that takes only a predicate. The existing overloads all require at least one "needle" to search for in the "haystack." An overload that doesn't require a needle could certainly be added, but there isn't one right now. > > - Jonathan M Davis https://github.com/D-Programming-Language/phobos/pull/3752 |
January 27, 2016 Re: std.algorithm.startsWith only predicate | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nordlöw | On Monday, 19 October 2015 at 19:20:15 UTC, Nordlöw wrote:
> https://github.com/D-Programming-Language/phobos/pull/3752
Is merged now!
|
Copyright © 1999-2021 by the D Language Foundation