README.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-FileCopyrightText: 2024 Adam Evyčędo
  2. // SPDX-FileCopyrightText: Adam Evyčędo
  3. //
  4. // SPDX-License-Identifier: MPL-2.0
  5. = gott
  6. apiote <me@apiote.xyz>
  7. v2.0.4 2022-05-29
  8. :toc:
  9. gott is a Railway Oriented Programming library for Go.
  10. In ROP a program is a chain of functions wrapped in blocks resembling track switches. It’s a simplification of an Either monad.
  11. gott provides N types of blocks:
  12. * Bind, which wraps a function that continues on the happy track or switches to the sad track
  13. >------+-------->
  14. \
  15. \
  16. >---------+----->
  17. * Map, which wraps a function that will alwayc continue on the happy track
  18. >--------------->
  19. >--------------->
  20. * Tee, which wraps a function performing side effects and can switch to the sad track
  21. _
  22. |
  23. >--------++----->
  24. \
  25. \
  26. >------------+-->
  27. * SafeTee, which is to Tee what Map is to Bind
  28. _
  29. |
  30. >--------+------>
  31. >--------------->
  32. * Recover, which wraps a function that tries to return to the happy Path
  33. >--------+------>
  34. /
  35. /
  36. >-----+--------->
  37. * Catch, which switches to the sad track in case of a panic
  38. * Handle, which does different things depending on which track the processing is
  39. == Usage
  40. Provided functions are methods of `R[T any]` generic and return `R[T]` so that they can be chained.
  41. Usage can be seen in tests, the simplest being
  42. import (
  43. "apiote.xyz/p/gott/v2"
  44. )
  45. func divide5(by int) (int, error) {
  46. if by == 0 {
  47. return by, errors.New("divideByZero")
  48. } else {
  49. return 5 / by, nil
  50. }
  51. }
  52. func main() {
  53. r := R[int]{S: 5}.Bind(divide5)
  54. // r.S == 1; r.E == nil
  55. }
  56. == Contribute
  57. This project is finished; no more functions will be implemented; all feature requests will be ignored.
  58. This project uses The Code of Merit, which is available as CODE_OF_CONDUCT file.
  59. 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].
  60. 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/.
  61. == Mirrors
  62. The canonical repository for this project is https://git.apiote.xyz/gott.git it’s mirrored at https://notabug.org/apiote/gott
  63. 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.
  64. == License
  65. ----
  66. This Source Code Form is subject to the terms of the Mozilla Public
  67. License, v. 2.0. If a copy of the MPL was not distributed with this
  68. file, You can obtain one at https://mozilla.org/MPL/2.0/.
  69. ----