• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang pipeline.In函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang pgmapper.Mapper类代码示例发布时间:2022-05-23
下一篇:
Golang expect.New函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap