www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a skipOver function for InputRanges?

reply realhet <real_het hotmail.com> writes:
Hello,

I wanted to use skipOver on my input range, but I ran into an 
error that it needs a .save method in the range.

I can't give that because it's a generator function that catches 
yield()s, I can't save the state of that.

What I wanted to simplify is this:
```
void skipWhite()
{
   while(!scanner.empty && scanner.front.src.all!isWhite)
     scanner.popFront;
}
```

Is there a way to do it nicer with Phobos?
Or do I have to write a popFrontWhile() template function for 
this? (And try not to forget it's name in the future ;)
Oct 08
parent reply Dennis <dkorpel gmail.com> writes:
On Tuesday, 8 October 2024 at 07:14:28 UTC, realhet wrote:
 Is there a way to do it nicer with Phobos?
You can use `find` with a negated predicate: `find!(x => !x.front.all!isWhite)`
Oct 08
parent realhet <real_het hotmail.com> writes:
On Tuesday, 8 October 2024 at 10:43:31 UTC, Dennis wrote:
 On Tuesday, 8 October 2024 at 07:14:28 UTC, realhet wrote:
 Is there a way to do it nicer with Phobos?
You can use `find` with a negated predicate: `find!(x => !x.front.all!isWhite)`
Perfect, Thank You! I guess skipOver is more complex, it looks ahead, it's not just for one element, that's why it needs a ForwardRange.
Oct 08