initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

25
example/fx/fx_test.go Normal file
View File

@@ -0,0 +1,25 @@
package main
import (
"testing"
"zero/core/fx"
)
func BenchmarkFx(b *testing.B) {
type Mixed struct {
Name string
Age int
Gender int
}
for i := 0; i < b.N; i++ {
var mx Mixed
fx.Parallel(func() {
mx.Name = "hello"
}, func() {
mx.Age = 20
}, func() {
mx.Gender = 1
})
}
}

36
example/fx/square.go Normal file
View File

@@ -0,0 +1,36 @@
package main
import (
"fmt"
"zero/core/fx"
)
func main() {
result, err := fx.From(func(source chan<- interface{}) {
for i := 0; i < 10; i++ {
source <- i
source <- i
}
}).Map(func(item interface{}) interface{} {
i := item.(int)
return i * i
}).Filter(func(item interface{}) bool {
i := item.(int)
return i%2 == 0
}).Distinct(func(item interface{}) interface{} {
return item
}).Reduce(func(pipe <-chan interface{}) (interface{}, error) {
var result int
for item := range pipe {
i := item.(int)
result += i
}
return result, nil
})
if err != nil {
fmt.Println(err)
} else {
fmt.Println(result)
}
}