Skip to content

Commit

Permalink
split functor.go (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
chen3feng authored Aug 30, 2022
1 parent 858db9f commit eb977b3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 38 deletions.
22 changes: 22 additions & 0 deletions functor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package stl4go

// Less wraps the '<' operator for ordered types.
func Less[T Ordered](a, b T) bool {
return a < b
}

// Greater wraps the '>' operator for ordered types.
func Greater[T Ordered](a, b T) bool {
return a > b
}

// OrderedCompare provide default CompareFn for ordered types.
func OrderedCompare[T Ordered](a, b T) int {
if a < b {
return -1
}
if a > b {
return 1
}
return 0
}
15 changes: 3 additions & 12 deletions generated_doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ Package stl4go is a generic container and algorithm library for go.
- [func DescSort[T Ordered](a []T)](<#func-descsort>)
- [func DescStableSort[T Ordered](a []T)](<#func-descstablesort>)
- [func Equal[T comparable](a, b []T) bool](<#func-equal>)
- [func Equals[T comparable](a, b T) bool](<#func-equals>)
- [func Find[T comparable](a []T, x T) (index int, ok bool)](<#func-find>)
- [func FindIf[T any](a []T, cond func(T) bool) (index int, ok bool)](<#func-findif>)
- [func Generate[T any](a []T, gen func() T)](<#func-generate>)
Expand Down Expand Up @@ -322,14 +321,6 @@ Equal returns whether two slices are equal. Return true if they are the same len

Complexity: O\(min\(len\(a\), len\(b\)\)\).

## func [Equals](<https://github.com/chen3feng/stl4go/blob/master/types.go#L57>)

```go
func Equals[T comparable](a, b T) bool
```

Equals wraps the '==' operator for comparable types.

## func [Find](<https://github.com/chen3feng/stl4go/blob/master/lookup.go#L90>)

```go
Expand Down Expand Up @@ -360,7 +351,7 @@ Generate fill each element of \`a\`\` with \`gen\(\)\`.

Complexity: O\(len\(a\)\).

## func [Greater](<https://github.com/chen3feng/stl4go/blob/master/types.go#L67>)
## func [Greater](<https://github.com/chen3feng/stl4go/blob/master/functor.go#L9>)

```go
func Greater[T Ordered](a, b T) bool
Expand Down Expand Up @@ -420,7 +411,7 @@ IsSorted returns whether the slice a is sorted in ascending order.

Complexity: O\(len\(a\)\).

## func [Less](<https://github.com/chen3feng/stl4go/blob/master/types.go#L62>)
## func [Less](<https://github.com/chen3feng/stl4go/blob/master/functor.go#L4>)

```go
func Less[T Ordered](a, b T) bool
Expand Down Expand Up @@ -540,7 +531,7 @@ NoneOf return true pred\(e\) returns true for none emements e in a.

Complexity: O\(len\(a\)\).

## func [OrderedCompare](<https://github.com/chen3feng/stl4go/blob/master/types.go#L72>)
## func [OrderedCompare](<https://github.com/chen3feng/stl4go/blob/master/functor.go#L14>)

```go
func OrderedCompare[T Ordered](a, b T) int
Expand Down
26 changes: 0 additions & 26 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,29 +52,3 @@ type CompareFn[T any] func(a, b T) int

// HashFn is a function that returns the hash of 't'.
type HashFn[T any] func(t T) uint64

// Equals wraps the '==' operator for comparable types.
func Equals[T comparable](a, b T) bool {
return a == b
}

// Less wraps the '<' operator for ordered types.
func Less[T Ordered](a, b T) bool {
return a < b
}

// Greater wraps the '>' operator for ordered types.
func Greater[T Ordered](a, b T) bool {
return a > b
}

// OrderedCompare provide default CompareFn for ordered types.
func OrderedCompare[T Ordered](a, b T) int {
if a < b {
return -1
}
if a > b {
return 1
}
return 0
}

0 comments on commit eb977b3

Please sign in to comment.