Simple function chaining

Yes, thank you for referencing that - I’d read it, and just re-read it. There are some important meatballs in that dialog. There’s also the fluent showcase and conversation that makes foundational use of chaining. In many cases, chaining seems to work well for “operational” ordered-step functionality, like matrix manipulations. As @mnemnion points out, such could be done in order-step by foo.a(); foo.b(); foo.c(), as well, and, in the case of zig, which doesn’t do exceptions, this could be the ONLY way to go if you have error potential in any of the operations because try-chaining is not pretty. Additionally, if any of the operations requires allocations, since an allocator needs to be passed, and can fail (resulting in a return error again), chaining doesn’t look like a nice option. The use case I was considering DID potentially involve allocations along the way and DID (also) involve error-potential along the way, so chaining was not a good option. My case was more of a “builder” pattern, though - not quite akin to matrix manipulation chains. It’s good to feel out the right “fit” of a language and a given pattern, and to not force fits, and this was a good fitting-room exercise.

3 Likes