Code Monkey home page Code Monkey logo

sloth-pipe's Introduction

sloth-pipe

Sloth Pipe

github latest release npm version npm weekly downloads dependencies license open issues minzipped size follow on xitter

Sloth Pipe is a tiny library for TypeScript and JavaScript that lets you create lazy, chainable, and reusable pipes for data transformation and processing. Borrowing from functional programming paradigms, it offers a convenient and powerful way to compose functions and manage data flow in an application, with an emphasis on lazy evaluation and efficient execution.

Why Sloth Pipe?

Developers want pipes. They've been one of the most requested features in JavaScript for years, and there's even a Stage 2 proposal for adding them to the language. Sloth Pipe isn't a direct replacement for the proposed pipeline operator, but it does offer a similar experience and many of the same benefits.

Features

  • Lazy Evaluation: Computations are only performed when necessary, optimizing performance and resource utilization.
  • Chainable API: Enables the creation of fluent and readable code by chaining multiple operations.
  • Error Handling: Built-in support for error handling within the pipe.
  • Async/Await Compatibility: Seamlessly integrate asynchronous functions into your pipes.
  • Tap Operations: Allows side-effects without altering the pipe's main data flow.
  • Reusable pipes: Easily reuse pipes, even after execution.
  • Extensible: Easily extendable with custom functions and operations.
  • Type-Safe: Written in TypeScript, with full support for type inference and type safety.
  • Lightweight: Small and lightweight, with no external dependencies.
  • Well-Tested: Thoroughly tested with 100% code coverage.

Installation

To install Sloth Pipe, use the following command:

bun i sloth-pipe

or

npm install sloth-pipe

Usage

Here's a simple example of how to use Sloth Pipe:

import { Pipe } from "sloth-pipe";

const result = Pipe(5)
    .to((x) => x * 2)
    .to((x) => x + 3)
    .exec();

console.log(result); // Outputs: 13

Async Operations

Sloth Pipe seamlessly integrates with asynchronous operations:

const add = async (x: Promise<number>, y: number) => {
    const xVal = await x;
    return xVal + y;
};
const asyncResult = await Pipe(5)
    .to(async (x) => x * 2)
    .to(add, 3) // pass additional arguments to any function
    .exec();

console.log(asyncResult); // Outputs: 13

Error Handling

Handle errors gracefully within the pipe:

const safeResult = Pipe(5)
    .to((x) => {
        if (x > 0) throw new Error("Example error");
        return x;
    })
    .catch((err) => 0)
    .exec();

console.log(safeResult); // Outputs: 0

API Reference

The API consists of a few key methods: to, tap, exec, and catch. For a detailed reference, please refer to the API documentation.

Contributing

Any and all contributions are welcome! Open an issue or submit a pull request to contribute.

This project uses Bun for development. To get started, clone the repository and run bun install to install dependencies. Then, run bun test to run the test suite.

To build the project, run bun build. The output will be in the dist directory.

License

This project is licensed under the MIT License.

sloth-pipe's People

Contributors

0v00 avatar alexkates avatar dreyfus92 avatar grumd avatar mehedihasan2810 avatar mgramigna avatar trvswgnr avatar vktrl avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sloth-pipe's Issues

Expand Getting Started Guide

Enhance documentation with more comprehensive examples for new users

Sloth Pipe provides a pretty easy-to-understand API, but new users might find it challenging to grasp its full potential from the current examples. To help them understand and improve their initial experience with the library, we need to expand our Getting Started Guide with more comprehensive and diverse examples.

Objective

  • Develop additional examples that cover a wider range of use cases.
  • Include complex chains and error handling scenarios to demonstrate the library's full capabilities.
  • Ensure that the documentation is accessible and understandable to users with varying levels of experience in TypeScript and functional programming.

Expected Benefits

  • Improved Accessibility for New Users: More examples and a comprehensive guide will make it easier for new users to understand and start using Sloth Pipe effectively.
  • Enhanced Adoption: Detailed documentation can increase the library's adoption by reducing the initial learning curve.
  • Community Engagement: Engaging examples could encourage community members to contribute their own use cases and examples.

Potential Challenges

  • Ensuring that the examples are both educational and practical.
  • Balancing the depth of documentation with the ease of understanding for beginners.

Additional Information

  • Consider feedback from current users about what they found challenging when they first started using Sloth Pipe.
  • Review other popular libraries for inspiration on how they structure their Getting Started guides.

Acceptance Criteria

  • A range of new examples added to the README or a dedicated Getting Started section.
  • Documentation should cover basic to advanced use cases.
  • Clear explanation of concepts and operations specific to Sloth Pipe.

Contributions from the community, especially from those who recently started using Sloth Pipe, are highly encouraged. Your fresh perspective will be invaluable in making our documentation more accessible to new users.

Create Advanced Use Case Tutorials

Goal: Develop detailed tutorials covering advanced functionalities of Sloth Pipe

To further assist users in understanding the full potential of Sloth Pipe, we are seeking contributions for creating detailed tutorials or guides that cover advanced use cases. These tutorials should provide in-depth explanations and examples of using Sloth Pipe in complex scenarios, such as integrating with other libraries or handling large datasets.

Objective

  • Identify advanced and less obvious use cases of Sloth Pipe that could benefit from detailed tutorials.
  • Create comprehensive, step-by-step tutorials for these use cases, including code examples and explanations.
  • Ensure the tutorials are clear, engaging, and useful for users with an intermediate to advanced understanding of TypeScript and functional programming.

Expected Benefits

  • Enhanced User Understanding: Users gain deeper insights into the capabilities of Sloth Pipe and how to leverage them in complex scenarios.
  • Increased Engagement: Providing advanced tutorials encourages users to explore more sophisticated uses of the library, fostering a deeper engagement with the tool.
  • Community Contributions: Inviting the community to contribute tutorials allows for a diverse range of examples and use cases to be showcased.

Potential Challenges

  • Ensuring that the tutorials are detailed yet accessible to users who may not be experts.
  • Keeping the tutorials up-to-date with any changes or updates in the Sloth Pipe library.

Additional Information

  • Contributors may draw inspiration from real-world problems or frequently asked questions in the community.
  • Collaboration with experienced users for insights and peer reviews of the tutorials is encouraged.

Acceptance Criteria

  • Tutorials should be comprehensive, covering the setup, implementation, and explanation of the use case.
  • Code examples provided must be tested, functional, and follow the coding standards of Sloth Pipe.
  • Tutorials should be added to the project's documentation, either as part of the README or in a dedicated documentation section.

Anyone is welcome to contribute.

Remove Perf Regression Test

The regression test for performance is not reliable enough (I figured this might be the case). If it's not going to be meaningful, it should be removed so it doesn't trigger CI errors.

Create a Community Contribution Guide

Goal: Develop a comprehensive guide to encourage and assist new contributors

To foster a welcoming and productive environment for new contributors, we're looking to create a Community Contribution Guide for the Sloth Pipe project. This guide will provide clear instructions and best practices for contributing to the project, making it easier for newcomers to get involved.

Objective

  • Outline the steps for contributing to the Sloth Pipe project, including setting up the development environment, making changes, and submitting pull requests.
  • Include best practices and tips for successful contributions.
  • Address common questions or concerns that new contributors might have.

Expected Benefits

  • Easier Onboarding: A clear guide will make it easier for new contributors to start working on the project.
  • Increased Contributions: By simplifying the contribution process, more people may be encouraged to contribute.
  • Community Building: A contribution guide helps build a stronger, more inclusive community.

Potential Challenges

  • Creating a guide that is comprehensive yet not overwhelming for new contributors.
  • Ensuring the guide stays updated with any changes in the project's contribution process.

Additional Information

  • Look at contribution guides from other open-source projects for inspiration.
  • Collaborate with existing contributors to gather insights and best practices.

Acceptance Criteria

  • The guide should be comprehensive, covering all aspects of the contribution process.
  • It should be accessible and easy to understand for contributors with varying levels of experience.
  • The guide should be added to the project's repository, either as a separate document or part of the README.

This task is perfect for someone who is new to the project and wants to contribute in a meaningful way. No extensive coding experience is required, just a willingness to help and engage with the community.

Add Benchmark Suite

Goal: Create a comprehensive benchmarking system for performance measurement

To consistently measure and improve the performance of Sloth Pipe, we need to develop a robust and comprehensive benchmark suite. This suite should be capable of assessing performance across a variety of scenarios, including different data sizes, operation complexities, and asynchronous vs. synchronous operations.

Objective

  • Design and implement a benchmark suite that accurately measures the performance of Sloth Pipe in various scenarios.
  • Ensure the suite is easy to use and integrate into our continuous integration (CI) process.
  • Create benchmarks that cover typical use cases, edge cases, and stress tests.

Expected Benefits

  • Accurate Performance Measurement: With a robust benchmark suite, we can more accurately track performance improvements and regressions.
  • Guided Optimization: The suite will help identify areas where performance can be enhanced.
  • Community Engagement: Encourage community members to contribute by adding their own benchmarks or improving existing ones.

Potential Challenges

  • Designing benchmarks that are representative of real-world use cases.
  • Ensuring that the benchmark results are reliable and consistent across different environments.

Additional Information

  • Familiarity with performance testing and benchmarking tools would be beneficial.
  • Research other open-source projects for inspiration on effective benchmarking practices.

Acceptance Criteria

  • A comprehensive set of benchmarks covering a wide range of use cases.
  • Documentation on how to run and interpret the benchmarks.
  • Integration of benchmark results into the CI process for continuous performance monitoring.

This task is super important for optimizing Sloth Pipe and maintaining high performance standards. Contributions from anyone interested in performance optimization and benchmarking are welcome.

Enhance Test Suite with More Examples

Expand testing suite to include diverse scenarios and use cases

We should expand our test suite. This task involves creating new test cases that cover a broader range of scenarios and use cases, especially focusing on new features and edge cases that may not have extensive tests yet.

Objective

  • Identify areas within the Sloth Pipe codebase where test coverage could be improved.
  • Develop new test cases that cover these areas, with a focus on diversity and comprehensiveness.
  • Ensure that the new tests are clear, maintainable, and well-documented.

Expected Benefits

  • Improved Code Reliability: Expanding the test suite helps prevent regressions and bugs.
  • Better Coverage: Broader testing ensures that more use cases and scenarios are covered.
  • Community Engagement: This is a great opportunity for new contributors to understand the codebase and contribute meaningfully.

Potential Challenges

  • Writing tests that are both comprehensive and understandable to new contributors.
  • Ensuring that new tests integrate seamlessly with the existing test suite.

Additional Information

  • Familiarity with testing frameworks used in the project would be beneficial but not necessary.
  • Review the CONTRIBUTING.md file for guidelines on how to set up the development environment and write tests.

Acceptance Criteria

  • New tests should cover scenarios that are currently under-tested or not tested at all.
  • All tests must pass and follow the coding standards of the project.
  • Documentation/comments in tests should be clear to assist future contributors in understanding the test cases.

This issue is ideal for first-time contributors or those new to the project. We encourage anyone interested in improving the quality of Sloth Pipe to take on this task. Guidance and support will be provided throughout the process.

[Feature]: i18n Support

Is there an existing issue for this?

  • I have searched the existing issues

Description of your feature request

Implementing i18n (internationalization) support would significantly enhance user accessibility by overcoming language barriers.

Motivation

Starlight already has built-in support for it as well, this will motivate other developers to jump in a contribute to this library.

Additional Context

No response

Version

0.0.7

Operating System

No response

Browsers

No response

Are you willing to work on this issue?

  • Yes I am. (leave this unchecked for No)

Optimize Async/Await Functionality

Sloth Pipe supports asynchronous operations using async/await, but there's potential to further optimize this functionality, especially in light of the recent performance improvements to the core Pipe functionality. We should explore and implement optimizations and make benchmarks more robust.

On this note, I want to consider changing how the API works with async functions. Currently, it is necessary to await values passed through from the previous async function (because it's a promise). It might be a little bit of a pain, and I want to see if it's possible to await them automatically, so the next value is the awaited value. Will probably require some reworking of types and will also need to keep an eye on performance so it doesn't regress. (TODO: make this its own issue probably)

Objective

  • Investigate current implementation of async/await in Sloth Pipe.
  • Identify potential areas for performance improvement.
  • Implement optimizations to enhance the efficiency and speed of async/await operations within Sloth Pipe.

Expected Benefits

  • Increased Performance: By optimizing the async/await feature, we can expect to see a noticeable improvement in performance, especially in scenarios involving heavy use of asynchronous operations.
  • Enhanced User Experience: Faster and more efficient async operations will lead to a smoother experience for developers using Sloth Pipe in their projects.
  • Alignment with Core Performance Goals: This optimization aligns with the recent performance enhancements, maintaining the high-performance standards set by the latest updates.

Potential Challenges

  • Ensuring that optimizations do not break existing functionality.
  • Balancing performance improvements with readability and maintainability of the code.

Additional Information

  • Any relevant information about the current implementation.
  • Reference to any specific files or sections of code that are particularly relevant.

Acceptance Criteria

  • Async/await operations in Sloth Pipe demonstrate improved performance benchmarks.
  • All existing tests pass, and new tests are added to cover the optimized functionality.
  • Documentation is updated to reflect any changes in usage or behavior.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.