libfn / functional

Extending C++ library for functional programming
ISC License
60 stars 8 forks source link

codecov FOSSA Status

functional

Functional programming in C++

Why

The purpose of this library is to exercise an approach to functional programming in C++ on top of the existing std C++ vocabulary types (such as std::expected and std::optional), with the aim of eventually extending the future versions of the C++ standard library with the functionality found to work well.

How

The approach is to take the existing std types in the C++ standard library (when appropriate) and extend them (via inheritance) with the facilities useful in writing functional style programs. Eventually, the proposed functionality will be (hopefully) folded into the existing std types and new std types will be added.

This library requires a very modern implementation of the C++ library which implements monadic operations in std::optional and std::expected, as defined in ISO/IEC 14882:2023. Currently, such implementations are provided with gcc 13 and clang 18, which are the recommended compilers for this project. A suggested approach to access the most recent version of the compiler (when it is not available in the operating system) is to use a devcontainer when working with this project. Alternatively take a look at Nix and nix/README.md.

Implementation note

This library requires standardized type ordering, which currently is a proposed C++26 feature and is not implemented by any compiler. Currently, the library relies on an internal, naive implementation of such a feature which is not expected to work with unnamed types, types without linkage etc.

Test Coverage

In this project, 100% tests coverage does not actually mean much, because the most useful tests cases are around compile-time language elements, such as overload resolution, built-in conversions etc. Any meaningful tests must execute the same set of functions in many, subtly different ways, rather than simply execute each function and branch at least once.

Backwards compatibility

The maintainers will aim to maintain compatibility with the proposed changes in the C++ standard library, rather than with the existing uses of the code in this repo. In practice, this means that all code in this repo should be considered "under intensive development and unstable" until the standardization of the proposed facilities.

Best make your private fork from this repo and use it as you see fit.

The maintainers are unable to guarantee that no significant refactoring will ever take place. The opposite is to be expected, since the process of standardization of any additions to the C++ standard library typically involves a fair number of changes and improvements, some of them quite fundamental. This includes all kinds of interfaces and names in this library, which until the moment of standardization are only proposed.

Acknowledgments

License

FOSSA Status