Skip to Content
Raku学习手册
book

Raku学习手册

by brian d foy
October 2020
Beginner to intermediate
499 pages
9h 13m
Chinese
China Electric Power Press Ltd.
Content preview from Raku学习手册
124
6
Seq
需要知道如何得到下一个元素,一旦使用了这个元素就可以将它删除,它不会记
住以前的值。如果处理完
Seq
的所有元素之后再试图使用这个
Seq
,你会得到一个错
误:
put $sequence.pick; # 3 (or maybe something else)
put $sequence; # Error
这个错误指出了你要怎么做:
This Seq has already been iterated, and its values consumed
(you might solve this by adding .cache on usages of the Seq, or
by assigning the Seq into an array)
增加
.cache
就能记住
Seq
的元素,从而能重用这些元素。现在使用了
.pick
之后不
再有错误:
my $range = 0 .. 5;
my $sequence = $range.reverse.cache;
say $sequence.^name; # Seq;
put $sequence.pick; # 5 (or maybe something else)
put $sequence; # 5 4 3 2 1 0
不过,这样做时要特别当心。
Seq
的好处之一就是它能节省内存,因为除非真正需要
否则它不复制数据。
6.3.1
无限惰性列表
Seq
必须创建所有元素从而使用
.pick
选择其中一个元素。一旦完成,它会忘记这些
元素,而且没有办法再创建更多元素。 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

可编程网络自动化

可编程网络自动化

Jason Edelman, Scott S. Lowe, Matt Oswalt
程序员学数据结构

程序员学数据结构

Posts & Telecom Press, William Smith
R深度学习权威指南

R深度学习权威指南

Posts & Telecom Press, Joshua F. Wiley
AI工程

AI工程

Chip Huyen

Publisher Resources

ISBN: 9787519848002