Skip to content

Commit

Permalink
feat: add fromNullable
Browse files Browse the repository at this point in the history
  • Loading branch information
Lonli-Lokli committed Jul 16, 2024
1 parent 23019cc commit 44a4553
Show file tree
Hide file tree
Showing 7 changed files with 1,400 additions and 9,681 deletions.
34 changes: 17 additions & 17 deletions .github/workflows/npm-publish.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
on:
push:
branches: release

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: "18"
- run: yarn
- run: yarn test
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
on:
push:
branches: master

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18'
- run: npm ci
- run: npm run test
- uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const user = getUser(1).map(({ email }) => email);
- [`fromTry`](#fromTry)
- [`fromMaybe`](#frommaybe)
- [`fromEither`](#fromeither)
- [`fromNullable`](#fromnullable)
- [`isResult`](#isresult)
- [`Result#isInitial`](#resultisinitial)
- [`Result#isPending`](#resultispending)
Expand Down Expand Up @@ -309,6 +310,21 @@ Example:
fromEither(right<string, number>(10)); // Result<string, number>.Success
```

#### `fromNullable`

```typescript
function fromNullable<T>(value: T): Result<unknown, NonNullable<T>>;
```

- Creates `Result` with `Success` state which contain value with `T` type if value is not null or undefined and `initial` otherwise.

Example:

```typescript
fromNullable(10); // Result<unknown, number>.Success
fromNullable(null as Nullable<number>); // Result<unknown, number>.Initial
```

#### `isResult`

```typescript
Expand Down
1 change: 0 additions & 1 deletion nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"appsDir": "packages",
"libsDir": "packages"
},
"nxCloudAccessToken": "MTljYTJkNjktYWI3YS00ZWIyLTlmZTktYjUzMzI5NTI3NTAzfHJlYWQtd3JpdGU=",
"useInferencePlugins": false,
"defaultBase": "master"
}
Loading

0 comments on commit 44a4553

Please sign in to comment.