{"id":30676924,"url":"https://github.com/ajitjha393/sthalit","last_synced_at":"2026-05-09T05:32:04.964Z","repository":{"id":240535124,"uuid":"802892913","full_name":"ajitjha393/sthalit","owner":"ajitjha393","description":"A library that mimics the concept of lazy evaluation, a feature  found in functional programming languages like Haskell. ","archived":false,"fork":false,"pushed_at":"2024-06-09T05:32:10.000Z","size":52,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-27T04:30:08.605Z","etag":null,"topics":["functional-programming","generators","iterators","javascript","proxy","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/sthalit","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ajitjha393.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-19T14:51:48.000Z","updated_at":"2024-06-09T10:06:52.000Z","dependencies_parsed_at":"2025-09-01T11:02:09.744Z","dependency_job_id":"89997e29-d170-48da-a9b1-f86f39106c10","html_url":"https://github.com/ajitjha393/sthalit","commit_stats":null,"previous_names":["ajitjha393/sthalit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ajitjha393/sthalit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitjha393%2Fsthalit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitjha393%2Fsthalit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitjha393%2Fsthalit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitjha393%2Fsthalit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajitjha393","download_url":"https://codeload.github.com/ajitjha393/sthalit/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajitjha393%2Fsthalit/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32808413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"online","status_checked_at":"2026-05-09T02:00:06.633Z","response_time":123,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["functional-programming","generators","iterators","javascript","proxy","typescript"],"created_at":"2025-09-01T11:01:58.287Z","updated_at":"2026-05-09T05:32:04.957Z","avatar_url":"https://github.com/ajitjha393.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sthalit\n\n`sthalit` : A Sanskrit word meaning \"deferred\" or \"postponed,\" which aligns with the concept of lazy evaluation where computation is deferred until necessary.\n\n`sthalit` is a powerful JavaScript library that brings lazy evaluation and efficient data processing to your projects. It allows you to handle large data sets and asynchronous operations in a memory-efficient and performant way.\n\n\n## Installation\n\nYou can install sthalit via npm:\n\n```bash\nnpm install sthalit\n```\n\n\n## Features\n\n- **Memory Efficiency**: Process data in chunks, reducing memory usage and avoiding memory exhaustion.\n- **Performance Optimization**: Optimize performance by only processing data when needed.\n- **Flexibility**: Provides a high-level, declarative API for transforming and processing data.\n- **Asynchronous Handling**: Simplifies asynchronous data processing with a consistent API.\n\n\n\n## Use Cases Demonstrating Benefits\n### 1. Processing Large Data Sets\n\nTraditional Method:\n\n  -  Loads the entire data set into memory, causing high memory usage and potential memory exhaustion.\n\n```js\nconst largeDataSet = new Array(1000000).fill(null).map((_, index) =\u003e index);\nconst totalSum = largeDataSet.reduce((sum, value) =\u003e sum + value, 0);\nconsole.log(totalSum);\n```\n\nSthalit method:\n\n- Processes data in chunks, reducing memory usage and optimizing performance.\n\n ```ts\nimport Lazy from '../core/Lazy';\n\n// Simulated large data set\nconst largeDataSet = new Array(1000000).fill(null).map((_, index) =\u003e index);\n\n// Lazy sequence to process data in chunks\nconst lazyProcessing = new Lazy\u003cnumber[]\u003e(function* () {\n    let start = 0;\n    const chunkSize = 1000;\n    while (start \u003c largeDataSet.length) {\n        const chunk = largeDataSet.slice(start, start + chunkSize);\n        start += chunkSize;\n        yield chunk;\n    }\n});\n\n// Flatten the lazy sequence and process data\nconst processLargeDataSet = (): number =\u003e {\n    const flattened = lazyProcessing.flatMap(chunk =\u003e new Lazy\u003cnumber\u003e(function* () { yield* chunk; }));\n    return flattened.reduce((sum, value) =\u003e sum + value, 0);\n};\n\n// Usage\nconst totalSum = processLargeDataSet();\nconsole.log(totalSum); // Total sum of all elements in the large data set\n\n\n ```\n\n\n### 2. Fetching Data in Chunks\n\nTraditional Method:\n\n- Requires manual management of asynchronous data fetching and processing, often leading to complex and error-prone code.\n\n```js\n\nconst fetchData = async (page) =\u003e {\n    // Simulate fetching data from API\n    return new Array(10).fill(null).map((_, i) =\u003e page * 10 + i);\n};\n\nconst fetchAllData = async () =\u003e {\n    const allData = [];\n    for (let page = 1; page \u003c= 3; page++) {\n        const data = await fetchData(page);\n        allData.push(...data);\n    }\n    return allData;\n};\n\nfetchAllData().then(data =\u003e {\n    console.log(data);\n});\n\n```\n\nSthalit Method:\n\n- Provides a clean, declarative API for fetching and processing data lazily and asynchronously.\n\n```ts\nimport Lazy from '../core/Lazy';\n\n// Function to fetch data from the API\nconst fetchData = async (page: number): Promise\u003cnumber[]\u003e =\u003e {\n    // Mocking API call with random data for demonstration\n    return new Promise(resolve =\u003e {\n        setTimeout(() =\u003e {\n            const data = Array.from({ length: 10 }, (_, i) =\u003e page * 10 + i);\n            resolve(data);\n        }, 100);\n    });\n};\n\n// Function to create a Lazy sequence of API data\nconst createLazyApiData = async (pages: number): Promise\u003cLazy\u003cnumber[]\u003e\u003e =\u003e {\n    const data: number[][] = [];\n    for (let page = 1; page \u003c= pages; page++) {\n        const fetchedData = await fetchData(page);\n        data.push(fetchedData);\n    }\n    return new Lazy\u003cnumber[]\u003e(function* () {\n        for (const chunk of data) {\n            yield chunk;\n        }\n    });\n};\n\n// Flatten the lazy sequence of arrays and take the first 10 items\nconst getFirstTenItems = async (lazySequence: Lazy\u003cnumber[]\u003e): Promise\u003cnumber[]\u003e =\u003e {\n    const flattened = lazySequence.flatMap(chunk =\u003e new Lazy\u003cnumber\u003e(function* () { yield* chunk; }));\n    return flattened.take(10).toArray();\n};\n\n\n// Usage\n(async () =\u003e {\n    const lazyApiData = await createLazyApiData(3); // Fetch data from 3 pages\n    const firstTenItems = await getFirstTenItems(lazyApiData);\n    console.log(firstTenItems); // Array of first ten items from the lazy sequence\n})();\n\n\n```\n\n## Advantages of Sthalit\n**1. Memory Efficiency**\n\n***Traditional Methods:*** Load the entire data set into memory, causing high memory usage and potential memory exhaustion.\n\n***Sthalit:*** Processes data in chunks, reducing memory usage and allowing for processing of large data sets.\n\n**2. Performance Optimization**\n    \n***Traditional Methods:*** Loading all data into memory can be time-consuming and inefficient.\n\n**Sthalit:** Optimizes performance by processing data only when needed.\n\n**3. Flexibility in Data Handling**\n\n***Traditional Methods:*** Often require writing complex logic for chunking, transforming, and processing data.\n\n***Sthalit:*** Provides a high-level, declarative API for handling data with methods like `map`, `filter`, `take`, `flatMap`, and `reduce`.\n\n\n**4. Asynchronous Data Processing**\n\n***Traditional Methods:*** Managing asynchronous data processing can be complex and error-prone.\n\n***Sthalit:*** Simplifies asynchronous data processing with a consistent API for handling both synchronous and asynchronous data.\n\n\nBy using Sthalit, you can handle large data sets and asynchronous operations in a clean, efficient, and scalable manner.\n\n\n## License\n\nThis project is licensed under the MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitjha393%2Fsthalit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajitjha393%2Fsthalit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajitjha393%2Fsthalit/lists"}