@fizzwiz/search
v0.0.0-dev.1
Published
Declarative lazy search abstractions for exploring and solving complex computational problems, synchronously or asynchronously.
Maintainers
Readme
🧘♂️ @fizzwiz/search
A lightweight JavaScript library for defining declarative, lazy search algorithms, both synchronous and asynchronous, with fluent, queue-driven iteration.
This library is ideal for exploring large or infinite search spaces efficiently and transparently, with full control over candidate generation, expansion, and concurrency.
Features
Synchronous search with
SearchAsynchronous search with
AsyncSearch(parallel or distributed)Fluent, chainable API:
- Define initial candidates via
from() - Describe expansion logic via
through() - Control iteration order with
via() - Limit branching with
max() - Control concurrency (async only) with
inParallel()
- Define initial candidates via
Fully lazy, iterable (or async iterable), suitable for memory-efficient algorithms
Compatible with any queue strategy (BFS, DFS, priority queues, custom)
🧠 Guides & Concepts
Deep-dive into practical patterns, real-world use cases, and advanced techniques:
👉 https://search.blog.fizzwiz.cloud
Installation
npm install @fizzwiz/searchUsage
Synchronous Search
import { Search } from "@fizzwiz/search";
import { ArrayQueue } from "@fizzwiz/sorted";
const search = new Search()
.from(1, 2, 3)
.through(x => [x + 1, x + 2])
.via(new ArrayQueue());
for (const candidate of search) {
console.log(candidate);
}Asynchronous Search
import { AsyncSearch } from "@fizzwiz/search";
import { ArrayQueue } from "@fizzwiz/sorted";
const asyncSearch = new AsyncSearch()
.from(1, 2, 3)
.through(async x => [x + 1, x + 2])
.via(new ArrayQueue())
.inParallel(4);
for await (const candidate of asyncSearch) {
console.log(candidate);
}API
Search (synchronous)
from(...starts)— set initial candidatesthrough(fn)— define search space expansion functionvia(queue, max)— set queue strategy and optional maximum queue size- Iterable: use
for...ofto iterate candidates lazily
AsyncSearch (asynchronous)
from(...starts)— set initial candidates (can be async iterable or promise)through(fn)— define asynchronous expansion functionvia(queue, max)— set queue strategyinParallel(cores)— define concurrent expansion batch- Async iterable: use
for await...ofto iterate candidates
