phobos/changelog/std-range-nullsink.dd
Sebastian Wilzbach b80820e50f std.range.nullSink - allow convenient use of the NullSink
`nullSink` returns the `NullSink` by reference and thus allows using it
directly in code which expects an OutputRange by reference.

The pattern is providing convenience wrappers for struct construction is
very common in Phobos, e.g. `rebindable`, `nullable`, `refCounted`, ...
2017-12-25 00:02:04 +01:00

20 lines
479 B
Text

`nullSink` was added to `std.range`
$(REF nullSink, std, range) is a convenience wrapper for $(REF NullSink, std,range)
and creates an output range that discards the data it receives. It's the range analog
of `/dev/null`.
---
import std.csv : csvNextToken;
string line = "a,b,c";
// ignore the first column
line.csvNextToken(nullSink, ',', '"');
line.popFront;
// look at the second column
Appender!string app;
line.csvNextToken(app, ',', '"');
assert(app.data == "b");
---