I didn't mean to mislead anyone. I made it for myself and didn't publish or share it anywhere besides GitHub. Sorry if I upset you.
I didn't mean to mislead anyone. I made it for myself and didn't publish or share it anywhere besides GitHub. Sorry if I upset you.
Sorry about that!
This is the same pattern used by:
- Redux-Saga for side effects
- Effect for ctx / effects
- Koa for middleware
Benefits:
β No dependency passing through layers
β Test with simple mock objects
β Add new dependencies without touching existing functions
β See dependencies at point of use
Complete working example:
The runtime that makes this work:
// Define what can be requested const getDB = () => (context) => context.db; const getLogger = () => (context) => context.logger; const getEmailer = () => (context) => context.emailer; // Pull only what you need async function* notifyUser(user) { const emailer = yield getEmailer(); // Pull emailer when needed return emailer.send(user.email); }
JavaScript generators let us flip this: instead of passing dependencies down, functions pull what they need:
async function handleRequest(req, res, db, logger, emailer) { // Only uses logger, but must accept all deps to pass down logger.info('Request received'); return processUser(req.userId, db, logger, emailer); } async function processUser(userId, db, logger, emailer) { // Still doesn't use emailer const user = await db.getUser(userId); return notifyUser(user, db, logger, emailer); } async function notifyUser(user, db, logger, emailer) { // Finally uses emailer! return emailer.send(user.email); }
The problem: dependency passing through function chains
Every JavaScript developer has written this function:
processOrder(orderId, userId, db, logger, cache, validator, emailer, metrics)
Where half the parameters are just passed to other functions.
Here's how to fix this with a pattern using generators - in just 16 lines.
My book "The Well-Grounded Data Analyst" is out early 2025!
It is a collection of real-world data analysis projects to level up your skills and you can already get it in early access.
Use the code au35asb to get 35% off (on any Manning title, not just mine!)
www.manning.com/books/the-we...
π The the first official release of the UCM Desktop app is here!
Browse your local codebase, click through to source definitions, and read the docs, all in a sleek new UI. β¨
github.com/unisonweb/uc...
I finished creating The Most Elegant Configuration Language.
Itβs done.
I can rest now.
My mission is accomplished.
chshersh.com/blog/2025-01...
years ago when i moved from react to solid it took me 1-2 months to undo react brain
i did some react yesterday for an example wow i had such a hard time with the fact that functions run more than once
crazy how your brain flips around
Exciting!
What sort of code/commands? Could you give an example of what you're looking for?
I'm watching the talk and saw that you're planning on using TypeScript types to aid in performance, that reminds me of kaleidawave.github.io/posts/a-prev... which you might find interesting.
Is node.js compatibility on the distant future roadmap? If so, will it have to be done from scratch, or do you think it'll be possible to steal most of the code?
Also, is it possible to make syscalls or have embedded C with porfor?
It's still possible to use eval, you'd just have to bundle the entire compiler, right?
π¦
πYou and your friends are cordially invited to Unison's #AdventOfCode season.
Spread the word: www.unison-lang.org/adventofcode...
I don't think enough people know scoped styles are built into the browser now...
Hello Bluesky π Is there anyone out there?
Or Rescript
On my list: Swift, Odin, or Roc
I admire how good TJ is at explaining technical concepts. Even if you have 0 interest in OCaml this has some great stuff about SQL in general and metaprogramming/macros
youtu.be/JFZvnGD_hV8