Store icon indicating copy to clipboard operation
Store copied to clipboard

[Feature Request] getOrError and freshOrError

Open matt-ramotar opened this issue 2 years ago • 2 comments

Additionally: have you considered adding a getOrError() (and freshOrError()) that return a Result<T> to the API? These are two functions I end up readding into all of my projects using Store, since the appropriate way to have a fetcher fail is by throwing. Which is fine if you're using .stream(), and much less fun if you forgot about that detail and called get() blindly

https://www.reddit.com/r/androiddev/comments/13mb2sz/comment/jkwwjxs/?utm_source=share&utm_medium=web2x&context=3

matt-ramotar avatar May 21 '23 11:05 matt-ramotar

Would this function any different than runCatching{ store.get()}

digitalbuddha avatar May 21 '23 11:05 digitalbuddha

Being the one that suggested it: absolutely not! However, I have noticed amongst my teams that it is relatively easy to forget about the fact that stores can throw (and seem to be expected to in Fetchers should anything go wrong). Having it part of the default API helps remember that, and is close to the kotlin .get/.getOrNull() equivalents

pikzen avatar May 21 '23 12:05 pikzen