3 ms·
Yeah, obligatory reminder that "chaining" is just function composition. As in: SecondQuery(FirstQuery(userInput)); "Advanced" chaining can be as simple as:
by TeMPOraL 3y ago
Yeah, obligatory reminder that "chaining" is just function composition. As in:
SecondQuery(FirstQuery(userInput));
"Advanced" chaining can be as simple as:
do {
partial = FirstQuery(input);
choice = DeciderQuery(partial);
input = choice ? Query2A(partial) : Query2B(partial);
} while(!ValidationQuery(input));
return input; // or print it or whatever
It only looks complex when you need to chain things at runtime through some interface, but that's the usual problem of having to reinvent basic blocks of your language as objects or data structures because your language doesn't let you treat code and data interchangeably. But if you're just experimenting with chains, using the most basic programming building blocks directly - functions, conditionals, loops - is by far the easiest.
- danenania 3y agoOr put even simpler: calling a function with the result of another function. I’d question how much value FP abstractions like partials and composition are really adding in your example.
- TeMPOraL 3y agoOh, I didn't mean to invoke FP abstractions - "composition" is used outside of FP, and "partial"... that's just bad naming choice on my end. This example was meant to be dumb, imperative C-like code.
- danenania 3y agoAh sorry, I saw ‘partial’ and thought you were passing around functions. Please disregard my comment :)