Ecosyste.ms: Packages

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

Top 8.2% on proxy.golang.org

proxy.golang.org : github.com/mauricioklein/go-chainable

Package chainable provides an easy and convenient way of chaining function calls in Golang. It's common to find Go programs similar to the one below: Error handling can make the codebase messy. At the same time, chaining function calls can obfuscate errors and cascading calls can increase the cognitive complexity. Elixir, F# and other languages solve this problem with the support to pipes, but Golang hasn't such feature. Chainable provides a clearer way to chain function calls, using the output of the previous function as the input of the next one. The example above could be re-written using Chainable as follow: Another advantage is that Chainable automatically handle errors in a chain. Thus, if one of the methods returns an error as the last argument, the chain is broken and the error is returned by the "Unwrap" method: If automatic error handling isn't desired (i.e. the error should be chained along with the other arguments), the method "ChainDummy" should be used instead of "Chain". Pay attention that the next function in the chain must be able to receive the error generated by the previous one: "Chain" and "DummyChain" methods are variadics, and can be used in conjunction: Finally, to reset a chain and make it ready to be reused, just call the method "Reset":

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/mauricioklein/go-chainable
Keywords: chainable, chainable-methods, go, golang, pipe
License: MIT
Latest release: over 4 years ago
First release: about 6 years ago
Namespace: github.com/mauricioklein
Stars: 19 on GitHub
Forks: 1 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 18 days ago

    Loading...
    Readme
    Loading...