Goderive
Derives and generates mundane golang functions that you do not want to maintain yourself
Install / Use
/learn @awalterschulze/GoderiveREADME
goderive
goderive derives mundane golang functions that you do not want to maintain and keeps them up to date.
It does this by parsing your go code for functions, which are not implemented, and then generates these functions for you by deriving their implementations from the input parameter types.
Examples
In the following code the deriveEqual function will be spotted as a function that was not implemented (or was previously derived) and has a prefix deriveEqual.
package main
type MyStruct struct {
Int64 int64
StringPtr *string
}
func (this *MyStruct) Equal(that *MyStruct) bool {
return deriveEqual(this, that)
}
goderive will then generate the following code in a derived.gen.go file in the same package:
func deriveEqual(this, that *MyStruct) bool {
return (this == nil && that == nil) ||
this != nil && that != nil &&
this.Int64 == that.Int64 &&
((this.StringPtr == nil && that.StringPtr == nil) ||
(this.StringPtr != nil && that.StringPtr != nil && *(this.StringPtr) == *(that.StringPtr)))
}
Recursive Examples:
Set Examples:
Functional Examples:
Concurrency Examples:
Functions
Recursive Functions:
- Equal
deriveEqual(T, T) boolderiveEqual(T) func(T) bool
- Compare
deriveCompare(T, T) intderiveCompare(T) func(T) int
- DeepCopy
deriveDeepCopy(dst *T, src *T)deriveDeepCopy(dst []T, src []T)deriveDeepCopy(dst map[A]B, src map[A]B)
- Clone
deriveClone(T) T - GoString
deriveGoString(T) string - Hash
deriveHash(T) uint64
Functional Functions:
- Fmap
deriveFmap(func(A) B, []A) []BderiveFmap(func(rune) B, string) []BderiveFmap(func(A) B, func() (A, error)) (B, error)deriveFmap(func(A) (B, error), func() (A, error)) (func() (B, error), error)deriveFmap(func(A), func() (A, error)) errorderiveFmap(func(A) (B, c, d, ...), func() (A, error)) (func() (B, c, d, ...), error)
- Join
deriveJoin([][]T) []TderiveJoin([]string) stringderiveJoin(func() (T, error), error) func() (T, error)deriveJoin(func() (T, ..., error), error) func() (T, ..., error)
- Flip
deriveFlip(f func(A, B, ...) T) func(B, A, ...) T - Curry
deriveCurry(f func(A, B, ...) T) func(A) func(B, ...) T - Uncurry
deriveUncurry(f func(A) func(B, ...) T) func(A, B, ...) T - Tuple
deriveTuple(A, B, ...) func() (A, B, ...) - Compose
deriveCompose(func() (A, error), func(A) (B, error)) func() (B, error)deriveCompose(func(A) (B, error), func(B) (C, error)) func(A) (C, error)deriveCompose(func(A...) (B..., error), func(B...) (C..., error)) func(A...) (C..., error)deriveCompose(func(A...) (B..., error), ..., func(C...) (D..., error)) func(A...) (D..., error)
- Mem
deriveMem(func(A...) (B...)) func(A...) (B...)
- Traverse
deriveTraverse(func(A) (B, error), []A) ([]B, error)
- ToError
deriveToError(error, func(A...) (B..., bool)) func(A...) (B..., error)deriveToError(error, func() bool) func() error
- Apply
deriveApply(f func(...A, B) C, B) func(...A) C
Concurrency Functions:
- Fmap
deriveFmap(func(A) B, <-chan A) <-chan B
- Join
deriveJoin(<-chan <-chan T) <-chan TderiveJoin(chan <-chan T) <-chan TderiveJoin([]<-chan T) <-chan TderiveJoin([]chan T) <-chan TderiveJoin(chan T, chan T, ...) <-chan T
- Pipeline
derivePipeline(func(A) <-chan B, func(B) <-chan C) func(A) <-chan C
- Do
deriveDo(func() (A, error), func (B, error)) (A, B, error)
- Dup
deriveDup(c <-chan T) (c1, c2 <-chan T)
Deprecated in favour of generics:
- Keys
deriveKeys(map[K]V) []K - Sort
deriveSort([]T) []T - Unique
deriveUnique([]T) []T - Set
deriveSet([]T) map[T]struct{} - Min
deriveMin(list []T, default T) (min T)deriveMin(T, T) T
- Max
deriveMax(list []T, default T) (max T)deriveMax(T, T) T
- Contains
deriveContains([]T, T) bool - Intersect
deriveIntersect(a, b []T) []TderiveIntersect(a, b map[T]struct{}) map[T]struct{}
- Union
deriveUnion(a, b []T) []TderiveUnion(a, b map[T]struct{}) map[T]struct{}
- Filter
deriveFilter(pred func(T) bool, []T) []T - All
deriveAll(pred func(T) bool, []T) bool - Any
deriveAny(pred func(T) bool, []T) bool - TakeWhile
deriveTakeWhile(pred func(T) bool, []T) []T
When goderive walks over your code it is looking for a function that:
- was not implemented (or was previously derived) and
- has a predefined prefix.
Functions which have been previously derived will be regenerated to keep them up to date with the latest modifications to your types. This keeps these functions, which are truly mundane to write, maintainable.
For example when someone in your team adds a new field to a struct and forgets to update the CopyTo method. This problem is solved by goderive, by generating generated functions given the new types.
Function prefixes are by default `deriveCamelCas
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
351.2kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
