Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kleisli Composition Operator and Apply_or Added #455

Merged
merged 7 commits into from
Jul 19, 2024

Conversation

NoahBatchelor
Copy link
Contributor

Added the Kleisli composition operator for Option, Result, and CCFun.

Added the Kleisli composition operator for Option, Result, and CCFun.
src/core/CCFun.mli Outdated Show resolved Hide resolved
c-cube and others added 3 commits July 9, 2024 10:15
Gave up on k_compose for CCFun. Unclear with how to translate function signature into CPS.
Added apply_or for chaining processing functions.
@NoahBatchelor
Copy link
Contributor Author

Updated PR to remove CCFun changes, added slight documentation to CCFun, and added a new apply_or function.

@NoahBatchelor NoahBatchelor changed the title Kleisli Composition Operator Added Kleisli Composition Operator and Apply_or Added Jul 19, 2024
@@ -111,6 +116,13 @@ let get_or ~default x =
| None -> default
| Some y -> y

let apply_or f x =
Copy link
Owner

@c-cube c-cube Jul 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't that fold? edit: oh, no, same default value…

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was motivated mostly by seeing places where CCString functions were being stringed together, combined with repeated CCOption's get_or to reset back to the original string if the string functions failed. Particularly the operator form would concisely shrink down that sort of pipeline to just the string functions.

Formatting had to be done manually due to mismatching ocamlformat installations.
@c-cube c-cube merged commit e933995 into c-cube:main Jul 19, 2024
6 of 7 checks passed
c-cube added a commit to c-cube/opam-repository that referenced this pull request Sep 10, 2024
CHANGES:

- predicate combinators: `and_pred` and `or_pred`
- feat `pp`: add a bunch of extensions
- Kleisli Composition Operator and Apply_or for option/result/fun (c-cube/ocaml-containers#455)
- add `CCByte_buffer.to_slice`
- add a byte slice type `CCByte_slice`
- add `cons_when` to `CCListLabels`
- add `(|||>)` and `||>` to `CCFun`
- `CCVector`: Add function foldi
- add `containers.pvec`, a persistent vector type.

- perf: use a monomorphic impl for `CCMonomorphic.{min,max}`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants