Hello! I have a question about Ring’s design. Why are middlewares implemented as higher-order functions? I was asked this a while back, when I was explaining my app’s middleware chain to someone, and I could sort of reverse-engineer a sensible answer — “they compose easily & are a natural abstraction for working with request and/or response” — but I wasn’t 100% sure.
Interesting. Thanks!
If you represent a handler as a function that takes in a request and returns a response, and if middleware is something that modifies the request, then in a functional language the most direct representation is a function that takes a handler function and returns a new handler function with some augmented behaviour.