An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 9.0% on proxy.golang.org

proxy.golang.org : github.com/metakeule/dispatch

Package dispatch provides an flexible way to structure dispatching based on types. Advantages over using a type switch: Let's say you have a struct with a method that uses a type switch If you want to handle a new type Using dispatch you have more flexibility: Now if MyStruct is used, new types, handlers and fallbacks can be added. No need to change anything inside MyStruct. If you use more than one fallback, be aware, that they are called in the reverse order of registration (last in first out). Why is that? If you want to add a fallback from the outside, you might want to intercept the fallback chain and decide, if the other fallbacks are called by returning true or false. Why does Dispatch() return an error instead of a centralized error handling? Well if you need a centralized error handling, simply wrap the call to Dispatch() into another function that handles the error. But you also could do the error handling when calling the Dispatch() where you have more information about the value, you pass to Dispatch and where you can make better decisions about what to do best.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/metakeule/dispatch
License: MIT
Latest release: over 10 years ago
First release: over 10 years ago
Namespace: github.com/metakeule
Stars: 0 on
Forks: 0 on
Last synced: 25 days ago