Remote Data-ish for Use Cases?

This came up at the latest meetup and started some interesting discussion so I thought I’d share it here as well.

In my mind I’ve been playing with the idea of modelling use cases as a custom type similar to remote data, something akin to:

type UseCase m a e =
    Processing m
    | Success a
    | Failure e

It stems from a wish to structure my code (hobby project) as individual use cases. I haven’t actually had time to experiment with it that much yet though. I’m thinking that it would fit nicely for form input. I’m also unsure if there are two variants needed, one for commands (such as form input) and another for queries (such as search).

1 Like

It seems like you may be doing some premature abstraction. It could be better if you laid out your code and types in more concrete terms first, then observe and abstract out similarities.

Maybe you have already done that but it’s not obvious from your question, which makes it hard to think on how suitable this is without knowing the context it will live in.

Can you elaborate on what this type will accomplish, with a couple of examples of what m, a and e could be?

4 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.