mirror of
https://github.com/samber/lo.git
synced 2026-04-22 23:47:11 +08:00
rename lo.Bind to lo.Partial
This commit is contained in:
@@ -10,6 +10,9 @@ Adding:
|
||||
- lo.FromPtr
|
||||
- lo.IsEmpty
|
||||
- lo.Compact
|
||||
- lo.ToPairs: alias to lo.Entries
|
||||
- lo.FromPairs: alias to lo.FromEntries
|
||||
- lo.Partial
|
||||
|
||||
Change:
|
||||
|
||||
|
||||
@@ -171,7 +171,10 @@ Type manipulation helpers:
|
||||
- Empty
|
||||
- IsEmpty
|
||||
- Coalesce
|
||||
- Bind
|
||||
|
||||
Function helpers:
|
||||
|
||||
- Partial
|
||||
|
||||
Concurrency helpers:
|
||||
|
||||
@@ -1467,14 +1470,19 @@ result, ok := lo.Coalesce[*string](nil, nilStr, &str)
|
||||
// &"foobar" true
|
||||
```
|
||||
|
||||
### Bind
|
||||
### Partial
|
||||
|
||||
Returns new function that, when called, has its first argument set to the provided value.
|
||||
|
||||
```go
|
||||
add := func(x, y int) int { return x + y }
|
||||
f := Bind(add, 5)
|
||||
f := lo.Partial(add, 5)
|
||||
|
||||
f(10)
|
||||
// 15
|
||||
|
||||
f(42)
|
||||
// 47
|
||||
```
|
||||
|
||||
### Attempt
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package lo
|
||||
|
||||
// Bind returns new function that, when called, has its first argument set to the provided value.
|
||||
func Bind[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R {
|
||||
// Partial returns new function that, when called, has its first argument set to the provided value.
|
||||
func Partial[T1, T2, R any](f func(T1, T2) R, arg1 T1) func(T2) R {
|
||||
return func(t2 T2) R {
|
||||
return f(arg1, t2)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user