示例#1
0
func TestFindBy(t *testing.T) {
	evens := func(d stream.T) bool { return d.(int)%2 == 0 }

	Convey("Given I have a context", t, func() {
		context := rivers.NewContext()

		Convey("And a stream of data", func() {
			in, out := stream.New(3)
			out <- 1
			out <- 2
			out <- 4
			close(out)

			Convey("When I apply the transformer to the stream", func() {
				transformer := transformers.FindBy(evens)
				transformer.Attach(context)
				next := transformer.Transform(in)

				Convey("Then a transformed stream is returned", func() {
					So(next.ReadAll(), ShouldResemble, []stream.T{2})
				})
			})

			Convey("When I close the context", func() {
				context.Close(stream.Done)

				Convey("And I apply the transformer to the stream", func() {
					transformer := transformers.FindBy(evens)
					transformer.Attach(context)
					next := transformer.Transform(in)

					Convey("Then no item is sent to the next stage", func() {
						So(next.ReadAll(), ShouldBeEmpty)
					})
				})
			})
		})
	})
}
示例#2
0
文件: rivers.go 项目: drborges/rivers
func (pipeline *Pipeline) FindBy(fn stream.PredicateFn) *Pipeline {
	return pipeline.Apply(transformers.FindBy(fn))
}
示例#3
0
文件: rivers.go 项目: drborges/rivers
func (pipeline *Pipeline) Find(subject stream.T) *Pipeline {
	return pipeline.Apply(transformers.FindBy(func(data stream.T) bool {
		return data == subject
	}))
}