@flarehr/apollo-benefits 0.1.109 → 0.3.53405
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/assets/@splitsoftware-7d799540.js +18 -0
- package/dist/assets/all_tab_color-548783b9.svg +21 -0
- package/dist/assets/all_tab_gray-a5051313.svg +6 -0
- package/dist/assets/check-57fe1dcb.svg +15 -0
- package/dist/assets/datadog-ff247651.js +5 -0
- package/dist/assets/date-fns-c5d8fbc0.js +1 -0
- package/dist/assets/default_backdrop-fdd955b8.png +0 -0
- package/dist/assets/external_link-599a0aec.svg +3 -0
- package/dist/assets/external_link_white-55111b2e.svg +3 -0
- package/dist/assets/framer-motion-bb8d6b82.js +1 -0
- package/dist/assets/index-0b3afb09.js +5 -0
- package/dist/assets/index-5e9e5aa9.js +35 -0
- package/dist/assets/index-cfa25e28.css +1 -0
- package/dist/assets/lodash-5d893f8c.js +1 -0
- package/dist/assets/logo-a34e9b4b.png +0 -0
- package/dist/assets/oidc-client-6f6e47c2.js +101 -0
- package/dist/assets/padlock-8c081120.svg +26 -0
- package/dist/assets/suitcase-6471ad05.svg +17 -0
- package/dist/assets/vendor-2d0139ca.js +788 -0
- package/dist/assets/warning-a7f1af23.svg +14 -0
- package/dist/assets/welcome_image_mobile-dbde6c80.png +0 -0
- package/dist/assets/welcome_image_v2-869c59e4.png +0 -0
- package/dist/assets/wellbeing_banner-6903d615.png +0 -0
- package/dist/assets/workplace_link_banner_mobile-6ebaa24b.png +0 -0
- package/dist/assets/workplace_link_banner_v2-c81ed849.png +0 -0
- package/dist/config.json +14 -0
- package/dist/favicon.ico +0 -0
- package/dist/icons/android-chrome-192x192.png +0 -0
- package/dist/icons/android-chrome-512x512.png +0 -0
- package/dist/icons/apple-touch-icon.png +0 -0
- package/dist/icons/favicon-16x16.png +0 -0
- package/dist/icons/favicon-32x32.png +0 -0
- package/dist/index.html +114 -0
- package/dist/manifest.json +21 -0
- package/dist/sw-esm.js +16 -0
- package/package.json +129 -60
- package/LICENSE +0 -21
- package/dist/lib/apollo-benefits/apollo-benefits.esm.js +0 -1
- package/dist/lib/apollo-benefits/assets/car-placeholder.svg +0 -5
- package/dist/lib/apollo-benefits/assets/check.svg +0 -13
- package/dist/lib/apollo-benefits/index.esm.js +0 -0
- package/dist/lib/apollo-benefits/p-06a1f65f.js +0 -1
- package/dist/lib/apollo-benefits/p-077d7f8d.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-14054f15.js +0 -1
- package/dist/lib/apollo-benefits/p-24a37d64.js +0 -1
- package/dist/lib/apollo-benefits/p-2b3f3b72.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-3111d565.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-327396fa.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-3d4d2683.js +0 -1
- package/dist/lib/apollo-benefits/p-4474bcf8.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-4bff99bd.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-50fe790f.js +0 -1
- package/dist/lib/apollo-benefits/p-53bcbd1d.js +0 -1
- package/dist/lib/apollo-benefits/p-68c136da.js +0 -1
- package/dist/lib/apollo-benefits/p-6bd16f5b.js +0 -1
- package/dist/lib/apollo-benefits/p-71dbc8ff.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-774d9bc5.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-7a2ca86d.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-7a572b50.js +0 -1
- package/dist/lib/apollo-benefits/p-7c2cd94a.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-839493d7.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-a24d169b.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-b33fc683.js +0 -1
- package/dist/lib/apollo-benefits/p-beb8f728.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-e241f55b.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-e28cee25.js +0 -1
- package/dist/lib/apollo-benefits/p-e3cf51f1.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-ef8ea713.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-f0a7c9fa.entry.js +0 -1
- package/dist/lib/apollo-benefits/p-f603197d.js +0 -15
- package/dist/lib/cjs/active-router-0ecaf2b8.js +0 -75
- package/dist/lib/cjs/ap-ben-choose-vehicle-section_4.cjs.entry.js +0 -2708
- package/dist/lib/cjs/ap-ben-complete-section_4.cjs.entry.js +0 -108
- package/dist/lib/cjs/ap-ben-notifications-section.cjs.entry.js +0 -238
- package/dist/lib/cjs/apollo-benefits.cjs.js +0 -25
- package/dist/lib/cjs/app-globals-67583b8b.js +0 -12
- package/dist/lib/cjs/async-6a7926f0.js +0 -753
- package/dist/lib/cjs/cars-calculator-app.cjs.entry.js +0 -55
- package/dist/lib/cjs/cars-calculator.service-c0e51584.js +0 -904
- package/dist/lib/cjs/context-consumer.cjs.entry.js +0 -29
- package/dist/lib/cjs/datorama-akita-31d23240.js +0 -2551
- package/dist/lib/cjs/delay-d31618c3.js +0 -206
- package/dist/lib/cjs/distinctUntilChanged-e8538790.js +0 -371
- package/dist/lib/cjs/dom-utils-b8befdd5.js +0 -63
- package/dist/lib/cjs/fl-button_2.cjs.entry.js +0 -50
- package/dist/lib/cjs/fl-dropdown-async_2.cjs.entry.js +0 -467
- package/dist/lib/cjs/fl-dropdown.cjs.entry.js +0 -232
- package/dist/lib/cjs/fl-style-guide.cjs.entry.js +0 -91
- package/dist/lib/cjs/index-f1fadf90.js +0 -1735
- package/dist/lib/cjs/index.cjs.js +0 -2
- package/dist/lib/cjs/loader.cjs.js +0 -27
- package/dist/lib/cjs/location-utils-36fe7e5e.js +0 -237
- package/dist/lib/cjs/match-path-be4ea5f6.js +0 -279
- package/dist/lib/cjs/session.query-d61ba7ec.js +0 -1731
- package/dist/lib/cjs/stencil-async-content.cjs.entry.js +0 -32
- package/dist/lib/cjs/stencil-route-link.cjs.entry.js +0 -78
- package/dist/lib/cjs/stencil-route-switch.cjs.entry.js +0 -104
- package/dist/lib/cjs/stencil-route-title.cjs.entry.js +0 -32
- package/dist/lib/cjs/stencil-route.cjs.entry.js +0 -97
- package/dist/lib/cjs/stencil-router-prompt.cjs.entry.js +0 -59
- package/dist/lib/cjs/stencil-router-redirect.cjs.entry.js +0 -32
- package/dist/lib/cjs/stencil-router.cjs.entry.js +0 -640
- package/dist/lib/collection/assets/image/complete.svg +0 -122
- package/dist/lib/collection/collection-manifest.json +0 -53
- package/dist/lib/collection/components/cars-calculator-app/api/api-client.js +0 -5
- package/dist/lib/collection/components/cars-calculator-app/api/cars-calculator.api.js +0 -45
- package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.css +0 -22
- package/dist/lib/collection/components/cars-calculator-app/cars-calculator-app.js +0 -97
- package/dist/lib/collection/components/cars-calculator-app/modal-section/modal-section.css +0 -0
- package/dist/lib/collection/components/cars-calculator-app/modal-section/modal-section.js +0 -144
- package/dist/lib/collection/components/cars-calculator-app/notifications-section/notifications-section.js +0 -25
- package/dist/lib/collection/components/cars-calculator-app/pages/assets/car-placeholder.svg +0 -5
- package/dist/lib/collection/components/cars-calculator-app/pages/assets/check.svg +0 -13
- package/dist/lib/collection/components/cars-calculator-app/pages/choose-vehicle-section.component.js +0 -196
- package/dist/lib/collection/components/cars-calculator-app/pages/complete-section.component.js +0 -38
- package/dist/lib/collection/components/cars-calculator-app/pages/cost-breakdown-section.component.js +0 -45
- package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.css +0 -34
- package/dist/lib/collection/components/cars-calculator-app/pages/model-variants-section.component.js +0 -85
- package/dist/lib/collection/components/cars-calculator-app/pages/personal-info-section.component.js +0 -66
- package/dist/lib/collection/components/cars-calculator-app/pages/quote-result-section.component.js +0 -86
- package/dist/lib/collection/components/cars-calculator-app/pages/submit-quote-section.component.js +0 -75
- package/dist/lib/collection/components/cars-calculator-app/services/app-configuration.service.js +0 -13
- package/dist/lib/collection/components/cars-calculator-app/services/cars-calculator.service.js +0 -106
- package/dist/lib/collection/components/cars-calculator-app/services/notifications.service.js +0 -37
- package/dist/lib/collection/components/cars-calculator-app/services/notifications.store.js +0 -3
- package/dist/lib/collection/components/cars-calculator-app/services/session.query.js +0 -35
- package/dist/lib/collection/components/cars-calculator-app/services/session.store.js +0 -78
- package/dist/lib/collection/global/config.js +0 -2
- package/dist/lib/collection/global/main.dev.js +0 -5
- package/dist/lib/collection/global/main.js +0 -5
- package/dist/lib/collection/index.js +0 -2
- package/dist/lib/collection/utils/config.js +0 -2
- package/dist/lib/collection/utils/index.js +0 -15
- package/dist/lib/collection/utils/lazy.js +0 -29
- package/dist/lib/esm/active-router-7c2ca849.js +0 -73
- package/dist/lib/esm/ap-ben-choose-vehicle-section_4.entry.js +0 -2701
- package/dist/lib/esm/ap-ben-complete-section_4.entry.js +0 -101
- package/dist/lib/esm/ap-ben-notifications-section.entry.js +0 -234
- package/dist/lib/esm/apollo-benefits.js +0 -23
- package/dist/lib/esm/app-globals-65714cca.js +0 -10
- package/dist/lib/esm/async-68e9cad7.js +0 -738
- package/dist/lib/esm/cars-calculator-app.entry.js +0 -51
- package/dist/lib/esm/cars-calculator.service-27826530.js +0 -897
- package/dist/lib/esm/context-consumer.entry.js +0 -25
- package/dist/lib/esm/datorama-akita-c87196a0.js +0 -2545
- package/dist/lib/esm/delay-115d4292.js +0 -200
- package/dist/lib/esm/distinctUntilChanged-bf69e0f8.js +0 -363
- package/dist/lib/esm/dom-utils-109a7d75.js +0 -55
- package/dist/lib/esm/fl-button_2.entry.js +0 -45
- package/dist/lib/esm/fl-dropdown-async_2.entry.js +0 -462
- package/dist/lib/esm/fl-dropdown.entry.js +0 -228
- package/dist/lib/esm/fl-style-guide.entry.js +0 -87
- package/dist/lib/esm/index-19c4d245.js +0 -1703
- package/dist/lib/esm/index.js +0 -1
- package/dist/lib/esm/loader.js +0 -23
- package/dist/lib/esm/location-utils-312665d3.js +0 -226
- package/dist/lib/esm/match-path-4b5c7d98.js +0 -276
- package/dist/lib/esm/polyfills/core-js.js +0 -11
- package/dist/lib/esm/polyfills/css-shim.js +0 -1
- package/dist/lib/esm/polyfills/dom.js +0 -79
- package/dist/lib/esm/polyfills/es5-html-element.js +0 -1
- package/dist/lib/esm/polyfills/index.js +0 -34
- package/dist/lib/esm/polyfills/system.js +0 -6
- package/dist/lib/esm/session.query-0f1c9503.js +0 -1719
- package/dist/lib/esm/stencil-async-content.entry.js +0 -28
- package/dist/lib/esm/stencil-route-link.entry.js +0 -74
- package/dist/lib/esm/stencil-route-switch.entry.js +0 -100
- package/dist/lib/esm/stencil-route-title.entry.js +0 -28
- package/dist/lib/esm/stencil-route.entry.js +0 -93
- package/dist/lib/esm/stencil-router-prompt.entry.js +0 -55
- package/dist/lib/esm/stencil-router-redirect.entry.js +0 -28
- package/dist/lib/esm/stencil-router.entry.js +0 -636
- package/dist/lib/index.cjs.js +0 -1
- package/dist/lib/index.js +0 -1
- package/dist/lib/loader/cdn.js +0 -3
- package/dist/lib/loader/index.cjs.js +0 -3
- package/dist/lib/loader/index.d.ts +0 -13
- package/dist/lib/loader/index.es2017.js +0 -3
- package/dist/lib/loader/index.js +0 -4
- package/dist/lib/loader/package.json +0 -10
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/button/button.css +0 -45
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown/dropdown.css +0 -9
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/dropdown-async/dropdown-async.css +0 -9
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/loading-indicator/loading-indicator.css +0 -141
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/promise-button/promise-button.css +0 -5
- package/dist/lib/node_modules/@flarehr/beacon/dist/collection/components/style-guide/style-guide.css +0 -0
- package/dist/lib/node_modules/@stencil/router/dist/collection/components/route/route.css +0 -3
- package/dist/lib/types/components/cars-calculator-app/api/api-client.d.ts +0 -2
- package/dist/lib/types/components/cars-calculator-app/api/cars-calculator.api.d.ts +0 -99
- package/dist/lib/types/components/cars-calculator-app/cars-calculator-app.d.ts +0 -17
- package/dist/lib/types/components/cars-calculator-app/modal-section/modal-section.d.ts +0 -16
- package/dist/lib/types/components/cars-calculator-app/notifications-section/notifications-section.d.ts +0 -5
- package/dist/lib/types/components/cars-calculator-app/pages/choose-vehicle-section.component.d.ts +0 -23
- package/dist/lib/types/components/cars-calculator-app/pages/complete-section.component.d.ts +0 -5
- package/dist/lib/types/components/cars-calculator-app/pages/cost-breakdown-section.component.d.ts +0 -6
- package/dist/lib/types/components/cars-calculator-app/pages/model-variants-section.component.d.ts +0 -12
- package/dist/lib/types/components/cars-calculator-app/pages/personal-info-section.component.d.ts +0 -10
- package/dist/lib/types/components/cars-calculator-app/pages/quote-result-section.component.d.ts +0 -13
- package/dist/lib/types/components/cars-calculator-app/pages/submit-quote-section.component.d.ts +0 -10
- package/dist/lib/types/components/cars-calculator-app/services/app-configuration.service.d.ts +0 -7
- package/dist/lib/types/components/cars-calculator-app/services/cars-calculator.service.d.ts +0 -11
- package/dist/lib/types/components/cars-calculator-app/services/notifications.service.d.ts +0 -15
- package/dist/lib/types/components/cars-calculator-app/services/notifications.store.d.ts +0 -14
- package/dist/lib/types/components/cars-calculator-app/services/session.query.d.ts +0 -25
- package/dist/lib/types/components/cars-calculator-app/services/session.store.d.ts +0 -77
- package/dist/lib/types/components.d.ts +0 -170
- package/dist/lib/types/global/config.d.ts +0 -2
- package/dist/lib/types/global/main.d.ts +0 -1
- package/dist/lib/types/global/main.dev.d.ts +0 -1
- package/dist/lib/types/index.d.ts +0 -2
- package/dist/lib/types/stencil-public-runtime.d.ts +0 -1555
- package/dist/lib/types/utils/config.d.ts +0 -2
- package/dist/lib/types/utils/index.d.ts +0 -7
- package/dist/lib/types/utils/lazy.d.ts +0 -12
- package/readme.md +0 -1
|
@@ -1,1731 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const datoramaAkita = require('./datorama-akita-31d23240.js');
|
|
4
|
-
|
|
5
|
-
// -------------------------------------------------------------------------------------
|
|
6
|
-
// guards
|
|
7
|
-
// -------------------------------------------------------------------------------------
|
|
8
|
-
/**
|
|
9
|
-
* Returns `true` if the option is an instance of `Some`, `false` otherwise.
|
|
10
|
-
*
|
|
11
|
-
* @example
|
|
12
|
-
* import { some, none, isSome } from 'fp-ts/Option'
|
|
13
|
-
*
|
|
14
|
-
* assert.strictEqual(isSome(some(1)), true)
|
|
15
|
-
* assert.strictEqual(isSome(none), false)
|
|
16
|
-
*
|
|
17
|
-
* @category guards
|
|
18
|
-
* @since 2.0.0
|
|
19
|
-
*/
|
|
20
|
-
var isSome = function (fa) { return fa._tag === 'Some'; };
|
|
21
|
-
/**
|
|
22
|
-
* Returns `true` if the option is `None`, `false` otherwise.
|
|
23
|
-
*
|
|
24
|
-
* @example
|
|
25
|
-
* import { some, none, isNone } from 'fp-ts/Option'
|
|
26
|
-
*
|
|
27
|
-
* assert.strictEqual(isNone(some(1)), false)
|
|
28
|
-
* assert.strictEqual(isNone(none), true)
|
|
29
|
-
*
|
|
30
|
-
* @category guards
|
|
31
|
-
* @since 2.0.0
|
|
32
|
-
*/
|
|
33
|
-
var isNone = function (fa) { return fa._tag === 'None'; };
|
|
34
|
-
// -------------------------------------------------------------------------------------
|
|
35
|
-
// constructors
|
|
36
|
-
// -------------------------------------------------------------------------------------
|
|
37
|
-
/**
|
|
38
|
-
* `None` doesn't have a constructor, instead you can use it directly as a value. Represents a missing value.
|
|
39
|
-
*
|
|
40
|
-
* @category constructors
|
|
41
|
-
* @since 2.0.0
|
|
42
|
-
*/
|
|
43
|
-
var none = { _tag: 'None' };
|
|
44
|
-
/**
|
|
45
|
-
* Constructs a `Some`. Represents an optional value that exists.
|
|
46
|
-
*
|
|
47
|
-
* @category constructors
|
|
48
|
-
* @since 2.0.0
|
|
49
|
-
*/
|
|
50
|
-
var some = function (a) { return ({ _tag: 'Some', value: a }); };
|
|
51
|
-
/**
|
|
52
|
-
* Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise
|
|
53
|
-
* returns the value wrapped in a `Some`.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* import { none, some, fromNullable } from 'fp-ts/Option'
|
|
57
|
-
*
|
|
58
|
-
* assert.deepStrictEqual(fromNullable(undefined), none)
|
|
59
|
-
* assert.deepStrictEqual(fromNullable(null), none)
|
|
60
|
-
* assert.deepStrictEqual(fromNullable(1), some(1))
|
|
61
|
-
*
|
|
62
|
-
* @category constructors
|
|
63
|
-
* @since 2.0.0
|
|
64
|
-
*/
|
|
65
|
-
function fromNullable(a) {
|
|
66
|
-
return a == null ? none : some(a);
|
|
67
|
-
}
|
|
68
|
-
// -------------------------------------------------------------------------------------
|
|
69
|
-
// destructors
|
|
70
|
-
// -------------------------------------------------------------------------------------
|
|
71
|
-
/**
|
|
72
|
-
* Takes a (lazy) default value, a function, and an `Option` value, if the `Option` value is `None` the default value is
|
|
73
|
-
* returned, otherwise the function is applied to the value inside the `Some` and the result is returned.
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* import { some, none, fold } from 'fp-ts/Option'
|
|
77
|
-
* import { pipe } from 'fp-ts/function'
|
|
78
|
-
*
|
|
79
|
-
* assert.strictEqual(
|
|
80
|
-
* pipe(
|
|
81
|
-
* some(1),
|
|
82
|
-
* fold(() => 'a none', a => `a some containing ${a}`)
|
|
83
|
-
* ),
|
|
84
|
-
* 'a some containing 1'
|
|
85
|
-
* )
|
|
86
|
-
*
|
|
87
|
-
* assert.strictEqual(
|
|
88
|
-
* pipe(
|
|
89
|
-
* none,
|
|
90
|
-
* fold(() => 'a none', a => `a some containing ${a}`)
|
|
91
|
-
* ),
|
|
92
|
-
* 'a none'
|
|
93
|
-
* )
|
|
94
|
-
*
|
|
95
|
-
* @category destructors
|
|
96
|
-
* @since 2.0.0
|
|
97
|
-
*/
|
|
98
|
-
function fold(onNone, onSome) {
|
|
99
|
-
return function (ma) { return (isNone(ma) ? onNone() : onSome(ma.value)); };
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Less strict version of [`getOrElse`](#getOrElse).
|
|
103
|
-
*
|
|
104
|
-
* @category destructors
|
|
105
|
-
* @since 2.6.0
|
|
106
|
-
*/
|
|
107
|
-
var getOrElseW = function (onNone) { return function (ma) { return (isNone(ma) ? onNone() : ma.value); }; };
|
|
108
|
-
/**
|
|
109
|
-
* Extracts the value out of the structure, if it exists. Otherwise returns the given default value
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* import { some, none, getOrElse } from 'fp-ts/Option'
|
|
113
|
-
* import { pipe } from 'fp-ts/function'
|
|
114
|
-
*
|
|
115
|
-
* assert.strictEqual(
|
|
116
|
-
* pipe(
|
|
117
|
-
* some(1),
|
|
118
|
-
* getOrElse(() => 0)
|
|
119
|
-
* ),
|
|
120
|
-
* 1
|
|
121
|
-
* )
|
|
122
|
-
* assert.strictEqual(
|
|
123
|
-
* pipe(
|
|
124
|
-
* none,
|
|
125
|
-
* getOrElse(() => 0)
|
|
126
|
-
* ),
|
|
127
|
-
* 0
|
|
128
|
-
* )
|
|
129
|
-
*
|
|
130
|
-
* @category destructors
|
|
131
|
-
* @since 2.0.0
|
|
132
|
-
*/
|
|
133
|
-
var getOrElse = getOrElseW;
|
|
134
|
-
|
|
135
|
-
function createCommonjsModule(fn, basedir, module) {
|
|
136
|
-
return module = {
|
|
137
|
-
path: basedir,
|
|
138
|
-
exports: {},
|
|
139
|
-
require: function (path, base) {
|
|
140
|
-
return commonjsRequire();
|
|
141
|
-
}
|
|
142
|
-
}, fn(module, module.exports), module.exports;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
function commonjsRequire () {
|
|
146
|
-
throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs');
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
var _function = createCommonjsModule(function (module, exports) {
|
|
150
|
-
/**
|
|
151
|
-
* @since 2.0.0
|
|
152
|
-
*/
|
|
153
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
154
|
-
exports.bindTo_ = exports.bind_ = exports.hole = exports.pipe = exports.untupled = exports.tupled = exports.absurd = exports.decrement = exports.increment = exports.tuple = exports.flow = exports.flip = exports.constVoid = exports.constUndefined = exports.constNull = exports.constFalse = exports.constTrue = exports.constant = exports.not = exports.unsafeCoerce = exports.identity = void 0;
|
|
155
|
-
/**
|
|
156
|
-
* @since 2.0.0
|
|
157
|
-
*/
|
|
158
|
-
function identity(a) {
|
|
159
|
-
return a;
|
|
160
|
-
}
|
|
161
|
-
exports.identity = identity;
|
|
162
|
-
/**
|
|
163
|
-
* @since 2.0.0
|
|
164
|
-
*/
|
|
165
|
-
exports.unsafeCoerce = identity;
|
|
166
|
-
/**
|
|
167
|
-
* @since 2.0.0
|
|
168
|
-
*/
|
|
169
|
-
function not(predicate) {
|
|
170
|
-
return function (a) { return !predicate(a); };
|
|
171
|
-
}
|
|
172
|
-
exports.not = not;
|
|
173
|
-
/**
|
|
174
|
-
* @since 2.0.0
|
|
175
|
-
*/
|
|
176
|
-
function constant(a) {
|
|
177
|
-
return function () { return a; };
|
|
178
|
-
}
|
|
179
|
-
exports.constant = constant;
|
|
180
|
-
/**
|
|
181
|
-
* A thunk that returns always `true`.
|
|
182
|
-
*
|
|
183
|
-
* @since 2.0.0
|
|
184
|
-
*/
|
|
185
|
-
exports.constTrue =
|
|
186
|
-
/*#__PURE__*/
|
|
187
|
-
constant(true);
|
|
188
|
-
/**
|
|
189
|
-
* A thunk that returns always `false`.
|
|
190
|
-
*
|
|
191
|
-
* @since 2.0.0
|
|
192
|
-
*/
|
|
193
|
-
exports.constFalse =
|
|
194
|
-
/*#__PURE__*/
|
|
195
|
-
constant(false);
|
|
196
|
-
/**
|
|
197
|
-
* A thunk that returns always `null`.
|
|
198
|
-
*
|
|
199
|
-
* @since 2.0.0
|
|
200
|
-
*/
|
|
201
|
-
exports.constNull =
|
|
202
|
-
/*#__PURE__*/
|
|
203
|
-
constant(null);
|
|
204
|
-
/**
|
|
205
|
-
* A thunk that returns always `undefined`.
|
|
206
|
-
*
|
|
207
|
-
* @since 2.0.0
|
|
208
|
-
*/
|
|
209
|
-
exports.constUndefined =
|
|
210
|
-
/*#__PURE__*/
|
|
211
|
-
constant(undefined);
|
|
212
|
-
/**
|
|
213
|
-
* A thunk that returns always `void`.
|
|
214
|
-
*
|
|
215
|
-
* @since 2.0.0
|
|
216
|
-
*/
|
|
217
|
-
exports.constVoid = exports.constUndefined;
|
|
218
|
-
// TODO: remove in v3
|
|
219
|
-
/**
|
|
220
|
-
* Flips the order of the arguments of a function of two arguments.
|
|
221
|
-
*
|
|
222
|
-
* @since 2.0.0
|
|
223
|
-
*/
|
|
224
|
-
function flip(f) {
|
|
225
|
-
return function (b, a) { return f(a, b); };
|
|
226
|
-
}
|
|
227
|
-
exports.flip = flip;
|
|
228
|
-
function flow(ab, bc, cd, de, ef, fg, gh, hi, ij) {
|
|
229
|
-
switch (arguments.length) {
|
|
230
|
-
case 1:
|
|
231
|
-
return ab;
|
|
232
|
-
case 2:
|
|
233
|
-
return function () {
|
|
234
|
-
return bc(ab.apply(this, arguments));
|
|
235
|
-
};
|
|
236
|
-
case 3:
|
|
237
|
-
return function () {
|
|
238
|
-
return cd(bc(ab.apply(this, arguments)));
|
|
239
|
-
};
|
|
240
|
-
case 4:
|
|
241
|
-
return function () {
|
|
242
|
-
return de(cd(bc(ab.apply(this, arguments))));
|
|
243
|
-
};
|
|
244
|
-
case 5:
|
|
245
|
-
return function () {
|
|
246
|
-
return ef(de(cd(bc(ab.apply(this, arguments)))));
|
|
247
|
-
};
|
|
248
|
-
case 6:
|
|
249
|
-
return function () {
|
|
250
|
-
return fg(ef(de(cd(bc(ab.apply(this, arguments))))));
|
|
251
|
-
};
|
|
252
|
-
case 7:
|
|
253
|
-
return function () {
|
|
254
|
-
return gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))));
|
|
255
|
-
};
|
|
256
|
-
case 8:
|
|
257
|
-
return function () {
|
|
258
|
-
return hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments))))))));
|
|
259
|
-
};
|
|
260
|
-
case 9:
|
|
261
|
-
return function () {
|
|
262
|
-
return ij(hi(gh(fg(ef(de(cd(bc(ab.apply(this, arguments)))))))));
|
|
263
|
-
};
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
exports.flow = flow;
|
|
268
|
-
/**
|
|
269
|
-
* @since 2.0.0
|
|
270
|
-
*/
|
|
271
|
-
function tuple() {
|
|
272
|
-
var t = [];
|
|
273
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
274
|
-
t[_i] = arguments[_i];
|
|
275
|
-
}
|
|
276
|
-
return t;
|
|
277
|
-
}
|
|
278
|
-
exports.tuple = tuple;
|
|
279
|
-
/**
|
|
280
|
-
* @since 2.0.0
|
|
281
|
-
*/
|
|
282
|
-
function increment(n) {
|
|
283
|
-
return n + 1;
|
|
284
|
-
}
|
|
285
|
-
exports.increment = increment;
|
|
286
|
-
/**
|
|
287
|
-
* @since 2.0.0
|
|
288
|
-
*/
|
|
289
|
-
function decrement(n) {
|
|
290
|
-
return n - 1;
|
|
291
|
-
}
|
|
292
|
-
exports.decrement = decrement;
|
|
293
|
-
/**
|
|
294
|
-
* @since 2.0.0
|
|
295
|
-
*/
|
|
296
|
-
function absurd(_) {
|
|
297
|
-
throw new Error('Called `absurd` function which should be uncallable');
|
|
298
|
-
}
|
|
299
|
-
exports.absurd = absurd;
|
|
300
|
-
/**
|
|
301
|
-
* Creates a tupled version of this function: instead of `n` arguments, it accepts a single tuple argument.
|
|
302
|
-
*
|
|
303
|
-
* @example
|
|
304
|
-
* import { tupled } from 'fp-ts/function'
|
|
305
|
-
*
|
|
306
|
-
* const add = tupled((x: number, y: number): number => x + y)
|
|
307
|
-
*
|
|
308
|
-
* assert.strictEqual(add([1, 2]), 3)
|
|
309
|
-
*
|
|
310
|
-
* @since 2.4.0
|
|
311
|
-
*/
|
|
312
|
-
function tupled(f) {
|
|
313
|
-
return function (a) { return f.apply(void 0, a); };
|
|
314
|
-
}
|
|
315
|
-
exports.tupled = tupled;
|
|
316
|
-
/**
|
|
317
|
-
* Inverse function of `tupled`
|
|
318
|
-
*
|
|
319
|
-
* @since 2.4.0
|
|
320
|
-
*/
|
|
321
|
-
function untupled(f) {
|
|
322
|
-
return function () {
|
|
323
|
-
var a = [];
|
|
324
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
325
|
-
a[_i] = arguments[_i];
|
|
326
|
-
}
|
|
327
|
-
return f(a);
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
exports.untupled = untupled;
|
|
331
|
-
function pipe(a, ab, bc, cd, de, ef, fg, gh, hi, ij, jk, kl, lm, mn, no, op, pq, qr, rs, st) {
|
|
332
|
-
switch (arguments.length) {
|
|
333
|
-
case 1:
|
|
334
|
-
return a;
|
|
335
|
-
case 2:
|
|
336
|
-
return ab(a);
|
|
337
|
-
case 3:
|
|
338
|
-
return bc(ab(a));
|
|
339
|
-
case 4:
|
|
340
|
-
return cd(bc(ab(a)));
|
|
341
|
-
case 5:
|
|
342
|
-
return de(cd(bc(ab(a))));
|
|
343
|
-
case 6:
|
|
344
|
-
return ef(de(cd(bc(ab(a)))));
|
|
345
|
-
case 7:
|
|
346
|
-
return fg(ef(de(cd(bc(ab(a))))));
|
|
347
|
-
case 8:
|
|
348
|
-
return gh(fg(ef(de(cd(bc(ab(a)))))));
|
|
349
|
-
case 9:
|
|
350
|
-
return hi(gh(fg(ef(de(cd(bc(ab(a))))))));
|
|
351
|
-
case 10:
|
|
352
|
-
return ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))));
|
|
353
|
-
case 11:
|
|
354
|
-
return jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))));
|
|
355
|
-
case 12:
|
|
356
|
-
return kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))));
|
|
357
|
-
case 13:
|
|
358
|
-
return lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))));
|
|
359
|
-
case 14:
|
|
360
|
-
return mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))));
|
|
361
|
-
case 15:
|
|
362
|
-
return no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))));
|
|
363
|
-
case 16:
|
|
364
|
-
return op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))));
|
|
365
|
-
case 17:
|
|
366
|
-
return pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))));
|
|
367
|
-
case 18:
|
|
368
|
-
return qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))));
|
|
369
|
-
case 19:
|
|
370
|
-
return rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a))))))))))))))))));
|
|
371
|
-
case 20:
|
|
372
|
-
return st(rs(qr(pq(op(no(mn(lm(kl(jk(ij(hi(gh(fg(ef(de(cd(bc(ab(a)))))))))))))))))));
|
|
373
|
-
}
|
|
374
|
-
return;
|
|
375
|
-
}
|
|
376
|
-
exports.pipe = pipe;
|
|
377
|
-
/**
|
|
378
|
-
* Type hole simulation
|
|
379
|
-
*
|
|
380
|
-
* @since 2.7.0
|
|
381
|
-
*/
|
|
382
|
-
exports.hole = absurd;
|
|
383
|
-
/**
|
|
384
|
-
* @internal
|
|
385
|
-
*/
|
|
386
|
-
var bind_ = function (a, name, b) {
|
|
387
|
-
var _a;
|
|
388
|
-
return Object.assign({}, a, (_a = {}, _a[name] = b, _a));
|
|
389
|
-
};
|
|
390
|
-
exports.bind_ = bind_;
|
|
391
|
-
/**
|
|
392
|
-
* @internal
|
|
393
|
-
*/
|
|
394
|
-
var bindTo_ = function (name) { return function (b) {
|
|
395
|
-
var _a;
|
|
396
|
-
return (_a = {}, _a[name] = b, _a);
|
|
397
|
-
}; };
|
|
398
|
-
exports.bindTo_ = bindTo_;
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
var Option = createCommonjsModule(function (module, exports) {
|
|
402
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
403
|
-
exports.getApplySemigroup = exports.getOrd = exports.getEq = exports.getShow = exports.URI = exports.wilt = exports.wither = exports.sequence = exports.traverse = exports.partitionMap = exports.partition = exports.filterMap = exports.filter = exports.separate = exports.compact = exports.reduceRight = exports.foldMap = exports.reduce = exports.duplicate = exports.extend = exports.throwError = exports.zero = exports.alt = exports.altW = exports.flatten = exports.chainFirst = exports.chain = exports.of = exports.apSecond = exports.apFirst = exports.ap = exports.map = exports.chainNullableK = exports.mapNullable = exports.fromNullableK = exports.getOrElse = exports.getOrElseW = exports.toUndefined = exports.toNullable = exports.fold = exports.fromEither = exports.getRight = exports.getLeft = exports.tryCatch = exports.fromPredicate = exports.fromNullable = exports.some = exports.none = exports.isNone = exports.isSome = void 0;
|
|
404
|
-
exports.sequenceArray = exports.traverseArray = exports.traverseArrayWithIndex = exports.apS = exports.bind = exports.bindTo = exports.Do = exports.getRefinement = exports.exists = exports.elem = exports.option = exports.MonadThrow = exports.Witherable = exports.Traversable = exports.Filterable = exports.Compactable = exports.Extend = exports.Alternative = exports.Alt = exports.Foldable = exports.Monad = exports.Applicative = exports.Functor = exports.getMonoid = exports.getLastMonoid = exports.getFirstMonoid = exports.getApplyMonoid = void 0;
|
|
405
|
-
|
|
406
|
-
// -------------------------------------------------------------------------------------
|
|
407
|
-
// guards
|
|
408
|
-
// -------------------------------------------------------------------------------------
|
|
409
|
-
/**
|
|
410
|
-
* Returns `true` if the option is an instance of `Some`, `false` otherwise.
|
|
411
|
-
*
|
|
412
|
-
* @example
|
|
413
|
-
* import { some, none, isSome } from 'fp-ts/Option'
|
|
414
|
-
*
|
|
415
|
-
* assert.strictEqual(isSome(some(1)), true)
|
|
416
|
-
* assert.strictEqual(isSome(none), false)
|
|
417
|
-
*
|
|
418
|
-
* @category guards
|
|
419
|
-
* @since 2.0.0
|
|
420
|
-
*/
|
|
421
|
-
var isSome = function (fa) { return fa._tag === 'Some'; };
|
|
422
|
-
exports.isSome = isSome;
|
|
423
|
-
/**
|
|
424
|
-
* Returns `true` if the option is `None`, `false` otherwise.
|
|
425
|
-
*
|
|
426
|
-
* @example
|
|
427
|
-
* import { some, none, isNone } from 'fp-ts/Option'
|
|
428
|
-
*
|
|
429
|
-
* assert.strictEqual(isNone(some(1)), false)
|
|
430
|
-
* assert.strictEqual(isNone(none), true)
|
|
431
|
-
*
|
|
432
|
-
* @category guards
|
|
433
|
-
* @since 2.0.0
|
|
434
|
-
*/
|
|
435
|
-
var isNone = function (fa) { return fa._tag === 'None'; };
|
|
436
|
-
exports.isNone = isNone;
|
|
437
|
-
// -------------------------------------------------------------------------------------
|
|
438
|
-
// constructors
|
|
439
|
-
// -------------------------------------------------------------------------------------
|
|
440
|
-
/**
|
|
441
|
-
* `None` doesn't have a constructor, instead you can use it directly as a value. Represents a missing value.
|
|
442
|
-
*
|
|
443
|
-
* @category constructors
|
|
444
|
-
* @since 2.0.0
|
|
445
|
-
*/
|
|
446
|
-
exports.none = { _tag: 'None' };
|
|
447
|
-
/**
|
|
448
|
-
* Constructs a `Some`. Represents an optional value that exists.
|
|
449
|
-
*
|
|
450
|
-
* @category constructors
|
|
451
|
-
* @since 2.0.0
|
|
452
|
-
*/
|
|
453
|
-
var some = function (a) { return ({ _tag: 'Some', value: a }); };
|
|
454
|
-
exports.some = some;
|
|
455
|
-
/**
|
|
456
|
-
* Constructs a new `Option` from a nullable type. If the value is `null` or `undefined`, returns `None`, otherwise
|
|
457
|
-
* returns the value wrapped in a `Some`.
|
|
458
|
-
*
|
|
459
|
-
* @example
|
|
460
|
-
* import { none, some, fromNullable } from 'fp-ts/Option'
|
|
461
|
-
*
|
|
462
|
-
* assert.deepStrictEqual(fromNullable(undefined), none)
|
|
463
|
-
* assert.deepStrictEqual(fromNullable(null), none)
|
|
464
|
-
* assert.deepStrictEqual(fromNullable(1), some(1))
|
|
465
|
-
*
|
|
466
|
-
* @category constructors
|
|
467
|
-
* @since 2.0.0
|
|
468
|
-
*/
|
|
469
|
-
function fromNullable(a) {
|
|
470
|
-
return a == null ? exports.none : exports.some(a);
|
|
471
|
-
}
|
|
472
|
-
exports.fromNullable = fromNullable;
|
|
473
|
-
function fromPredicate(predicate) {
|
|
474
|
-
return function (a) { return (predicate(a) ? exports.some(a) : exports.none); };
|
|
475
|
-
}
|
|
476
|
-
exports.fromPredicate = fromPredicate;
|
|
477
|
-
/**
|
|
478
|
-
* Transforms an exception into an `Option`. If `f` throws, returns `None`, otherwise returns the output wrapped in a
|
|
479
|
-
* `Some`.
|
|
480
|
-
*
|
|
481
|
-
* @example
|
|
482
|
-
* import { none, some, tryCatch } from 'fp-ts/Option'
|
|
483
|
-
*
|
|
484
|
-
* assert.deepStrictEqual(
|
|
485
|
-
* tryCatch(() => {
|
|
486
|
-
* throw new Error()
|
|
487
|
-
* }),
|
|
488
|
-
* none
|
|
489
|
-
* )
|
|
490
|
-
* assert.deepStrictEqual(tryCatch(() => 1), some(1))
|
|
491
|
-
*
|
|
492
|
-
* @category constructors
|
|
493
|
-
* @since 2.0.0
|
|
494
|
-
*/
|
|
495
|
-
function tryCatch(f) {
|
|
496
|
-
try {
|
|
497
|
-
return exports.some(f());
|
|
498
|
-
}
|
|
499
|
-
catch (e) {
|
|
500
|
-
return exports.none;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
exports.tryCatch = tryCatch;
|
|
504
|
-
/**
|
|
505
|
-
* Returns the `Left` value of an `Either` if possible.
|
|
506
|
-
*
|
|
507
|
-
* @example
|
|
508
|
-
* import { getLeft, none, some } from 'fp-ts/Option'
|
|
509
|
-
* import { right, left } from 'fp-ts/Either'
|
|
510
|
-
*
|
|
511
|
-
* assert.deepStrictEqual(getLeft(right(1)), none)
|
|
512
|
-
* assert.deepStrictEqual(getLeft(left('a')), some('a'))
|
|
513
|
-
*
|
|
514
|
-
* @category constructors
|
|
515
|
-
* @since 2.0.0
|
|
516
|
-
*/
|
|
517
|
-
function getLeft(ma) {
|
|
518
|
-
return ma._tag === 'Right' ? exports.none : exports.some(ma.left);
|
|
519
|
-
}
|
|
520
|
-
exports.getLeft = getLeft;
|
|
521
|
-
/**
|
|
522
|
-
* Returns the `Right` value of an `Either` if possible.
|
|
523
|
-
*
|
|
524
|
-
* @example
|
|
525
|
-
* import { getRight, none, some } from 'fp-ts/Option'
|
|
526
|
-
* import { right, left } from 'fp-ts/Either'
|
|
527
|
-
*
|
|
528
|
-
* assert.deepStrictEqual(getRight(right(1)), some(1))
|
|
529
|
-
* assert.deepStrictEqual(getRight(left('a')), none)
|
|
530
|
-
*
|
|
531
|
-
* @category constructors
|
|
532
|
-
* @since 2.0.0
|
|
533
|
-
*/
|
|
534
|
-
function getRight(ma) {
|
|
535
|
-
return ma._tag === 'Left' ? exports.none : exports.some(ma.right);
|
|
536
|
-
}
|
|
537
|
-
exports.getRight = getRight;
|
|
538
|
-
/**
|
|
539
|
-
* Transforms an `Either` to an `Option` discarding the error.
|
|
540
|
-
*
|
|
541
|
-
* Alias of [getRight](#getRight)
|
|
542
|
-
*
|
|
543
|
-
* Derivable from `MonadThrow`.
|
|
544
|
-
*
|
|
545
|
-
* @category constructors
|
|
546
|
-
* @since 2.0.0
|
|
547
|
-
*/
|
|
548
|
-
exports.fromEither = getRight;
|
|
549
|
-
// -------------------------------------------------------------------------------------
|
|
550
|
-
// destructors
|
|
551
|
-
// -------------------------------------------------------------------------------------
|
|
552
|
-
/**
|
|
553
|
-
* Takes a (lazy) default value, a function, and an `Option` value, if the `Option` value is `None` the default value is
|
|
554
|
-
* returned, otherwise the function is applied to the value inside the `Some` and the result is returned.
|
|
555
|
-
*
|
|
556
|
-
* @example
|
|
557
|
-
* import { some, none, fold } from 'fp-ts/Option'
|
|
558
|
-
* import { pipe } from 'fp-ts/function'
|
|
559
|
-
*
|
|
560
|
-
* assert.strictEqual(
|
|
561
|
-
* pipe(
|
|
562
|
-
* some(1),
|
|
563
|
-
* fold(() => 'a none', a => `a some containing ${a}`)
|
|
564
|
-
* ),
|
|
565
|
-
* 'a some containing 1'
|
|
566
|
-
* )
|
|
567
|
-
*
|
|
568
|
-
* assert.strictEqual(
|
|
569
|
-
* pipe(
|
|
570
|
-
* none,
|
|
571
|
-
* fold(() => 'a none', a => `a some containing ${a}`)
|
|
572
|
-
* ),
|
|
573
|
-
* 'a none'
|
|
574
|
-
* )
|
|
575
|
-
*
|
|
576
|
-
* @category destructors
|
|
577
|
-
* @since 2.0.0
|
|
578
|
-
*/
|
|
579
|
-
function fold(onNone, onSome) {
|
|
580
|
-
return function (ma) { return (exports.isNone(ma) ? onNone() : onSome(ma.value)); };
|
|
581
|
-
}
|
|
582
|
-
exports.fold = fold;
|
|
583
|
-
/**
|
|
584
|
-
* Extracts the value out of the structure, if it exists. Otherwise returns `null`.
|
|
585
|
-
*
|
|
586
|
-
* @example
|
|
587
|
-
* import { some, none, toNullable } from 'fp-ts/Option'
|
|
588
|
-
* import { pipe } from 'fp-ts/function'
|
|
589
|
-
*
|
|
590
|
-
* assert.strictEqual(
|
|
591
|
-
* pipe(
|
|
592
|
-
* some(1),
|
|
593
|
-
* toNullable
|
|
594
|
-
* ),
|
|
595
|
-
* 1
|
|
596
|
-
* )
|
|
597
|
-
* assert.strictEqual(
|
|
598
|
-
* pipe(
|
|
599
|
-
* none,
|
|
600
|
-
* toNullable
|
|
601
|
-
* ),
|
|
602
|
-
* null
|
|
603
|
-
* )
|
|
604
|
-
*
|
|
605
|
-
* @category destructors
|
|
606
|
-
* @since 2.0.0
|
|
607
|
-
*/
|
|
608
|
-
function toNullable(ma) {
|
|
609
|
-
return exports.isNone(ma) ? null : ma.value;
|
|
610
|
-
}
|
|
611
|
-
exports.toNullable = toNullable;
|
|
612
|
-
/**
|
|
613
|
-
* Extracts the value out of the structure, if it exists. Otherwise returns `undefined`.
|
|
614
|
-
*
|
|
615
|
-
* @example
|
|
616
|
-
* import { some, none, toUndefined } from 'fp-ts/Option'
|
|
617
|
-
* import { pipe } from 'fp-ts/function'
|
|
618
|
-
*
|
|
619
|
-
* assert.strictEqual(
|
|
620
|
-
* pipe(
|
|
621
|
-
* some(1),
|
|
622
|
-
* toUndefined
|
|
623
|
-
* ),
|
|
624
|
-
* 1
|
|
625
|
-
* )
|
|
626
|
-
* assert.strictEqual(
|
|
627
|
-
* pipe(
|
|
628
|
-
* none,
|
|
629
|
-
* toUndefined
|
|
630
|
-
* ),
|
|
631
|
-
* undefined
|
|
632
|
-
* )
|
|
633
|
-
*
|
|
634
|
-
* @category destructors
|
|
635
|
-
* @since 2.0.0
|
|
636
|
-
*/
|
|
637
|
-
function toUndefined(ma) {
|
|
638
|
-
return exports.isNone(ma) ? undefined : ma.value;
|
|
639
|
-
}
|
|
640
|
-
exports.toUndefined = toUndefined;
|
|
641
|
-
/**
|
|
642
|
-
* Less strict version of [`getOrElse`](#getOrElse).
|
|
643
|
-
*
|
|
644
|
-
* @category destructors
|
|
645
|
-
* @since 2.6.0
|
|
646
|
-
*/
|
|
647
|
-
var getOrElseW = function (onNone) { return function (ma) { return (exports.isNone(ma) ? onNone() : ma.value); }; };
|
|
648
|
-
exports.getOrElseW = getOrElseW;
|
|
649
|
-
/**
|
|
650
|
-
* Extracts the value out of the structure, if it exists. Otherwise returns the given default value
|
|
651
|
-
*
|
|
652
|
-
* @example
|
|
653
|
-
* import { some, none, getOrElse } from 'fp-ts/Option'
|
|
654
|
-
* import { pipe } from 'fp-ts/function'
|
|
655
|
-
*
|
|
656
|
-
* assert.strictEqual(
|
|
657
|
-
* pipe(
|
|
658
|
-
* some(1),
|
|
659
|
-
* getOrElse(() => 0)
|
|
660
|
-
* ),
|
|
661
|
-
* 1
|
|
662
|
-
* )
|
|
663
|
-
* assert.strictEqual(
|
|
664
|
-
* pipe(
|
|
665
|
-
* none,
|
|
666
|
-
* getOrElse(() => 0)
|
|
667
|
-
* ),
|
|
668
|
-
* 0
|
|
669
|
-
* )
|
|
670
|
-
*
|
|
671
|
-
* @category destructors
|
|
672
|
-
* @since 2.0.0
|
|
673
|
-
*/
|
|
674
|
-
exports.getOrElse = exports.getOrElseW;
|
|
675
|
-
// -------------------------------------------------------------------------------------
|
|
676
|
-
// combinators
|
|
677
|
-
// -------------------------------------------------------------------------------------
|
|
678
|
-
/**
|
|
679
|
-
* Returns a *smart constructor* from a function that returns a nullable value.
|
|
680
|
-
*
|
|
681
|
-
* @example
|
|
682
|
-
* import { fromNullableK, none, some } from 'fp-ts/Option'
|
|
683
|
-
*
|
|
684
|
-
* const f = (s: string): number | undefined => {
|
|
685
|
-
* const n = parseFloat(s)
|
|
686
|
-
* return isNaN(n) ? undefined : n
|
|
687
|
-
* }
|
|
688
|
-
*
|
|
689
|
-
* const g = fromNullableK(f)
|
|
690
|
-
*
|
|
691
|
-
* assert.deepStrictEqual(g('1'), some(1))
|
|
692
|
-
* assert.deepStrictEqual(g('a'), none)
|
|
693
|
-
*
|
|
694
|
-
* @category combinators
|
|
695
|
-
* @since 2.9.0
|
|
696
|
-
*/
|
|
697
|
-
function fromNullableK(f) {
|
|
698
|
-
return function () {
|
|
699
|
-
var a = [];
|
|
700
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
701
|
-
a[_i] = arguments[_i];
|
|
702
|
-
}
|
|
703
|
-
return fromNullable(f.apply(void 0, a));
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
exports.fromNullableK = fromNullableK;
|
|
707
|
-
/**
|
|
708
|
-
* @category combinators
|
|
709
|
-
* @since 2.0.0
|
|
710
|
-
* @deprecated
|
|
711
|
-
*/
|
|
712
|
-
exports.mapNullable = chainNullableK;
|
|
713
|
-
/**
|
|
714
|
-
* This is `chain` + `fromNullable`, useful when working with optional values.
|
|
715
|
-
*
|
|
716
|
-
* @example
|
|
717
|
-
* import { some, none, fromNullable, chainNullableK } from 'fp-ts/Option'
|
|
718
|
-
* import { pipe } from 'fp-ts/function'
|
|
719
|
-
*
|
|
720
|
-
* interface Employee {
|
|
721
|
-
* company?: {
|
|
722
|
-
* address?: {
|
|
723
|
-
* street?: {
|
|
724
|
-
* name?: string
|
|
725
|
-
* }
|
|
726
|
-
* }
|
|
727
|
-
* }
|
|
728
|
-
* }
|
|
729
|
-
*
|
|
730
|
-
* const employee1: Employee = { company: { address: { street: { name: 'high street' } } } }
|
|
731
|
-
*
|
|
732
|
-
* assert.deepStrictEqual(
|
|
733
|
-
* pipe(
|
|
734
|
-
* fromNullable(employee1.company),
|
|
735
|
-
* chainNullableK(company => company.address),
|
|
736
|
-
* chainNullableK(address => address.street),
|
|
737
|
-
* chainNullableK(street => street.name)
|
|
738
|
-
* ),
|
|
739
|
-
* some('high street')
|
|
740
|
-
* )
|
|
741
|
-
*
|
|
742
|
-
* const employee2: Employee = { company: { address: { street: {} } } }
|
|
743
|
-
*
|
|
744
|
-
* assert.deepStrictEqual(
|
|
745
|
-
* pipe(
|
|
746
|
-
* fromNullable(employee2.company),
|
|
747
|
-
* chainNullableK(company => company.address),
|
|
748
|
-
* chainNullableK(address => address.street),
|
|
749
|
-
* chainNullableK(street => street.name)
|
|
750
|
-
* ),
|
|
751
|
-
* none
|
|
752
|
-
* )
|
|
753
|
-
*
|
|
754
|
-
* @category combinators
|
|
755
|
-
* @since 2.9.0
|
|
756
|
-
*/
|
|
757
|
-
function chainNullableK(f) {
|
|
758
|
-
return function (ma) { return (exports.isNone(ma) ? exports.none : fromNullable(f(ma.value))); };
|
|
759
|
-
}
|
|
760
|
-
exports.chainNullableK = chainNullableK;
|
|
761
|
-
// -------------------------------------------------------------------------------------
|
|
762
|
-
// non-pipeables
|
|
763
|
-
// -------------------------------------------------------------------------------------
|
|
764
|
-
var map_ = function (fa, f) { return _function.pipe(fa, exports.map(f)); };
|
|
765
|
-
var ap_ = function (fab, fa) { return _function.pipe(fab, exports.ap(fa)); };
|
|
766
|
-
var chain_ = function (ma, f) { return _function.pipe(ma, exports.chain(f)); };
|
|
767
|
-
var reduce_ = function (fa, b, f) { return _function.pipe(fa, exports.reduce(b, f)); };
|
|
768
|
-
var foldMap_ = function (M) {
|
|
769
|
-
var foldMapM = exports.foldMap(M);
|
|
770
|
-
return function (fa, f) { return _function.pipe(fa, foldMapM(f)); };
|
|
771
|
-
};
|
|
772
|
-
var reduceRight_ = function (fa, b, f) { return _function.pipe(fa, exports.reduceRight(b, f)); };
|
|
773
|
-
var traverse_ = function (F) {
|
|
774
|
-
var traverseF = exports.traverse(F);
|
|
775
|
-
return function (ta, f) { return _function.pipe(ta, traverseF(f)); };
|
|
776
|
-
};
|
|
777
|
-
/* istanbul ignore next */
|
|
778
|
-
var alt_ = function (fa, that) { return _function.pipe(fa, exports.alt(that)); };
|
|
779
|
-
var filter_ = function (fa, predicate) {
|
|
780
|
-
return _function.pipe(fa, exports.filter(predicate));
|
|
781
|
-
};
|
|
782
|
-
/* istanbul ignore next */
|
|
783
|
-
var filterMap_ = function (fa, f) { return _function.pipe(fa, exports.filterMap(f)); };
|
|
784
|
-
/* istanbul ignore next */
|
|
785
|
-
var extend_ = function (wa, f) { return _function.pipe(wa, exports.extend(f)); };
|
|
786
|
-
/* istanbul ignore next */
|
|
787
|
-
var partition_ = function (fa, predicate) { return _function.pipe(fa, exports.partition(predicate)); };
|
|
788
|
-
/* istanbul ignore next */
|
|
789
|
-
var partitionMap_ = function (fa, f) { return _function.pipe(fa, exports.partitionMap(f)); };
|
|
790
|
-
/* istanbul ignore next */
|
|
791
|
-
var wither_ = function (F) {
|
|
792
|
-
var witherF = exports.wither(F);
|
|
793
|
-
return function (fa, f) { return _function.pipe(fa, witherF(f)); };
|
|
794
|
-
};
|
|
795
|
-
/* istanbul ignore next */
|
|
796
|
-
var wilt_ = function (F) {
|
|
797
|
-
var wiltF = exports.wilt(F);
|
|
798
|
-
return function (fa, f) { return _function.pipe(fa, wiltF(f)); };
|
|
799
|
-
};
|
|
800
|
-
// -------------------------------------------------------------------------------------
|
|
801
|
-
// pipeables
|
|
802
|
-
// -------------------------------------------------------------------------------------
|
|
803
|
-
/**
|
|
804
|
-
* `map` can be used to turn functions `(a: A) => B` into functions `(fa: F<A>) => F<B>` whose argument and return types
|
|
805
|
-
* use the type constructor `F` to represent some computational context.
|
|
806
|
-
*
|
|
807
|
-
* @category Functor
|
|
808
|
-
* @since 2.0.0
|
|
809
|
-
*/
|
|
810
|
-
var map = function (f) { return function (fa) {
|
|
811
|
-
return exports.isNone(fa) ? exports.none : exports.some(f(fa.value));
|
|
812
|
-
}; };
|
|
813
|
-
exports.map = map;
|
|
814
|
-
/**
|
|
815
|
-
* Apply a function to an argument under a type constructor.
|
|
816
|
-
*
|
|
817
|
-
* @category Apply
|
|
818
|
-
* @since 2.0.0
|
|
819
|
-
*/
|
|
820
|
-
var ap = function (fa) { return function (fab) {
|
|
821
|
-
return exports.isNone(fab) ? exports.none : exports.isNone(fa) ? exports.none : exports.some(fab.value(fa.value));
|
|
822
|
-
}; };
|
|
823
|
-
exports.ap = ap;
|
|
824
|
-
/**
|
|
825
|
-
* Combine two effectful actions, keeping only the result of the first.
|
|
826
|
-
*
|
|
827
|
-
* Derivable from `Apply`.
|
|
828
|
-
*
|
|
829
|
-
* @category combinators
|
|
830
|
-
* @since 2.0.0
|
|
831
|
-
*/
|
|
832
|
-
var apFirst = function (fb) {
|
|
833
|
-
return _function.flow(exports.map(function (a) { return function () { return a; }; }), exports.ap(fb));
|
|
834
|
-
};
|
|
835
|
-
exports.apFirst = apFirst;
|
|
836
|
-
/**
|
|
837
|
-
* Combine two effectful actions, keeping only the result of the second.
|
|
838
|
-
*
|
|
839
|
-
* Derivable from `Apply`.
|
|
840
|
-
*
|
|
841
|
-
* @category combinators
|
|
842
|
-
* @since 2.0.0
|
|
843
|
-
*/
|
|
844
|
-
var apSecond = function (fb) {
|
|
845
|
-
return _function.flow(exports.map(function () { return function (b) { return b; }; }), exports.ap(fb));
|
|
846
|
-
};
|
|
847
|
-
exports.apSecond = apSecond;
|
|
848
|
-
/**
|
|
849
|
-
* Wrap a value into the type constructor.
|
|
850
|
-
*
|
|
851
|
-
* @category Applicative
|
|
852
|
-
* @since 2.7.0
|
|
853
|
-
*/
|
|
854
|
-
exports.of = exports.some;
|
|
855
|
-
/**
|
|
856
|
-
* Composes computations in sequence, using the return value of one computation to determine the next computation.
|
|
857
|
-
*
|
|
858
|
-
* @category Monad
|
|
859
|
-
* @since 2.0.0
|
|
860
|
-
*/
|
|
861
|
-
var chain = function (f) { return function (ma) {
|
|
862
|
-
return exports.isNone(ma) ? exports.none : f(ma.value);
|
|
863
|
-
}; };
|
|
864
|
-
exports.chain = chain;
|
|
865
|
-
/**
|
|
866
|
-
* Composes computations in sequence, using the return value of one computation to determine the next computation and
|
|
867
|
-
* keeping only the result of the first.
|
|
868
|
-
*
|
|
869
|
-
* Derivable from `Monad`.
|
|
870
|
-
*
|
|
871
|
-
* @category combinators
|
|
872
|
-
* @since 2.0.0
|
|
873
|
-
*/
|
|
874
|
-
var chainFirst = function (f) {
|
|
875
|
-
return exports.chain(function (a) {
|
|
876
|
-
return _function.pipe(f(a), exports.map(function () { return a; }));
|
|
877
|
-
});
|
|
878
|
-
};
|
|
879
|
-
exports.chainFirst = chainFirst;
|
|
880
|
-
/**
|
|
881
|
-
* Derivable from `Monad`.
|
|
882
|
-
*
|
|
883
|
-
* @category combinators
|
|
884
|
-
* @since 2.0.0
|
|
885
|
-
*/
|
|
886
|
-
exports.flatten =
|
|
887
|
-
/*#__PURE__*/
|
|
888
|
-
exports.chain(_function.identity);
|
|
889
|
-
/**
|
|
890
|
-
* Less strict version of [`alt`](#alt).
|
|
891
|
-
*
|
|
892
|
-
* @category Alt
|
|
893
|
-
* @since 2.9.0
|
|
894
|
-
*/
|
|
895
|
-
var altW = function (that) { return function (fa) {
|
|
896
|
-
return exports.isNone(fa) ? that() : fa;
|
|
897
|
-
}; };
|
|
898
|
-
exports.altW = altW;
|
|
899
|
-
/**
|
|
900
|
-
* Identifies an associative operation on a type constructor. It is similar to `Semigroup`, except that it applies to
|
|
901
|
-
* types of kind `* -> *`.
|
|
902
|
-
*
|
|
903
|
-
* In case of `Option` returns the left-most non-`None` value.
|
|
904
|
-
*
|
|
905
|
-
* @example
|
|
906
|
-
* import * as O from 'fp-ts/Option'
|
|
907
|
-
* import { pipe } from 'fp-ts/function'
|
|
908
|
-
*
|
|
909
|
-
* assert.deepStrictEqual(
|
|
910
|
-
* pipe(
|
|
911
|
-
* O.some('a'),
|
|
912
|
-
* O.alt(() => O.some('b'))
|
|
913
|
-
* ),
|
|
914
|
-
* O.some('a')
|
|
915
|
-
* )
|
|
916
|
-
* assert.deepStrictEqual(
|
|
917
|
-
* pipe(
|
|
918
|
-
* O.none,
|
|
919
|
-
* O.alt(() => O.some('b'))
|
|
920
|
-
* ),
|
|
921
|
-
* O.some('b')
|
|
922
|
-
* )
|
|
923
|
-
*
|
|
924
|
-
* @category Alt
|
|
925
|
-
* @since 2.0.0
|
|
926
|
-
*/
|
|
927
|
-
exports.alt = exports.altW;
|
|
928
|
-
/**
|
|
929
|
-
* @category Alternative
|
|
930
|
-
* @since 2.7.0
|
|
931
|
-
*/
|
|
932
|
-
var zero = function () { return exports.none; };
|
|
933
|
-
exports.zero = zero;
|
|
934
|
-
/**
|
|
935
|
-
* @category MonadThrow
|
|
936
|
-
* @since 2.7.0
|
|
937
|
-
*/
|
|
938
|
-
var throwError = function () { return exports.none; };
|
|
939
|
-
exports.throwError = throwError;
|
|
940
|
-
/**
|
|
941
|
-
* @category Extend
|
|
942
|
-
* @since 2.0.0
|
|
943
|
-
*/
|
|
944
|
-
var extend = function (f) { return function (wa) {
|
|
945
|
-
return exports.isNone(wa) ? exports.none : exports.some(f(wa));
|
|
946
|
-
}; };
|
|
947
|
-
exports.extend = extend;
|
|
948
|
-
/**
|
|
949
|
-
* Derivable from `Extend`.
|
|
950
|
-
*
|
|
951
|
-
* @category combinators
|
|
952
|
-
* @since 2.0.0
|
|
953
|
-
*/
|
|
954
|
-
exports.duplicate =
|
|
955
|
-
/*#__PURE__*/
|
|
956
|
-
exports.extend(_function.identity);
|
|
957
|
-
/**
|
|
958
|
-
* @category Foldable
|
|
959
|
-
* @since 2.0.0
|
|
960
|
-
*/
|
|
961
|
-
var reduce = function (b, f) { return function (fa) {
|
|
962
|
-
return exports.isNone(fa) ? b : f(b, fa.value);
|
|
963
|
-
}; };
|
|
964
|
-
exports.reduce = reduce;
|
|
965
|
-
/**
|
|
966
|
-
* @category Foldable
|
|
967
|
-
* @since 2.0.0
|
|
968
|
-
*/
|
|
969
|
-
var foldMap = function (M) { return function (f) { return function (fa) {
|
|
970
|
-
return exports.isNone(fa) ? M.empty : f(fa.value);
|
|
971
|
-
}; }; };
|
|
972
|
-
exports.foldMap = foldMap;
|
|
973
|
-
/**
|
|
974
|
-
* @category Foldable
|
|
975
|
-
* @since 2.0.0
|
|
976
|
-
*/
|
|
977
|
-
var reduceRight = function (b, f) { return function (fa) {
|
|
978
|
-
return exports.isNone(fa) ? b : f(fa.value, b);
|
|
979
|
-
}; };
|
|
980
|
-
exports.reduceRight = reduceRight;
|
|
981
|
-
/**
|
|
982
|
-
* @category Compactable
|
|
983
|
-
* @since 2.0.0
|
|
984
|
-
*/
|
|
985
|
-
exports.compact = exports.flatten;
|
|
986
|
-
var defaultSeparate = { left: exports.none, right: exports.none };
|
|
987
|
-
/**
|
|
988
|
-
* @category Compactable
|
|
989
|
-
* @since 2.0.0
|
|
990
|
-
*/
|
|
991
|
-
var separate = function (ma) {
|
|
992
|
-
var o = _function.pipe(ma, exports.map(function (e) { return ({
|
|
993
|
-
left: getLeft(e),
|
|
994
|
-
right: getRight(e)
|
|
995
|
-
}); }));
|
|
996
|
-
return exports.isNone(o) ? defaultSeparate : o.value;
|
|
997
|
-
};
|
|
998
|
-
exports.separate = separate;
|
|
999
|
-
/**
|
|
1000
|
-
* @category Filterable
|
|
1001
|
-
* @since 2.0.0
|
|
1002
|
-
*/
|
|
1003
|
-
var filter = function (predicate) { return function (fa) { return (exports.isNone(fa) ? exports.none : predicate(fa.value) ? fa : exports.none); }; };
|
|
1004
|
-
exports.filter = filter;
|
|
1005
|
-
/**
|
|
1006
|
-
* @category Filterable
|
|
1007
|
-
* @since 2.0.0
|
|
1008
|
-
*/
|
|
1009
|
-
var filterMap = function (f) { return function (fa) {
|
|
1010
|
-
return exports.isNone(fa) ? exports.none : f(fa.value);
|
|
1011
|
-
}; };
|
|
1012
|
-
exports.filterMap = filterMap;
|
|
1013
|
-
/**
|
|
1014
|
-
* @category Filterable
|
|
1015
|
-
* @since 2.0.0
|
|
1016
|
-
*/
|
|
1017
|
-
var partition = function (predicate) { return function (fa) {
|
|
1018
|
-
return {
|
|
1019
|
-
left: filter_(fa, function (a) { return !predicate(a); }),
|
|
1020
|
-
right: filter_(fa, predicate)
|
|
1021
|
-
};
|
|
1022
|
-
}; };
|
|
1023
|
-
exports.partition = partition;
|
|
1024
|
-
/**
|
|
1025
|
-
* @category Filterable
|
|
1026
|
-
* @since 2.0.0
|
|
1027
|
-
*/
|
|
1028
|
-
var partitionMap = function (f) { return _function.flow(exports.map(f), exports.separate); };
|
|
1029
|
-
exports.partitionMap = partitionMap;
|
|
1030
|
-
/**
|
|
1031
|
-
* @category Traversable
|
|
1032
|
-
* @since 2.6.3
|
|
1033
|
-
*/
|
|
1034
|
-
var traverse = function (F) { return function (f) { return function (ta) { return (exports.isNone(ta) ? F.of(exports.none) : F.map(f(ta.value), exports.some)); }; }; };
|
|
1035
|
-
exports.traverse = traverse;
|
|
1036
|
-
/**
|
|
1037
|
-
* @category Traversable
|
|
1038
|
-
* @since 2.6.3
|
|
1039
|
-
*/
|
|
1040
|
-
var sequence = function (F) { return function (ta) { return (exports.isNone(ta) ? F.of(exports.none) : F.map(ta.value, exports.some)); }; };
|
|
1041
|
-
exports.sequence = sequence;
|
|
1042
|
-
/**
|
|
1043
|
-
* @category Witherable
|
|
1044
|
-
* @since 2.6.5
|
|
1045
|
-
*/
|
|
1046
|
-
var wither = function (F) { return function (f) { return function (fa) { return (exports.isNone(fa) ? F.of(exports.none) : f(fa.value)); }; }; };
|
|
1047
|
-
exports.wither = wither;
|
|
1048
|
-
/**
|
|
1049
|
-
* @category Witherable
|
|
1050
|
-
* @since 2.6.5
|
|
1051
|
-
*/
|
|
1052
|
-
var wilt = function (F) { return function (f) { return function (fa) {
|
|
1053
|
-
return exports.isNone(fa)
|
|
1054
|
-
? F.of({
|
|
1055
|
-
left: exports.none,
|
|
1056
|
-
right: exports.none
|
|
1057
|
-
})
|
|
1058
|
-
: F.map(f(fa.value), function (e) { return ({
|
|
1059
|
-
left: getLeft(e),
|
|
1060
|
-
right: getRight(e)
|
|
1061
|
-
}); });
|
|
1062
|
-
}; }; };
|
|
1063
|
-
exports.wilt = wilt;
|
|
1064
|
-
// -------------------------------------------------------------------------------------
|
|
1065
|
-
// instances
|
|
1066
|
-
// -------------------------------------------------------------------------------------
|
|
1067
|
-
/**
|
|
1068
|
-
* @category instances
|
|
1069
|
-
* @since 2.0.0
|
|
1070
|
-
*/
|
|
1071
|
-
exports.URI = 'Option';
|
|
1072
|
-
/**
|
|
1073
|
-
* @category instances
|
|
1074
|
-
* @since 2.0.0
|
|
1075
|
-
*/
|
|
1076
|
-
function getShow(S) {
|
|
1077
|
-
return {
|
|
1078
|
-
show: function (ma) { return (exports.isNone(ma) ? 'none' : "some(" + S.show(ma.value) + ")"); }
|
|
1079
|
-
};
|
|
1080
|
-
}
|
|
1081
|
-
exports.getShow = getShow;
|
|
1082
|
-
/**
|
|
1083
|
-
* @example
|
|
1084
|
-
* import { none, some, getEq } from 'fp-ts/Option'
|
|
1085
|
-
* import { eqNumber } from 'fp-ts/Eq'
|
|
1086
|
-
*
|
|
1087
|
-
* const E = getEq(eqNumber)
|
|
1088
|
-
* assert.strictEqual(E.equals(none, none), true)
|
|
1089
|
-
* assert.strictEqual(E.equals(none, some(1)), false)
|
|
1090
|
-
* assert.strictEqual(E.equals(some(1), none), false)
|
|
1091
|
-
* assert.strictEqual(E.equals(some(1), some(2)), false)
|
|
1092
|
-
* assert.strictEqual(E.equals(some(1), some(1)), true)
|
|
1093
|
-
*
|
|
1094
|
-
* @category instances
|
|
1095
|
-
* @since 2.0.0
|
|
1096
|
-
*/
|
|
1097
|
-
function getEq(E) {
|
|
1098
|
-
return {
|
|
1099
|
-
equals: function (x, y) { return x === y || (exports.isNone(x) ? exports.isNone(y) : exports.isNone(y) ? false : E.equals(x.value, y.value)); }
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
|
-
exports.getEq = getEq;
|
|
1103
|
-
/**
|
|
1104
|
-
* The `Ord` instance allows `Option` values to be compared with
|
|
1105
|
-
* `compare`, whenever there is an `Ord` instance for
|
|
1106
|
-
* the type the `Option` contains.
|
|
1107
|
-
*
|
|
1108
|
-
* `None` is considered to be less than any `Some` value.
|
|
1109
|
-
*
|
|
1110
|
-
*
|
|
1111
|
-
* @example
|
|
1112
|
-
* import { none, some, getOrd } from 'fp-ts/Option'
|
|
1113
|
-
* import { ordNumber } from 'fp-ts/Ord'
|
|
1114
|
-
*
|
|
1115
|
-
* const O = getOrd(ordNumber)
|
|
1116
|
-
* assert.strictEqual(O.compare(none, none), 0)
|
|
1117
|
-
* assert.strictEqual(O.compare(none, some(1)), -1)
|
|
1118
|
-
* assert.strictEqual(O.compare(some(1), none), 1)
|
|
1119
|
-
* assert.strictEqual(O.compare(some(1), some(2)), -1)
|
|
1120
|
-
* assert.strictEqual(O.compare(some(1), some(1)), 0)
|
|
1121
|
-
*
|
|
1122
|
-
* @category instances
|
|
1123
|
-
* @since 2.0.0
|
|
1124
|
-
*/
|
|
1125
|
-
function getOrd(O) {
|
|
1126
|
-
return {
|
|
1127
|
-
equals: getEq(O).equals,
|
|
1128
|
-
compare: function (x, y) { return (x === y ? 0 : exports.isSome(x) ? (exports.isSome(y) ? O.compare(x.value, y.value) : 1) : -1); }
|
|
1129
|
-
};
|
|
1130
|
-
}
|
|
1131
|
-
exports.getOrd = getOrd;
|
|
1132
|
-
/**
|
|
1133
|
-
* `Apply` semigroup
|
|
1134
|
-
*
|
|
1135
|
-
* | x | y | concat(x, y) |
|
|
1136
|
-
* | ------- | ------- | ------------------ |
|
|
1137
|
-
* | none | none | none |
|
|
1138
|
-
* | some(a) | none | none |
|
|
1139
|
-
* | none | some(a) | none |
|
|
1140
|
-
* | some(a) | some(b) | some(concat(a, b)) |
|
|
1141
|
-
*
|
|
1142
|
-
* @example
|
|
1143
|
-
* import { getApplySemigroup, some, none } from 'fp-ts/Option'
|
|
1144
|
-
* import { semigroupSum } from 'fp-ts/Semigroup'
|
|
1145
|
-
*
|
|
1146
|
-
* const S = getApplySemigroup(semigroupSum)
|
|
1147
|
-
* assert.deepStrictEqual(S.concat(none, none), none)
|
|
1148
|
-
* assert.deepStrictEqual(S.concat(some(1), none), none)
|
|
1149
|
-
* assert.deepStrictEqual(S.concat(none, some(1)), none)
|
|
1150
|
-
* assert.deepStrictEqual(S.concat(some(1), some(2)), some(3))
|
|
1151
|
-
*
|
|
1152
|
-
* @category instances
|
|
1153
|
-
* @since 2.0.0
|
|
1154
|
-
*/
|
|
1155
|
-
function getApplySemigroup(S) {
|
|
1156
|
-
return {
|
|
1157
|
-
concat: function (x, y) { return (exports.isSome(x) && exports.isSome(y) ? exports.some(S.concat(x.value, y.value)) : exports.none); }
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
|
-
exports.getApplySemigroup = getApplySemigroup;
|
|
1161
|
-
/**
|
|
1162
|
-
* @category instances
|
|
1163
|
-
* @since 2.0.0
|
|
1164
|
-
*/
|
|
1165
|
-
function getApplyMonoid(M) {
|
|
1166
|
-
return {
|
|
1167
|
-
concat: getApplySemigroup(M).concat,
|
|
1168
|
-
empty: exports.some(M.empty)
|
|
1169
|
-
};
|
|
1170
|
-
}
|
|
1171
|
-
exports.getApplyMonoid = getApplyMonoid;
|
|
1172
|
-
/**
|
|
1173
|
-
* Monoid returning the left-most non-`None` value
|
|
1174
|
-
*
|
|
1175
|
-
* | x | y | concat(x, y) |
|
|
1176
|
-
* | ------- | ------- | ------------ |
|
|
1177
|
-
* | none | none | none |
|
|
1178
|
-
* | some(a) | none | some(a) |
|
|
1179
|
-
* | none | some(a) | some(a) |
|
|
1180
|
-
* | some(a) | some(b) | some(a) |
|
|
1181
|
-
*
|
|
1182
|
-
* @example
|
|
1183
|
-
* import { getFirstMonoid, some, none } from 'fp-ts/Option'
|
|
1184
|
-
*
|
|
1185
|
-
* const M = getFirstMonoid<number>()
|
|
1186
|
-
* assert.deepStrictEqual(M.concat(none, none), none)
|
|
1187
|
-
* assert.deepStrictEqual(M.concat(some(1), none), some(1))
|
|
1188
|
-
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
1189
|
-
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(1))
|
|
1190
|
-
*
|
|
1191
|
-
* @category instances
|
|
1192
|
-
* @since 2.0.0
|
|
1193
|
-
*/
|
|
1194
|
-
function getFirstMonoid() {
|
|
1195
|
-
return {
|
|
1196
|
-
concat: function (x, y) { return (exports.isNone(x) ? y : x); },
|
|
1197
|
-
empty: exports.none
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1200
|
-
exports.getFirstMonoid = getFirstMonoid;
|
|
1201
|
-
/**
|
|
1202
|
-
* Monoid returning the right-most non-`None` value
|
|
1203
|
-
*
|
|
1204
|
-
* | x | y | concat(x, y) |
|
|
1205
|
-
* | ------- | ------- | ------------ |
|
|
1206
|
-
* | none | none | none |
|
|
1207
|
-
* | some(a) | none | some(a) |
|
|
1208
|
-
* | none | some(a) | some(a) |
|
|
1209
|
-
* | some(a) | some(b) | some(b) |
|
|
1210
|
-
*
|
|
1211
|
-
* @example
|
|
1212
|
-
* import { getLastMonoid, some, none } from 'fp-ts/Option'
|
|
1213
|
-
*
|
|
1214
|
-
* const M = getLastMonoid<number>()
|
|
1215
|
-
* assert.deepStrictEqual(M.concat(none, none), none)
|
|
1216
|
-
* assert.deepStrictEqual(M.concat(some(1), none), some(1))
|
|
1217
|
-
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
1218
|
-
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(2))
|
|
1219
|
-
*
|
|
1220
|
-
* @category instances
|
|
1221
|
-
* @since 2.0.0
|
|
1222
|
-
*/
|
|
1223
|
-
function getLastMonoid() {
|
|
1224
|
-
return {
|
|
1225
|
-
concat: function (x, y) { return (exports.isNone(y) ? x : y); },
|
|
1226
|
-
empty: exports.none
|
|
1227
|
-
};
|
|
1228
|
-
}
|
|
1229
|
-
exports.getLastMonoid = getLastMonoid;
|
|
1230
|
-
/**
|
|
1231
|
-
* Monoid returning the left-most non-`None` value. If both operands are `Some`s then the inner values are
|
|
1232
|
-
* concatenated using the provided `Semigroup`
|
|
1233
|
-
*
|
|
1234
|
-
* | x | y | concat(x, y) |
|
|
1235
|
-
* | ------- | ------- | ------------------ |
|
|
1236
|
-
* | none | none | none |
|
|
1237
|
-
* | some(a) | none | some(a) |
|
|
1238
|
-
* | none | some(a) | some(a) |
|
|
1239
|
-
* | some(a) | some(b) | some(concat(a, b)) |
|
|
1240
|
-
*
|
|
1241
|
-
* @example
|
|
1242
|
-
* import { getMonoid, some, none } from 'fp-ts/Option'
|
|
1243
|
-
* import { semigroupSum } from 'fp-ts/Semigroup'
|
|
1244
|
-
*
|
|
1245
|
-
* const M = getMonoid(semigroupSum)
|
|
1246
|
-
* assert.deepStrictEqual(M.concat(none, none), none)
|
|
1247
|
-
* assert.deepStrictEqual(M.concat(some(1), none), some(1))
|
|
1248
|
-
* assert.deepStrictEqual(M.concat(none, some(1)), some(1))
|
|
1249
|
-
* assert.deepStrictEqual(M.concat(some(1), some(2)), some(3))
|
|
1250
|
-
*
|
|
1251
|
-
* @category instances
|
|
1252
|
-
* @since 2.0.0
|
|
1253
|
-
*/
|
|
1254
|
-
function getMonoid(S) {
|
|
1255
|
-
return {
|
|
1256
|
-
concat: function (x, y) { return (exports.isNone(x) ? y : exports.isNone(y) ? x : exports.some(S.concat(x.value, y.value))); },
|
|
1257
|
-
empty: exports.none
|
|
1258
|
-
};
|
|
1259
|
-
}
|
|
1260
|
-
exports.getMonoid = getMonoid;
|
|
1261
|
-
/**
|
|
1262
|
-
* @category instances
|
|
1263
|
-
* @since 2.7.0
|
|
1264
|
-
*/
|
|
1265
|
-
exports.Functor = {
|
|
1266
|
-
URI: exports.URI,
|
|
1267
|
-
map: map_
|
|
1268
|
-
};
|
|
1269
|
-
/**
|
|
1270
|
-
* @category instances
|
|
1271
|
-
* @since 2.7.0
|
|
1272
|
-
*/
|
|
1273
|
-
exports.Applicative = {
|
|
1274
|
-
URI: exports.URI,
|
|
1275
|
-
map: map_,
|
|
1276
|
-
ap: ap_,
|
|
1277
|
-
of: exports.of
|
|
1278
|
-
};
|
|
1279
|
-
/**
|
|
1280
|
-
* @category instances
|
|
1281
|
-
* @since 2.7.0
|
|
1282
|
-
*/
|
|
1283
|
-
exports.Monad = {
|
|
1284
|
-
URI: exports.URI,
|
|
1285
|
-
map: map_,
|
|
1286
|
-
ap: ap_,
|
|
1287
|
-
of: exports.of,
|
|
1288
|
-
chain: chain_
|
|
1289
|
-
};
|
|
1290
|
-
/**
|
|
1291
|
-
* @category instances
|
|
1292
|
-
* @since 2.7.0
|
|
1293
|
-
*/
|
|
1294
|
-
exports.Foldable = {
|
|
1295
|
-
URI: exports.URI,
|
|
1296
|
-
reduce: reduce_,
|
|
1297
|
-
foldMap: foldMap_,
|
|
1298
|
-
reduceRight: reduceRight_
|
|
1299
|
-
};
|
|
1300
|
-
/**
|
|
1301
|
-
* @category instances
|
|
1302
|
-
* @since 2.7.0
|
|
1303
|
-
*/
|
|
1304
|
-
exports.Alt = {
|
|
1305
|
-
URI: exports.URI,
|
|
1306
|
-
map: map_,
|
|
1307
|
-
alt: alt_
|
|
1308
|
-
};
|
|
1309
|
-
/**
|
|
1310
|
-
* @category instances
|
|
1311
|
-
* @since 2.7.0
|
|
1312
|
-
*/
|
|
1313
|
-
exports.Alternative = {
|
|
1314
|
-
URI: exports.URI,
|
|
1315
|
-
map: map_,
|
|
1316
|
-
ap: ap_,
|
|
1317
|
-
of: exports.of,
|
|
1318
|
-
alt: alt_,
|
|
1319
|
-
zero: exports.zero
|
|
1320
|
-
};
|
|
1321
|
-
/**
|
|
1322
|
-
* @category instances
|
|
1323
|
-
* @since 2.7.0
|
|
1324
|
-
*/
|
|
1325
|
-
exports.Extend = {
|
|
1326
|
-
URI: exports.URI,
|
|
1327
|
-
map: map_,
|
|
1328
|
-
extend: extend_
|
|
1329
|
-
};
|
|
1330
|
-
/**
|
|
1331
|
-
* @category instances
|
|
1332
|
-
* @since 2.7.0
|
|
1333
|
-
*/
|
|
1334
|
-
exports.Compactable = {
|
|
1335
|
-
URI: exports.URI,
|
|
1336
|
-
compact: exports.compact,
|
|
1337
|
-
separate: exports.separate
|
|
1338
|
-
};
|
|
1339
|
-
/**
|
|
1340
|
-
* @category instances
|
|
1341
|
-
* @since 2.7.0
|
|
1342
|
-
*/
|
|
1343
|
-
exports.Filterable = {
|
|
1344
|
-
URI: exports.URI,
|
|
1345
|
-
map: map_,
|
|
1346
|
-
compact: exports.compact,
|
|
1347
|
-
separate: exports.separate,
|
|
1348
|
-
filter: filter_,
|
|
1349
|
-
filterMap: filterMap_,
|
|
1350
|
-
partition: partition_,
|
|
1351
|
-
partitionMap: partitionMap_
|
|
1352
|
-
};
|
|
1353
|
-
/**
|
|
1354
|
-
* @category instances
|
|
1355
|
-
* @since 2.7.0
|
|
1356
|
-
*/
|
|
1357
|
-
exports.Traversable = {
|
|
1358
|
-
URI: exports.URI,
|
|
1359
|
-
map: map_,
|
|
1360
|
-
reduce: reduce_,
|
|
1361
|
-
foldMap: foldMap_,
|
|
1362
|
-
reduceRight: reduceRight_,
|
|
1363
|
-
traverse: traverse_,
|
|
1364
|
-
sequence: exports.sequence
|
|
1365
|
-
};
|
|
1366
|
-
/**
|
|
1367
|
-
* @category instances
|
|
1368
|
-
* @since 2.7.0
|
|
1369
|
-
*/
|
|
1370
|
-
exports.Witherable = {
|
|
1371
|
-
URI: exports.URI,
|
|
1372
|
-
map: map_,
|
|
1373
|
-
reduce: reduce_,
|
|
1374
|
-
foldMap: foldMap_,
|
|
1375
|
-
reduceRight: reduceRight_,
|
|
1376
|
-
traverse: traverse_,
|
|
1377
|
-
sequence: exports.sequence,
|
|
1378
|
-
compact: exports.compact,
|
|
1379
|
-
separate: exports.separate,
|
|
1380
|
-
filter: filter_,
|
|
1381
|
-
filterMap: filterMap_,
|
|
1382
|
-
partition: partition_,
|
|
1383
|
-
partitionMap: partitionMap_,
|
|
1384
|
-
wither: wither_,
|
|
1385
|
-
wilt: wilt_
|
|
1386
|
-
};
|
|
1387
|
-
/**
|
|
1388
|
-
* @category instances
|
|
1389
|
-
* @since 2.7.0
|
|
1390
|
-
*/
|
|
1391
|
-
exports.MonadThrow = {
|
|
1392
|
-
URI: exports.URI,
|
|
1393
|
-
map: map_,
|
|
1394
|
-
ap: ap_,
|
|
1395
|
-
of: exports.of,
|
|
1396
|
-
chain: chain_,
|
|
1397
|
-
throwError: exports.throwError
|
|
1398
|
-
};
|
|
1399
|
-
// TODO: remove in v3
|
|
1400
|
-
/**
|
|
1401
|
-
* @category instances
|
|
1402
|
-
* @since 2.0.0
|
|
1403
|
-
*/
|
|
1404
|
-
exports.option = {
|
|
1405
|
-
URI: exports.URI,
|
|
1406
|
-
map: map_,
|
|
1407
|
-
of: exports.of,
|
|
1408
|
-
ap: ap_,
|
|
1409
|
-
chain: chain_,
|
|
1410
|
-
reduce: reduce_,
|
|
1411
|
-
foldMap: foldMap_,
|
|
1412
|
-
reduceRight: reduceRight_,
|
|
1413
|
-
traverse: traverse_,
|
|
1414
|
-
sequence: exports.sequence,
|
|
1415
|
-
zero: exports.zero,
|
|
1416
|
-
alt: alt_,
|
|
1417
|
-
extend: extend_,
|
|
1418
|
-
compact: exports.compact,
|
|
1419
|
-
separate: exports.separate,
|
|
1420
|
-
filter: filter_,
|
|
1421
|
-
filterMap: filterMap_,
|
|
1422
|
-
partition: partition_,
|
|
1423
|
-
partitionMap: partitionMap_,
|
|
1424
|
-
wither: wither_,
|
|
1425
|
-
wilt: wilt_,
|
|
1426
|
-
throwError: exports.throwError
|
|
1427
|
-
};
|
|
1428
|
-
// -------------------------------------------------------------------------------------
|
|
1429
|
-
// utils
|
|
1430
|
-
// -------------------------------------------------------------------------------------
|
|
1431
|
-
/**
|
|
1432
|
-
* Returns `true` if `ma` contains `a`
|
|
1433
|
-
*
|
|
1434
|
-
* @example
|
|
1435
|
-
* import { some, none, elem } from 'fp-ts/Option'
|
|
1436
|
-
* import { eqNumber } from 'fp-ts/Eq'
|
|
1437
|
-
*
|
|
1438
|
-
* assert.strictEqual(elem(eqNumber)(1, some(1)), true)
|
|
1439
|
-
* assert.strictEqual(elem(eqNumber)(2, some(1)), false)
|
|
1440
|
-
* assert.strictEqual(elem(eqNumber)(1, none), false)
|
|
1441
|
-
*
|
|
1442
|
-
* @since 2.0.0
|
|
1443
|
-
*/
|
|
1444
|
-
function elem(E) {
|
|
1445
|
-
return function (a, ma) { return (exports.isNone(ma) ? false : E.equals(a, ma.value)); };
|
|
1446
|
-
}
|
|
1447
|
-
exports.elem = elem;
|
|
1448
|
-
/**
|
|
1449
|
-
* Returns `true` if the predicate is satisfied by the wrapped value
|
|
1450
|
-
*
|
|
1451
|
-
* @example
|
|
1452
|
-
* import { some, none, exists } from 'fp-ts/Option'
|
|
1453
|
-
* import { pipe } from 'fp-ts/function'
|
|
1454
|
-
*
|
|
1455
|
-
* assert.strictEqual(
|
|
1456
|
-
* pipe(
|
|
1457
|
-
* some(1),
|
|
1458
|
-
* exists(n => n > 0)
|
|
1459
|
-
* ),
|
|
1460
|
-
* true
|
|
1461
|
-
* )
|
|
1462
|
-
* assert.strictEqual(
|
|
1463
|
-
* pipe(
|
|
1464
|
-
* some(1),
|
|
1465
|
-
* exists(n => n > 1)
|
|
1466
|
-
* ),
|
|
1467
|
-
* false
|
|
1468
|
-
* )
|
|
1469
|
-
* assert.strictEqual(
|
|
1470
|
-
* pipe(
|
|
1471
|
-
* none,
|
|
1472
|
-
* exists(n => n > 0)
|
|
1473
|
-
* ),
|
|
1474
|
-
* false
|
|
1475
|
-
* )
|
|
1476
|
-
*
|
|
1477
|
-
* @since 2.0.0
|
|
1478
|
-
*/
|
|
1479
|
-
function exists(predicate) {
|
|
1480
|
-
return function (ma) { return (exports.isNone(ma) ? false : predicate(ma.value)); };
|
|
1481
|
-
}
|
|
1482
|
-
exports.exists = exists;
|
|
1483
|
-
/**
|
|
1484
|
-
* Returns a `Refinement` (i.e. a custom type guard) from a `Option` returning function.
|
|
1485
|
-
* This function ensures that a custom type guard definition is type-safe.
|
|
1486
|
-
*
|
|
1487
|
-
* ```ts
|
|
1488
|
-
* import { some, none, getRefinement } from 'fp-ts/Option'
|
|
1489
|
-
*
|
|
1490
|
-
* type A = { type: 'A' }
|
|
1491
|
-
* type B = { type: 'B' }
|
|
1492
|
-
* type C = A | B
|
|
1493
|
-
*
|
|
1494
|
-
* const isA = (c: C): c is A => c.type === 'B' // <= typo but typescript doesn't complain
|
|
1495
|
-
* const isA = getRefinement<C, A>(c => (c.type === 'B' ? some(c) : none)) // static error: Type '"B"' is not assignable to type '"A"'
|
|
1496
|
-
* ```
|
|
1497
|
-
*
|
|
1498
|
-
* @since 2.0.0
|
|
1499
|
-
*/
|
|
1500
|
-
function getRefinement(getOption) {
|
|
1501
|
-
return function (a) { return exports.isSome(getOption(a)); };
|
|
1502
|
-
}
|
|
1503
|
-
exports.getRefinement = getRefinement;
|
|
1504
|
-
// -------------------------------------------------------------------------------------
|
|
1505
|
-
// do notation
|
|
1506
|
-
// -------------------------------------------------------------------------------------
|
|
1507
|
-
/**
|
|
1508
|
-
* @since 2.9.0
|
|
1509
|
-
*/
|
|
1510
|
-
exports.Do =
|
|
1511
|
-
/*#__PURE__*/
|
|
1512
|
-
exports.of({});
|
|
1513
|
-
/**
|
|
1514
|
-
* @since 2.8.0
|
|
1515
|
-
*/
|
|
1516
|
-
var bindTo = function (name) { return exports.map(_function.bindTo_(name)); };
|
|
1517
|
-
exports.bindTo = bindTo;
|
|
1518
|
-
/**
|
|
1519
|
-
* @since 2.8.0
|
|
1520
|
-
*/
|
|
1521
|
-
var bind = function (name, f) {
|
|
1522
|
-
return exports.chain(function (a) {
|
|
1523
|
-
return _function.pipe(f(a), exports.map(function (b) { return _function.bind_(a, name, b); }));
|
|
1524
|
-
});
|
|
1525
|
-
};
|
|
1526
|
-
exports.bind = bind;
|
|
1527
|
-
// -------------------------------------------------------------------------------------
|
|
1528
|
-
// pipeable sequence S
|
|
1529
|
-
// -------------------------------------------------------------------------------------
|
|
1530
|
-
/**
|
|
1531
|
-
* @since 2.8.0
|
|
1532
|
-
*/
|
|
1533
|
-
var apS = function (name, fb) {
|
|
1534
|
-
return _function.flow(exports.map(function (a) { return function (b) { return _function.bind_(a, name, b); }; }), exports.ap(fb));
|
|
1535
|
-
};
|
|
1536
|
-
exports.apS = apS;
|
|
1537
|
-
// -------------------------------------------------------------------------------------
|
|
1538
|
-
// array utils
|
|
1539
|
-
// -------------------------------------------------------------------------------------
|
|
1540
|
-
/**
|
|
1541
|
-
*
|
|
1542
|
-
* @since 2.9.0
|
|
1543
|
-
*/
|
|
1544
|
-
var traverseArrayWithIndex = function (f) { return function (arr) {
|
|
1545
|
-
// tslint:disable-next-line: readonly-array
|
|
1546
|
-
var result = [];
|
|
1547
|
-
for (var i = 0; i < arr.length; i++) {
|
|
1548
|
-
var b = f(i, arr[i]);
|
|
1549
|
-
if (exports.isNone(b)) {
|
|
1550
|
-
return exports.none;
|
|
1551
|
-
}
|
|
1552
|
-
result.push(b.value);
|
|
1553
|
-
}
|
|
1554
|
-
return exports.some(result);
|
|
1555
|
-
}; };
|
|
1556
|
-
exports.traverseArrayWithIndex = traverseArrayWithIndex;
|
|
1557
|
-
/**
|
|
1558
|
-
* Runs an action for every element in array and accumulates the results in option
|
|
1559
|
-
*
|
|
1560
|
-
* this function has the same behavior of `A.sequence(O.option)` but it's optimized and performs better
|
|
1561
|
-
*
|
|
1562
|
-
* @example
|
|
1563
|
-
*
|
|
1564
|
-
* import * as A from 'fp-ts/Array'
|
|
1565
|
-
* import { traverseArray, some, fromPredicate, none } from 'fp-ts/Option'
|
|
1566
|
-
* import { pipe } from 'fp-ts/function'
|
|
1567
|
-
*
|
|
1568
|
-
* const arr = A.range(0, 10)
|
|
1569
|
-
* assert.deepStrictEqual(pipe(arr, traverseArray(some)), some(arr))
|
|
1570
|
-
* assert.deepStrictEqual(pipe(arr, traverseArray(fromPredicate((x) => x > 5))), none)
|
|
1571
|
-
*
|
|
1572
|
-
* @since 2.9.0
|
|
1573
|
-
*/
|
|
1574
|
-
var traverseArray = function (f) { return exports.traverseArrayWithIndex(function (_, a) { return f(a); }); };
|
|
1575
|
-
exports.traverseArray = traverseArray;
|
|
1576
|
-
/**
|
|
1577
|
-
* get an array of option and convert it to option of array
|
|
1578
|
-
*
|
|
1579
|
-
* this function has the same behavior of `A.sequence(O.option)` but it's optimized and performs better
|
|
1580
|
-
*
|
|
1581
|
-
* @example
|
|
1582
|
-
*
|
|
1583
|
-
* import * as A from 'fp-ts/Array'
|
|
1584
|
-
* import { sequenceArray, some, none, fromPredicate } from 'fp-ts/Option'
|
|
1585
|
-
* import { pipe } from 'fp-ts/function'
|
|
1586
|
-
*
|
|
1587
|
-
* const arr = A.range(0, 10)
|
|
1588
|
-
* assert.deepStrictEqual(pipe(arr, A.map(some), sequenceArray), some(arr))
|
|
1589
|
-
* assert.deepStrictEqual(pipe(arr, A.map(fromPredicate(x => x > 8)), sequenceArray), none)
|
|
1590
|
-
*
|
|
1591
|
-
* @since 2.9.0
|
|
1592
|
-
*/
|
|
1593
|
-
exports.sequenceArray =
|
|
1594
|
-
/*#__PURE__*/
|
|
1595
|
-
exports.traverseArray(_function.identity);
|
|
1596
|
-
});
|
|
1597
|
-
|
|
1598
|
-
class AppConfigurationService {
|
|
1599
|
-
set apiBaseUrl(url) {
|
|
1600
|
-
AppConfigurationService._apiBaseUrl = Option.fromNullable(url);
|
|
1601
|
-
}
|
|
1602
|
-
get apiBaseUrl() {
|
|
1603
|
-
if (Option.isNone(AppConfigurationService._apiBaseUrl)) {
|
|
1604
|
-
throw Error('API base URL is not set');
|
|
1605
|
-
}
|
|
1606
|
-
return AppConfigurationService._apiBaseUrl.value;
|
|
1607
|
-
}
|
|
1608
|
-
}
|
|
1609
|
-
const appConfigurationService = new AppConfigurationService();
|
|
1610
|
-
|
|
1611
|
-
var __decorate = (undefined && undefined.__decorate) || function (decorators, target, key, desc) {
|
|
1612
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
1613
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
1614
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
1615
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
1616
|
-
};
|
|
1617
|
-
function createInitialState() {
|
|
1618
|
-
return {
|
|
1619
|
-
vehicle: {
|
|
1620
|
-
make: none,
|
|
1621
|
-
makeId: none,
|
|
1622
|
-
model: none,
|
|
1623
|
-
modelId: none,
|
|
1624
|
-
year: none,
|
|
1625
|
-
bodyType: none,
|
|
1626
|
-
bodyTypeId: none,
|
|
1627
|
-
selectedVariant: none,
|
|
1628
|
-
isUsedCarRequested: some(false),
|
|
1629
|
-
approximatePrice: none
|
|
1630
|
-
},
|
|
1631
|
-
user: {
|
|
1632
|
-
annualSalary: none,
|
|
1633
|
-
annualKms: none,
|
|
1634
|
-
paymentPeriod: none,
|
|
1635
|
-
state: none,
|
|
1636
|
-
term: none
|
|
1637
|
-
},
|
|
1638
|
-
quote: {
|
|
1639
|
-
afterTaxEffectPerPayCycle: none,
|
|
1640
|
-
taxSaving: none,
|
|
1641
|
-
residualValue: none,
|
|
1642
|
-
financedAmount: none,
|
|
1643
|
-
fuel: none,
|
|
1644
|
-
serviceAndMaintenance: none,
|
|
1645
|
-
registrationAndCtp: none,
|
|
1646
|
-
comprehensiveInsurance: none,
|
|
1647
|
-
managementFee: none,
|
|
1648
|
-
quoteState: 'Not calculated'
|
|
1649
|
-
},
|
|
1650
|
-
userDetails: {
|
|
1651
|
-
employerName: none,
|
|
1652
|
-
userFirstName: none,
|
|
1653
|
-
userLastName: none,
|
|
1654
|
-
contactNumber: none,
|
|
1655
|
-
emailAddress: none
|
|
1656
|
-
},
|
|
1657
|
-
refLists: {
|
|
1658
|
-
makeList: none,
|
|
1659
|
-
modelList: none,
|
|
1660
|
-
yearList: none,
|
|
1661
|
-
bodyTypeList: none,
|
|
1662
|
-
modelVariantsList: none
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
}
|
|
1666
|
-
let SessionStore = class SessionStore extends datoramaAkita.Store {
|
|
1667
|
-
constructor() {
|
|
1668
|
-
super(createInitialState());
|
|
1669
|
-
}
|
|
1670
|
-
updateQuote(quote) {
|
|
1671
|
-
this.update({
|
|
1672
|
-
quote: quote
|
|
1673
|
-
});
|
|
1674
|
-
}
|
|
1675
|
-
setVehicleState(key, value) {
|
|
1676
|
-
this.update((state) => (Object.assign(Object.assign({}, state), { vehicle: Object.assign(Object.assign({}, state.vehicle), { [key]: value === null ? none : some(value) }) })));
|
|
1677
|
-
}
|
|
1678
|
-
updateList(name, value) {
|
|
1679
|
-
this.update((state) => (Object.assign(Object.assign({}, state), { refLists: Object.assign(Object.assign({}, state.refLists), { [name]: some(value) }) })));
|
|
1680
|
-
}
|
|
1681
|
-
};
|
|
1682
|
-
SessionStore = __decorate([
|
|
1683
|
-
datoramaAkita.StoreConfig({ name: 'cars-calc-session', resettable: true })
|
|
1684
|
-
], SessionStore);
|
|
1685
|
-
const sessionStore = new SessionStore();
|
|
1686
|
-
|
|
1687
|
-
class SessionQuery extends datoramaAkita.Query {
|
|
1688
|
-
constructor(store) {
|
|
1689
|
-
super(store);
|
|
1690
|
-
this.store = store;
|
|
1691
|
-
this.vehicle$ = this.select((state) => state.vehicle);
|
|
1692
|
-
this.user$ = this.select((state) => state.user);
|
|
1693
|
-
this.result$ = this.select((state) => state.quote);
|
|
1694
|
-
this.userDetails$ = this.select((state) => state.userDetails);
|
|
1695
|
-
this.makeList$ = this.select((state) => state.refLists.makeList);
|
|
1696
|
-
this.modelList$ = this.select((state) => state.refLists.modelList);
|
|
1697
|
-
this.yearList$ = this.select((state) => state.refLists.yearList);
|
|
1698
|
-
this.bodyTypeList$ = this.select((state) => state.refLists.bodyTypeList);
|
|
1699
|
-
this.modelVariantsList$ = this.select((state) => state.refLists.modelVariantsList);
|
|
1700
|
-
this.selectedVariant$ = this.select((state) => state.vehicle.selectedVariant);
|
|
1701
|
-
this.quote$ = this.select((state) => state.quote);
|
|
1702
|
-
}
|
|
1703
|
-
get selectedVariant() {
|
|
1704
|
-
return this.getValue().vehicle.selectedVariant;
|
|
1705
|
-
}
|
|
1706
|
-
get vehicle() {
|
|
1707
|
-
return this.getValue().vehicle;
|
|
1708
|
-
}
|
|
1709
|
-
get user() {
|
|
1710
|
-
return this.getValue().user;
|
|
1711
|
-
}
|
|
1712
|
-
get result() {
|
|
1713
|
-
return this.getValue().quote;
|
|
1714
|
-
}
|
|
1715
|
-
get userDetails() {
|
|
1716
|
-
return this.getValue().userDetails;
|
|
1717
|
-
}
|
|
1718
|
-
}
|
|
1719
|
-
const sessionQuery = new SessionQuery(sessionStore);
|
|
1720
|
-
|
|
1721
|
-
exports.appConfigurationService = appConfigurationService;
|
|
1722
|
-
exports.fold = fold;
|
|
1723
|
-
exports.fromNullable = fromNullable;
|
|
1724
|
-
exports.getOrElse = getOrElse;
|
|
1725
|
-
exports.getOrElseW = getOrElseW;
|
|
1726
|
-
exports.isNone = isNone;
|
|
1727
|
-
exports.isSome = isSome;
|
|
1728
|
-
exports.none = none;
|
|
1729
|
-
exports.sessionQuery = sessionQuery;
|
|
1730
|
-
exports.sessionStore = sessionStore;
|
|
1731
|
-
exports.some = some;
|