gott_v2.adoc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. = gott
  2. apiote <me@apiote.xyz>
  3. v2.0.3 2022-04-12
  4. :toc:
  5. gott is a Railway Oriented Programming library for Go.
  6. In ROP a program is a chain of functions wrapped in blocks resembling track switches. It’s a simplification of an Either monad.
  7. gott provides N types of blocks:
  8. * Bind, which wraps a function that continues on the happy track or switches to the sad track
  9. >------+-------->
  10. \
  11. \
  12. >---------+----->
  13. * Map, which wraps a function that will alwayc continue on the happy track
  14. >--------------->
  15. >--------------->
  16. * Tee, which wraps a function performing side effects and can switch to the sad track
  17. _
  18. |
  19. >--------++----->
  20. \
  21. \
  22. >------------+-->
  23. * SafeTee, which is to Tee what Map is to Bind
  24. _
  25. |
  26. >--------+------>
  27. >--------------->
  28. * Recover, which wraps a function that tries to return to the happy Path
  29. >--------+------>
  30. /
  31. /
  32. >-----+--------->
  33. * Catch, which switches to the sad track in case of a panic
  34. * Handle, which does different things depending on which track the processing is
  35. == Usage
  36. Provided functions are methods of `R[T any]` generic and return `R[T]` so that they can be chained.
  37. Usage can be seen in tests, the simplest being
  38. import (
  39. "apiote.xyz/p/gott/v2"
  40. )
  41. func divide5(by int) (int, error) {
  42. if by == 0 {
  43. return by, errors.New("divideByZero")
  44. } else {
  45. return 5 / by, nil
  46. }
  47. }
  48. func main() {
  49. r := R[int]{S: 5}.Bind(divide5)
  50. // r.S == 1; r.E == nil
  51. }
  52. == Contribute
  53. This project is finished; no more functions will be implemented; all feature requests will be ignored.
  54. This project uses The Code of Merit, which is available as CODE_OF_CONDUCT file.
  55. Fixes and patches are welcome; please send them to `gott@git.apiote.xyz` using `git send-email`. They must include a sign-off to certify agreement to https://developercertificate.org/[Developer Certificate of Origin].
  56. All communication—questions, bugs, etc.—should go through the mailing list available at `gott@git.apiote.xyz`. Note that all communication will be made public at https://asgard.apiote.xyz/.
  57. == Mirrors
  58. The canonical repository for this project is https://git.apiote.xyz/gott.git it’s mirrored at https://notabug.org/apiote/gott
  59. Mirrors exist solely for the sake of the code and any additional functions provided by third-party services (including but not limited to issues and pull requests) will not be used and will be ignored.
  60. == License
  61. ----
  62. This Source Code Form is subject to the terms of the Mozilla Public
  63. License, v. 2.0. If a copy of the MPL was not distributed with this
  64. file, You can obtain one at https://mozilla.org/MPL/2.0/.
  65. ----