问题描述
我想看看在接收器上下文中抛出地图的方式.在这段代码中
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($_) ) };
for
循环有效地接收所有创建的内容,map
没有.知道为什么吗?
The for
loop effectively sinks all the created, the map
does not. Any idea why?
此烤肉测试:https:/github.com/perl6/roast/blob/b9bfe1844db25f65a4aeb351a0107f83689cb5c2/S04-statements/sink.t#L27-L32 应该作为测试.地图实际上是在接收器上下文中,但我不知道它是如何按沉没运行"的.它只是运行.
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.
推荐答案
在您的示例中,map
返回带有 Sunk
对象的 Seq
在里面.整个 Seq
是沉没的,它有效地调用了 Seq.iterator.sink-all
,它不会沉没它的所有元素:它只是拉通过调用 pull-one
将 Seq
清空,直到返回 IterationEnd
.
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.
这篇关于无法在接收器上下文中放置地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!