Real-World Event Sourcing: Command Tense (page 6)
In v2 of the calculator, does it make sens for the command tenses to be present?
defmodule EventSourcedCalculator.V2 do
def handle_command(%{value: _val}, %{cmd: :add, value: v}) do
%{event_type: :value_added, value: v}
end
def handle_command(%{value: _val}, %{cmd: :sub, value: v}) do
%{event_type: :value_subtracted, value: v}
end
def handle_command(%{value: _val}, %{cmd: :mul, value: v}) do
%{event_type: :value_multiplied, value: v}
end
def handle_command(%{value: _val}, %{cmd: :div, value: v}) do
%{event_type: :value_divided, value: v}
end
def handle_event(%{value: val},
%{event_type: :value_added, value: v}) do
%{value: val + v}
end
def handle_event(%{value: val},
%{event_type: :value_subtracted, value: v}) do
%{value: val - v}
end
def handle_event(%{value: val},
%{event_type: :value_multiplied, value: v}) do
%{value: val * v}
end
def handle_event(%{value: val},
%{event_type: :value_divided, value: v}) do
%{value: val / v}
end
end
For instance the command to add a value is value_added
, however, making it add_value
does 2 things. Communicates that the value has not been added yet and also allows consumers to more naturally respond to a command to add a value. It makes sense for handlers upon adding the numbers to emit value_added
as an event.
Am I misunderstanding something?
Popular Prag Prog topics

Title: Web Development with Clojure, Third Edition, pg 116
Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New

your book suggests to use Image.toByteData() to convert image to bytes, however I get the following error: "the getter ‘toByteData’ ...
New

On the page xv there is an instruction to run bin/setup from the main folder. I downloaded the source code today (12/03/21) and can’t see...
New

The generated iex result below should list products instead of product for the metadata. (page 67)
iex> product = %Product{}
%Pento....
New

I think I might have found a problem involving SwitchCompat, thumbTint, and trackTint.
As entered, the SwitchCompat changes color to hol...
New

I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
New

@parrt
In the context of Chapter 4.3, the grammar Java.g4, meant to parse Java 6 compilation units, no longer passes ANTLR (currently 4....
New

root_layout: {PentoWeb.LayoutView, :root},
This results in the following following error:
no “root” html template defined for PentoWeb...
New

Getting an error when installing the dependencies at the start of this chapter:
could not compile dependency :exla, "mix compile&qu...
New

From page 13:
On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
New
Other popular topics

Reading something? Working on something? Planning something? Changing jobs even!?
If you’re up for sharing, please let us know what you’...
New

New

I have seen the keycaps I want - they are due for a group-buy this week but won’t be delivered until October next year!!! :rofl:
The Ser...
New

A Hero’s Journey with Chris Pine
Chris Pine, author of Learn to Program, Third Edition, discusses his journey to becoming a Pragm...
New

Woooooooo! This is such a huge release for it, and 2 years incoming!
In short, the library is now using an updated hyper backend (not j...
New

Saw this on TikTok of all places! :lol:
Anyone heard of them before?
Lite:
New

Hi folks,
I don’t know if I saw this here but, here’s a new programming language, called Roc
Reminds me a bit of Elm and thus Haskell. ...
New

Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New

The File System Access API with Origin Private File System.
WebKit supports new API that makes it possible for web apps to create, open,...
New

Will Swifties’ war on AI fakes spark a deepfake porn reckoning?
New
Latest in PragProg
Latest (all)
Categories:
Popular Portals
- /elixir
- /opensuse
- /rust
- /kotlin
- /ruby
- /erlang
- /python
- /clojure
- /react
- /quarkus
- /go
- /vapor
- /v
- /react-native
- /wasm
- /security
- /django
- /nodejs
- /centos
- /haskell
- /rails
- /fable
- /gleam
- /swift
- /js
- /deno
- /assemblyscript
- /tailwind
- /laravel
- /symfony
- /phoenix
- /crystal
- /typescript
- /debian
- /adonisjs
- /julia
- /arch-linux
- /svelte
- /spring
- /preact
- /flutter
- /c-plus-plus
- /actix
- /java
- /angular
- /ocaml
- /zig
- /kubuntu
- /scala
- /zotonic
- /vim
- /rocky
- /lisp
- /html
- /keyboards
- /vuejs
- /nim
- /emacs
- /nerves
- /elm