A little help with Ranges

Stefan Koch uplink.coder at googlemail.com
Fri Aug 27 02:35:19 UTC 2021


On Friday, 27 August 2021 at 02:17:21 UTC, Merlin Diavova wrote:
> On Friday, 27 August 2021 at 02:10:48 UTC, Stefan Koch wrote:
>> On Friday, 27 August 2021 at 01:51:42 UTC, Merlin Diavova 
>> wrote:
>>> Hi all,
>>>
>>> I'm Merlin, I'm just starting out in D and super excited.
>>>
>>> My questions are:-
>>>
>>> 1. In a range pipeline how does one handle the event of a 
>>> filter range returning empty?
>>>
>>> 2. How does one unwrap a single result from a range operation?
>>>
>>>
>>> Look forward to your assistance!
>>>
>>> Merlin
>>
>> 1. you don't have to handle it.
>> it just won't go.
>>
>> 2. `takeOne` put it into the search on the dlang site
>
> Thanks for the quick response!
>
> Took a look at takeOne and yep that's the ticket.
>
> What I meant about the handling an empty filter is, what if I 
> want to take an alternative route if the filter returns empty?

You check if it's by calling empty.
or do you want a default value? I am sure there is a convince 
function for that somewhere in phobos.


More information about the Digitalmars-d-learn mailing list