Code Monkey home page Code Monkey logo

stream's Introduction

stream's People

Contributors

dashclab avatar dependabot[bot] avatar newsning avatar roinnn avatar xyctruth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

stream's Issues

optimize func variable 3.287 ns/op, other(normal,anonymous) 1.553 ns/op

// TODO optimize func variable 3.287 ns/op, other(normal,anonymous) 1.553 ns/op

	"testing"
)

func BenchmarkShortCircuiting(b *testing.B) {
	tests := []struct {
		name  string
		count int
	}{
		{count: 100},
		{count: 200},
		{count: 300},
		{count: 400},
		{count: 500},
		{count: 1000},
		{count: 2000},
	}
	for _, tt := range tests {
		b.Run(fmt.Sprintf("%s(%d)", "count:", tt.count), func(b *testing.B) {
			s := newArray(tt.count)
			s[0] = 101
			b.ResetTimer()

			for n := 0; n < b.N; n++ {
				_ = NewSlice(s).
					Filter(func(v int) bool { return true }).
					Map(func(v int) int {
						return v
					}).
					AllMatch(func(v int) bool { return v < 100 })
			}
		})
	}
}

var funcVal = mapperFunc

func mapperFunc(v int) int { return v * 2 }

// TODO optimize func variable 3.287 ns/op, other(normal,anonymous) 1.553 ns/op
func BenchmarkPipelineFuncVariable(b *testing.B) {
	tests := []struct {
		name       string
		goroutines int
		stage      func(index int, e int) (isReturn bool, isComplete bool, ret int)
	}{
		{
			name: "variable func",
			stage: func(index int, e int) (isReturn bool, isComplete bool, ret int) {
				return true, false, funcVal(e)
			},
		},
		{
			name: "normal func",
			stage: func(index int, e int) (isReturn bool, isComplete bool, ret int) {
				return true, false, mapperFunc(e)
			},
		},
		{
			name: "anonymous func",
			stage: func(index int, e int) (isReturn bool, isComplete bool, ret int) {
				return true, false, func(v int) int { return v * 2 }(e)
			},
		},
	}
	for _, tt := range tests {
		b.Run(fmt.Sprintf("%s(%d)", tt.name, tt.goroutines), func(b *testing.B) {
			b.ResetTimer()
			for n := 0; n < b.N; n++ {
				tt.stage(0, 0)
			}
		})
	}
}

Map 是否支持映射为非原本的 “Elem” 类型

现在go泛型不支持struct的method添加类型参数,是否可以在NewSlice传入MapElem?

type sliceStream[Elem any, MapElem any] struct 

func NewSlice[Elem any, MapElem any](v []Elem) sliceStream[Elem, MapElem] 

func (stream sliceStream[Elem, MapElem]) Map(mapper func(Elem) MapElem) sliceStream[MapElem, MapElem] 

Insert中的evaluation应该放在一开始

func (stream SliceStream[E]) Insert(index int, elements ...E) SliceStream[E] {
        // 如果不在一开始stream.evaluation(),stream.source 个数是未知。有可能会出现bug。
	if len(stream.source) <= index {
		return stream.Append(elements...)
	}
        stream.evaluation()
	stream.source = slices.Insert(stream.source, index, elements...)
	return stream
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.