Containers
Box.of(42); Either.right(42); Promise.resolve(42);
let maybe: number | null = 42; type Pair = { a?: number; b?: number };
type Option<T> = { kind: 'some'; value: T } | { kind: 'none' };
std::optional<int>; std::tuple<int>; std::reference_wrapper<int>;
Nullable<int> maybe = 42; new StrongBox<int>(value); Tuple.Create(myIntValue);
Guards
func process(_ x: Int?) -> Int? {
guard let v = x else { return nil }
guard v >= 0 else { return nil }
return v * 2
}in JavaScript
const process = (x) => {
if (x === null) return null;
if (x < 0) return null;
return x * 2;
};Pattern matching
fn process(x: Option<i32>) -> Option<i32> {
match x {
None => None,
Some(v) if v < 0 => None,
Some(v) => Some(v * 2),
}
}in JavaScript
const match = (variant, handlers) => handlers[variant.tag](variant);
match({ tag: 'point', x: 10, y: 20 }, {
point: ({ x, y }) => `(${x}, ${y})`,
circle: ({ r }) => `radius: ${r}`
});
Do-notation
Do({ id: 15 })
.chain(({ id }) => ({ id, name: 'marcus', age: 42 }))
.chain(({ name, age }) => name === 'marcus' ? (log) => log(age) : () => {})
.run()(console.log);Pipeline operator
(({ id: 15 })
|> read
|> (({ name, age }) => name === 'marcus' ? (log) => log(age) : () => {})
)(console.log);Declarative style
execute({
read: { id: 15 },
success: {
match: { name: 'marcus' },
success: { effect: { log: 'age' } },
fail: { effect: 'noop' },
},
})(reader)(console.log);🧐 заходим, не стесняемся 👉 https://nodeua.com/Patterns-2025-paradigms