Skip to content

Commit

Permalink
chore: add new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
inaiat committed Apr 8, 2024
1 parent 9fe5c14 commit 71dedf2
Show file tree
Hide file tree
Showing 6 changed files with 217 additions and 166 deletions.
53 changes: 49 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
- [`Result.andThen` (method)](#resultandthen-method)
- [`Result.asyncAndThen` (method)](#resultasyncandthen-method)
- [`Result.orElse` (method)](#resultorelse-method)
- [`Result.tap` (method)](#resulttap-method)
- [`Result.finally` (method)](#resultfinally-method)
- [`Result.match` (method)](#resultmatch-method)
- [`Result.asyncMap` (method)](#resultasyncmap-method)
- [`Result.fromThrowable` (static class method)](#resultfromthrowable-static-class-method)
Expand All @@ -52,6 +54,7 @@ For asynchronous tasks, `resultar` offers a `ResultAsync` class which wraps a `P
- [`ResultAsync.unwrapOr` (method)](#resultasyncunwrapor-method)
- [`ResultAsync.andThen` (method)](#resultasyncandthen-method)
- [`ResultAsync.orElse` (method)](#resultasyncorelse-method)
- [`Result.tap` (method)](#resultasynctap-method)
- [`ResultAsync.match` (method)](#resultasyncmatch-method)
- [`ResultAsync.combine` (static class method)](#resultasynccombine-static-class-method)
- [`ResultAsync.combineWithAllErrors` (static class method)](#resultasynccombinewithallerrors-static-class-method)
Expand Down Expand Up @@ -990,7 +993,34 @@ const mapped = okVal.tap((value) => {
console.log(value) // print foo
})
// mapped.value === 'foo'
```
[⬆️ Back to top](#toc)
---
---
#### `Result.finally` (method)
Executes a cleanup function wether the is ok or error. This method is usefull to cleanup resources.
**Signature:**
```typescript
class Result<T, E> {
finally(f: (value: T, error: E) => void): DisposableResult<T, E> {..}
}
```
**Example:**
```typescript
const reader = ok(file) // content file is line 01

const result = reader.map(it => it.content).finally(_ => {
file.close()
})

if (resul.isOk()) {
console.log(result.value) // print line 01
}

```
[⬆️ Back to top](#toc)
---
#### `ResultAsync.orElse` (method)
Expand All @@ -1011,6 +1041,25 @@ class ResultAsync<T, E> {
---
#### `ResultAsync.tap` (method)
Executes a side effect function with the `Ok` value and returns the original `ResultAsync`.
This method is useful for performing actions that do not modify the `ResultAsyn` itself, such as logging or updating external state.
**Signature:**
```typescript
class ResultAsync<T, E> {
tap(f: (t: T) => void | Promise<void>): ResultAsync<T, E> {...}
}
```
**Example:**
See [`Result.tap` (method)](#resulttap-method)
```

[⬆️ Back to top](#toc)
---

#### `ResultAsync.match` (method)

Given 2 functions (one for the `Ok` variant and one for the `Err` variant) execute the function that matches the `ResultAsync` variant.
Expand Down Expand Up @@ -1296,10 +1345,6 @@ _unsafeUnwrapErr({
---
If you find this package useful, please consider [sponsoring me](https://github.com/sponsors/supermacro/) or simply [buying me a coffee](https://ko-fi.com/gdelgado)!
---
### License
The resultar project is available as open source under the terms of the [MIT license](https://github.com/inaiat/resultar/blob/master/LICENSE).
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@inaiat/resultar",
"version": "0.8.5",
"version": "0.8.6",
"exports": "./src/index.ts"
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "resultar",
"version": "0.8.5",
"version": "0.8.6",
"description": "Result pattern for typescript",
"type": "module",
"packageManager": "[email protected]",
Expand Down Expand Up @@ -50,18 +50,18 @@
},
"homepage": "https://github.com/inaiat/resultar",
"devDependencies": {
"@types/node": "^20.12.3",
"@types/node": "^20.12.5",
"eslint-plugin-unused-imports": "^3.1.0",
"husky": "^9.0.11",
"rimraf": "^5.0.5",
"semver": "^7.6.0",
"testdouble": "^3.20.2",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"tsx": "^4.7.2",
"typedoc": "^0.25.13",
"typedoc-github-wiki-theme": "2.0.0-next.8",
"typedoc-plugin-markdown": "4.0.0-next.55",
"typescript": "5.4.2",
"typescript": "5.4.4",
"xo": "0.58.0"
},
"tsup": {
Expand Down
Loading

0 comments on commit 71dedf2

Please sign in to comment.