You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Perhaps we could add some helpers that combine functions and Tuples, so that multi-parameter functions (both input and output) can be easily applied to Maps.
Like This
package main
import"github.com/samber/lo"funcf21(a, bint) int {
returna+b
}
funcf22(a, bint) (int, int) {
returna, b
}
funcTupleFun21[Aany, Bany, Rany](ffunc(A, B) R) func(lo.Tuple2[A, B]) R {
returnfunc(tuple lo.Tuple2[A, B]) R {
a:=f(tuple.A, tuple.B)
returna
}
}
funcTupleFun22[Aany, Bany, R1any, R2any](ffunc(A, B) (R1, R2)) func(lo.Tuple2[A, B]) lo.Tuple2[R1, R2] {
returnfunc(tuple lo.Tuple2[A, B]) lo.Tuple2[R1, R2] {
a, b:=f(tuple.A, tuple.B)
return lo.Tuple2[R1, R2]{A: a, B: b}
}
}
funcFakeIndex[Aany, Rany](ffunc(A) R) func(A, int) R {
returnfunc(aA, _int) R {
returnf(a)
}
}
funcmain() {
data:= []lo.Tuple2[int, int]{
{1, 2},
{3, 4},
{5, 6},
}
lo.Map(data, FakeIndex(TupleFun21(f21)))
lo.Map(data, FakeIndex(TupleFun22(f22)))
}
The text was updated successfully, but these errors were encountered:
0x587
changed the title
Helpers for combine function and tuple
Proposal: Helpers for combine function and tuple
Jun 6, 2024
oh yes your solution is possible.
In most cases, our function will return (val, err). When an error occurs, we want to stop or ignore the process. If only have Map2 is difficult to apply to this situation.
Perhaps we could add some helpers that combine functions and Tuples, so that multi-parameter functions (both input and output) can be easily applied to Maps.
Like This
The text was updated successfully, but these errors were encountered: