An open API service indexing awesome lists of open source software.

https://github.com/hyper63/task


https://github.com/hyper63/task

Last synced: 6 months ago
JSON representation

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.



Current Version

---

## 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/