Skip to content

Commit 0f36e35

Browse files
committed
callerError replaced with errorhelper.CallerError
1 parent e5d9360 commit 0f36e35

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+331
-278
lines changed

aggregate.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package go2linq
33
import (
44
"iter"
55

6+
"github.com/solsw/errorhelper"
67
"github.com/solsw/generichelper"
78
)
89

@@ -11,10 +12,10 @@ import (
1112
// [Aggregate]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.aggregate
1213
func Aggregate[Source any](source iter.Seq[Source], accumulator func(Source, Source) Source) (Source, error) {
1314
if source == nil {
14-
return generichelper.ZeroValue[Source](), callerError(ErrNilSource)
15+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrNilSource)
1516
}
1617
if accumulator == nil {
17-
return generichelper.ZeroValue[Source](), callerError(ErrNilAccumulator)
18+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrNilAccumulator)
1819
}
1920
var res Source
2021
empty := true
@@ -29,7 +30,7 @@ func Aggregate[Source any](source iter.Seq[Source], accumulator func(Source, Sou
2930
res = accumulator(res, s)
3031
}
3132
if empty {
32-
return generichelper.ZeroValue[Source](), callerError(ErrEmptySource)
33+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrEmptySource)
3334
}
3435
return res, nil
3536
}
@@ -41,10 +42,10 @@ func Aggregate[Source any](source iter.Seq[Source], accumulator func(Source, Sou
4142
func AggregateSeed[Source, Accumulate any](source iter.Seq[Source],
4243
seed Accumulate, accumulator func(Accumulate, Source) Accumulate) (Accumulate, error) {
4344
if source == nil {
44-
return generichelper.ZeroValue[Accumulate](), callerError(ErrNilSource)
45+
return generichelper.ZeroValue[Accumulate](), errorhelper.CallerError(ErrNilSource)
4546
}
4647
if accumulator == nil {
47-
return generichelper.ZeroValue[Accumulate](), callerError(ErrNilAccumulator)
48+
return generichelper.ZeroValue[Accumulate](), errorhelper.CallerError(ErrNilAccumulator)
4849
}
4950
res := seed
5051
for s := range source {
@@ -61,13 +62,13 @@ func AggregateSeed[Source, Accumulate any](source iter.Seq[Source],
6162
func AggregateSeedSel[Source, Accumulate, Result any](source iter.Seq[Source], seed Accumulate,
6263
accumulator func(Accumulate, Source) Accumulate, resultSelector func(Accumulate) Result) (Result, error) {
6364
if source == nil {
64-
return generichelper.ZeroValue[Result](), callerError(ErrNilSource)
65+
return generichelper.ZeroValue[Result](), errorhelper.CallerError(ErrNilSource)
6566
}
6667
if accumulator == nil {
67-
return generichelper.ZeroValue[Result](), callerError(ErrNilAccumulator)
68+
return generichelper.ZeroValue[Result](), errorhelper.CallerError(ErrNilAccumulator)
6869
}
6970
if resultSelector == nil {
70-
return generichelper.ZeroValue[Result](), callerError(ErrNilSelector)
71+
return generichelper.ZeroValue[Result](), errorhelper.CallerError(ErrNilSelector)
7172
}
7273
res := seed
7374
for s := range source {

all.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [All] determines whether all elements of a sequence satisfy a condition.
810
//
911
// [All]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.all
1012
func All[Source any](source iter.Seq[Source], predicate func(Source) bool) (bool, error) {
1113
if source == nil {
12-
return false, callerError(ErrNilSource)
14+
return false, errorhelper.CallerError(ErrNilSource)
1315
}
1416
if predicate == nil {
15-
return false, callerError(ErrNilPredicate)
17+
return false, errorhelper.CallerError(ErrNilPredicate)
1618
}
1719
for s := range source {
1820
if !predicate(s) {

any.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Any] determines whether a sequence contains any elements.
810
//
911
// [Any]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.any
1012
func Any[Source any](source iter.Seq[Source]) (bool, error) {
1113
if source == nil {
12-
return false, callerError(ErrNilSource)
14+
return false, errorhelper.CallerError(ErrNilSource)
1315
}
1416
for _ = range source {
1517
return true, nil
@@ -22,10 +24,10 @@ func Any[Source any](source iter.Seq[Source]) (bool, error) {
2224
// [AnyPred]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.any
2325
func AnyPred[Source any](source iter.Seq[Source], predicate func(Source) bool) (bool, error) {
2426
if source == nil {
25-
return false, callerError(ErrNilSource)
27+
return false, errorhelper.CallerError(ErrNilSource)
2628
}
2729
if predicate == nil {
28-
return false, callerError(ErrNilPredicate)
30+
return false, errorhelper.CallerError(ErrNilPredicate)
2931
}
3032
for s := range source {
3133
if predicate(s) {

append.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Append] appends a value to the end of the sequence.
810
//
911
// [Append]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.append
1012
func Append[Source any](source iter.Seq[Source], element Source) (iter.Seq[Source], error) {
1113
if source == nil {
12-
return nil, callerError(ErrNilSource)
14+
return nil, errorhelper.CallerError(ErrNilSource)
1315
}
1416
repeat1, _ := Repeat(element, 1)
1517
return Concat(source, repeat1)

cast.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Cast] casts the elements of a sequence to a specified type.
810
//
911
// [Cast]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.cast
1012
func Cast[Source, Result any](source iter.Seq[Source]) (iter.Seq[Result], error) {
1113
if source == nil {
12-
return nil, callerError(ErrNilSource)
14+
return nil, errorhelper.CallerError(ErrNilSource)
1315
}
1416
return func(yield func(Result) bool) {
1517
for s := range source {

chunk.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Chunk] splits the elements of a sequence into chunks of size at most 'size'.
810
//
911
// [Chunk]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.chunk
1012
func Chunk[Source any](source iter.Seq[Source], size int) (iter.Seq[[]Source], error) {
1113
if source == nil {
12-
return nil, callerError(ErrNilSource)
14+
return nil, errorhelper.CallerError(ErrNilSource)
1315
}
1416
if size <= 0 {
15-
return nil, callerError(ErrSizeOutOfRange)
17+
return nil, errorhelper.CallerError(ErrSizeOutOfRange)
1618
}
1719
return func(yield func([]Source) bool) {
1820
next, stop := iter.Pull(source)

concat.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Concat] concatenates two sequences.
810
//
911
// [Concat]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.concat
1012
func Concat[Source any](first, second iter.Seq[Source]) (iter.Seq[Source], error) {
1113
if first == nil || second == nil {
12-
return nil, callerError(ErrNilSource)
14+
return nil, errorhelper.CallerError(ErrNilSource)
1315
}
1416
return func(yield func(Source) bool) {
1517
for s1 := range first {

contains.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package go2linq
33
import (
44
"iter"
55

6+
"github.com/solsw/errorhelper"
67
"github.com/solsw/generichelper"
78
)
89

@@ -11,7 +12,7 @@ import (
1112
// [Contains]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.contains
1213
func Contains[Source any](source iter.Seq[Source], value Source) (bool, error) {
1314
if source == nil {
14-
return false, callerError(ErrNilSource)
15+
return false, errorhelper.CallerError(ErrNilSource)
1516
}
1617
return ContainsEq(source, value, generichelper.DeepEqual[Source])
1718
}
@@ -21,10 +22,10 @@ func Contains[Source any](source iter.Seq[Source], value Source) (bool, error) {
2122
// [ContainsEq]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.contains
2223
func ContainsEq[Source any](source iter.Seq[Source], value Source, equal func(Source, Source) bool) (bool, error) {
2324
if source == nil {
24-
return false, callerError(ErrNilSource)
25+
return false, errorhelper.CallerError(ErrNilSource)
2526
}
2627
if equal == nil {
27-
return false, callerError(ErrNilEqual)
28+
return false, errorhelper.CallerError(ErrNilEqual)
2829
}
2930
for s := range source {
3031
if equal(s, value) {

count.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ package go2linq
22

33
import (
44
"iter"
5+
6+
"github.com/solsw/errorhelper"
57
)
68

79
// [Count] returns the number of elements in a sequence.
810
//
911
// [Count]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.count
1012
func Count[Source any](source iter.Seq[Source]) (int, error) {
1113
if source == nil {
12-
return -1, callerError(ErrNilSource)
14+
return -1, errorhelper.CallerError(ErrNilSource)
1315
}
1416
res := 0
1517
for _ = range source {
@@ -23,10 +25,10 @@ func Count[Source any](source iter.Seq[Source]) (int, error) {
2325
// [CountPred]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.count
2426
func CountPred[Source any](source iter.Seq[Source], predicate func(Source) bool) (int, error) {
2527
if source == nil {
26-
return -1, callerError(ErrNilSource)
28+
return -1, errorhelper.CallerError(ErrNilSource)
2729
}
2830
if predicate == nil {
29-
return -1, callerError(ErrNilPredicate)
31+
return -1, errorhelper.CallerError(ErrNilPredicate)
3032
}
3133
res := 0
3234
for s := range source {

defaultifempty.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package go2linq
33
import (
44
"iter"
55

6+
"github.com/solsw/errorhelper"
67
"github.com/solsw/generichelper"
78
)
89

@@ -13,7 +14,7 @@ import (
1314
// [zero value]: https://go.dev/ref/spec#The_zero_value
1415
func DefaultIfEmpty[Source any](source iter.Seq[Source]) (iter.Seq[Source], error) {
1516
if source == nil {
16-
return nil, callerError(ErrNilSource)
17+
return nil, errorhelper.CallerError(ErrNilSource)
1718
}
1819
return DefaultIfEmptyDef(source, generichelper.ZeroValue[Source]())
1920
}
@@ -24,7 +25,7 @@ func DefaultIfEmpty[Source any](source iter.Seq[Source]) (iter.Seq[Source], erro
2425
// [DefaultIfEmptyDef]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.defaultifempty
2526
func DefaultIfEmptyDef[Source any](source iter.Seq[Source], defaultValue Source) (iter.Seq[Source], error) {
2627
if source == nil {
27-
return nil, callerError(ErrNilSource)
28+
return nil, errorhelper.CallerError(ErrNilSource)
2829
}
2930
return func(yield func(Source) bool) {
3031
empty := true

distinct.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package go2linq
33
import (
44
"iter"
55

6+
"github.com/solsw/errorhelper"
67
"github.com/solsw/generichelper"
78
)
89

@@ -12,7 +13,7 @@ import (
1213
// [Distinct]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.distinct
1314
func Distinct[Source any](source iter.Seq[Source]) (iter.Seq[Source], error) {
1415
if source == nil {
15-
return nil, callerError(ErrNilSource)
16+
return nil, errorhelper.CallerError(ErrNilSource)
1617
}
1718
return DistinctEq(source, generichelper.DeepEqual[Source])
1819
}

distinctby.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package go2linq
33
import (
44
"iter"
55

6+
"github.com/solsw/errorhelper"
67
"github.com/solsw/generichelper"
78
)
89

@@ -12,10 +13,10 @@ import (
1213
// [DistinctBy]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.distinctby
1314
func DistinctBy[Source, Key any](source iter.Seq[Source], keySelector func(Source) Key) (iter.Seq[Source], error) {
1415
if source == nil {
15-
return nil, callerError(ErrNilSource)
16+
return nil, errorhelper.CallerError(ErrNilSource)
1617
}
1718
if keySelector == nil {
18-
return nil, callerError(ErrNilSelector)
19+
return nil, errorhelper.CallerError(ErrNilSelector)
1920
}
2021
return DistinctByEq(source, keySelector, generichelper.DeepEqual[Key])
2122
}
@@ -27,13 +28,13 @@ func DistinctBy[Source, Key any](source iter.Seq[Source], keySelector func(Sourc
2728
func DistinctByEq[Source, Key any](source iter.Seq[Source],
2829
keySelector func(Source) Key, equal func(Key, Key) bool) (iter.Seq[Source], error) {
2930
if source == nil {
30-
return nil, callerError(ErrNilSource)
31+
return nil, errorhelper.CallerError(ErrNilSource)
3132
}
3233
if keySelector == nil {
33-
return nil, callerError(ErrNilSelector)
34+
return nil, errorhelper.CallerError(ErrNilSelector)
3435
}
3536
if equal == nil {
36-
return nil, callerError(ErrNilEqual)
37+
return nil, errorhelper.CallerError(ErrNilEqual)
3738
}
3839
return func(yield func(Source) bool) {
3940
var seen []Key
@@ -57,13 +58,13 @@ func DistinctByEq[Source, Key any](source iter.Seq[Source],
5758
func DistinctByCmp[Source, Key any](source iter.Seq[Source],
5859
keySelector func(Source) Key, compare func(Key, Key) int) (iter.Seq[Source], error) {
5960
if source == nil {
60-
return nil, callerError(ErrNilSource)
61+
return nil, errorhelper.CallerError(ErrNilSource)
6162
}
6263
if keySelector == nil {
63-
return nil, callerError(ErrNilSelector)
64+
return nil, errorhelper.CallerError(ErrNilSelector)
6465
}
6566
if compare == nil {
66-
return nil, callerError(ErrNilCompare)
67+
return nil, errorhelper.CallerError(ErrNilCompare)
6768
}
6869
return func(yield func(Source) bool) {
6970
seen := make([]Key, 0)

elementat.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"iter"
66

7+
"github.com/solsw/errorhelper"
78
"github.com/solsw/generichelper"
89
)
910

@@ -12,10 +13,10 @@ import (
1213
// [ElementAt]: https://learn.microsoft.com/dotnet/api/system.linq.enumerable.elementat
1314
func ElementAt[Source any](source iter.Seq[Source], index int) (Source, error) {
1415
if source == nil {
15-
return generichelper.ZeroValue[Source](), callerError(ErrNilSource)
16+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrNilSource)
1617
}
1718
if index < 0 {
18-
return generichelper.ZeroValue[Source](), callerError(ErrIndexOutOfRange)
19+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrIndexOutOfRange)
1920
}
2021
i := 0
2122
for s := range source {
@@ -24,7 +25,7 @@ func ElementAt[Source any](source iter.Seq[Source], index int) (Source, error) {
2425
}
2526
i++
2627
}
27-
return generichelper.ZeroValue[Source](), callerError(ErrIndexOutOfRange)
28+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrIndexOutOfRange)
2829
}
2930

3031
// [ElementAtOrDefault] returns the element at a specified index in a sequence or a [zero value] if the index is out of range.
@@ -33,7 +34,7 @@ func ElementAt[Source any](source iter.Seq[Source], index int) (Source, error) {
3334
// [zero value]: https://go.dev/ref/spec#The_zero_value
3435
func ElementAtOrDefault[Source any](source iter.Seq[Source], index int) (Source, error) {
3536
if source == nil {
36-
return generichelper.ZeroValue[Source](), callerError(ErrNilSource)
37+
return generichelper.ZeroValue[Source](), errorhelper.CallerError(ErrNilSource)
3738
}
3839
s, err := ElementAt(source, index)
3940
if errors.Is(err, ErrIndexOutOfRange) {

0 commit comments

Comments
 (0)