https://github.com/hyper63/task
https://github.com/hyper63/task
Last synced: 6 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/hyper63/task
- Owner: hyper63
- Created: 2021-01-17T00:06:46.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-09T20:08:13.000Z (about 5 years ago)
- Last Synced: 2025-01-13T05:41:38.716Z (about 1 year ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
task
Task is a ADT that can wrap async functions and make them execute in a lazy path. This allows for better error management and consistents results. You can use `fromPromise` and `fromNode` to wrap promises and callbacks then chain them together in a lazy pipeline that does not execute the async code until `fork` is applied.
---
## Table of Contents
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Features](#features)
- [Methods](#methods)
- [Contributing](#contributing)
- [License](#license)
## Getting Started
see example.js
```js
import { Task } from "https://x.nest.land/task@1.0.4/mod.ts";
const { fromPromise } = Task;
fromPromise((x) => Promise.resolve(x + " :tada:"))("Hello")
.fork(
(e) => console.log("promise was rejected"),
(r) => console.log(r),
);
```
## Installation
This is a Deno module available to import from https://nest.land/package/task
deps.js
```
export { Task } from 'https://x.nest.land/task@1.0.4/mod.js'
```
## Features
- fromPromise
- fromNode
## methods
- map - applys function to value
- chain - applys function that retuns task
- ap
- concat - forks the passed in task then concats the task with the current one
- fork - fork runs the task contained function
- toPromise - forks the task and returns a promise
## constructors
- Task.of - creates a Task with a value eg. Task.of('foo')
- Task.resolve - creates a Task with a value and puts Task in resolved state
- Task.reject - creates a Task with a value in rejected state
- Task.fromPromise - returns a constructor function that will create a Task
- Task.fromNode - returns a constructor function that will create a Task
## Contributing
Pull Requests are welcome
## License
MIT
## Acknowledgements
The core code for this library was initiated from code shared by Brian Londorf
in a course from frontend masters. If you want to learn more about functional
programming in javascript check it out:
https://frontendmasters.com/courses/hardcore-js-v2/