On Wed, 2 Dec 2020 at 09:15, roger peppe <rogpe...@gmail.com> wrote: > Also your delayed blocks don't wait for the preceding set of futures to be >> exhausted before proceeding, I think they're all triggered once the initial >> set is completed > > > Each delayed block is triggered when its associated delay has elapsed. > Once the initial set is completed, it returns immediately. Isn't that what > you want? As I said, I'm finding it hard to imagine a scenario where these > particular semantics are useful, so it's not easy to decide how to treat > the edge cases. > > I think my issue comes down to being unsure about how to >> easily/consistently perform mappings between generic types (like F[A] -> >> F[B]). > > > I assume that by "perform mappings" you're wondering how to write a > function like this: > > // Map returns a future that yields fn(r) where r is the result value of f. > func Map[A, B any](f *F[A], fn func(A) B) *F[B] > > I don't believe that's possible with your existing package. >
I'm talking rubbish there, I'm afraid. It's entirely possible to do this, albeit at the cost of an extra goroutine: func Map[A, B any](f *F[A], fn func(A) B) *F[B] { return Start(func() (B, error) { a, err := f.Result() if err != nil { return *new(B), err } return fn(a), nil }) } -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CAJhgacjEkffmOptr%2Bg_q19wdNYp88f8g5g4oMKXQX4wLzdiBog%40mail.gmail.com.