diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 00000000..c6a8e479 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,50 @@ +name: docs +on: + push: + branches: [main, feature/doxygen] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + generate_docs: + name: Generate and upload docs + runs-on: ubuntu-20.04 + container: + image: godexsoft/functional-ci:0.0.4 + steps: + - uses: actions/checkout@v3 + with: + submodules: 'true' + + - name: Export docs + continue-on-error: false + shell: bash + id: run_cmake + run: | + mkdir .build + cd .build + cmake -DDOCS=True .. + cmake --build . --target export_docs + + - name: Setup Pages + uses: actions/configure-pages@v4 + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./.build/docs + name: docs-develop + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 + with: + artifact_name: docs-develop diff --git a/CMakeLists.txt b/CMakeLists.txt index 472bdbf5..0114571f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,11 +7,17 @@ include(Ccache) option(USE_NIX "Use nix packages to resolve dependencies." OFF) option(COVERARE "Enable coverage report." OFF) +option(DOCS "Generate documentation." OFF) + if(COVERAGE) include(CodeCoverage) include(Coverage) endif() +if (DOCS) + include(Docs) +endif() + set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/ci/Dockerfile b/ci/Dockerfile new file mode 100644 index 00000000..1cb8a878 --- /dev/null +++ b/ci/Dockerfile @@ -0,0 +1,23 @@ +FROM fedora:39 + +WORKDIR /root + +RUN dnf -y update ;\ + dnf -y install redhat-lsb python3.11 gcc libstdc++-static ccache \ + vim wget sudo curl git grep sed gdb zsh cmake doxygen ninja-build \ + unzip java-latest-openjdk clang git-clang-format clang-tools-extra llvm ;\ + dnf -y clean all + +# Fail build if unexpected gcc version +RUN gcc --version | grep -E "^gcc \(GCC\) 13" + +RUN wget https://repo.maven.apache.org/maven2/org/testingisdocumenting/znai/znai-dist/1.70/znai-dist-1.70-znai.zip ;\ + unzip znai-dist-1.70-znai.zip -d znai_tmp; mv znai_tmp/dist /opt/znai ;\ + rm -rf znai-dist-1.70-znai.zip znai_tmp +ENV PATH=/opt/znai:${PATH} + +ENV CC=/usr/bin/gcc +ENV CXX=/usr/bin/g++ +ENV CMAKE_GENERATOR='Ninja' +ENV CMAKE_C_COMPILER=${CC} +ENV CMAKE_CXX_COMPILER=${CXX} diff --git a/ci/doc_export/_structure_settings.db b/ci/doc_export/_structure_settings.db new file mode 100644 index 00000000..e69de29b diff --git a/cmake/Docs.cmake b/cmake/Docs.cmake new file mode 100644 index 00000000..80551747 --- /dev/null +++ b/cmake/Docs.cmake @@ -0,0 +1,27 @@ +find_package(Doxygen REQUIRED) +find_package(Znai REQUIRED) + +set(DOXYGEN_GENERATE_HTML NO) +set(DOXYGEN_GENERATE_XML YES) + +macro(znai_export_docs TARGET SOURCE_DIR DEPLOY_DIR) +add_custom_target(${TARGET} +COMMAND ${Znai} --source ${SOURCE_DIR} --deploy ${DEPLOY_DIR} --doc-id '""' --lookup-paths ${CMAKE_BINARY_DIR} +COMMENT "Exporting documentation to ${DEPLOY_DIR}" + ) +endmacro() + +doxygen_add_docs( + docs + ${CMAKE_CURRENT_SOURCE_DIR}/include + COMMENT "Generate documentation" +) + +znai_export_docs( + export_docs + ${CMAKE_CURRENT_SOURCE_DIR}/docs + ${CMAKE_BINARY_DIR}/docs + COMMENT "Export final documentation" +) + +add_dependencies(export_docs docs) diff --git a/cmake/FindZnai.cmake b/cmake/FindZnai.cmake new file mode 100644 index 00000000..ec06993f --- /dev/null +++ b/cmake/FindZnai.cmake @@ -0,0 +1,4 @@ +find_program (Znai NAMES znai) +if(Znai_FOUND) + message(STATUS "Znai found at ${Znai}") +endif() diff --git a/docs/choice.md b/docs/choice.md new file mode 100644 index 00000000..f49299b8 --- /dev/null +++ b/docs/choice.md @@ -0,0 +1,15 @@ +--- +title: fn::choice +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::choice + +--- + +## Return value {style: "api"} +TODO + diff --git a/docs/choice/and_then.md b/docs/choice/and_then.md new file mode 100644 index 00000000..233891bb --- /dev/null +++ b/docs/choice/and_then.md @@ -0,0 +1,28 @@ +--- +title: fn::and_then +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::and_then_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::and_then_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + +--- + +## Examples {style: "api"} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-choice-parse", "// example-choice-checks"] +} diff --git a/docs/choice/index.md b/docs/choice/index.md new file mode 100644 index 00000000..bc76ac7b --- /dev/null +++ b/docs/choice/index.md @@ -0,0 +1,28 @@ +--- +title: Choice monad +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::choice + +## choice_for {style: "api"} +Used to generate `fn::choice` correctly. Sorts and deduplicates types under the hood. + +Some text explaining this section... + +:include-doxygen-member: fn::choice_for { signatureOnly: false, includeAllMatches: true } + +## choice {style: "api"} +Some text explaining this section... + +:include-doxygen-member: fn::choice { signatureOnly: false, includeAllMatches: true } + +## value {style: "api"} +Some text explaining this section... + +:include-doxygen-member: fn::choice< Ts... >::value { signatureOnly: false, includeAllMatches: true } + + diff --git a/docs/choice/transform.md b/docs/choice/transform.md new file mode 100644 index 00000000..e08f37ab --- /dev/null +++ b/docs/choice/transform.md @@ -0,0 +1,19 @@ +--- +title: fn::transform +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::transform_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::transform_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/doxygen.json b/docs/doxygen.json new file mode 100644 index 00000000..12dac565 --- /dev/null +++ b/docs/doxygen.json @@ -0,0 +1,3 @@ +{ + "indexPath": "xml/index.xml" +} diff --git a/docs/expected/and_then.md b/docs/expected/and_then.md new file mode 100644 index 00000000..64d1f378 --- /dev/null +++ b/docs/expected/and_then.md @@ -0,0 +1,35 @@ +--- +title: fn::and_then +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::and_then_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::and_then_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + +--- + +## Examples {style: "api"} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-error-struct", "// example-expected-and_then-value"], + desc: "The resulting value is `13` because `ex` does not contain an `Error` and therefore `and_then` is called." +} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-error-struct", "// example-expected-and_then-error"], + desc: "The result is an `Error` because `ex` already contained an `Error` and therefore `and_then` is not called." +} diff --git a/docs/expected/fail.md b/docs/expected/fail.md new file mode 100644 index 00000000..bf6747a0 --- /dev/null +++ b/docs/expected/fail.md @@ -0,0 +1,20 @@ +--- +title: fn::fail +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::fail_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::fail_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + diff --git a/docs/expected/filter.md b/docs/expected/filter.md new file mode 100644 index 00000000..f1ea7845 --- /dev/null +++ b/docs/expected/filter.md @@ -0,0 +1,35 @@ +--- +title: fn::filter +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::filter_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::filter_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + +--- + +## Examples {style: "api"} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-error-struct", "// example-expected-filter-value"], + desc: "The resulting value is `42` because the filter predicate returns `true` for `42` as it is not less than `42`." +} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-error-struct", "// example-expected-filter-error"], + desc: "The error is set to `Less than 42` because the predicate returns `false` for `12` since it's less than `42`." +} diff --git a/docs/expected/inspect.md b/docs/expected/inspect.md new file mode 100644 index 00000000..693473f4 --- /dev/null +++ b/docs/expected/inspect.md @@ -0,0 +1,19 @@ +--- +title: fn::inspect +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::inspect_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::inspect_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/expected/inspect_error.md b/docs/expected/inspect_error.md new file mode 100644 index 00000000..14fba4b1 --- /dev/null +++ b/docs/expected/inspect_error.md @@ -0,0 +1,20 @@ +--- +title: fn::inspect_error +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::inspect_error_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::inspect_error_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + diff --git a/docs/expected/or_else.md b/docs/expected/or_else.md new file mode 100644 index 00000000..c6b1e140 --- /dev/null +++ b/docs/expected/or_else.md @@ -0,0 +1,19 @@ +--- +title: fn::or_else +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::or_else_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::or_else_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/expected/recover.md b/docs/expected/recover.md new file mode 100644 index 00000000..703b7602 --- /dev/null +++ b/docs/expected/recover.md @@ -0,0 +1,19 @@ +--- +title: fn::recover +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::recover_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::recover_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/expected/transform.md b/docs/expected/transform.md new file mode 100644 index 00000000..e08f37ab --- /dev/null +++ b/docs/expected/transform.md @@ -0,0 +1,19 @@ +--- +title: fn::transform +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::transform_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::transform_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/expected/transform_error.md b/docs/expected/transform_error.md new file mode 100644 index 00000000..07b0de0d --- /dev/null +++ b/docs/expected/transform_error.md @@ -0,0 +1,19 @@ +--- +title: fn::transform_error +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::transform_error_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::transform_error_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/expected/value_or.md b/docs/expected/value_or.md new file mode 100644 index 00000000..c8d83c40 --- /dev/null +++ b/docs/expected/value_or.md @@ -0,0 +1,14 @@ +--- +title: fn::value_or +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::value_or_t + +--- + +## Return value {style: "api"} +The value of the monadic type if present; otherwise the user-provided fallback value. diff --git a/docs/footer.md b/docs/footer.md new file mode 100644 index 00000000..28f370c0 --- /dev/null +++ b/docs/footer.md @@ -0,0 +1 @@ +Copyright (c) 2024 Bronek Kozicki, Alex Kremer, Gašper Ažman diff --git a/docs/index.md b/docs/index.md new file mode 100644 index 00000000..9b493f02 --- /dev/null +++ b/docs/index.md @@ -0,0 +1,47 @@ +# 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][gcc-standard-support] and [clang 18][clang-standard-support], 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][nix] and [nix/README.md][nixmd]. + +### Implementation note + +This library requires standardized type ordering, which currently is a [proposed C++26 feature][standardized-type-ordering] 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. + +[clang-standard-support]: https://clang.llvm.org/cxx_status.html +[gcc-standard-support]: https://gcc.gnu.org/projects/cxx-status.html +[devcontainer]: https://github.com/libfn/devcontainer +[standardized-type-ordering]: https://wg21.link/P2830 +[nix]: https://nixos.org +[nixmd]: https://github.com/libfn/functional/blob/main/nix/README.md + +## 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 + +* Gašper Ažman, for providing the inspiration in ["(Fun)ctional C++ and the M-word"][gasper-functional-presentation] +* Bartosz Milewski, for taking the time to explain [parametrised and graded monads][parametrised-and-graded-monads] +* [Ripple][ripple], for allowing the main author the time to work on this library + +[gasper-functional-presentation]: https://youtu.be/Jhggz8rtHbk?si=T-3DXPcvgE_Y5cpH +[parametrised-and-graded-monads]: https://arxiv.org/pdf/2001.10274.pdf +[similar-work]: https://www.doc.ic.ac.uk/~dorchard/publ/haskell14-effects.pdf +[ripple]: https://ripple.com/ diff --git a/docs/lookup-paths b/docs/lookup-paths new file mode 100644 index 00000000..38d605ce --- /dev/null +++ b/docs/lookup-paths @@ -0,0 +1,2 @@ +../tests/ +../include/ diff --git a/docs/meta.json b/docs/meta.json new file mode 100644 index 00000000..671cc1c7 --- /dev/null +++ b/docs/meta.json @@ -0,0 +1,12 @@ +{ + "title": "Functional", + "type": "Library", + "support": { + "link": "https://github.com/libfn/functional", + "title": "Support" + }, + "viewOn": { + "link": "https://github.com/libfn/functional/docs", + "title": "View On GitHub" + } +} diff --git a/docs/optional/and_then.md b/docs/optional/and_then.md new file mode 100644 index 00000000..dacddb3b --- /dev/null +++ b/docs/optional/and_then.md @@ -0,0 +1,35 @@ +--- +title: fn::and_then +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::and_then_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::and_then_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + +--- + +## Examples {style: "api"} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-optional-and_then-value"], + desc: "The resulting value is `13` because `op` is not a `nullopt` and therefore `and_then` is called." +} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-optional-and_then-empty"], + desc: "The result is a `nullopt` because `op` was already a `nullopt` and therefore `and_then` is not called." +} diff --git a/docs/optional/fail.md b/docs/optional/fail.md new file mode 100644 index 00000000..bf6747a0 --- /dev/null +++ b/docs/optional/fail.md @@ -0,0 +1,20 @@ +--- +title: fn::fail +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::fail_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::fail_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + diff --git a/docs/optional/filter.md b/docs/optional/filter.md new file mode 100644 index 00000000..0e72631f --- /dev/null +++ b/docs/optional/filter.md @@ -0,0 +1,35 @@ +--- +title: fn::filter +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::filter_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::filter_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + +--- + +## Examples {style: "api"} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-optional-filter-value"], + desc: "The resulting value is `42` because the filter predicate returns `true` for `42` as it is not less than `42`." +} + +:include-template: templates/snippet.md { + path: "examples/simple.cpp", + surroundedBy: ["// example-optional-filter-empty"], + desc: "The optional is empty because the predicate returns `false` for `12` since it's less than `42`." +} diff --git a/docs/optional/inspect.md b/docs/optional/inspect.md new file mode 100644 index 00000000..693473f4 --- /dev/null +++ b/docs/optional/inspect.md @@ -0,0 +1,19 @@ +--- +title: fn::inspect +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::inspect_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::inspect_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/optional/inspect_error.md b/docs/optional/inspect_error.md new file mode 100644 index 00000000..14fba4b1 --- /dev/null +++ b/docs/optional/inspect_error.md @@ -0,0 +1,20 @@ +--- +title: fn::inspect_error +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::inspect_error_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::inspect_error_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. + diff --git a/docs/optional/or_else.md b/docs/optional/or_else.md new file mode 100644 index 00000000..c6b1e140 --- /dev/null +++ b/docs/optional/or_else.md @@ -0,0 +1,19 @@ +--- +title: fn::or_else +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::or_else_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::or_else_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/optional/recover.md b/docs/optional/recover.md new file mode 100644 index 00000000..703b7602 --- /dev/null +++ b/docs/optional/recover.md @@ -0,0 +1,19 @@ +--- +title: fn::recover +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::recover_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::recover_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/optional/transform.md b/docs/optional/transform.md new file mode 100644 index 00000000..e08f37ab --- /dev/null +++ b/docs/optional/transform.md @@ -0,0 +1,19 @@ +--- +title: fn::transform +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::transform_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::transform_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/optional/transform_error.md b/docs/optional/transform_error.md new file mode 100644 index 00000000..07b0de0d --- /dev/null +++ b/docs/optional/transform_error.md @@ -0,0 +1,19 @@ +--- +title: fn::transform_error +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::transform_error_t + +--- + +## Call signatures {style: "api"} +:include-doxygen-member: fn::transform_error_t::operator() { signatureOnly: false, includeAllMatches: true } + +--- + +## Return value {style: "api"} +A monadic type of the same kind. diff --git a/docs/optional/value_or.md b/docs/optional/value_or.md new file mode 100644 index 00000000..c8d83c40 --- /dev/null +++ b/docs/optional/value_or.md @@ -0,0 +1,14 @@ +--- +title: fn::value_or +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::value_or_t + +--- + +## Return value {style: "api"} +The value of the monadic type if present; otherwise the user-provided fallback value. diff --git a/docs/pack.md b/docs/pack.md new file mode 100644 index 00000000..bae4e03d --- /dev/null +++ b/docs/pack.md @@ -0,0 +1,83 @@ +--- +title: fn::pack +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + + +:include-doxygen-doc: fn::detail::pack_impl + +--- + +## Return value {style: "api"} +TODO + diff --git a/docs/pack/index.md b/docs/pack/index.md new file mode 100644 index 00000000..4d70d922 --- /dev/null +++ b/docs/pack/index.md @@ -0,0 +1,17 @@ +--- +title: Packs +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::pack + +## Append {style: "api"} +Some text explaining this section... +:include-doxygen-member: fn::pack::append { signatureOnly: false, includeAllMatches: true } + +## Invoke {style: "api"} +Some text explaining this section... +:include-doxygen-member: fn::pack::invoke { signatureOnly: false, includeAllMatches: true } diff --git a/docs/sum.md b/docs/sum.md new file mode 100644 index 00000000..4c541875 --- /dev/null +++ b/docs/sum.md @@ -0,0 +1,15 @@ +--- +title: fn::sum +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::sum + +--- + +## Return value {style: "api"} +TODO + diff --git a/docs/sum/index.md b/docs/sum/index.md new file mode 100644 index 00000000..ed00115e --- /dev/null +++ b/docs/sum/index.md @@ -0,0 +1,11 @@ +--- +title: Sum +--- + +##### Defined in {style: "api", badge: "#include "} + +--- + +:include-doxygen-doc: fn::sum + +:include-doxygen-doc: fn::sum_for diff --git a/docs/templates/snippet.md b/docs/templates/snippet.md new file mode 100644 index 00000000..dc245889 --- /dev/null +++ b/docs/templates/snippet.md @@ -0,0 +1,16 @@ +<#if desc??> +```columns +left: + +:include-file: ${path} { +<#if surroundedBy??> + surroundedBy: ["${surroundedBy?join("\", \"")}"], + + surroundedBySeparator: ["\n...\n"], + commentsType: "inline" +} +<#if desc??> +right: +${desc} +``` + diff --git a/docs/toc b/docs/toc new file mode 100644 index 00000000..075ef9de --- /dev/null +++ b/docs/toc @@ -0,0 +1,31 @@ +expected + and_then + fail + filter + inspect_error + inspect + or_else + recover + transform_error + transform + value_or +optional + and_then + fail + filter + inspect_error + inspect + or_else + recover + transform_error + transform + value_or +choice + index + and_then + transform +pack + index +sum + index + \ No newline at end of file diff --git a/include/functional/and_then.hpp b/include/functional/and_then.hpp index 603a2d36..1b1846b2 100644 --- a/include/functional/and_then.hpp +++ b/include/functional/and_then.hpp @@ -16,6 +16,12 @@ #include namespace fn { +/** + * @brief Checks if the monadic type can be used with the `and_then` operation + * + * @tparam Fn The function to execute on the value + * @tparam V The monadic type + */ template concept invocable_and_then // = (some_expected_non_void && requires(Fn &&fn, V &&v) { @@ -46,7 +52,17 @@ concept invocable_and_then // } -> same_kind; }); +/** + * @brief Execute a function on the value of the monadic type if the value is present + * + * Use through the `fn::and_then` nielbloid. + */ constexpr inline struct and_then_t final { + /** + * @brief Execute a function on the value of the monadic type if the value is present + * @param fn The function to execute on the value + * @return A functor that will execute the function on the value + */ [[nodiscard]] constexpr auto operator()(auto &&fn) const noexcept -> functor // { return {FWD(fn)}; @@ -56,6 +72,12 @@ constexpr inline struct and_then_t final { } and_then = {}; struct and_then_t::apply final { + /** + * @brief TODO + * + * @param v The monad + * @param fn The function to apply + */ [[nodiscard]] static constexpr auto operator()(some_monadic_type auto &&v, auto &&fn) noexcept // -> same_kind auto requires invocable_and_then diff --git a/include/functional/choice.hpp b/include/functional/choice.hpp index 91d9fc8c..1b779ee3 100644 --- a/include/functional/choice.hpp +++ b/include/functional/choice.hpp @@ -14,6 +14,11 @@ namespace fn { +/** + * @brief TODO + * + * @tparam T TODO + */ template concept some_choice = detail::_some_choice; @@ -29,6 +34,11 @@ static constexpr bool _is_valid_choice_subtype // &&(std::is_same_v>); } +/** + * @brief TODO + * + * @tparam Ts TODO + */ template requires(sizeof...(Ts) > 0) struct choice : sum { @@ -41,17 +51,35 @@ struct choice : sum { template using select_nth = detail::select_nth_t; template static constexpr bool has_type = _impl::template has_type; + /** + * @brief TODO + * + * @tparam Ret TODO + * @param fn TODO + */ template [[nodiscard]] constexpr auto _invoke(auto &&fn) const & noexcept { return detail::invoke_type_variadic_union(this->data, this->index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Ret TODO + * @param fn TODO + */ template [[nodiscard]] constexpr auto _invoke(auto &&fn) && noexcept { return detail::invoke_type_variadic_union( // std::move(*this).data, std::move(*this).index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam T TODO + * @param v TODO + */ template constexpr choice(T &&v) requires has_type> && (std::is_constructible_v, decltype(v)>) @@ -60,6 +88,12 @@ struct choice : sum { { } + /** + * @brief TODO + * + * @tparam T TODO + * @param v TODO + */ template constexpr explicit choice(T &&v) requires has_type> && (std::is_constructible_v, decltype(v)>) @@ -68,6 +102,13 @@ struct choice : sum { { } + /** + * @brief TODO + * + * @tparam T TODO + * @param d TODO + * @param v TODO + */ template constexpr choice(std::in_place_type_t d, auto &&...args) noexcept requires has_type @@ -75,6 +116,12 @@ struct choice : sum { { } + /** + * @brief TODO + * + * @tparam Tx TODO + * @param v TODO + */ template constexpr choice(sum const &v) noexcept requires detail::is_superset_of> && (... && std::is_copy_constructible_v) @@ -82,6 +129,12 @@ struct choice : sum { { } + /** + * @brief TODO + * + * @tparam Tx TODO + * @param v TODO + */ template constexpr choice(sum &&v) noexcept requires detail::is_superset_of> && (... && std::is_move_constructible_v) @@ -89,6 +142,12 @@ struct choice : sum { { } + /** + * @brief TODO + * + * @tparam Tx TODO + * @param v TODO + */ template constexpr choice(std::in_place_type_t>, some_sum auto &&v) noexcept requires std::is_same_v, sum> @@ -101,11 +160,41 @@ struct choice : sum { constexpr choice(choice &&other) noexcept = default; constexpr ~choice() = default; + /** + * @brief TODO + * + * @return TODO + */ [[nodiscard]] constexpr value_type &value() & noexcept { return *this; } + + /** + * @brief TODO + * + * @return TODO + */ [[nodiscard]] constexpr value_type const &value() const & noexcept { return *this; } + + /** + * @brief TODO + * + * @return TODO + */ [[nodiscard]] constexpr value_type &&value() && noexcept { return std::move(*this); } + + /** + * @brief TODO + * + * @return TODO + */ [[nodiscard]] constexpr value_type const &&value() const && noexcept { return std::move(*this); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke(Fn &&fn) & noexcept requires typelist_invocable @@ -114,6 +203,13 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke(Fn &&fn) const & noexcept requires typelist_invocable @@ -122,6 +218,13 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke(Fn &&fn) && noexcept requires typelist_invocable @@ -130,6 +233,13 @@ struct choice : sum { return detail::invoke_variadic_union(std::move(_impl::data), _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke(Fn &&fn) const && noexcept requires typelist_invocable @@ -138,6 +248,14 @@ struct choice : sum { return detail::invoke_variadic_union(std::move(_impl::data), _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam T TODO + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke_r(Fn &&fn) & noexcept requires typelist_invocable @@ -146,6 +264,14 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam T TODO + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke_r(Fn &&fn) const & noexcept requires typelist_invocable @@ -154,6 +280,14 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam T TODO + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke_r(Fn &&fn) && noexcept requires typelist_invocable @@ -162,6 +296,14 @@ struct choice : sum { return detail::invoke_variadic_union(std::move(_impl::data), _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam T TODO + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke_r(Fn &&fn) const && noexcept requires typelist_invocable @@ -171,6 +313,13 @@ struct choice : sum { } // NOTE Monadic operations, only `and_then` and `transform` are supported + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto transform(Fn &&fn) & noexcept requires typelist_invocable @@ -179,6 +328,13 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto transform(Fn &&fn) const & noexcept requires typelist_invocable @@ -187,6 +343,13 @@ struct choice : sum { return detail::invoke_variadic_union(_impl::data, _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto transform(Fn &&fn) && noexcept requires typelist_invocable @@ -195,6 +358,13 @@ struct choice : sum { return detail::invoke_variadic_union(std::move(_impl::data), _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template [[nodiscard]] constexpr auto transform(Fn &&fn) const && noexcept requires typelist_invocable @@ -203,24 +373,52 @@ struct choice : sum { return detail::invoke_variadic_union(std::move(_impl::data), _impl::index, FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template constexpr auto and_then(Fn &&fn) & noexcept -> decltype(this->invoke(FWD(fn))) { static_assert(some_choiceinvoke(FWD(fn)))>); return this->invoke(FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template constexpr auto and_then(Fn &&fn) const & noexcept -> decltype(this->invoke(FWD(fn))) { static_assert(some_choiceinvoke(FWD(fn)))>); return this->invoke(FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template constexpr auto and_then(Fn &&fn) && noexcept -> decltype(std::move(*this).invoke(FWD(fn))) { static_assert(some_choice); return std::move(*this).invoke(FWD(fn)); } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @return TODO + */ template constexpr auto and_then(Fn &&fn) const && noexcept -> decltype(std::move(*this).invoke(FWD(fn))) { @@ -233,6 +431,15 @@ struct choice : sum { template explicit choice(std::in_place_type_t, auto &&...) -> choice; template explicit choice(T) -> choice; +/** + * @brief TODO + * + * @tparam Ts TODO + * @tparam Tx TODO + * @param lh TODO + * @param rh TODO + * @return TODO + */ template [[nodiscard]] constexpr bool operator==(choice const &lh, choice const &rh) noexcept requires(... && (std::equality_comparable || not detail::type_one_of)) @@ -247,6 +454,15 @@ template }); } +/** + * @brief TODO + * + * @tparam Ts TODO + * @tparam Tx TODO + * @param lh TODO + * @param rh TODO + * @return TODO + */ template [[nodiscard]] constexpr bool operator!=(choice const &lh, choice const &rh) noexcept requires(... && (std::equality_comparable || not detail::type_one_of)) @@ -254,6 +470,11 @@ template return not(lh == rh); } +/** + * @brief TODO + * + * @tparam Ts TODO + */ template using choice_for = detail::_collapsing_sum::normalized<::fn::choice, detail::_collapsing_sum::flattened>::type; diff --git a/include/functional/concepts.hpp b/include/functional/concepts.hpp index dfce8ce2..883696ae 100644 --- a/include/functional/concepts.hpp +++ b/include/functional/concepts.hpp @@ -16,11 +16,22 @@ namespace fn { +/** + * @brief TODO + * + * @tparam T TODO + */ template concept some_monadic_type = some_expected || some_optional || some_choice; -// NOTE `same_kind` is a fundamental concept in category theory; it allows -// transformation of a value_type, but not an error_type (where applicable) +/** + * @brief TODO + * @note `same_kind` is a fundamental concept in category theory; it allows + * transformation of a value_type, but not an error_type (where applicable) + * + * @tparam T TODO + * @tparam U TODO + */ template concept same_kind = (some_expected && some_expected @@ -30,7 +41,13 @@ concept same_kind || (some_optional && some_optional) // || (some_choice && some_choice); -// NOTE symmetrical to the above +/** + * @brief TODO + * @note symmetrical to the above + * + * @tparam T TODO + * @tparam U TODO + */ template concept same_value_kind = (some_expected && some_expected @@ -43,24 +60,56 @@ concept same_value_kind && some_optional && some_sum::value_type>) || (some_choice && some_choice); +/** + * @brief TODO + * + * @tparam T TODO + * @tparam U TODO + */ template concept same_monadic_type_as = same_kind && same_value_kind; +/** + * @brief TODO + * + * @tparam T TODO + */ template concept convertible_to_unexpected = requires { static_cast>>(std::declval()); }; +/** + * @brief TODO + * + * @tparam T TODO + * @tparam E TODO + */ template concept convertible_to_expected = (not std::same_as && requires { static_cast, E>>(std::declval()); }) || (std::same_as); +/** + * @brief TODO + * + * @tparam T TODO + */ template concept convertible_to_optional = requires { static_cast>>(std::declval()); }; +/** + * @brief TODO + * + * @tparam T TODO + */ template concept convertible_to_choice = requires { static_cast>>(std::declval()); }; +/** + * @brief TODO + * + * @tparam T TODO + */ template concept convertible_to_bool = requires { static_cast(std::declval()); }; diff --git a/include/functional/fail.hpp b/include/functional/fail.hpp index 984721f5..9c49a871 100644 --- a/include/functional/fail.hpp +++ b/include/functional/fail.hpp @@ -13,6 +13,14 @@ #include namespace fn { +/** + * @brief TODO + * + * @tparam Fn TODO + * @tparam V TODO + * @param fn TODO + * @param v TODO + */ template concept invocable_fail // = (some_expected_non_void && requires(Fn &&fn, V &&v) { @@ -23,6 +31,9 @@ concept invocable_fail // { ::fn::invoke(FWD(fn), FWD(v).value()) } -> std::same_as; }); +/** + * @brief TODO + */ constexpr inline struct fail_t final { [[nodiscard]] constexpr auto operator()(auto &&fn) const noexcept -> functor // { @@ -32,7 +43,17 @@ constexpr inline struct fail_t final { struct apply; } fail = {}; +/** + * @brief TODO + */ struct fail_t::apply final { + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_non_void auto &&v, auto &&fn) noexcept // -> same_monadic_type_as auto requires invocable_fail @@ -44,6 +65,13 @@ struct fail_t::apply final { return type{std::unexpect, FWD(v).error()}; } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_void auto &&v, auto &&fn) noexcept // -> same_monadic_type_as auto requires invocable_fail @@ -55,6 +83,13 @@ struct fail_t::apply final { return type{std::unexpect, FWD(v).error()}; } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&fn) noexcept -> same_monadic_type_as auto requires invocable_fail diff --git a/include/functional/filter.hpp b/include/functional/filter.hpp index 0ee1d487..315f251c 100644 --- a/include/functional/filter.hpp +++ b/include/functional/filter.hpp @@ -14,6 +14,13 @@ #include namespace fn { +/** + * @brief Checks if the monadic type can be used with the `filter` operation + * + * @tparam Pred The predicate to filter the value + * @tparam Err The error handler + * @tparam V The monadic type + */ template concept invocable_filter // = (some_expected_non_void && requires(Pred &&pred, Err &&on_err, V &&v) { @@ -28,18 +35,52 @@ concept invocable_filter // { ::fn::invoke(FWD(pred), std::as_const(v).value()) } -> convertible_to_bool; }); +/** + * @brief Filter the value of the monadic type using a predicate and an error handler + * + * When used on `fn::expected`, this operation takes both a predicate and an error handler. + * However, when used on `fn::optional`, this operation only takes a predicate. + * + * Use through the `fn::filter` nielbloid. + */ constexpr inline struct filter_t final { - // NOTE Optional needs one arguments, expected needs two - [[nodiscard]] constexpr auto operator()(auto &&...args) const noexcept -> functor - requires(sizeof...(args) >= 1) && (sizeof...(args) < 3) + /** + * @brief Filter the value of the monadic type using a predicate and an error handler + * @param pred The predicate to filter the value, takes the value by const reference and returns bool + * @param on_err The error handler, takes the value by const reference and returns the error type + * @return A functor that will filter the value of the monadic type + */ + [[nodiscard]] constexpr auto + operator()(auto &&pred, auto &&on_err) const noexcept -> functor { - return {FWD(args)...}; + return {FWD(pred), FWD(on_err)}; + } + + /** + * @brief Filter the value of the `fn::optional` using a predicate and an error handler + * @param pred The predicate to filter the value, takes the value by const reference and returns bool + * @return A functor that will filter the value of the monadic type + */ + [[nodiscard]] constexpr auto operator()(auto &&pred) const noexcept -> functor + { + return {FWD(pred)}; } struct apply; } filter = {}; +/** + * @brief TODO + */ struct filter_t::apply final { + /** + * @brief TODO + * + * @param v TODO + * @param pred TODO + * @param on_err TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_non_void auto &&v, auto &&pred, auto &&on_err) noexcept -> same_monadic_type_as auto requires invocable_filter @@ -53,6 +94,14 @@ struct filter_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param pred TODO + * @param on_err TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_void auto &&v, auto &&pred, auto &&on_err) noexcept -> same_monadic_type_as auto requires invocable_filter @@ -66,6 +115,13 @@ struct filter_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param pred TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&pred) noexcept -> same_monadic_type_as auto requires invocable_filter diff --git a/include/functional/functor.hpp b/include/functional/functor.hpp index fb065e5c..076d4093 100644 --- a/include/functional/functor.hpp +++ b/include/functional/functor.hpp @@ -15,10 +15,23 @@ #include namespace fn { +/** + * @brief TODO + * + * @tparam Functor TODO + * @tparam V TODO + * @tparam Args TODO + */ template concept monadic_invocable // = some_monadic_type && ::std::invocable; +/** + * @brief TODO + * + * @tparam Functor TODO + * @tparam Args TODO + */ template struct functor final { using functor_type = Functor; using functor_apply = typename functor_type::apply; @@ -30,6 +43,13 @@ template struct functor final { static_assert(std::is_empty_v && std::is_empty_v && std::is_default_constructible_v && std::is_default_constructible_v); + /** + * @brief TODO + * + * @param v TODO + * @param self TODO + * @return TODO + */ [[nodiscard]] constexpr friend auto operator|(some_monadic_type auto &&v, auto &&self) noexcept -> decltype(auto) requires std::same_as, functor> && monadic_invocable diff --git a/include/functional/inspect.hpp b/include/functional/inspect.hpp index 4b3a187a..c4f7b19d 100644 --- a/include/functional/inspect.hpp +++ b/include/functional/inspect.hpp @@ -14,6 +14,12 @@ #include namespace fn { +/** + * @brief TODO + * + * @tparam Fn TODO + * @tparam V TODO + */ template concept invocable_inspect // = (some_expected_non_void && requires(Fn &&fn, V &&v) { @@ -26,7 +32,16 @@ concept invocable_inspect // { ::fn::invoke(FWD(fn), std::as_const(v).value()) } -> std::same_as; }); +/** + * @brief TODO + */ constexpr inline struct inspect_t final { + /** + * @brief TODO + * + * @param fn TODO + * @return TODO + */ [[nodiscard]] constexpr auto operator()(auto &&fn) const noexcept -> functor { return {FWD(fn)}; @@ -36,6 +51,13 @@ constexpr inline struct inspect_t final { } inspect = {}; struct inspect_t::apply final { + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_non_void auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect { @@ -45,6 +67,13 @@ struct inspect_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected_void auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect { @@ -54,6 +83,13 @@ struct inspect_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect { @@ -63,6 +99,13 @@ struct inspect_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_choice auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect { diff --git a/include/functional/inspect_error.hpp b/include/functional/inspect_error.hpp index 5ee2ea67..9f48f2be 100644 --- a/include/functional/inspect_error.hpp +++ b/include/functional/inspect_error.hpp @@ -13,6 +13,12 @@ #include namespace fn { +/** + * @brief TODO + * + * @tparam Fn TODO + * @tparam V TODO + */ template concept invocable_inspect_error // = (some_expected && requires(Fn &&fn, V &&v) { @@ -21,7 +27,16 @@ concept invocable_inspect_error // { ::fn::invoke(FWD(fn)) } -> std::same_as; }); +/** + * @brief TODO + */ constexpr inline struct inspect_error_t final { + /** + * @brief TODO + * + * @param fn TODO + * @return TODO + */ [[nodiscard]] constexpr auto operator()(auto &&fn) const noexcept -> functor // { return {FWD(fn)}; @@ -30,7 +45,17 @@ constexpr inline struct inspect_error_t final { struct apply; } inspect_error = {}; +/** + * @brief TODO + */ struct inspect_error_t::apply final { + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_expected auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect_error { @@ -40,6 +65,13 @@ struct inspect_error_t::apply final { return FWD(v); } + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_optional auto &&v, auto &&fn) noexcept -> decltype(v) requires invocable_inspect_error { diff --git a/include/functional/or_else.hpp b/include/functional/or_else.hpp index ea02fa72..9fae5d5b 100644 --- a/include/functional/or_else.hpp +++ b/include/functional/or_else.hpp @@ -11,6 +11,12 @@ #include "functional/functor.hpp" namespace fn { +/** + * @brief TODO + * + * @tparam Fn TODO + * @tparam V TODO + */ template concept invocable_or_else // = (some_expected && requires(Fn &&fn, V &&v) { @@ -33,7 +39,16 @@ concept invocable_or_else // } -> some_optional; }); +/** + * @brief TODO + */ constexpr inline struct or_else_t final { + /** + * @brief TODO + * + * @param fn TODO + * @return TODO + */ [[nodiscard]] constexpr auto operator()(auto &&fn) const noexcept -> functor // { return {FWD(fn)}; @@ -42,7 +57,17 @@ constexpr inline struct or_else_t final { struct apply; } or_else = {}; +/** + * @brief TODO + */ struct or_else_t::apply final { + /** + * @brief TODO + * + * @param v TODO + * @param fn TODO + * @return TODO + */ [[nodiscard]] static constexpr auto operator()(some_monadic_type auto &&v, auto &&fn) noexcept // -> same_value_kind auto requires invocable_or_else diff --git a/include/functional/pack.hpp b/include/functional/pack.hpp index da447a0b..292af009 100644 --- a/include/functional/pack.hpp +++ b/include/functional/pack.hpp @@ -13,15 +13,34 @@ namespace fn { +/** + * @brief TODO + * + * @tparam T TODO + */ template concept some_pack = detail::_some_pack; +/** + * @brief TODO + * + * Some more text here. + * + * @tparam Ts TODO + */ template struct pack : detail::pack_impl, Ts...> { using _impl = detail::pack_impl, Ts...>; static_assert((... && (not some_sum))); template using append_type = _impl::template append_type; + /** + * @brief appends a thing + * + * @tparam T TODO + * @param args TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(std::in_place_type_t, auto &&...args) & noexcept -> append_type requires std::is_constructible_v @@ -30,6 +49,13 @@ template struct pack : detail::pack_impl(*this, FWD(args)...)}; } + /** + * @brief appends a thing + * + * @tparam T TODO + * @param args TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(std::in_place_type_t, auto &&...args) const & noexcept -> append_type requires std::is_constructible_v @@ -38,6 +64,13 @@ template struct pack : detail::pack_impl(*this, FWD(args)...)}; } + /** + * @brief appends a thing + * + * @tparam T TODO + * @param args TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(std::in_place_type_t, auto &&...args) && noexcept -> append_type requires std::is_constructible_v @@ -46,6 +79,13 @@ template struct pack : detail::pack_impl(std::move(*this), FWD(args)...)}; } + /** + * @brief appends a thing + * + * @tparam T TODO + * @param args TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(std::in_place_type_t, auto &&...args) const && noexcept -> append_type requires std::is_constructible_v @@ -54,6 +94,13 @@ template struct pack : detail::pack_impl(std::move(*this), FWD(args)...)}; } + /** + * @brief appends a thing + * + * @tparam Arg TODO + * @param arg TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(Arg &&arg) & noexcept -> append_type requires requires { static_cast>(_impl::template _append(*this, FWD(arg))); } @@ -61,6 +108,13 @@ template struct pack : detail::pack_impl(*this, FWD(arg))}; } + /** + * @brief appends a thing + * + * @tparam Arg TODO + * @param arg TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(Arg &&arg) const & noexcept -> append_type requires requires { static_cast>(_impl::template _append(*this, FWD(arg))); } @@ -68,6 +122,13 @@ template struct pack : detail::pack_impl(*this, FWD(arg))}; } + /** + * @brief appends a thing + * + * @tparam Arg TODO + * @param arg TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(Arg &&arg) && noexcept -> append_type requires requires { static_cast>(_impl::template _append(std::move(*this), FWD(arg))); } @@ -75,6 +136,13 @@ template struct pack : detail::pack_impl(std::move(*this), FWD(arg))}; } + /** + * @brief appends a thing + * + * @tparam Arg TODO + * @param arg TODO + * @return TODO + */ template [[nodiscard]] constexpr auto append(Arg &&arg) const && noexcept -> append_type requires requires { static_cast>(_impl::template _append(std::move(*this), FWD(arg))); } @@ -82,6 +150,14 @@ template struct pack : detail::pack_impl(std::move(*this), FWD(arg))}; } + /** + * @brief TODO + * + * @tparam Fn TODO + * @param fn TODO + * @param args TODO + * @return TODO + */ template [[nodiscard]] constexpr auto invoke(Fn &&fn, auto &&...args) & noexcept -> decltype(auto) requires requires { _impl::_invoke(*this, FWD(fn), FWD(args)...); } @@ -89,6 +165,14 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke(Fn &&fn, auto &&...args) const & noexcept -> decltype(auto) requires requires { _impl::_invoke(*this, FWD(fn), FWD(args)...); } @@ -96,6 +180,14 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke(Fn &&fn, auto &&...args) && noexcept -> decltype(auto) requires requires { _impl::_invoke(std::move(*this), FWD(fn), FWD(args)...); } @@ -103,6 +195,14 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke(Fn &&fn, auto &&...args) const && noexcept -> decltype(auto) requires requires { _impl::_invoke(std::move(*this), FWD(fn), FWD(args)...); } @@ -110,6 +210,15 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke_r(Fn &&fn, auto &&...args) & noexcept -> Ret requires requires { _impl::_invoke(*this, FWD(fn), FWD(args)...); } @@ -118,6 +227,15 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke_r(Fn &&fn, auto &&...args) const & noexcept -> Ret requires requires { _impl::_invoke(*this, FWD(fn), FWD(args)...); } @@ -126,6 +244,15 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke_r(Fn &&fn, auto &&...args) && noexcept -> Ret requires requires { _impl::_invoke(std::move(*this), FWD(fn), FWD(args)...); } @@ -134,6 +261,15 @@ template struct pack : detail::pack_impl [[nodiscard]] constexpr auto invoke_r(Fn &&fn, auto &&...args) const && noexcept -> Ret requires requires { _impl::_invoke(std::move(*this), FWD(fn), FWD(args)...); } @@ -146,6 +282,15 @@ template struct pack : detail::pack_impl pack(Args &&...args) -> pack; // Lifts +/** + * @brief TODO + * + * @tparam T TODO + * @tparam Args TODO + * @param src TODO + * @param args TODO + * @return TODO + */ [[nodiscard]] constexpr auto as_pack() -> pack<> { return {}; } template requires(not some_in_place_type) @@ -172,7 +317,13 @@ template