Skip to content

Commit 119d77e

Browse files
authored
is.Not (#30)
feat(predicate): is.Not chore(loop): comments
1 parent 6d56281 commit 119d77e

File tree

8 files changed

+25
-14
lines changed

8 files changed

+25
-14
lines changed

break/kv/loop/loop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package loop
22

3-
// Loop is a function that returns the next key, value or false if there are no more elements.
4-
type Loop[K, V any] func() (K, V, bool, error)
3+
// Loop is a function that returns the next key\value or ok==false if there are no more elements.
4+
type Loop[K, V any] func() (key K, value V, ok bool, error error)
55

66
// Track applies the 'consumer' function to position/element pairs retrieved by the 'next' function until the consumer returns the c.Break to stop.
77
func (next Loop[K, V]) Track(consumer func(K, V) error) error {

break/loop/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ func Append[T any, TS ~[]T](next func() (T, bool, error), out TS) (TS, error) {
200200
return out, nil
201201
}
202202

203-
// ReduceOK reduces the elements retrieved by the 'next' function into an one using the 'merge' function.
203+
// Reduce reduces the elements retrieved by the 'next' function into an one using the 'merge' function.
204204
// If the 'next' function returns ok=false at the first call, the zero value of 'T' type is returned.
205205
func Reduce[T any](next func() (T, bool, error), merge func(T, T) T) (T, error) {
206206
result, _, err := ReduceOK(next, merge)

break/loop/loop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package loop
22

3-
// Loop is a function that returns the next element, false if there are no more elements or error if something is wrong.
4-
type Loop[T any] func() (T, bool, error)
3+
// Loop is a function that returns the next element, ok==false if there are no more elements or an error if something is wrong.
4+
type Loop[T any] func() (element T, ok bool, err error)
55

66
// All is used to iterate through the loop using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.
77
func (next Loop[T]) All(consumer func(T, error) bool) {

kv/loop/loop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
kvPredicate "github.com/m4gshm/gollections/kv/predicate"
99
)
1010

11-
// Loop is a function that returns the next key, value or false if there are no more elements.
12-
type Loop[K, V any] func() (K, V, bool)
11+
// Loop is a function that returns the next key\value or ok==false if there are no more elements.
12+
type Loop[K, V any] func() (key K, value V, ok bool)
1313

1414
// All is used to iterate through the loop using `for ... range`. Supported since go 1.22 with GOEXPERIMENT=rangefunc enabled.
1515
func (next Loop[K, V]) All(consumer func(key K, value V) bool) {

loop/loop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"github.com/m4gshm/gollections/c"
66
)
77

8-
// Loop is a function that returns the next element or false if there are no more elements.
9-
type Loop[T any] func() (T, bool)
8+
// Loop is a function that returns the next element or ok=false if there are no more elements.
9+
type Loop[T any] func() (element T, ok bool)
1010

1111
var (
1212
_ c.Filterable[any, Loop[any], loop.Loop[any]] = (Loop[any])(nil)

predicate/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func Eq[T comparable](v T) Predicate[T] {
2222
return func(c T) bool { return v == c }
2323
}
2424

25-
// Not negates the 'p' predicate
25+
// Not creates a 'not p' predicate
2626
func Not[T any](p Predicate[T]) Predicate[T] {
2727
return func(v T) bool { return !p(v) }
2828
}

predicate/is/api.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package is
2+
3+
import (
4+
"github.com/m4gshm/gollections/predicate"
5+
)
6+
7+
// Not - is.Not creates a 'not p' predicate.
8+
func Not[T any](p predicate.Predicate[T]) predicate.Predicate[T] {
9+
return predicate.Not(p)
10+
}

predicate/not/api.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@ package not
44
import (
55
"github.com/m4gshm/gollections/predicate"
66
"github.com/m4gshm/gollections/predicate/eq"
7+
"github.com/m4gshm/gollections/predicate/is"
78
)
89

9-
// Eq - not.Eq makes reverse of the eq.To predicate
10+
// Eq - not.Eq makes a 'not eq.To' predicate
1011
func Eq[T comparable](v T) predicate.Predicate[T] {
11-
return predicate.Not(eq.To(v))
12+
return is.Not(eq.To(v))
1213
}
1314

14-
// Match - not.Match alias of predicate.Not
15+
// Match - not.Match makes a 'not predicate.Match' predicate
1516
func Match[From, To any](getter func(From) To, condition predicate.Predicate[To]) predicate.Predicate[From] {
16-
return predicate.Not(predicate.Match(getter, condition))
17+
return is.Not(predicate.Match(getter, condition))
1718
}

0 commit comments

Comments
 (0)