14 Commits
Author SHA1 Message Date
Gijs van Dam e7b9515edd fn: fix Result[T].FlatMap
For a Result[T], FlatMap should apply f when the result is Ok, and
propagate the error unchanged when it's Err. The original code returns r
on Ok and tries to use r.left when Err, which is wrong. This commit
fixes that.

Secondly, the group of FlatMap/AndThen and OrElse functions and methods
are now properly tested with new unit tests.

fixes #10401
2026-01-06 10:51:49 +01:00
Keagan McClelland 9f35664a12 fn: breaking - make or else functions accept error argument 2024-11-06 17:32:59 -07:00
Keagan McClelland 5e947046a3 fn: breaking - give Result's FlatMap proper functor annotation 2024-11-06 17:32:59 -07:00
Keagan McClelland 4d16d5ff15 fn: breaking - replace AndThen2 with more principled LiftA2Result 2024-11-06 17:32:59 -07:00
Keagan McClelland be50dd9acb fn: breaking - remove deprecated Result functions 2024-11-06 17:32:59 -07:00
Keagan McClelland 1805fd6f19 fn: breaking - polish Either API 2024-11-06 17:32:58 -07:00
Keagan McClelland 9bbd327a10 fn: add Sink to Result 2024-11-06 16:50:02 -07:00
Keagan McClelland 5dec35426c fn: add transpositions for Option and Result 2024-11-06 16:40:36 -07:00
Keagan McClelland 8971c4c3ae fn: add operations to Result API 2024-11-06 16:40:15 -07:00
Keagan McClelland 5faad77f33 fn: add conversions between Result and Option 2024-11-06 16:39:33 -07:00
Keagan McClelland 7a7f3bdb2c fn: fix UnwrapOrFail semantics 2024-11-06 15:55:18 -07:00
Keagan McClelland c4df2f1dce fn: reimplement internals of either, add tests 2024-07-10 15:37:27 -07:00
Olaoluwa Osuntokun f1a38714d4 fn: add additional utility methods for Result[T]
`NewResult` makes it easy to wrap a normal function call in a result
value.

`Err` can be used to check the error case of the result without
unpacking the entire thing.

`AndThen2` allows a caller to compose a function on two results values,
with the closure only executing if both values are non-error.
2024-06-20 15:05:28 -07:00
Oliver Gugger c95505db1e fn: add Result type
In this commit, we add a new result type, which is just Either[A, error]. This is useful as we can always pass around/accept a single value. We add an Unpack() method which is the most idiomatic way of handling errors in Go, as we revert back to (A, error) when necessary.
2024-05-29 09:39:39 +02:00