rename lo.Bind to lo.Partial

This commit is contained in:
Samuel Berthe
2022-07-04 00:22:20 +02:00
parent e00a624c19
commit 828393ec21
3 changed files with 16 additions and 5 deletions
+3
View File
@@ -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:
+11 -3
View File
@@ -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
+2 -2
View File
@@ -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)
}