Package: def-result
def_resultProject Discontinuation Announcementdef_resultwill not be developed anymore.Please useon_railslibrary.Theon_railsproject is better and more complete than this project. In
addition to the features of this project, it has tools for railway oriented programming (ROP).Thank youGetting Started »Report a Bug·Request a Feature.Ask a QuestionTable of ContentsAboutPurposeMotivationWhat problems are solved?Getting StartedUsageDocumentationCHANGELOGFeaturesRoadmapSupportFAQProject assistanceContributingAuthors & contributorsSecurityLicenseAboutdef_resultis a library forpython.It is a library for functional error handling to improvemanaging errors.It stores result of functions and provides a simple way to handle and manipulate the return values of functions, with
built-in support for error handling and more.PurposeIn functional programming, it is not always appropriate to use traditionaltry-exceptblocks because they can lead to
code that is difficult to read, understand, and maintain.The purpose of Functional Error Handling Libraries is to provide developers with a set of abstractions and tools for
managing errors in a functional way.def_resultis a functional error handling library. The goal of this library is to make error handling more explicit,
composable, and testable. By using this library, developers can write code that ismore robust, maintainable, and
expressive.MotivationThe motivation behind this library is the desire to write code that ismore reliable, easier to understand, and less
prone to errors. In many cases, functional programming languages provide built-in abstractions for handling errors.
However, for languages that do not have built-in support for functional error handling, libraries like this can provide
a useful alternative.What problems are solved?This library can solve several problems, including:Ensuring that error handling is consistent across an application.Making it easier to test error handling code.Making error handling code more readable and maintainable.Encouraging developers to handle errors in a more functional way, which can lead to more reliable and robust code.Developers can spend less time debugging and more time writing code that adds value to their organization. Additionally,
by using functional programming concepts, developers can write code that is easier to reason about and understand, which
can lead to faster development cycles and better quality code.Getting StartedUsepipto install package:pip install def_resultUsageSample 1: use decorator for pure functionsIn this example,def_resultis used as a decorator to wrap thedivide_numbersfunction.fromdef_resultimportdef_result@def_resultdefdivide_numbers(a:int,b:int):ifb==0:raiseValueError("Cannot divide by zero")returna/bresult=divide_numbers(10,0)ifresult.success:print(f"Operation was successful:{result.value}")else:print(f"Operation failed:{str(result.detail)}")Sample 2: useResultin functionfromdef_resultimportResultfromdef_result.ResultDetails.ErrorsimportValidationErrordefdivide_numbers(a:int,b:int):ifb==0:returnResult.fail(ValidationError(message="Cannot divide by zero"))returnResult.ok(a/b)result=divide_numbers(10,0)ifresult.success:print(f"Operation was successful:{result.value}")else:print(f"Operation failed:")print(str(result.detail))CHANGELOGPlease see theCHANGELOGfile.FeaturesEasy to use:def_resultis designed to be simple and easy to use, with a minimal API and clear documentation.Compatibility with existing code:def_resultcan be easily added to existing codes without the need for major
refactoring. You can use decorator for wrap old functions or write new functions without worrying about
incompatibilities.Save any details you like:Thanks to
theResultDetailclass, you can store
various information about the output of the function. Also, by inheriting from this class, you can write new and
customized classes for your project.Special details for errors:With
theErrorDetailclass, you
can store specific details about errors. For example, this class supportsstack tracein a built-in way.Support for common details by default:Inthis link, you can see the different
types of details that are supported.RoadmapSee theopen issuesfor a list of proposed features (and known issues).Top Feature Requests(
Add your votes using the 👍 reaction)Top Bugs(
Add your votes using the 👍 reaction)Newest BugsSupportReach out to the maintainers at one of the following places:GitHub issuesFAQDo I need rewrite all the functions in a new way?not necessarily.You can add this library and write new functions without changing the previous codes.Also for old functions, you can usedecorator. By using decorator, The output of the function is converted
toResultformat. This way, your code is wrap in atry-exceptblock to handle all exceptions.How to manage all function exceptions?By using decorator, your code is wrap in atry-exceptblock and the final output is converted to Result. In this way,
all exceptions are handled.Project assistanceFirst of, thank you.If you want to say thank you or/and support active development ofdef_result:Add aGitHub Starto the project.Write interesting articles about the project onDev.to,Mediumor your
personal blog.Together, we can makedef_resultbetter!ContributingFirst off, thanks for taking the time to contribute! Contributions are what make the free/open-source community such an
amazing place to learn, inspire, and create. Any contributions you make will benefit everybody else and aregreatly
appreciated.Please readour contribution guidelines, and
thank you for being involved!Please do not forget that this project usesconventional commits, so please
follow the specification in your commit messages. You can see valid types
fromthis file.Authors & contributorsThe original setup of this repository is byPayadel.For a full list of all authors and contributors,
seethe contributors page.Securitydef_resultfollows good practices of security, but 100% security cannot be assured.def_resultis provided"as
is"without anywarranty.For more information and to report security issues, please refer to
oursecurity documentation.LicenseThis project is licensed under theGPLv3.SeeLICENSEfor more information.