Skip to content

Commit

Permalink
Merge pull request #144 from seasonedcc/readme-dw
Browse files Browse the repository at this point in the history
README polish
  • Loading branch information
danielweinmann authored May 29, 2024
2 parents 3bcbb84 + 92a123e commit f88d8b8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
A set of types and functions to make compositions easy and safe.

- 🛟 Type-Safe Compositions: Ensure robust type-safety during function composition, preventing incompatible functions from being combined and reducing runtime errors.
- 🔄 Promise and Error Handling: Focus on the happy-path of your functions eliminating the need for verbose try/catch syntax.
- 🔄 Promise and Error Handling: Focus on the happy-path of your functions, eliminating the need for verbose try/catch syntax.
- 🏝️ Isolated Business Logic: Split your code into composable functions, making your code easier to test and maintain.
- 🔒 End-to-End Type Safety: Achieve end-to-end type safety from the backend to the UI with serializable results, ensuring data integrity across your entire application.
- ⚡ Parallel and Sequential Compositions: Compose functions both in parallel - with `all` and `collect` - and sequentially - with `pipe`, `branch`, and `sequence` -, to manage complex data flows optimizing your code for performance and clarity.
Expand Down Expand Up @@ -127,7 +127,7 @@ const addAndReturnString = pipe(toString, add)
```

Since pipe will compose from left to right, the only `string` output from `toString` will not fit into the first argument of `add` which is a `number`.
The error message comes in the form of an inferred `FailToCompose` type, this failure type is not callable therefore it will break any attempts to call `addAndReturnString`.
The error message comes in the form of an inferred `FailToCompose` type. This failure type is not callable, therefore it will break any attempts to call `addAndReturnString`.

### Using non-composables (mapping)

Expand Down Expand Up @@ -163,7 +163,7 @@ Two neat consequences is that we can handle errors using functions (no need for

### Throwing

You can throw anything derived from `Error`. Check [this documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types) on how to define your custom errors. The library will also wrap anything that does not extends `Error`, just to keep compatibility with code-bases that throw strings or objects.
You can throw anything derived from `Error`. Check [this documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#custom_error_types) on how to define your custom errors. The library will also wrap anything that does not extend `Error`, just to keep compatibility with code-bases that throw strings or objects.

```typescript
import { composable } from 'composable-functions'
Expand All @@ -183,11 +183,11 @@ const getUser = composable((userId: string, users: Array<string>) => {
})
```

The library defines a few custom errors out of the box but these will be more important later on, whend dealing with external input and schemas.
The library defines a few custom errors out of the box but these will be more important later on, when dealing with external input and schemas.
See [the errors module](./src/errors.ts) for more details.

### Catching
You can catch an error in a `Composable`, using `catchFailure` which is similar to `map` but will run whenever the first composable fails:
You can catch an error in a `Composable` using `catchFailure`, which is similar to `map` but will run whenever the first composable fails:

```typescript
import { composable, catchFailure } from 'composable-functions'
Expand Down Expand Up @@ -240,7 +240,7 @@ const fn = composable(async (id: string) => {
```
We recomend only using `fromSuccess` when you are sure the composable must succeed, like when you are testing the happy path of a composable.

You can also use it within other composables whenever the composition utilities fall short, the error will be propagated as `ErrorList` and available in the caller `Result`.
You can also use it within other composables whenever the composition utilities fall short. In that case, the error will be propagated as `ErrorList` and available in the caller `Result`.

```ts
const getUser = composable((id: string) => db().collection('users').findOne({ id }))
Expand All @@ -267,7 +267,7 @@ If you are using [Deno](https://deno.land/), just directly import the functions
import { composable } from "https://deno.land/x/composable_functions/mod.ts";
```

This documentation will use Node.JS imports by convention, just replace `composable-functions` with `https://deno.land/x/composable_functions/mod.ts` when using [Deno](https://deno.land/).
This documentation will use Node.JS imports by convention. Just replace `composable-functions` with `https://deno.land/x/composable_functions/mod.ts` when using [Deno](https://deno.land/).


## Acknowledgements
Expand Down
2 changes: 1 addition & 1 deletion migrating-df.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This document will guide you through the migration process.
- 🕵🏽 Runtime Validation: Use the [`withSchema`](./API.md#withschema) function for optional runtime validation of inputs and environments. This provides flexibility to enforce data integrity when needed without mandating it for every function. Assuming you have a big chain of composables you can use [`applySchema`](./API.md#applyschema) to run your runtime validation only once **avoiding unnecessary processing**.
- 🔀 Flexible Compositions: The new combinators, such as [`environment.pipe`](./API.md#environmentpipe), [`environment.sequence`](./API.md#environmentsequence), and [`environment.branch`](./API.md#environmentbranch), offer powerful ways to manage **typed environments** and contextual information across your compositions.
- 🛠️ Incremental Migration: Seamlessly migrate your existing codebase incrementally. **Both `domain-functions` and `composable-functions` can coexist**, allowing you to transition module by module.
- 🛟 Enhanced Combinators: New and improved combinators like [`map`](./API.md#map), [`mapParameters`](./API.md#mapparameters), [`mapErrors`](./API.md#maperrors) and [`catchFailure`](./API.md#catchfailure) provide more control over handling and error transformation, making your **code more resilient**.
- 🛟 Enhanced Combinators: New and improved combinators like [`map`](./API.md#map), [`mapParameters`](./API.md#mapparameters), [`mapErrors`](./API.md#maperrors) and [`catchFailure`](./API.md#catchfailure) provide more control over error handling and transformation, making your **code more resilient**.

# Table of contents
- [First steps](#first-steps)
Expand Down

0 comments on commit f88d8b8

Please sign in to comment.