当前位置: 首页>>代码示例>>Golang>>正文


Golang Stream.Next方法代码示例

本文整理汇总了Golang中github.com/keep94/gofunctional2/functional.Stream.Next方法的典型用法代码示例。如果您正苦于以下问题:Golang Stream.Next方法的具体用法?Golang Stream.Next怎么用?Golang Stream.Next使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/keep94/gofunctional2/functional.Stream的用法示例。


在下文中一共展示了Stream.Next方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Consume

// Consume fetches the values. s is a Stream of T.
func (pb *PageBuffer) Consume(s functional.Stream) {
	defer s.Close()
	pb.page_no = 0
	pb.idx = 0
	pb.is_end = false
	pb.err = nil
	for pb.err == nil && !pb.isDesiredPageRead() {
		if pb.idx > 0 {
			pb.page_no++
		}
		offset := pb.pageOffset(pb.page_no)
		pb.idx, pb.err = readStreamIntoSlice(
			s, pb.buffer.Slice(offset, offset+pb.pageLen), pb.addrFunc)
	}
	if pb.err == nil {
		pb.is_end = s.Next(pb.addrFunc(pb.buffer.Index(pb.pageOffset(pb.page_no+1)))) == functional.Done
	} else if pb.err == functional.Done {
		pb.is_end = true
		pb.err = nil
		if pb.page_no > 0 && pb.idx == 0 {
			pb.page_no--
			pb.idx = pb.pageLen
		}
	}
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:26,代码来源:consume.go

示例2: Consume

// Consume prints all Entry values that s emits to stdout. On error, prints
// the error encountered and halts.
func (p Printer) Consume(s functional.Stream) {
	var entry Entry
	err := s.Next(&entry)
	for ; err == nil; err = s.Next(&entry) {
		fmt.Println(&entry)
	}
	if err != functional.Done {
		fmt.Printf("Error happened: %v\n", err)
		s.Close()
	}
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:13,代码来源:checkbook.go

示例3: readStreamIntoSlice

func readStreamIntoSlice(
	s functional.Stream,
	aSlice reflect.Value,
	addrFunc func(reflect.Value) interface{}) (numRead int, err error) {
	l := aSlice.Len()
	for numRead = 0; numRead < l; numRead++ {
		err = s.Next(addrFunc(aSlice.Index(numRead)))
		if err != nil {
			break
		}
	}
	return
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:13,代码来源:consume.go

示例4: FirstOnly

// FirstOnly reads the first value from stream storing it in ptr.
// FirstOnly closes the stream.
// FirstOnly returns emptyError if no values were on stream.
func FirstOnly(stream functional.Stream, emptyError error, ptr interface{}) (err error) {
	defer func() {
		closeError := stream.Close()
		if err == nil {
			err = closeError
		}
	}()
	err = stream.Next(ptr)
	if err == functional.Done {
		err = emptyError
		return
	}
	return
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:17,代码来源:consume.go

示例5: Consume

func (c *errorReportingConsumerForTesting) Consume(s functional.Stream) {
	var x int
	for s.Next(&x) != functional.Done {
		c.count++
	}
}
开发者ID:keep94,项目名称:gofunctional2,代码行数:6,代码来源:consume_test.go


注:本文中的github.com/keep94/gofunctional2/functional.Stream.Next方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。