-
Notifications
You must be signed in to change notification settings - Fork 16
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
add a sequence
function based on fold_effect
#52
Conversation
Conflicts: effect/fold.py effect/test_fold.py
Conflicts: effect/test_fold.py
Implementing sequence this way makes it much harder to inspect, since there are all sorts of closures involved. (See here for an example of where we do this). |
def folder(acc, el): | ||
l.append(el) | ||
return l | ||
return fold_effect(lambda acc, el: acc + [el], l, effects) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
folder
isn't used here.
@tomprince - have you seen SequenceDispatcher? It gives you a way to test the sequence of effects in your program in a general way. Let me rewrite your example in a way that would work with this implementation (and any other that simply runs each effect in turn) noop = lambda i: None
seq = SequenceDispatcher([
(run(command="yum install -y %s" % ZFS_REPO[distribution]).intent, noop),
(run(command="yum install -y %s" % CLUSTERHQ_REPO[distribution]).intent, noop),
(run(command="yum install -y clusterhq-flocker-node").intent, noop),
])
with seq.consume():
self.assertEqual(
sync_perform(
ComposedDispatcher([base_dispatcher, seq]),
task_install_flocker(distribution=distribution)),
[]) Granted, it's not as concise, but it has these benefits:
This kind of "I want to check equality but, oops, callbacks" was exactly one of the things that got us to switch to actually performing the effects with a testing dispatcher, and SequenceDispatcher was the best formulation of a testing dispatcher we could find, giving us the best guarantees. So, we could add a Sequence intent, but I don't think the benefits are that great (making some testing code slightly more concise, if you're not already using SequenceDispatcher, which I think most Effect-testing code should). |
A couple of random musings about
Other than that, this LGTM, and if an extra intent is required (doesn't seem like it is right now), it can probably be added in a separate PR without too much breakage. Seems pretty elegant and testable without it currently :) |
Thanks for the comments @cyli :)
I think I'll go ahead and merge this. I hope this is acceptable, @tomprince. Let me know if you want to talk more about |
add a `sequence` function based on `fold_effect`
Since this is based on the
foldE
branch it has the changes from it as well. This will be remedied oncefoldE
is merged to master. Until then I'll leave this PRin progress
.Pretty straightforward implementation of
sequence
based onfold_effect
.