本文整理汇总了Golang中github.com/interactiv/pipeline.In函数的典型用法代码示例。如果您正苦于以下问题:Golang In函数的具体用法?Golang In怎么用?Golang In使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了In函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
示例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)
}
示例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)
}
示例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)
}
示例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()
}
示例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}}))
}
示例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)
}
示例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)
}
示例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)
}
示例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)
}
示例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()
}
示例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'}))
}
示例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}))
}
示例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}))
}
示例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>
}