Chaining Immutable Data Structures In 3 Languages
Chaining immutable data structures in 3 languages: TypeScript, ReScript, and F# with Fable compiler.
How could you get the nice obj.add(obj2).add(obj2) chaining from OOP, without the downside of unrestricted mutability? Let's compare how 3 languages that compile to JavaScript - TypeScript, ReScript, and F# with the Fable compiler - are able to chain immutable data (aka. create an Immutable Fluent Interface aka. a kind of Fluent API). We'll use the simplest appropriate data structure we can think of: a Rectangle with 2 properties (height and width). Let's make some Rectangles, and add their properties together, so the resulting Rectangle is a square. (Huge thanks to @texastoland for coming up...