new stuff dropped in duckkit 🦆
typed event emitter. function composition. partial application.
here's what it looks like.
before
emitter.on('win', (amount) => {
// amount is any 😬
})
emitter.emit('win', 'oops') // no error
emitter.emit('wiiin', 500) // typo. also no error.
after
const emitter = createEmitter<{
win: number
spin: void
error: { code: number; message: string }
}>()
emitter.emit('win', 500) // ✅
emitter.emit('win', 'oops') // ❌ TypeScript error
emitter.emit('wiiin', 500) // ❌ TypeScript error
emitter.emit('win') // ❌ payload missing
define the map once. TypeScript does the rest.
pipeline — reusable composed functions
const process = pipeline(
(s: string) => s.trim(),
s => s.toUpperCase(),
s => s.split(' '),
)
process(' hello world ') // ["HELLO", "WORLD"]
process(' foo bar ') // ["FOO", "BAR"]
async steps work too — mix sync and async freely.
curry
const multiply = curry((factor: number, value: number) => value * factor)
[1, 2, 3].map(multiply(2)) // [2, 4, 6]
[1, 2, 3].map(multiply(10)) // [10, 20, 30]
npm install duckkit
do you use typed emitters? or just wing it with strings? 👇
Top comments (0)