Iterator Pattern

http://groovy-lang.org/design-patterns.html#_flyweight_pattern

迭代器模式,允许顺序访问 聚集对象中的中元素, 而不用关心起内部是如何实现的。

groovy有自己的语言内置的闭包操作, 例如 each

The Iterator Pattern allows sequential access to the elements of an aggregate object without exposing its underlying representation.

Groovy has the iterator pattern built right in to many of its closure operators, e.g. each and eachWithIndex as well as the for .. in loop.

例子

def printAll(container) {
for (item in container) { println item }
} def numbers = [ 1,2,3,4 ]
def months = [ Mar:31, Apr:30, May:31 ]
def colors = [ java.awt.Color.BLACK, java.awt.Color.WHITE ]
printAll numbers
printAll months
printAll colors
colors.eachWithIndex { item, pos ->
println "Position $pos contains '$item'"
}

最新文章

  1. Android MVP+Retrofit+RxJava实践小结
  2. JavaScript--面向对象--猜拳游戏
  3. Delphi TListView刷新闪烁问题
  4. .NET NLog 详解(一)
  5. 小白学数据分析----->DNU/DAU
  6. spring mvc jsp运行不起来的问题
  7. 哎呀,发现自己不会用模块的方式用kprobe啊,弱爆了
  8. euqals和hashcode
  9. 使用websocket-sharp来创建c#版本的websocket服务
  10. 正确使用volatile场景--状态标志
  11. H5自定义金额键盘,改良后ios体验效果流畅
  12. 视觉SLAM中的数学基础 第二篇 四元数
  13. 【DB】MYSQL相关细节
  14. Code Signal_练习题_shapeArea
  15. 安装framework 4.6.2的时报错 “无法建立到信任根颁发机构的证书链”
  16. C#中调用Dll动态链接库
  17. 分分钟钟学会Python - 数据类型(int、bool、str)
  18. oracle procedure简单的将临时表的数据插入或更新到目标表
  19. phantomjs的和谷歌浏览器的简单使用
  20. GreenPlum 与hadoop什么关系?(转)

热门文章

  1. Netty(RPC高性能之道)原理剖析
  2. SpringBoot打包成war
  3. PHP 练习(新闻发布)
  4. OCR技术浅析-无代码篇(1)
  5. virtualbox 设置centos7 双网卡上网
  6. app.use和app.get,app.post区别
  7. 其他综合-使用Xshell远程连接管理Linux实践
  8. python之路6-迭代器、生成器、装饰器
  9. 常用的flex布局
  10. IE 11 flex布局兼容性问题 ---- 不支持min-height 和flex:1