-
-
Notifications
You must be signed in to change notification settings - Fork 898
Open
Description
I make use of partial application quite a lot, especially with lodash/fp, it's handy for building ad-hoc easily testable transformers.
Would be nice to see some added here! One repo that's growing out of #82 is dt
where I'm dropping all these useful functions but it would be great to have it all in one place.
https://github.com/Southclaws/dt
An example of partial application would be:
func Map[T any, R any](iteratee func(T) R) func([]T) []R {
return func(collection []T) []R {
result := make([]R, len(collection))
for i, item := range collection {
result[i] = iteratee(item)
}
return result
}
}
so the argument order is flipped and separated into two separate function calls. This allows you to "build" a "mapper": mapper := Map(someFunc)
then re-use it later: updated := mapper(list)
Metadata
Metadata
Assignees
Labels
No labels