News for hackers. Stuff that matters.
Re:Why nullable types? by contravariant on Tuesday December 08, 2020 @03:42PM (#25351070)
You missed out the most interesting one, which is 'reduce':

    extension NullableIteratorExtensions<T> on Iterator<T?> {     
      T? reduce<T>(T? Function(T,T) f, T? x0)
         => this.moveNext()
            ? (this.reduce(f, (x0 == null || this.current == null) ? null : f(x0,current)))
            : x0;
    }
Not sure if this is the best notation but then I've never written Dart before.

Of course this is all a bit easier to read if we use some syntax specially built for Monads such as Haskell's do syntax:

    reduce f (head:tail) x0 = do { x <- x0 
                                 ; y <- head
                                 ; reduce f tail (f x y) }
    reduce f [] x0 = x0
which has the advantage that it works for all Monads.

There are no comments on this comment yet.