Skip to content

Commit

Permalink
replace custom constraint by stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
samber committed Mar 3, 2022
1 parent 4e339ad commit 0a9b671
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.3.0 (2022-03-03)

Last and Nth return errors

## 1.2.0 (2022-03-03)

Adding `lop.Map` and `lop.ForEach`.
Expand Down Expand Up @@ -65,4 +69,3 @@ Other functional programming helpers:
Constraints:

- Clonable
- Ordered
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

This project have started as an experiment to discover generics implementation. It may look like Lodash in some aspects. I used to code with the awesome [go-funk](https://github.com/thoas/go-funk) package, but it uses reflection and therefore is not typesafe.

As expected, my benchmarks demonstrate that generics will be much faster than reflect-based implementations.
As expected, benchmarks demonstrate that generics will be much faster than implementations based on reflect stdlib package.

In the future, some of these helpers will be available in the Go standard library (under package names "slice" and "maps").
In the future, some of these helpers will be available in the Go standard library (under package names "slices" and "maps").

### Why this name?

Expand Down
4 changes: 0 additions & 4 deletions constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,3 @@ package lo
type Clonable[T any] interface {
Clone() T
}

type Ordered interface {
int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64 | uintptr | float32 | float64 | string
}
5 changes: 3 additions & 2 deletions find.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package lo
import (
"fmt"
"math"
"golang.org/x/exp/constraints"
)

// import "golang.org/x/exp/constraints"
Expand Down Expand Up @@ -46,7 +47,7 @@ func Find[T any](collection []T, predicate func(T) bool) (T, bool) {
}

// Min search the minimum value of a collection.
func Min[T Ordered](collection []T) T {
func Min[T constraints.Ordered](collection []T) T {
var min T

for i := 0; i < len(collection); i++ {
Expand All @@ -67,7 +68,7 @@ func Min[T Ordered](collection []T) T {
}

// Max search the maximum value of a collection.
func Max[T Ordered](collection []T) T {
func Max[T constraints.Ordered](collection []T) T {
var max T

for i := 0; i < len(collection); i++ {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ require (
github.com/davecgh/go-spew v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/thoas/go-funk v0.9.1 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/thoas/go-funk v0.9.1 h1:O549iLZqPpTUQ10ykd26sZhzD+rmR5pWhuElrhbC20M=
github.com/thoas/go-funk v0.9.1/go.mod h1:+IWnUfUmFO1+WVYQWQtIJHeRRdaIyyYglZN7xzUPe4Q=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down

0 comments on commit 0a9b671

Please sign in to comment.