Article: the feature that makes D my favorite programming language

aberba karabutaworld at gmail.com
Sun Jul 26 11:13:06 UTC 2020


On Sunday, 26 July 2020 at 01:14:53 UTC, Paul Backus wrote:
> On Saturday, 25 July 2020 at 18:24:22 UTC, Jesse Phillips wrote:
>> On Saturday, 25 July 2020 at 14:47:01 UTC, aberba wrote:
>>> [...]
>>
>> It bugs me too, though I have done it.
>>
>> I think the right answer of why it is odd is because writeln 
>> is void. As soon as it is placed on the end the chain is 
>> broken and you can't expand on it.
>
> This is no different from any other "sink" that consumes a 
> range:
>
> someSource
>     .map!foo
>     .filter!bar
>     .splitter(baz)
>     .each!quux;
>
> `each` returns void [1], so using it ends the chain. But that's 
> not a problem, because the whole *point* of using `each` is to 
> consume the range.
>
> [1] Not exactly, but close enough.

I believe one can use tee!(writeln) to avoid consuming the range.


More information about the Digitalmars-d-announce mailing list