-
Notifications
You must be signed in to change notification settings - Fork 96
Description
Like a comment in the current definition says, the definition is wrong:
// This ap strictly speaking incompatible with chain. If we derive ap from chain we get
// different (not very useful) behavior. But spec requires that if method can be derived
// it must have the same behavior as hand-written method. We intentionally violate the spec
// in hope that it won't cause many troubles in practice. And in return we have more useful type.
ap(obsFn, obsVal) {
return combine([obsFn, obsVal], (fn, val) => fn(val))
},I can see the "good intention" behind the above definition, but a major advantage of Static Land is precisely the fact that for a single type you can simply have as many different algebra module instances as needed:
- We can implement many modules for one type, therefore we can have more than one instance of the same Algebra for a single type. For example, we can implement two Monoids for numbers: Addition and Multiplication.
Observables support multiple different algebras. For example, basically every flatMapXXX operation induces a Monad with different semantics. With Static Land, each of those can be supported as different algebra modules (all of them fully correct) from which the user can then pick and choose the appropriate one depending on which semantics are needed.
So, why is the above definition wrong? Because it breaks the sequential semantics of the chain. Let's say that you wish to perform a sequence of, say, database operations using the Observable definition. You should be able to do that with an applicative sequence function, but now you cannot, because the above definition executes the operations in parallel, rather than sequentially.
Of course, another major advantage of Static Land is that this issue can be worked around simply by providing the proper algebra modules outside of the library core.