本文整理汇总了Golang中github.com/interactiv/pipeline.In函数的典型用法代码示例。如果您正苦于以下问题:Golang In函数的具体用法?Golang In怎么用?Golang In使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了In函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMap
func TestMap(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 3}).Map(func(element interface{}, index int) interface{} {
return element.(int) * 2
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(3)
e.Expect(result[0]).ToEqual(2)
var result2 *[]int
err = pipeline.In(&[]int{1, 2, 3}).Out(&result2)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result2)).ToEqual(fmt.Sprint(&[]int{1, 2, 3}))
var result3 string
err = pipeline.In("foo").Out(&result3)
e.Expect(err).ToBeNil()
e.Expect(result3).ToBe("foo")
var result4 []string
err = pipeline.In([]int{1, 2, 3}).Out(&result4)
e.Expect(err).Not().ToBeNil()
t.Log(err)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:25,代码来源:pipeline_test.go
示例2: TestGroupBy
func TestGroupBy(t *testing.T) {
e := expect.New(t)
var result map[int][]Person
err := pipeline.In([]Person{{12, "John"}, {12, "Jane"}, {20, "Joe"}}).
GroupBy(func(el interface{}, i int) interface{} {
return el.(Person).Age
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(2)
e.Expect(len(result[12])).ToEqual(2)
e.Expect(result[12][0].Age).ToEqual(12)
var result1 map[string][]map[string]string
err = pipeline.In([]map[string]string{
{"product": "trousers", "category": "clothes"},
{"product": "beer", "category": "drinks"},
{"product": "coat", "category": "clothes"},
}).
GroupBy(func(el interface{}, i int) interface{} {
return el.(map[string]string)["category"]
}).Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(len(result1)).ToEqual(2)
e.Expect(len(result1["clothes"])).ToEqual(2)
e.Expect(len(result1["drinks"])).ToEqual(1)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:28,代码来源:pipeline_test.go
示例3: TestIndexOf
func TestIndexOf(t *testing.T) {
e := expect.New(t)
var result int = -1
err := pipeline.In([]string{"i", "j", "k", "l"}).IndexOf("k", 0).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual(2)
var res int = -1
err = pipeline.In("foobar").IndexOf('a', 0).Out(&res)
e.Expect(err).ToBeNil()
e.Expect(res).ToEqual(4)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:11,代码来源:pipeline_test.go
示例4: TestReduceRight
func TestReduceRight(t *testing.T) {
e := expect.New(t)
var result string
err := pipeline.In("kayak").ReduceRight(func(r interface{}, e interface{}, i int) interface{} {
return r.(string) + string(e.(rune))
}, "").Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual("kayak")
var result2 int
pipeline.In([]int{1, 2, 3}).ReduceRight(func(r interface{}, e interface{}, i int) interface{} {
return r.(int) - e.(int)
}, nil).Out(&result2)
e.Expect(result2).ToEqual(0)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:14,代码来源:pipeline_test.go
示例5: TestEvery
func TestEvery(t *testing.T) {
e := expect.New(t)
var result bool
err := pipeline.In([]int{2, 4, 6}).Every(func(element interface{}, index int) bool {
return element.(int)%2 == 0
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeTrue()
err = pipeline.In([]int{2, 4, 5}).Every(func(element interface{}, index int) bool {
return element.(int)%2 == 0
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeFalse()
}
开发者ID:interactiv,项目名称:pipeline,代码行数:14,代码来源:pipeline_test.go
示例6: TestZip
func TestZip(t *testing.T) {
e := expect.New(t)
var result1 [][]interface{}
err := pipeline.In([][]int{{1, 2, 3}}).Zip().Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result1)).ToEqual(fmt.Sprint([][]interface{}{{1}, {2}, {3}}))
err = pipeline.In([][]interface{}{{1, 2, 3}, {"John", "Jane", "David"}}).Zip().Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result1)).
ToEqual(fmt.Sprint([][]interface{}{{1, "John"}, {2, "Jane"}, {3, "David"}}))
err = pipeline.In([][]interface{}{{"US", "FR"}, {"John", "Jane", "David"}, {true}}).Zip().Out(&result1)
e.Expect(fmt.Sprint(result1)).
ToEqual(fmt.Sprint([][]interface{}{{"US", "John", true}, {"FR", "Jane", nil}, {nil, "David", nil}}))
}
开发者ID:interactiv,项目名称:pipeline,代码行数:14,代码来源:pipeline_test.go
示例7: TestLast
func TestLast(t *testing.T) {
e := expect.New(t)
var result int
err := pipeline.In([]int{1, 3, 6}).Last().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual(6)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例8: TestReverse
func TestReverse(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 3}).Reverse().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result[0]).ToEqual(3)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例9: TestConcat
func TestConcat(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{}).Concat([]int{1, 2, 3}, []int{4, 5, 6}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(6)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例10: TestLastIndexOf
func TestLastIndexOf(t *testing.T) {
e := expect.New(t)
var result int = -1
err := pipeline.In("abba").LastIndexOf('a', 0).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToEqual(3)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例11: TestEqual
func TestEqual(t *testing.T) {
e := expect.New(t)
var result bool
err := pipeline.In([]int{1, 2, 3}).Equals([]int{1, 2, 3}, []int{1, 2, 3}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeTrue()
err = pipeline.In([]int{1, 2, 3}).Equals([]int{1, 2, 3}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeTrue()
err = pipeline.In([]int{1, 2, 3}).Equals().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeTrue()
err = pipeline.In([]int{1, 2, 3}).Equals([]int{1, 2}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(result).ToBeFalse()
}
开发者ID:interactiv,项目名称:pipeline,代码行数:16,代码来源:pipeline_test.go
示例12: TestCompact
func TestCompact(t *testing.T) {
e := expect.New(t)
var result1 []interface{}
err := pipeline.In([]interface{}{1, nil, 2, 'a', nil}).Compact().Out(&result1)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result1)).ToEqual(fmt.Sprint([]interface{}{1, 2, 'a'}))
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例13: TestUnion
func TestUnion(t *testing.T) {
e := expect.New(t)
var res []int
err := pipeline.In([]int{1, 2}).Union([]int{2, 3}, []int{3, 4}).Out(&res)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(res)).ToEqual(fmt.Sprint([]int{1, 2, 3, 4}))
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例14: TestIntersection
func TestIntersection(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{1, 2, 4}).Intersection([]int{3, 2, 1}, []int{2, 5, 6}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(fmt.Sprint(result)).ToEqual(fmt.Sprint([]int{2}))
}
开发者ID:interactiv,项目名称:pipeline,代码行数:7,代码来源:pipeline_test.go
示例15: ExamplePipeline_Sort
func ExamplePipeline_Sort() {
var result []int
err := pipeline.In([]int{2, 1, 6, 3, 5, 4}).Sort(func(a interface{}, b interface{}) bool {
return a.(int) <= b.(int)
}).Out(&result)
fmt.Print(result, " ", err)
// Output: [1 2 3 4 5 6] <nil>
}
开发者ID:interactiv,项目名称:pipeline,代码行数:8,代码来源:pipeline_test.go
示例16: TestFlatten
func TestFlatten(t *testing.T) {
e := expect.New(t)
var result []int
Error := pipeline.In([]interface{}{[]int{1, 2}, 3, []int{4, 5}}).Flatten().Out(&result)
e.Expect(Error).ToBeNil()
e.Expect(len(result)).ToEqual(5)
t.Log(result)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:8,代码来源:pipeline_test.go
示例17: TestToMap
func TestToMap(t *testing.T) {
e := expect.New(t)
in := map[string]string{"a": "angel", "b": "bookmark", "c": "card"}
result := pipeline.In(in).ToMap(func(val interface{}, key interface{}) (interface{}, interface{}) {
return key, val
}).MustOut()
e.Expect(result.(map[interface{}]interface{})["angel"]).ToEqual("a")
}
开发者ID:interactiv,项目名称:pipeline,代码行数:8,代码来源:pipeline_test.go
示例18: TestUnique
func TestUnique(t *testing.T) {
e := expect.New(t)
var result []string
err := pipeline.In([]string{"a", "b", "b", "a"}).Unique().Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToEqual(2)
e.Expect(result[1]).ToEqual("b")
}
开发者ID:interactiv,项目名称:pipeline,代码行数:8,代码来源:pipeline_test.go
示例19: TestPush
func TestPush(t *testing.T) {
e := expect.New(t)
var result []int
err := pipeline.In([]int{2, 3, 4}).Push(5, 6, 7).Out(&result)
e.Expect(err).ToBeNil()
for i, val := range []int{2, 3, 4, 5, 6, 7} {
e.Expect(result[i]).ToEqual(val)
}
}
开发者ID:interactiv,项目名称:pipeline,代码行数:9,代码来源:pipeline_test.go
示例20: TestFilter
func TestFilter(t *testing.T) {
e := expect.New(t)
var result []string
err := pipeline.In([]string{"a", "b", "c"}).Filter(func(element interface{}, index int) bool {
return element.(string) != "a"
}).Out(&result)
e.Expect(err).ToBeNil()
e.Expect(len(result)).ToBe(2)
products := Products{{0, "Iphone 6", 0, 500}, {1, "HTC one", 0, 300}, {2, "Apple Watch", 1, 600}, {3, "ThinkPad", 2, 250}}
var sample []Product
Error := pipeline.In(products).
Filter(func(el interface{}, i int) bool { return el.(Product).Price < 499 }).
Out(&sample)
e.Expect(Error).ToBeNil()
e.Expect(len(sample)).ToEqual(2)
e.Expect(sample[0].Price).ToEqual(300)
}
开发者ID:interactiv,项目名称:pipeline,代码行数:18,代码来源:pipeline_test.go
注:本文中的github.com/interactiv/pipeline.In函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论