Giter Site home page Giter Site logo

runnable-chains's Introduction

Runnable Class in Python

This project demonstrates a powerful way to chain functions together using a class called Runnable.

This project was inspired by runnables in LangChain Expression Language (LCEL).

Overview

The Runnable class is defined in main.py. It represents a function that can be run, and it provides a mechanism to chain multiple functions together using the bitwise OR operator (|).

Usage

Here's an example of how to use the Runnable class:

from main import Runnable

def add_five(x):
    return x + 5

def multiply_by_two(x):
    return x * 2

def square(x):
    return x * x

add_five = Runnable(add_five)
multiply_by_two = Runnable(multiply_by_two)
square = Runnable(square)

x = 5

# Using the Runnable class, we can chain functions together
print((add_five | multiply_by_two | square)(x))

In this example, we first define three functions: add_five, multiply_by_two, and square. We then wrap each function in a Runnable instance.

We can then chain these functions together using the | operator. The result is a new Runnable that, when called, will call the first function, pass its result to the second function, and so on.

For example, (add_five | multiply_by_two | square)(x) is equivalent to square(multiply_by_two(add_five(x))).

Installation

To use this project, you need to have Python installed on your machine. You can then clone this repository and run main.py.

runnable-chains's People

Contributors

concaption avatar

Stargazers

Danish Azam avatar  avatar Buildberg avatar

Watchers

 avatar

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.