5 Star 2 Fork 0

Gitee 极速下载 / go-linq

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/ahmetalpbalkan/go-linq
克隆/下载
concat.go 1.34 KB
一键复制 编辑 原始数据 按行查看 历史
kalan 提交于 2016-08-29 23:57 . v2.0
package linq
// Append inserts an item to the end of a collection,
// so it becomes the last item.
func (q Query) Append(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
appended := false
return func() (interface{}, bool) {
i, ok := next()
if ok {
return i, ok
}
if !appended {
appended = true
return item, true
}
return nil, false
}
},
}
}
// Concat concatenates two collections.
//
// The Concat method differs from the Union method because the Concat method
// returns all the original elements in the input sequences.
// The Union method returns only unique elements.
func (q Query) Concat(q2 Query) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
next2 := q2.Iterate()
use1 := true
return func() (item interface{}, ok bool) {
if use1 {
item, ok = next()
if ok {
return
}
use1 = false
}
return next2()
}
},
}
}
// Prepend inserts an item to the beginning of a collection,
// so it becomes the first item.
func (q Query) Prepend(item interface{}) Query {
return Query{
Iterate: func() Iterator {
next := q.Iterate()
prepended := false
return func() (interface{}, bool) {
if prepended {
return next()
}
prepended = true
return item, true
}
},
}
}
1
https://gitee.com/mirrors/go-linq.git
git@gitee.com:mirrors/go-linq.git
mirrors
go-linq
go-linq
v2.0.0-rc0

搜索帮助