Foldable represents a type that can be folded into a single value based on its state. - T: the type of the value in the failure state (e.g., an error type). - U: the type of the value in the success state.
| 6 | // - T: the type of the value in the failure state (e.g., an error type). |
| 7 | // - U: the type of the value in the success state. |
| 8 | type Foldable[T any, U any] interface { |
| 9 | leftValue() T |
| 10 | rightValue() U |
| 11 | hasLeftValue() bool |
| 12 | } |
| 13 | |
| 14 | // Fold applies one of the two functions based on the state of the Foldable type, |
| 15 | // and it returns the result of applying either successFunc or failureFunc. |