-
Notifications
You must be signed in to change notification settings - Fork 431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Composing actions: how to do something like "firstEnabled"? #366
Comments
How about this?
|
Typechecks and my tests pass! Thanks @ikesyo, and I'm learning by studying this too. If you want SO cred I'll happily accept this as an answer over there too. If I understand correctly, this assumes the |
I think I can answer my own question: if |
And for completeness: I ended up with the following, which I think improves slightly on the correctness of the original solution (by checking if
|
I have two
Action
s with the same input/output/error types, and I'd like to compose them into a singleAction
that runs whichever of the two is enabled (with an arbitrary tie-breaker if they both are).Here's my first, failing, attempt:
This fails because the inner
add.apply(input)
can't see that I checkedadd.isEnabled
, so it wraps an additionalActionError<>
layer around the error type. (This might be legit, as I'm not sure how thread-safe this approach would be, or might be a case of us knowing something the type system doesn't.) The corresponding type error is:What would y'all suggest as a better approach?
I've asked this on Stack Overflow as well, might be a better venue: http://stackoverflow.com/q/43888981/323083
The text was updated successfully, but these errors were encountered: