For starters, we can should only do a pure calculation inside snapshot
, and do the side effect inside listen
. So we are forced to do it in two phases. One advantage I can think of is that, for languages that do not have good support for variadic arguments, you can save on packing and unpacking all your parameters together.
E.g.
listener =
sMouseDown
.snapshot(
cMousePos,
(mouseBtn, mousePos) => () => {
/* do an effect with the params */
}
)
.actuate()
You can see above that mouseBtn and mousePos can be used in the side effect directly without packing, then unpacking the parameters. It is a lot more useful in Java, because Java does not have any tuples in their standard API. You have to roll your own tuples or use a library.
I suppose also, if you avoid using ...args
in TypeScript and follow the example above, you can gain some extra type safety, because I'd imagine ...args
is dynamically typed.