Range to Nullable conversion

Antonio antonio at abrevia.net
Fri Jun 10 18:18:17 UTC 2022


On Friday, 10 June 2022 at 17:37:13 UTC, Ali Çehreli wrote:
> On 6/10/22 10:22, Antonio wrote:
> > Is there any alternative to ***range front*** that returns a
> Nullable
> > (i.e. **frontAsMonad** or **frontAsNullable**)?
>
> import std;
>
> // Spelling? :)
> auto nullablelize(R)(R range) {
>   ...
> }
>
> void main() {
>   // Wow! We can take 10 elements without error. :)
>   writeln(iota(5)
>           .filter!(i => i % 2)
>           .nullablelize
>           .take(10));
> }
>
> Ali

That's cheating :-p... you used a helper method+structure.

Nice example, Thank you Ali.


More information about the Digitalmars-d-learn mailing list