Impossible to put a map in sink context

jjmerelo :

I'm trying to see the way of throwing a map in sink context. In this code

class Sunk {
    has $.titanic;
    method sink {
        say "Sinking $!titanic";
    }
}

Sunk.new( :titanic($_) ) for 1..3;

(1..3).map: { Sunk.new( :titanic($_) ) };

The for loop effectively sinks all the created, the map does not. Any idea why?

This test in roast:https://github.com/perl6/roast/blob/b9bfe1844db25f65a4aeb351a0107f83689cb5c2/S04-statements/sink.t#L27-L32 is supposed to work as a test for that. And map is effectively in a sink context, but I dont' see how it's "run as sunk". It's simply run.

Elizabeth Mattijsen :

In your example, the map returns a Seq with Sunk objects in it. The entire Seq is sunk, which effectively calls Seq.iterator.sink-all, which does not sink all of its elements: it just pulls the Seq empty by calling pull-one until IterationEnd is returned.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=33043&siteId=1