4 ms·
As an advanced case, CPS works within any functor (aka map-able data structure). A standard CPS function returning type t has the signature (t -> a) -> a. More
by yccs27 4y ago
As an advanced case, CPS works within any functor (aka map-able data structure).
A standard CPS function returning type t has the signature (t -> a) -> a. More generally, the Yoneda lemma implies that the signature (t -> a) -> f a is equivalent to a return value f t, where f is a functor.
When f is the async/promise functor, this leads to the common pattern of passing callbacks for asynchronicity: Instead of eventually returning type t, you take a callback with argument t and eventually return its result (of type a).