Sakuraflow
A lightweight, memory-efficient library for working with generator functions in TypeScript.
Install / Use
/learn @tigerabrodi/SakuraflowREADME
SakuraFlow
A lightweight, memory-efficient library for working with generator functions in TypeScript. Transform, combine, and process data streams with an elegant API that maintains the benefits of lazy evaluation.
Why?
- 🌸 Memory Efficient: Process large datasets without loading everything into memory
- 🎯 Composable: Build complex data transformations with simple, chainable operations
- 🔄 Lazy Evaluation: Only process what you need, when you need it
- 🎭 Flexible: Works with both sync and async generators
- 🧪 Type-Safe: Built with TypeScript for great developer experience
Installation
npm install @tigerabrodioss/sakuraflow
# or
pnpm add @tigerabrodioss/sakuraflow
# or
yarn add @tigerabrodioss/sakuraflow
# or
bun add @tigerabrodioss/sakuraflow
Quick Example
import { flow } from '@tigerabrodioss/sakuraflow'
// Process numbers with multiple transformations
const result = flow([1, 2, 3, 4, 5]).pipe(
filter((x) => x % 2 === 0), // Keep even numbers
map((x) => x * 2), // Double them
batch(2) // Group in pairs
)
console.log([...result])
// Output: [[2, 4], [8]]
// Work with async data
async function* source() {
yield 1
await sleep(1000)
yield 2
await sleep(1000)
yield 3
}
const numbers = flow(source()).pipe(
map((x) => x * 2),
rateLimit(2000) // Ensure at least 2s between values
)
for await (const num of numbers) {
console.log(num) // Logs 2, 4, 6 with 2s delays
}
API Reference
Transform Operations
map(fn: (value: T) => U)
filter(predicate: (value: T) => boolean)
Control Operations
take(n: number)
skip(n: number)
takeWhile(predicate: (value: T) => boolean)
skipWhile(predicate: (value: T) => boolean)
Collection Operations
batch(size: number)
window(size: number)
Combine Operations
concat(...flows: Flow<T>[])
zip(otherFlow: Flow<U>)
Async Operations
rateLimit(msBetweenYield: number)
Limitations
- 🚫 Maximum 10 operations inside a pipe
License
MIT
Related Skills
node-connect
341.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Writing Hookify Rules
84.6kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
99.5kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
