Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/briancavalier/fx-ts
Computational environments and effects for TypeScript
https://github.com/briancavalier/fx-ts
algebraic-effects effects functional-programming typescript
Last synced: 2 months ago
JSON representation
Computational environments and effects for TypeScript
- Host: GitHub
- URL: https://github.com/briancavalier/fx-ts
- Owner: briancavalier
- Created: 2019-11-13T13:43:54.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-24T01:40:50.000Z (almost 2 years ago)
- Last Synced: 2024-10-20T07:45:55.141Z (2 months ago)
- Topics: algebraic-effects, effects, functional-programming, typescript
- Language: TypeScript
- Homepage:
- Size: 2.17 MB
- Stars: 59
- Watchers: 5
- Forks: 7
- Open Issues: 23
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-list - fx-ts
README
fx-ts
Capabilities & Effects for TypeScript
Features • Install • Examples • Documentation## 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
```shell
npm install --save fx-ts
```## Examples
These examples are intended to be run against master using ts-node. For example:
```sh
$ ./node_modules/.bin/ts-node -O '{ "module": "commonjs" }' ./examples/echo-console.ts
```* [echo-console](examples/echo-console.ts): A simple read-print loop. A good introduction to the basics of capabilities and effects.
* [fp-to-the-max](examples/fp-to-the-max-1.ts): A more involved example number guessing game example from https://www.youtube.com/watch?v=sxudIMiOo68This example runs on AWS Lambda. [**If you have a serverless account and have setup your AWS credentials**](https://www.serverless.com/framework/docs/getting-started#set-up-your-free-pro-account), you can deploy it using `serverless`:
```sh
$ cd examples/lambda-pets
$ ./node_modules/.bin/serverless deploy
```* [lambda-pets](examples/lambda-pets): A realistic AWS Lambda application that shows adoptable pets near the user's IP Address using https://ipstack.com and https://petfinder.com
### 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.
```ts
// Abstract Print & Read capabilitiestype Print = { print(s: string): Fx }
type Read = { read: Fx }
const main = doFx(function* () {
const { print, read } = yield* get()
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
* [koka](https://github.com/koka-lang/koka)
* [ZIO](https://zio.dev)
* [forgefx](https://github.com/briancavalier/forgefx)
* [ambient](https://github.com/briancavalier/ambient)