Skip to content

Commit 5dc0ebc

Browse files
authored
Merge pull request #8 from hyphennn/hyphen/dev
chore: change pakage
2 parents ba0aefa + 70edc61 commit 5dc0ebc

12 files changed

Lines changed: 42 additions & 43 deletions

File tree

README.md

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,31 @@ package main
1010
import (
1111
"fmt"
1212

13-
"github.com/hyphennn/glamda/lslice"
13+
"github.com/hyphennn/glamda/gstream"
1414
)
1515

1616
func main() {
17-
s := []int{1, 1, 4, 5, 1, 4}
18-
ss := lslice.Map(s, func(f int) int {
19-
return f + 1
20-
})
21-
fmt.Println(ss) //[2 2 5 6 2 5]
17+
s := []int{1, 1, 4, 5, 1, 4, 114514, 0, 0, 0}
18+
s2 := gstream.AsSliceStream(s).Filter(func(i int) bool {
19+
return i%2 == 0
20+
}).Convert(func(i int) int {
21+
return i + 1
22+
}).Sort(func(t1, t2 int) bool {
23+
return t1 < t2
24+
}).Collect()
25+
fmt.Println(s2) // [1 1 1 5 5 114515]
2226
}
2327
```
2428

25-
Dedicated to providing a go lamda expression library that does not introduce any additional dependencies and only incurs minimal additional performance costs
29+
致力于构建一个 Go Stream API 以及一些常用的泛型、闭包工具,并且不引入任何第三方依赖以及过多的性能消耗
2630

31+
Source of inspiration: Bytedance code.byted.org.lang/gg
2732

33+
This package was not open source when the author resigned, and a similar repository was not found, so this package was
34+
made based on some ideas from the Java Stream API and lang/gg
2835

29-
Inspiration source: ByteDance code.byted.org/lang/gg
30-
31-
32-
33-
This package was not yet open source at the time of the author's resignation, and also cannot find a similar repository, so some ideas from lang/gg were used to create this package. If lang/gg plans to open source it in the future, please feel free to contact me so that ownership of this repository can be transferred
34-
35-
致力于提供一个不引入任何额外依赖以及只带来极小额外性能成本的 go lamda 表达式库,涵盖面向 go 的一些 lamda 常用表达式
36+
致力于构建一个 Go Stream API 以及一些常用的泛型、闭包工具,并且不引入任何第三方依赖以及过多的性能消耗
3637

3738
灵感来源:字节跳动 code.byted.org/lang/gg
3839

39-
此包在作者离职时仍未开源,也未找到一个类似的仓库,因此基于 lang/gg 的一些思想做了此包,若后续 lang/gg 计划开源,欢迎联系我,可以转移此仓库的所有权
40-
41-
注:所有代码均为手写,个人理解不存在侵权问题,如果 lang/gg 愿意开源自然更好
40+
此包在作者离职时仍未开源,也未找到一个类似的仓库,因此基于 Java Stream API 以及 lang/gg 的一些思想做了此包

lcollection/disjoint-set/disjoint-set-with-pc.go renamed to gcollection/disjoint-set/disjoint-set-with-pc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ package disjoint_set
88
import (
99
"fmt"
1010

11-
"github.com/hyphennn/glamda/lutils"
11+
"github.com/hyphennn/glamda/gutils"
1212
)
1313

1414
type DisjointSetWithPC[T comparable] struct {
@@ -34,7 +34,7 @@ func (d *DisjointSetWithPC[T]) Find(value T) (T, error) {
3434
}
3535

3636
func (d *DisjointSetWithPC[T]) innerFind(value T) T {
37-
return lutils.TernaryForm(d.parent[value] != value, func() T {
37+
return gutils.TernaryForm(d.parent[value] != value, func() T {
3838
d.parent[value] = d.innerFind(d.parent[value])
3939
return value
4040
}(), d.parent[value])
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Package lset
1+
// Package gset
22
// Author: hyphen
33
// Copyright 2023 hyphen. All rights reserved.
44
// Create-time: 2023/12/8
5-
package lset
5+
package gset
66

77
type SliceSet[K comparable, V any] struct {
88
m map[K]int

lmap/lmap.go renamed to gmap/gmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package lmap
1+
package gmap
22

33
func Map[K1, K2 comparable, V1, V2 any](m map[K1]V1, fc func(K1, V1) (K2, V2)) map[K2]V2 {
44
ret := make(map[K2]V2, len(m))
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
// Package lmap
1+
// Package gmap
22
// Author: hyphen
33
// Copyright 2023 hyphen. All rights reserved.
44
// Create-time: 2023/12/8
5-
package lmap_test
5+
package gmap_test
66

77
import (
88
"strconv"
99
"testing"
1010

11+
"github.com/hyphennn/glamda/gmap"
1112
"github.com/hyphennn/glamda/internal/assert"
12-
"github.com/hyphennn/glamda/lmap"
1313
)
1414

1515
func TestMap(t *testing.T) {
1616
assert.Equal(t,
1717
map[string]string{"1": "1", "4": "4", "5": "5"},
18-
lmap.Map(map[int]int{1: 1, 4: 4, 5: 5}, func(k1 int, v1 int) (string, string) {
18+
gmap.Map(map[int]int{1: 1, 4: 4, 5: 5}, func(k1 int, v1 int) (string, string) {
1919
return strconv.Itoa(k1), strconv.Itoa(v1)
2020
}))
2121
}
2222

2323
func TestUnion(t *testing.T) {
2424
assert.Equal(t,
2525
map[string]string{"1": "1", "4": "4", "5": "5"},
26-
lmap.Union(map[string]string{"1": "1", "4": "4"}, map[string]string{"4": "4", "5": "5"}),
26+
gmap.Union(map[string]string{"1": "1", "4": "4"}, map[string]string{"4": "4", "5": "5"}),
2727
)
2828
}

lmap/union.go renamed to gmap/union.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Package lmap
1+
// Package gmap
22
// Author: hyphen
33
// Copyright 2023 hyphen. All rights reserved.
44
// Create-time: 2023/12/8
5-
package lmap
5+
package gmap
66

77
func Union[K comparable, V any](ms ...map[K]V) map[K]V {
88
if len(ms) == 0 {

lslice/lslice.go renamed to gslice/gslice.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
// Package lslice
1+
// Package gslice
22
// Author: hyphen
33
// Copyright 2023 hyphen. All rights reserved.
44
// Create-time: 2023/12/4
5-
package lslice
5+
package gslice
66

77
func Map[F, T any](s []F, fc func(F) T) []T {
88
ret := make([]T, 0, len(s))
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
// Package lslice
1+
// Package gslice
22
// Author: hyphen
33
// Copyright 2023 hyphen. All rights reserved.
44
// Create-time: 2023/12/4
5-
package lslice_test
5+
package gslice_test
66

77
import (
88
"strconv"
99
"testing"
1010

11+
"github.com/hyphennn/glamda/gslice"
1112
"github.com/hyphennn/glamda/internal/assert"
12-
"github.com/hyphennn/glamda/lslice"
1313
)
1414

1515
func TestMap(t *testing.T) {
1616
assert.Equal(t,
17-
lslice.Map([]int{1, 1, 4, 5, 1, 4}, strconv.Itoa),
17+
gslice.Map([]int{1, 1, 4, 5, 1, 4}, strconv.Itoa),
1818
[]string{"1", "1", "4", "5", "1", "4"},
1919
)
2020
}
2121

2222
func TestToMap(t *testing.T) {
2323
assert.Equal(t,
2424
map[int]bool{1: true, 4: true, 5: true},
25-
lslice.ToMap([]int{1, 1, 4, 5, 1, 4}, func(f int) (int, bool) { return f, true }),
25+
gslice.ToMap([]int{1, 1, 4, 5, 1, 4}, func(f int) (int, bool) { return f, true }),
2626
)
2727
}
2828

2929
func TestTryMap(t *testing.T) {
30-
m, err := lslice.TryMap([]string{"1", "1", "4", "5", "1", "4"}, strconv.Atoi)
30+
m, err := gslice.TryMap([]string{"1", "1", "4", "5", "1", "4"}, strconv.Atoi)
3131
assert.Nil(t, err)
3232
assert.Equal(t, m, []int{1, 1, 4, 5, 1, 4})
3333

34-
m2, err := lslice.TryMap([]string{"1", "1", "4", "5a", "1", "4"}, strconv.Atoi)
34+
m2, err := gslice.TryMap([]string{"1", "1", "4", "5a", "1", "4"}, strconv.Atoi)
3535
t.Log(err)
3636
assert.NotNil(t, err)
3737
assert.Equal(t, m2, []int{1, 1, 4})
3838
}
3939

4040
func TestFilter(t *testing.T) {
4141
assert.Equal(t,
42-
lslice.Filter([]int{1, 1, 4, 5, 1, 4}, func(i int) bool {
42+
gslice.Filter([]int{1, 1, 4, 5, 1, 4}, func(i int) bool {
4343
return i%2 == 1
4444
}),
4545
[]int{1, 1, 5, 1},

0 commit comments

Comments
 (0)