Skip to content

Commit

Permalink
chore: Update with "reject" usage
Browse files Browse the repository at this point in the history
  • Loading branch information
iainjreid committed Aug 7, 2022
1 parent 8e27c8e commit 6de775b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ the right place!
[readme]: https://github.com/emphori/compose/blob/HEAD/README.md


<!-- Note: This is commented out until we sort out our contribution processes,
if you're reading this though, we'll still be very happy to accept
contributions in the meantime!
## Contributing
We welcome contributions of any size from anyone. Please do take a moment to
Expand All @@ -18,6 +22,7 @@ our process.
[contributing]: https://github.com/emphori/.github/blob/HEAD/CONTRIBUTING.md
-->

## Issues

Expand Down
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Compose

A drop in extension for Promises, adding oodles of functional goodness through
A drop-in extension for Promises, adding oodles of functional goodness through
composition and taking error handling to an entirely different level.


Expand All @@ -22,8 +22,8 @@ composition and taking error handling to an entirely different level.

## Installation

Compose is distributed to both NPM and GitHub Packages. Whichever registry you
prefer to use, the installation instructions should remain the same.
Compose is available through both NPM and GitHub Packages. Whichever registry
you prefer to use, the installation instructions should remain the same.

```sh
# Using NPM
Expand All @@ -37,20 +37,21 @@ yarn add @emphori/compose
## Examples

```ts
import { compose } from '@emphori/compose'
import { compose, reject } from '@emphori/compose'
import type { Promise } from '@emphori/promise'

// (userId: string) => Promise<Org, UserNotFound | OrgNotFound>
const getUserOrg = compose(getUser).then(getOrgForUser)

function getUser(userId: string): Promise<User, UserNotFound> {
return User.getById(userId).then((user) => {
return user ?? Promise.reject(UserNotFound)
return user ?? reject(UserNotFound)
})
}

function getOrgForUser(user: User): Promise<Org, OrgNotFound> {
return Org.getById(user.orgId).then((org) => {
return org ?? Promise.reject(OrgNotFound)
return org ?? reject(OrgNotFound)
})
}
```
Expand Down

0 comments on commit 6de775b

Please sign in to comment.