├── .npmignore ├── .travis.yml ├── README.md ├── .template └── README.md ├── src ├── index.test.ts └── index.ts ├── .editorconfig ├── CONTRIBUTING.md ├── tsconfig.json ├── .github └── ISSUE_TEMPLATE.md ├── .config ├── tsconfig.commonjs.json └── tsconfig.es2015.json ├── .gitignore ├── LICENSE.md └── package.json /.npmignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - 8 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # typed-future 2 | 3 | > Experiment with TS Futures 4 | 5 | 6 | #### made with 7 | [lib-starter](https://github.com/TylorS/lib-starter) :fire: 8 | -------------------------------------------------------------------------------- /.template/README.md: -------------------------------------------------------------------------------- 1 | # Package Name 2 | 3 | ## Get It 4 | ```sh 5 | npm install --save package-name 6 | # or 7 | yarn add package-name 8 | ``` 9 | 10 | ## Basic usage 11 | 12 | ## API 13 | -------------------------------------------------------------------------------- /src/index.test.ts: -------------------------------------------------------------------------------- 1 | import { Test, describe, given, it } from '@typed/test' 2 | 3 | export const test: Test = describe(`Foo`, [ 4 | given(`Bar`, [ 5 | it(`Baz`, ({ ok }) => { 6 | ok(true) 7 | }) 8 | ]) 9 | ]) 10 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | tab_width = 2 7 | end_of_line = lf 8 | charset = utf-8 9 | trim_trailing_whitespace = true 10 | insert_final_newline = true 11 | 12 | [*.md] 13 | trim_trailing_whitespace = false 14 | insert_final_newline = false -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | First of all, thank you so much, we need your help. 4 | 5 | ## Contributing a fix or feature 6 | 7 | 1. Fork the repository 8 | 2. Switch to a new branch `git checkout -b [branchName]` 9 | 3. Produce your fix or feature 10 | 4. Use Angular-style git commit messages, PLEASE! 11 | 5. Submit a pull request for review 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": [ 4 | "es5", 5 | "es2015" 6 | ], 7 | "target": "es5", 8 | "moduleResolution": "node", 9 | "declaration": true, 10 | "noImplicitAny": true, 11 | "sourceMap": true, 12 | "noUnusedParameters": true, 13 | "noUnusedLocals": true 14 | }, 15 | "include": [ 16 | "src/**/*.ts" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 6 | 7 | **Code to reproduce the issue:** 8 | 9 | 10 | **Expected behavior:** 11 | 12 | 13 | **Actual behavior:** 14 | 15 | 16 | **Versions of packages used:** 17 | -------------------------------------------------------------------------------- /.config/tsconfig.commonjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "es5", 6 | "es2015" 7 | ], 8 | "target": "es5", 9 | "moduleResolution": "node", 10 | "module": "commonjs", 11 | "declaration": true, 12 | "noImplicitAny": true, 13 | "sourceMap": true, 14 | "noUnusedParameters": true, 15 | "noUnusedLocals": true, 16 | "outDir": "../lib" 17 | }, 18 | "exclude": [ 19 | "../src/**/*.test.ts" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.config/tsconfig.es2015.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "lib": [ 5 | "es5", 6 | "es2015" 7 | ], 8 | "target": "es5", 9 | "moduleResolution": "node", 10 | "module": "es2015", 11 | "declaration": true, 12 | "noImplicitAny": true, 13 | "sourceMap": true, 14 | "noUnusedParameters": true, 15 | "noUnusedLocals": true, 16 | "outDir": "../lib.es2015" 17 | }, 18 | "exclude": [ 19 | "../src/**/*.test.ts" 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | 20 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 21 | .grunt 22 | 23 | # node-waf configuration 24 | .lock-wscript 25 | 26 | # Compiled binary addons (http://nodejs.org/api/addons.html) 27 | build/Release 28 | 29 | # Dependency directories 30 | node_modules 31 | jspm_packages 32 | 33 | # Optional npm cache directory 34 | .npm 35 | 36 | # Optional REPL history 37 | .node_repl_history 38 | 39 | # generated files 40 | lib 41 | lib.es2015 42 | .tmp 43 | 44 | # other stuff 45 | src/test.ts 46 | .DS_STORE 47 | 48 | yarn.lock 49 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Tylor Steinberger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | export type Reject = (error: L) => void 2 | export type Resolve = (value: R) => void 3 | export type Computation = (reject: Reject, resolve: Resolve) => void 4 | 5 | export default class Future { 6 | public static of(value: R): Future { 7 | return new Future((_, resolve) => resolve(value)) 8 | } 9 | 10 | public static reject(reason: L): Future { 11 | return new Future(reject => reject(reason)) 12 | } 13 | 14 | constructor(public fork: Computation) {} 15 | 16 | public map(f: (value: R) => B): Future { 17 | return this.chain(x => Future.of(f(x))) 18 | } 19 | 20 | public bimap(f: (reason: L) => A, g: (value: R) => B): Future { 21 | return new Future((reject, resolve) => 22 | this.fork( 23 | (reason: L) => reject(f(reason)), 24 | (value: R) => resolve(g(value)) 25 | ) 26 | ) 27 | } 28 | 29 | public swap(): Future { 30 | return new Future((reject, resolve) => 31 | this.fork(reason => resolve(reason), value => reject(value)) 32 | ) 33 | } 34 | 35 | public fold(f: (reason: L) => B, g: (value: R) => B): Future { 36 | return new Future((_, resolve) => 37 | this.fork( 38 | (reason: L) => resolve(f(reason)), 39 | (value: R) => resolve(g(value)) 40 | ) 41 | ) 42 | } 43 | 44 | public mapRej(f: (reason: L) => B): Future { 45 | return this.bimap(f, x => x) 46 | } 47 | 48 | public chain(f: (value: R) => Future): Future { 49 | return new Future((reject, resolve) => 50 | this.fork( 51 | reason => reject(reason), 52 | (value: R) => f(value).fork(reject, resolve) 53 | ) 54 | ) 55 | } 56 | 57 | public ap( 58 | this: Future B>, 59 | m: Future 60 | ): Future { 61 | return this.chain(f => m.map(f)) 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typed-future", 3 | "description": "typed-future experiment", 4 | "repository": "https://github.com/davidchase/typed-future", 5 | "version": "1.0.0", 6 | "main": "lib/index.js", 7 | "types": "lib/index.d.ts", 8 | "typings": "lib/index.d.ts", 9 | "jsnext:main": "lib.es2015/index.js", 10 | "module": "lib.es2015/index.js", 11 | "author": "David Chase ", 12 | "license": "MIT", 13 | "devDependencies": { 14 | "@typed/test": "2.5.0", 15 | "@types/node": "8.0.23", 16 | "conventional-changelog-cli": "1.3.2", 17 | "dox": "0.9.0", 18 | "gaze-run-interrupt": "1.0.1", 19 | "glob-expand": "0.2.1", 20 | "husky": "0.14.3", 21 | "lint-staged": "4.0.3", 22 | "marked": "0.3.6", 23 | "prettier": "1.5.3", 24 | "rimraf": "2.6.1", 25 | "ts-node": "3.3.0", 26 | "typescript": "2.4.2", 27 | "validate-commit-message": "3.0.1" 28 | }, 29 | "dependencies": {}, 30 | "lint-staged": { 31 | "*.ts": [ 32 | "prettier --write --print-width 80 --tab-width 2 --no-semi --single-quote --parser typescript", 33 | "git add" 34 | ] 35 | }, 36 | "scripts": { 37 | "build": "yarn build:commonjs && yarn build:es2015", 38 | "build:commonjs": "tsc -P .config/tsconfig.commonjs.json", 39 | "build:es2015": "tsc -P .config/tsconfig.es2015.json", 40 | "changelog": "conventional-changelog -i CHANGELOG.md -s -r 0 -p angular && git add CHANGELOG.md && git commit -m 'docs(CHANGELOG): amend changelog'", 41 | "commitmsg": "validate-commit-msg", 42 | "postversion": "yarn changelog && git push origin master --tags && npm publish --access=public", 43 | "precommit": "lint-staged", 44 | "preversion": "npm test && yarn build", 45 | "release:major": "npm version major -m 'chore(package): v%s'", 46 | "release:minor": "npm version minor -m 'chore(package): v%s'", 47 | "test": "yarn test:lint && yarn test:unit", 48 | "test:lint": "prettier --write --print-width 80--tab-width 2 --no-semi --single-quote --parser typescript 'src/*.ts' 'src/**/*.ts'", 49 | "test:unit": "typed-test 'src/*.test.ts' 'src/**/*.test.ts'" 50 | } 51 | } 52 | --------------------------------------------------------------------------------