Giter VIP home page Giter VIP logo

generator-effects's Introduction

Generator Effects

A proof-of-concept effect interpreter for generator functions.

Purpose

The idea of pairing generator functions with an interpreter has eaten at my psyche for years. This "library" is an attempt to see just how far you can take it, and with luck, purge my nagging curiosity.

I put "library" in quotes because it's not a real library and it will never be published. The only value this codebase can offer is demonstrating just how much is possible with generators. Spoilers: much. Check out the examples folder.

Gist

The experiment was a thrilling success. Here's what's implemented:

  • Deeply linked Algebraic Effects resume execution through yield statements.
  • Context trees allow isolated state sharing with entire branches of the call stack (think React hooks).
  • Async effects that read as though they're blocking (this is how async/await is implemented, after all).
  • Effect composition - all effects can be programmatically manipulated as data structures (just like promises).

Possibilities

There are some capabilities that I didn't explore, but realized they were possible.

  • Nearly any API can be expressed as a generator effect, including data streams, mutable objects APIs, and concurrent process management.
  • Since every effect travels through the interpreter, every effect can be logged, ignored, composed, or replaced.
  • Purely functional dependency injection is possible through context trees, and is even easily integrated into the interpreter.

In JavaScript it's rare to see generators used outside of iteration, but they're capable of much more.

See the examples for more details.

generator-effects's People

Stargazers

 avatar

Watchers

 avatar  avatar  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.