Make Command trait API more functional by eliminating mutable parameters #22
Labels
No labels
adr
automated
bug
chore
dependencies
documentation
enhancement
epic
github-actions
P1-high
P2-medium
P3-low
release
research
rust
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jwilger/eventcore#22
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
During the refactoring of
executor.rsin PR #10, it was noted that theCommandtrait'shandlemethod requires a mutable reference toStreamResolver, which goes against functional programming principles.Current API
Proposed Functional API
A more functional approach would return the modified
StreamResolveralong with the events:Or use a more structured return type:
Benefits
Considerations
Related Discussion
See PR #10 review comments: https://github.com/jwilger/eventcore/pull/10#discussion_r1924574630
I'd like to push back on this. mutable references can be a beautiful part of a functional API. in purely functional languages we have no choice but to take-by-value and return a new copy "writer pattern". but in rust when we're able to use a
&mutthis is exactly the same as if using the "writer" pattern. basically I don't believe the "benefits" because the code can be written equivalently both ones, one is just slightly friendly to the compiler. to phrase another way, "please don't replace rust's unique language feature with an ugly writer monad"