Giter Club home page Giter Club logo

fx-ts's Introduction

fx-ts

Capabilities & Effects for TypeScript

FeaturesInstallExamplesDocumentation

Features

  • Do-notation for effects: Write imperative-looking code that's fully referentially transparent
  • Asychronous effects with cancelation: Seamlessly mix synchronous and asynchronous effects without worry
  • Effect inference: Effects can be inferred without explicit type annotations
  • Extensible: Implement new effects in user land
  • Testable: Code to interfaces, and easily use different implementations for development, production, and testing
  • Efficient: Synchronous and Asynchronous effects run in constant stack

Install

npm install --save fx-ts

Examples

These examples are intended to be run against master using ts-node. For example:

$ ./node_modules/.bin/ts-node -O '{ "module": "commonjs" }' ./examples/echo-console.ts

This example runs on AWS Lambda. If you have a serverless account and have setup your AWS credentials, you can deploy it using serverless:

$ cd examples/lambda-pets
$ ./node_modules/.bin/serverless deploy

Running the examples

The

Documentation

Pure functions are easy to reason about and test because they aren't entangled with the environment in which they're called. They always give the same answer for the same inputs. Nevertheless, useful programs need to interact with their environment. They need access to databases, external services, or configuration, and need to perform effects like reading and writing files, updating databases, etc.

The goal of fx-ts is to help in writing programs that interact with their environment and are easy to reason about and test.

// Abstract Print & Read capabilities

type Print = { print(s: string): Fx<unknown, void> }

type Read = { read: Fx<Async, string> }

const main = doFx(function* () {
  const { print, read } = yield* get<Print & Read>()
  while (true) {
    yield* print('> ')
    const s = yield* read
    yield* print(`${s}${EOL}`)
  }
})

const capabilities = {
  // ...Concrete implementation of Print and Read...
}

runFx(main(), capabilities)

API

Coming soon

Inspiration

fx-ts's People

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

Watchers

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