Documentation ¶
Overview ¶
实现了一种惰性列表数据结构:流。
该结构中的数据是不可修改的,并且会对已经计算的数据进行缓存,不会重复计算。 由于采用了惰性计算,因此该结构中的数据个数可以是无限的。
Index ¶
- type Stream
- func (self *Stream) All(f interface{}) bool
- func (self *Stream) Any(f interface{}) bool
- func (self *Stream) Count() int
- func (self *Stream) Cut(x interface{}) *Stream
- func (self *Stream) Drop(x interface{}) *Stream
- func (self *Stream) Each(f interface{}) *Stream
- func (self *Stream) Filter(f interface{}) *Stream
- func (self *Stream) Fold(a interface{}, f interface{}) interface{}
- func (self *Stream) Force() *Stream
- func (self *Stream) Head() interface{}
- func (self *Stream) Map(f interface{}) *Stream
- func (self *Stream) Tail() *Stream
- func (self *Stream) Take(x interface{}) *Stream
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
流结构
func (*Stream) Cut ¶
如果x是整数,返回丢弃尾部x个数据的流。 如果x是函数,通过x判断数据,丢弃尾部的数据直到x返回false,返回相应的流。 其他情况抛出异常。
提示:该方法不是完全惰性计算的,极端的情况:所有的数据都该被丢弃。
func (*Stream) Drop ¶
如果x是整数,返回丢弃头部x个数据的流。 如果x是函数,通过x判断数据,丢弃头部的数据直到x返回false,返回相应的流。 其他情况抛出异常。
提示:该方法不是完全惰性计算的,极端的情况:所有的数据都该被丢弃。
func (*Stream) Filter ¶
将流中的数据通过函数f进行筛选,剔除返回值为false的数据,返回筛选后的流。
提示:该方法不是完全惰性计算的,极端的情况:所有的数据都不满足筛选条件。
func (*Stream) Fold ¶
func (self *Stream) Fold(a interface{}, f interface{}) interface{}
将流中的数据通过函数f进行叠加,返回叠加后的结果。 a为初始叠加值,函数f的第1个参数为叠加值,第2个参数为流中的数据。
提示:不要在一个无限流上调用此方法。
Click to show internal directories.
Click to hide internal directories.