Skip to content

Commit

Permalink
chore: remote useless types
Browse files Browse the repository at this point in the history
  • Loading branch information
thoas committed Jun 20, 2023
1 parent 4107456 commit 209322f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Expand Up @@ -16,4 +16,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.50.1
version: v1.52.2
4 changes: 2 additions & 2 deletions assign.go
Expand Up @@ -22,7 +22,7 @@ import (
// is a short hand wrapper to discard error return
func Set(in interface{}, val interface{}, path string) error {
if in == nil {
return errors.New("Cannot Set nil")
return errors.New("cannot set nil")
}
parts := []string{}
if path != "" {
Expand All @@ -36,7 +36,7 @@ func setByParts(in interface{}, val interface{}, parts []string) error {

if in == nil {
// nil interface can happen during traversing the path
return errors.New("Cannot traverse nil/uninitialized interface{}")
return errors.New("cannot traverse nil/uninitialized interface{}")
}

inValue := reflect.ValueOf(in)
Expand Down
7 changes: 3 additions & 4 deletions builder.go
Expand Up @@ -46,7 +46,7 @@ type Builder interface {
Values() interface{}
}

// Chain creates a simple new go-funk.Builder from a collection. Each method
// Chain creates a simple new go-funk.Builder from a collection. Each method
// call generate a new builder containing the previous result.
func Chain(v interface{}) Builder {
isNotNil(v, "Chain")
Expand All @@ -73,13 +73,12 @@ func LazyChain(v interface{}) Builder {
}

panic(fmt.Sprintf("Type %s is not supported by LazyChain", valueType.String()))

}

// LazyChainWith creates a lazy go-funk.Builder from a generator. Like LazyChain, each
// LazyChainWith creates a lazy go-funk.Builder from a generator. Like LazyChain, each
// method call generate a new builder containing a method generating the previous value.
// But, instead of using a collection, it takes a generator which can generate values.
// With LazyChainWith, to can create a generic pipeline of collection transformation and,
// With LazyChainWith, to can create a generic pipeline of collection transformation and,
// throw the generator, sending different collection.
func LazyChainWith(generator func() interface{}) Builder {
isNotNil(generator, "LazyChainWith")
Expand Down
60 changes: 30 additions & 30 deletions chain_builder_test.go
Expand Up @@ -128,10 +128,10 @@ func TestChainFilter_SideEffect(t *testing.T) {
type foo struct {
bar string
}
in := []*foo{&foo{"foo"}, &foo{"bar"}}
in := []*foo{{"foo"}, {"bar"}}

chain := Chain(in)
is.Equal([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.Equal([]*foo{{"foo"}, {"bar"}}, chain.Value())

filtered := chain.Filter(func(x *foo) bool {
x.bar = "__" + x.bar + "__"
Expand All @@ -140,8 +140,8 @@ func TestChainFilter_SideEffect(t *testing.T) {
is.Equal([]*foo{}, filtered.Value())

// Side effect: in and chain.Value modified
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, in)
is.NotEqual([]*foo{{"foo"}, {"bar"}}, chain.Value())
is.NotEqual([]*foo{{"foo"}, {"bar"}}, in)
}

func TestChainFlatten(t *testing.T) {
Expand Down Expand Up @@ -318,10 +318,10 @@ func TestChainMap_SideEffect(t *testing.T) {
type foo struct {
bar string
}
in := []*foo{&foo{"foo"}, &foo{"bar"}}
in := []*foo{{"foo"}, {"bar"}}

chain := Chain(in)
is.Equal([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.Equal([]*foo{{"foo"}, {"bar"}}, chain.Value())

mapped := chain.Map(func(x *foo) (string, bool) {
x.bar = "__" + x.bar + "__"
Expand All @@ -330,8 +330,8 @@ func TestChainMap_SideEffect(t *testing.T) {
is.Equal(map[string]bool{"__foo__": false, "__bar__": false}, mapped.Value())

// Side effect: in and chain.Value modified
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, in)
is.NotEqual([]*foo{{"foo"}, {"bar"}}, chain.Value())
is.NotEqual([]*foo{{"foo"}, {"bar"}}, in)
}

func TestChainReverse(t *testing.T) {
Expand Down Expand Up @@ -492,8 +492,8 @@ func TestChainContains(t *testing.T) {
Contains: "bar",
},
{
In: []string{"foo", "bar"},
Contains: func (value string) bool {
In: []string{"foo", "bar"},
Contains: func(value string) bool {
return value == "bar"
},
},
Expand Down Expand Up @@ -526,8 +526,8 @@ func TestChainContains(t *testing.T) {
Contains: 2,
},
{
In: map[int]*Foo{1: f, 3: c},
Contains: func (key int, foo *Foo) bool {
In: map[int]*Foo{1: f, 3: c},
Contains: func(key int, foo *Foo) bool {
return key == 3 && foo.FirstName == "Harald"
},
},
Expand Down Expand Up @@ -625,10 +625,10 @@ func TestChainFind_SideEffect(t *testing.T) {
type foo struct {
bar string
}
in := []*foo{&foo{"foo"}, &foo{"bar"}}
in := []*foo{{"foo"}, {"bar"}}

chain := Chain(in)
is.Equal([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.Equal([]*foo{{"foo"}, {"bar"}}, chain.Value())

result := chain.Find(func(x *foo) bool {
x.bar = "__" + x.bar + "__"
Expand All @@ -637,8 +637,8 @@ func TestChainFind_SideEffect(t *testing.T) {
is.Nil(result)

// Side effect: in and chain.Value modified
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, in)
is.NotEqual([]*foo{{"foo"}, {"bar"}}, chain.Value())
is.NotEqual([]*foo{{"foo"}, {"bar"}}, in)
}

func TestChainForEach(t *testing.T) {
Expand Down Expand Up @@ -690,20 +690,20 @@ func TestChainForEach_SideEffect(t *testing.T) {
bar string
}
var out []*foo
in := []*foo{&foo{"foo"}, &foo{"bar"}}
in := []*foo{{"foo"}, {"bar"}}

chain := Chain(in)
is.Equal([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.Equal([]*foo{{"foo"}, {"bar"}}, chain.Value())

chain.ForEach(func(x *foo) {
x.bar = "__" + x.bar + "__"
out = append(out, x)
})
is.Equal([]*foo{&foo{"__foo__"}, &foo{"__bar__"}}, out)
is.Equal([]*foo{{"__foo__"}, {"__bar__"}}, out)

// Side effect: in and chain.Value modified
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, in)
is.NotEqual([]*foo{{"foo"}, {"bar"}}, chain.Value())
is.NotEqual([]*foo{{"foo"}, {"bar"}}, in)
}

func TestChainForEachRight(t *testing.T) {
Expand Down Expand Up @@ -755,20 +755,20 @@ func TestChainForEachRight_SideEffect(t *testing.T) {
bar string
}
var out []*foo
in := []*foo{&foo{"foo"}, &foo{"bar"}}
in := []*foo{{"foo"}, {"bar"}}

chain := Chain(in)
is.Equal([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.Equal([]*foo{{"foo"}, {"bar"}}, chain.Value())

chain.ForEachRight(func(x *foo) {
x.bar = "__" + x.bar + "__"
out = append(out, x)
})
is.Equal([]*foo{&foo{"__bar__"}, &foo{"__foo__"}}, out)
is.Equal([]*foo{{"__bar__"}, {"__foo__"}}, out)

// Side effect: in and chain.Value modified
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, chain.Value())
is.NotEqual([]*foo{&foo{"foo"}, &foo{"bar"}}, in)
is.NotEqual([]*foo{{"foo"}, {"bar"}}, chain.Value())
is.NotEqual([]*foo{{"foo"}, {"bar"}}, in)
}

func TestChainHead(t *testing.T) {
Expand Down Expand Up @@ -823,8 +823,8 @@ func TestChainIndexOf(t *testing.T) {
Item: "bar",
},
{
In: []string{"foo", "bar"},
Item: func (value string) bool {
In: []string{"foo", "bar"},
Item: func(value string) bool {
return value == "bar"
},
},
Expand Down Expand Up @@ -907,8 +907,8 @@ func TestChainLastIndexOf(t *testing.T) {
Item: "bar",
},
{
In: []string{"foo", "bar", "bar"},
Item: func (value string) bool {
In: []string{"foo", "bar", "bar"},
Item: func(value string) bool {
return value == "bar"
},
},
Expand Down
4 changes: 2 additions & 2 deletions fill.go
Expand Up @@ -11,14 +11,14 @@ func Fill(in interface{}, fillValue interface{}) (interface{}, error) {
inValue := reflect.ValueOf(in)
inKind := inValue.Type().Kind()
if inKind != reflect.Slice && inKind != reflect.Array {
return nil, errors.New("Can only fill slices and arrays")
return nil, errors.New("can only fill slices and arrays")
}

inType := reflect.TypeOf(in).Elem()
value := reflect.ValueOf(fillValue)
if inType != value.Type() {
return nil, fmt.Errorf(
"Cannot fill '%s' with '%s'", reflect.TypeOf(in), value.Type(),
"cannot fill '%s' with '%s'", reflect.TypeOf(in), value.Type(),
)
}

Expand Down

0 comments on commit 209322f

Please sign in to comment.