New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Backport Option.orElse from effect/ #1868
Conversation
Thanks @george-wilson-rea, though I would backport /cc @sukovanej So, adapted to /**
* Returns the provided `Option` `that` if `self` is `None`, otherwise returns `self`.
*
* @param self - The first `Option` to be checked.
* @param that - The `Option` to return if `self` is `None`.
*
* @example
* import * as O from "fp-ts/Option"
*
* assert.deepStrictEqual(O.orElse(O.none, () => O.none), O.none)
* assert.deepStrictEqual(O.orElse(O.some(1), () => O.none), O.some(1))
* assert.deepStrictEqual(O.orElse(O.none, () => O.some('b')), O.some('b'))
* assert.deepStrictEqual(O.orElse(O.some(1), () => O.some('b')), O.some(1))
*
* @category error handling
* @since 2.16.0
*/
export const orElse: {
<B>(that: LazyArg<Option<B>>): <A>(self: Option<A>) => Option<A | B>
<A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B>
} = dual(2, <A, B>(self: Option<A>, that: LazyArg<Option<B>>): Option<A | B> => (isNone(self) ? that() : self)) p.s. pipe(self, orElse(that)) // data-last
orElse(self, that) // data-first |
2e4e6d1
to
4916289
Compare
Thanks, I've updated the PR to exactly what you posted there. Hopefully it's good now. |
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [fp-ts](https://togithub.com/gcanti/fp-ts) | [`2.13.1` -> `2.16.1`](https://renovatebot.com/diffs/npm/fp-ts/2.13.1/2.16.1) | [![age](https://developer.mend.io/api/mc/badges/age/npm/fp-ts/2.16.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/fp-ts/2.16.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/fp-ts/2.13.1/2.16.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/fp-ts/2.13.1/2.16.1?slim=true)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>gcanti/fp-ts (fp-ts)</summary> ### [`v2.16.1`](https://togithub.com/gcanti/fp-ts/blob/HEAD/CHANGELOG.md#2161) [Compare Source](https://togithub.com/gcanti/fp-ts/compare/2.16.0...01b8661f2fa594d6f2010573f010d358e6808d13) **Bug Fix** - fix type signature of `ReaderTaskEither.tapReaderIO`, [#​1895](https://togithub.com/gcanti/fp-ts/issues/1895) ### [`v2.16.0`](https://togithub.com/gcanti/fp-ts/blob/HEAD/CHANGELOG.md#2160) [Compare Source](https://togithub.com/gcanti/fp-ts/compare/2.15.0...2.16.0) - `tapEither` (dual) (aka `chainFirstEitherK` / `chainFirstEitherKW`) [gcanti/fp-ts#1864 - `tapIO` (dual) (aka `chainFirstIOK`) [gcanti/fp-ts#1865 - `as` / `asUnit` [gcanti/fp-ts#1867 - `tapTask` (dual) (aka `chainFirstTaskK`) [gcanti/fp-ts#1869 - `mapError` (dual) (aka `mapLeft`) [gcanti/fp-ts#1870 - `mapBoth` (dual) (aka `bimap`) [gcanti/fp-ts#1872 - `tapReader` (dual) (aka `chainFirstReaderK` / `chainFirstIReaderKW`) [gcanti/fp-ts#1871 - `tapReaderEither` (dual) (aka `chainFirstReaderEitherK` / `chainFirstEitherKW`) [gcanti/fp-ts#1873 - `tapReaderIO` (dual) (aka `chainFirstReaderIOK`) [gcanti/fp-ts#1873 - `tapReaderTask` (dual) (aka `chainFirstReaderTaskK`) [gcanti/fp-ts#1873 - `tapTaskEither` (dual) (aka `chainFirstTaskEitherK` / `chainFirstTaskEitherKW`) [gcanti/fp-ts#1873 - `flatMapReaderTask` (dual) (aka `chainReaderTaskK` / `chainReaderTaskKW`) [gcanti/fp-ts#1874 - `flatMapTaskEither` (dual) (aka `chainTaskEitherK` / `chainTaskEitherKW`) [gcanti/fp-ts#1874 - `flatMapIO` (dual) (aka `chainIOK`) [gcanti/fp-ts#1874 - `Option.orElse` (dual) (aka `alt` / `altW`) [gcanti/fp-ts#1868 - `flatMapTask` (dual) (aka `chainTaskK`) [gcanti/fp-ts#1876 - `flatMapReader` (dual) (aka `chainReaderK` / `chainReaderKW`) [gcanti/fp-ts#1876 - `flatMapReaderIO` (dual) (aka `chainReaderIOK` / `chainReaderIOKW`) [gcanti/fp-ts#1879 - `flatMap*` (aka `chain*K` / `chain*KW`) [gcanti/fp-ts#1880 ### [`v2.15.0`](https://togithub.com/gcanti/fp-ts/blob/HEAD/CHANGELOG.md#2150) [Compare Source](https://togithub.com/gcanti/fp-ts/compare/2.14.0...2.15.0) **New Feature** - `function` - add `LazyArg` - add `tap` to - `Either` - `IO` - `IOEither` - `IOOption` - `Option` - `Reader` - `ReaderEither` - `ReaderIO` - `ReaderTask` - `ReaderTaskEither` - `State` - `StateReaderTaskEither` - `Task` - `TaskEither` - `TaskOption` - add `flatMapNullable` (dual) to - `Either` - `IOEither` - `ReaderEither` - `ReaderTaskEither` - `StateReaderTaskEither` - `TaskEither` - add `flatMapOption` (dual) to - `Either` - `IOEither` - `ReaderEither` - `ReaderTaskEither` - `StateReaderTaskEither` - `TaskEither` - add `liftNullable` to - `Either` - `IOEither` - `ReaderEither` - `ReaderTaskEither` - `StateReaderTaskEither` - `TaskEither` - add `liftOption` to - `Either` - `IOEither` - `ReaderEither` - `ReaderTaskEither` - `StateReaderTaskEither` - `TaskEither` - add `flatMapEither` (dual) to - `IOEither` - `ReaderEither` - `ReaderTaskEither` - `TaskEither` - `Array` - add index to `flatMap` - `NonEmptyArray` - add index to `flatMap` - `ReadonlyArray` - add index to `flatMap` - `ReadonlyNonEmptyArray` - add index to `flatMap` ### [`v2.14.0`](https://togithub.com/gcanti/fp-ts/blob/HEAD/CHANGELOG.md#2140) [Compare Source](https://togithub.com/gcanti/fp-ts/compare/2.13.2...2.14.0) **New Feature** - add `flatMap` to - `Either` - `IOEither` - `Reader` - `ReaderEither` - `ReaderIO` - `ReaderTask` - `ReaderTaskEither` - `StateReaderTaskEither` - `TaskEither` - `NonEmptyArray` - `ReadonlyNonEmptyArray` - `Tree` - `Array` - `Identity` - `IO` - `IOOption` - `Option` - `ReadonlyArray` - `State` - `Task` - `TaskOption` ### [`v2.13.2`](https://togithub.com/gcanti/fp-ts/blob/HEAD/CHANGELOG.md#2132) [Compare Source](https://togithub.com/gcanti/fp-ts/compare/2.13.1...2.13.2) - add `chainOptionKW`, [#​1846](https://togithub.com/gcanti/fp-ts/issues/1846) ([@​DenisFrezzato](https://togithub.com/DenisFrezzato)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "after 5pm,every weekend" in timezone America/Los_Angeles, Automerge - "after 5pm,every weekend" in timezone America/Los_Angeles. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://developer.mend.io/github/valora-inc/wallet). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41Ni4wIiwidXBkYXRlZEluVmVyIjoiMzYuNTYuMCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
There is precedent for this naming in Scala
Before submitting a pull request, please make sure the following is done:
master
.npm install
in the repository root.npm test
).Note. If you've fixed a bug please link the related issue or, if missing, open an issue before sending a PR.
Note. If you find a typo in the documentation, make sure to modify the corresponding source (docs are generated).
Note. If you want to send a PR related to
fp-ts@1.x
please create your branch from1.x