Patterns and streams

This part collects patterns over the language: iterators and generators, mixins, branded nominal types, result types, the options object, a builder and an event emitter. The part ends with streams, workers, and the deserialization that turns unknown JSON into a trusted record.

86 Iterators and generators the iterator protocol, a generator function, and a pipeline of yield steps Open 87 Mixins shared behaviour as small mixin functions over a class, explicit and composable Open 88 Branding nominal types a branded string that the compiler keeps apart from a plain one Open 89 Result types an ok and an error shape, both branches handled, chained without nesting Open 90 Options objects one options object with defaults in place of a long argument list Open 91 Builder small setters chained into one build call that validates at the end Open 92 Event emitters a listener list, one emit to all of them, and the removal when done Open 93 Streams a big file in small chunks, a pipe, a transform, and backpressure Open 94 Workers heavy work off the main thread, and messages between the worker and it Open 95 Deserialization unknown JSON into a trusted record, with small guards for fields and arrays Open

Lessons