當前位置: 首頁>>代碼示例>>Golang>>正文


Golang functional.Stream類代碼示例

本文整理匯總了Golang中github.com/keep94/gofunctional2/functional.Stream的典型用法代碼示例。如果您正苦於以下問題:Golang Stream類的具體用法?Golang Stream怎麽用?Golang Stream使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Stream類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Consume

// Consume fetches the values. s is a Stream of T.
func (b *Buffer) Consume(s functional.Stream) {
	defer s.Close()
	b.idx, b.err = readStreamIntoSlice(s, b.buffer, b.addrFunc)
	if b.err == functional.Done {
		b.err = nil
	}
}
開發者ID:keep94,項目名稱:gofunctional2,代碼行數:8,代碼來源:consume.go

示例2: 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

示例3: 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

示例4: 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

示例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類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。