@ekz/option 1.2.6 → 2.0.1

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 CHANGED
@@ -1,242 +1,23 @@
1
- # Description
1
+ # @ekz/option
2
2
 
3
- Simply get rid of all nulls in your code.
3
+ Option/Maybe type for TypeScript a port of Scala's `Option`.
4
4
 
5
- This is a clone of Scala's Option class to be used with flow.js.
5
+ **Documentation:** [https://docs.ekz.io/option/](https://docs.ekz.io/option/)
6
6
 
7
- # Examples
7
+ ## Install
8
8
 
9
- ```javascript
10
- // @flow
11
-
12
- let valueA = Option.of(null).map(x => x + 2).getOrElse(() => 0);
13
- // valueA = 0
14
-
15
- let valueB = Some('any object').flatMap(x => Some(`${x}!!!`)).getOrUndefined();
16
- // valueB = 'any object!!!'
17
-
18
- let valueC = Some(null).flatMap(() => Option.of(2)).map(x => x * 3).getOrElse(() => 0);
19
- // valueC = 6
20
-
21
- let valueD = Some(1).mapNullable(() => null).getOrReturn(-1);
22
- // valueD = -1
23
-
24
- Some(1).equals(Some(1))
25
- // true
26
-
27
- None.equals(None)
28
- // true
29
-
30
- Some('abc').equals(None)
31
- // false
32
-
33
- None.isDefined; // false
34
- Some(1).isDefined; // true
35
- Some(1).isEmpty; // false
36
- Some(null).isEmpty; // false! Option<null> is valid!
37
-
38
- Some('foo').get(); // 'foo'
39
- None.get(); // throws an error, use getOrElse or getOrUndefined instead
40
-
41
- Some(3).filter(x => x % 2 === 0); // None
42
-
43
- Some('bar').forEach(x => {
44
- console.log(`my value: ${x}`);
45
- });
9
+ ```bash
10
+ npm install @ekz/option
46
11
  ```
47
12
 
48
- # API
49
-
50
- <!-- Generated by documentation.js. Update this documentation by updating the source code. -->
51
-
52
- ### Table of Contents
53
-
54
- * [Option](#option)
55
- * [Parameters](#parameters)
56
- * [get](#get)
57
- * [isEmpty](#isempty)
58
- * [isDefined](#isdefined)
59
- * [map](#map)
60
- * [Parameters](#parameters-1)
61
- * [mapNullable](#mapnullable)
62
- * [Parameters](#parameters-2)
63
- * [flatMap](#flatmap)
64
- * [Parameters](#parameters-3)
65
- * [forEach](#foreach)
66
- * [Parameters](#parameters-4)
67
- * [filter](#filter)
68
- * [Parameters](#parameters-5)
69
- * [getOrElse](#getorelse)
70
- * [Parameters](#parameters-6)
71
- * [getOrReturn](#getorreturn)
72
- * [Parameters](#parameters-7)
73
- * [getOrUndefined](#getorundefined)
74
- * [equals](#equals)
75
- * [Parameters](#parameters-8)
76
- * [toJSON](#tojson)
77
- * [of](#of)
78
- * [Parameters](#parameters-9)
79
- * [None](#none)
80
- * [Some](#some)
81
- * [None](#none-1)
82
- * [Some](#some-1)
83
- * [Parameters](#parameters-10)
84
-
85
- ## Option
86
-
87
- Represents optional values. Instances of Option are either an instance of Some or the object None.
88
-
89
- ### Parameters
90
-
91
- * `$privateToken` **any**&#x20;
92
-
93
- ### get
94
-
95
- Returns the option's value.
96
-
97
- Type: function (): A
98
-
99
- ### isEmpty
100
-
101
- Returns true if the option is None, false otherwise.
102
-
103
- Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
104
-
105
- ### isDefined
106
-
107
- Returns true if the option is an instance of Some, false otherwise.
108
-
109
- Type: [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
110
-
111
- Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
112
-
113
- ### map
114
-
115
- Returns a Some containing the result of applying f to this Option's value if this Option is nonempty.
116
-
117
- #### Parameters
118
-
119
- * `f` **function (A): B**&#x20;
120
-
121
- Returns **[Option](#option)\<B>**&#x20;
122
-
123
- ### mapNullable
124
-
125
- Like map, but if resulting value is null, then returns None.
126
-
127
- #### Parameters
128
-
129
- * `f` **function (A): B?**&#x20;
130
-
131
- Returns **[Option](#option)\<B>**&#x20;
132
-
133
- ### flatMap
134
-
135
- Returns the result of applying f to this Option's value if this Option is nonempty. Returns None if this Option is empty. Slightly different from map in that f is expected to return an Option (which could be None).
136
-
137
- #### Parameters
138
-
139
- * `f` **function (A): [Option](#option)\<B>**&#x20;
140
-
141
- Returns **[Option](#option)\<B>**&#x20;
142
-
143
- ### forEach
144
-
145
- Apply the given procedure f to the option's value, if it is nonempty.
13
+ ## Quick example
146
14
 
147
- #### Parameters
15
+ ```typescript
16
+ import { Option, Some, None } from '@ekz/option';
148
17
 
149
- * `f` **function (A): any**&#x20;
18
+ const label = Option.of(maybeName).map((n) => n.trim()).getOrElse(() => 'Anonymous');
150
19
 
151
- Returns **void**&#x20;
152
-
153
- ### filter
154
-
155
- Returns this Option if it is nonempty and applying the predicate to this Option's value returns true.
156
-
157
- #### Parameters
158
-
159
- * `predicate` **function (A): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
160
-
161
- Returns **[Option](#option)\<A>**&#x20;
162
-
163
- ### getOrElse
164
-
165
- Returns the option's value if the option is nonempty, otherwise return the result of evaluating other.
166
-
167
- #### Parameters
168
-
169
- * `other` **function (): B**&#x20;
170
-
171
- Returns **(A | B)**&#x20;
172
-
173
- ### getOrReturn
174
-
175
- Returns the option's value if the option is nonempty, otherwise return other.
176
-
177
- #### Parameters
178
-
179
- * `other` **B**&#x20;
180
-
181
- Returns **(A | B)**&#x20;
182
-
183
- ### getOrUndefined
184
-
185
- Returns the option's value if the option is nonempty, otherwise returns undefined.
186
-
187
- Returns **(A | void)**&#x20;
188
-
189
- ### equals
190
-
191
- Compares the option's value with other option's value and returns true when they match. None always matches other None.
192
-
193
- #### Parameters
194
-
195
- * `other` **[Option](#option)\<B>**&#x20;
196
-
197
- Returns **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**&#x20;
198
-
199
- ### toJSON
200
-
201
- Returns value if present, null otherwise. If value contains a method `toJSON`,
202
- returns the result of method call.
203
-
204
- Returns **any**&#x20;
205
-
206
- ### of
207
-
208
- An Option factory which creates Some(x) if the argument is not null, and None if it is null.
209
-
210
- #### Parameters
211
-
212
- * `value` **V??**&#x20;
213
-
214
- Returns **[Option](#option)\<V>**&#x20;
215
-
216
- ### None
217
-
218
- The empty None object
219
-
220
- Type: [Option](#option)\<any>
221
-
222
- ### Some
223
-
224
- Creates Some(x). Note that Some(null) is valid.
225
-
226
- Type: function (value: A): [Option](#option)\<A>
227
-
228
- ## None
229
-
230
- The empty None object.
231
-
232
- Type: [Option](#option)\<any>
233
-
234
- ## Some
235
-
236
- Creates Some(x). Note that Some(null) is valid.
237
-
238
- ### Parameters
239
-
240
- * `value` **A**&#x20;
20
+ Some(1).flatMap((n) => (n > 0 ? Some(n) : None)); // Some(1)
21
+ ```
241
22
 
242
- Returns **[Option](#option)\<A>**&#x20;
23
+ See the [docs](https://docs.ekz.io/option/) for constructors, transformations, and safe unwrapping.
package/package.json CHANGED
@@ -1,47 +1,45 @@
1
1
  {
2
2
  "name": "@ekz/option",
3
- "version": "1.2.6",
4
- "packageManager": "yarn@4.12.0",
5
- "description": "Option/Maybe type to be used with flow.js",
6
- "types": "index.d.ts",
7
- "keywords": [
8
- "option",
9
- "maybe",
10
- "flow",
11
- "scala",
12
- "type-safe"
13
- ],
14
- "author": {
15
- "name": "Alan Heitkotter",
16
- "email": "heitkotter@gmail.com"
17
- },
3
+ "version": "2.0.1",
4
+ "license": "MIT",
5
+ "description": "Option/Maybe type for TypeScript",
6
+ "homepage": "https://docs.ekz.io/option/",
18
7
  "repository": {
19
8
  "type": "git",
20
- "url": "git+https://github.com/erkez/flow-option.git"
9
+ "url": "https://github.com/erkez/ekz.git",
10
+ "directory": "option"
21
11
  },
22
- "bugs": {
23
- "url": "https://github.com/erkez/flow-option/issues"
12
+ "publishConfig": {
13
+ "access": "public",
14
+ "registry": "https://registry.npmjs.org"
24
15
  },
25
- "homepage": "https://github.com/erkez/flow-option#readme",
26
- "main": "lib/index.js",
27
- "license": "MIT",
16
+ "main": "lib/cjs/index.js",
17
+ "module": "lib/esm/index.js",
18
+ "esnext": "lib/esnext/index.js",
19
+ "typings": "lib/esm/index.d.ts",
28
20
  "files": [
29
- "index.d.ts",
30
21
  "lib",
31
22
  "README.md",
32
23
  "LICENSE"
33
24
  ],
25
+ "keywords": [
26
+ "option",
27
+ "maybe",
28
+ "scala",
29
+ "type-safe"
30
+ ],
34
31
  "devDependencies": {
35
- "babel-cli": "^6.26.0",
36
- "babel-preset-env": "^1.7.0",
37
- "babel-preset-flow": "^6.23.0",
38
- "documentation": "^14.0.3",
39
- "flow-bin": "^0.294.0",
40
- "flow-copy-source": "^2.0.9"
32
+ "npm-run-all": "^4.1.5",
33
+ "typescript": "^6.0.3"
41
34
  },
42
35
  "scripts": {
43
- "build": "babel src/ -d lib/ && flow-copy-source -v src lib",
44
- "docs": "documentation readme src/index.js --section=API",
45
- "prepublish": "yarn run docs && yarn run build"
36
+ "clean": "rm -rf lib/* || true",
37
+ "lint": "npx eslint ./src/main/web",
38
+ "lint:fix": "yarn lint --fix",
39
+ "compile": "run-p \"compile:*\"",
40
+ "compile:esm": "tsc -p ./src/main/web --outDir ./lib/esm",
41
+ "compile:cjs": "tsc -p ./src/main/web -m commonjs --verbatimModuleSyntax false --outDir ./lib/cjs",
42
+ "compile:esnext": "tsc -p ./src/main/web -t esnext --outDir ./lib/esnext",
43
+ "prepublish": "yarn clean && yarn lint && yarn compile"
46
44
  }
47
45
  }
package/index.d.ts DELETED
@@ -1,29 +0,0 @@
1
- declare module '@ekz/option' {
2
-
3
- export class Option<A> {
4
- private constructor();
5
- get(): A;
6
- readonly isEmpty: boolean;
7
- readonly isDefined: boolean;
8
- map<B>(f: (value: A) => B): Option<B>;
9
- mapNullable<B>(f: (value: A) => B | null | void | undefined): Option<B>;
10
- flatMap<B>(f: (value: A) => Option<B>): Option<B>;
11
- forEach(f: (value: A) => any): void;
12
- filter(predicate: (value: A) => boolean): Option<A>;
13
- getOrElse<B>(other: () => B): A | B;
14
- getOrReturn<B>(other: B): A | B;
15
- getOrUndefined(): A | undefined;
16
- equals<B>(other: Option<B>): boolean;
17
- toJSON(): unknown;
18
-
19
- static of<V>(value?: V | null | void | undefined): Option<V>;
20
-
21
- static None: Option<never>;
22
- static Some<A>(value: A): Option<A>;
23
- }
24
-
25
- export const None: Option<never>;
26
-
27
- export function Some<A>(value: A): Option<A>;
28
-
29
- }
package/lib/index.js DELETED
@@ -1,254 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
-
9
- exports.Some = Some;
10
-
11
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
12
-
13
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
14
-
15
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
-
17
- var PrivateToken = Symbol('Option');
18
-
19
- /**
20
- * Represents optional values. Instances of Option are either an instance of Some or the object None.
21
- */
22
-
23
- var Option = exports.Option = function () {
24
- /**
25
- * Returns the option's value.
26
- */
27
- function Option($privateToken) {
28
- _classCallCheck(this, Option);
29
-
30
- if ($privateToken !== PrivateToken) {
31
- throw new Error('Option cannot be manually instantiated. Use Option.of, Some or None.');
32
- }
33
- }
34
-
35
- /**
36
- * Returns true if the option is an instance of Some, false otherwise.
37
- */
38
-
39
-
40
- /**
41
- * Returns true if the option is None, false otherwise.
42
- */
43
-
44
-
45
- _createClass(Option, [{
46
- key: 'map',
47
-
48
-
49
- /**
50
- * Returns a Some containing the result of applying f to this Option's value if this Option is nonempty.
51
- */
52
- value: function map(f) {
53
- return this.isEmpty ? None : Some(f(this.get()));
54
- }
55
-
56
- /**
57
- * Like map, but if resulting value is null, then returns None.
58
- */
59
-
60
- }, {
61
- key: 'mapNullable',
62
- value: function mapNullable(f) {
63
- return this.isEmpty ? None : Option.of(f(this.get()));
64
- }
65
-
66
- /**
67
- * Returns the result of applying f to this Option's value if this Option is nonempty. Returns None if this Option is empty. Slightly different from map in that f is expected to return an Option (which could be None).
68
- */
69
-
70
- }, {
71
- key: 'flatMap',
72
- value: function flatMap(f) {
73
- return this.isEmpty ? None : f(this.get());
74
- }
75
-
76
- /**
77
- * Apply the given procedure f to the option's value, if it is nonempty.
78
- */
79
-
80
- }, {
81
- key: 'forEach',
82
- value: function forEach(f) {
83
- if (!this.isEmpty) {
84
- f(this.get());
85
- }
86
- }
87
-
88
- /**
89
- * Returns this Option if it is nonempty and applying the predicate to this Option's value returns true.
90
- */
91
-
92
- }, {
93
- key: 'filter',
94
- value: function filter(predicate) {
95
- return this.isEmpty || predicate(this.get()) ? this : None;
96
- }
97
-
98
- /**
99
- * Returns the option's value if the option is nonempty, otherwise return the result of evaluating other.
100
- */
101
-
102
- }, {
103
- key: 'getOrElse',
104
- value: function getOrElse(other) {
105
- return this.isEmpty ? other() : this.get();
106
- }
107
-
108
- /**
109
- * Returns the option's value if the option is nonempty, otherwise return other.
110
- */
111
-
112
- }, {
113
- key: 'getOrReturn',
114
- value: function getOrReturn(other) {
115
- return this.isEmpty ? other : this.get();
116
- }
117
-
118
- /**
119
- * Returns the option's value if the option is nonempty, otherwise returns undefined.
120
- */
121
-
122
- }, {
123
- key: 'getOrUndefined',
124
- value: function getOrUndefined() {
125
- return this.isEmpty ? undefined : this.get();
126
- }
127
-
128
- /**
129
- * Compares the option's value with other option's value and returns true when they match. None always matches other None.
130
- */
131
-
132
- }, {
133
- key: 'equals',
134
- value: function equals(other) {
135
- return this.isDefined && other.isDefined ? this.get() === other.get() : this === other;
136
- }
137
-
138
- /**
139
- * Returns value if present, null otherwise. If value contains a method `toJSON`,
140
- * returns the result of method call.
141
- */
142
-
143
- }, {
144
- key: 'toJSON',
145
- value: function toJSON() {
146
- var value = this.getOrReturn(null);
147
-
148
- if (value != null && typeof value.toJSON === 'function') {
149
- // $FlowFixMe
150
- return value.toJSON();
151
- } else {
152
- return value;
153
- }
154
- }
155
-
156
- /**
157
- * An Option factory which creates Some(x) if the argument is not null, and None if it is null.
158
- */
159
-
160
- }, {
161
- key: 'isDefined',
162
- get: function get() {
163
- return !this.isEmpty;
164
- }
165
- }], [{
166
- key: 'of',
167
- value: function of(value) {
168
- return value == null ? None : Some(value);
169
- }
170
-
171
- /**
172
- * The empty None object
173
- */
174
-
175
-
176
- /**
177
- * Creates Some(x). Note that Some(null) is valid.
178
- */
179
-
180
- }]);
181
-
182
- return Option;
183
- }();
184
-
185
- var $None = function (_Option) {
186
- _inherits($None, _Option);
187
-
188
- function $None() {
189
- _classCallCheck(this, $None);
190
-
191
- return _possibleConstructorReturn(this, ($None.__proto__ || Object.getPrototypeOf($None)).apply(this, arguments));
192
- }
193
-
194
- _createClass($None, [{
195
- key: 'get',
196
- value: function get() {
197
- throw new Error('No such element');
198
- }
199
- }, {
200
- key: 'isEmpty',
201
- get: function get() {
202
- return true;
203
- }
204
- }]);
205
-
206
- return $None;
207
- }(Option);
208
-
209
- /**
210
- * The empty None object.
211
- */
212
-
213
-
214
- var None = exports.None = new $None(PrivateToken);
215
-
216
- Option.None = None;
217
-
218
- var $Some = function (_Option2) {
219
- _inherits($Some, _Option2);
220
-
221
- function $Some(value) {
222
- _classCallCheck(this, $Some);
223
-
224
- var _this2 = _possibleConstructorReturn(this, ($Some.__proto__ || Object.getPrototypeOf($Some)).call(this, PrivateToken));
225
-
226
- _this2._value = value;
227
- return _this2;
228
- }
229
-
230
- _createClass($Some, [{
231
- key: 'get',
232
- value: function get() {
233
- return this._value;
234
- }
235
- }, {
236
- key: 'isEmpty',
237
- get: function get() {
238
- return false;
239
- }
240
- }]);
241
-
242
- return $Some;
243
- }(Option);
244
-
245
- /**
246
- * Creates Some(x). Note that Some(null) is valid.
247
- */
248
-
249
-
250
- function Some(value) {
251
- return new $Some(value);
252
- }
253
-
254
- Option.Some = Some;
package/lib/index.js.flow DELETED
@@ -1,172 +0,0 @@
1
- // @flow
2
- 'use strict';
3
-
4
- const PrivateToken = Symbol('Option');
5
-
6
- /**
7
- * Represents optional values. Instances of Option are either an instance of Some or the object None.
8
- */
9
- export class Option<+A> {
10
- /**
11
- * Returns the option's value.
12
- */
13
- +get: () => A;
14
-
15
- /**
16
- * Returns true if the option is None, false otherwise.
17
- */
18
- +isEmpty: boolean;
19
-
20
- constructor($privateToken: typeof PrivateToken) {
21
- if ($privateToken !== PrivateToken) {
22
- throw new Error('Option cannot be manually instantiated. Use Option.of, Some or None.');
23
- }
24
- }
25
-
26
- /**
27
- * Returns true if the option is an instance of Some, false otherwise.
28
- */
29
- get isDefined(): boolean {
30
- return !this.isEmpty;
31
- }
32
-
33
- /**
34
- * Returns a Some containing the result of applying f to this Option's value if this Option is nonempty.
35
- */
36
- map<B>(f: A => B): Option<B> {
37
- return this.isEmpty ? None : Some(f(this.get()));
38
- }
39
-
40
- /**
41
- * Like map, but if resulting value is null, then returns None.
42
- */
43
- mapNullable<B>(f: A => ?B): Option<B> {
44
- return this.isEmpty ? None : Option.of(f(this.get()));
45
- }
46
-
47
- /**
48
- * Returns the result of applying f to this Option's value if this Option is nonempty. Returns None if this Option is empty. Slightly different from map in that f is expected to return an Option (which could be None).
49
- */
50
- flatMap<B>(f: A => Option<B>): Option<B> {
51
- return this.isEmpty ? None : f(this.get());
52
- }
53
-
54
- /**
55
- * Apply the given procedure f to the option's value, if it is nonempty.
56
- */
57
- forEach(f: A => any): void {
58
- if (!this.isEmpty) {
59
- f(this.get());
60
- }
61
- }
62
-
63
- /**
64
- * Returns this Option if it is nonempty and applying the predicate to this Option's value returns true.
65
- */
66
- filter(predicate: A => boolean): Option<A> {
67
- return this.isEmpty || predicate(this.get()) ? this : None;
68
- }
69
-
70
- /**
71
- * Returns the option's value if the option is nonempty, otherwise return the result of evaluating other.
72
- */
73
- getOrElse<B>(other: () => B): A | B {
74
- return this.isEmpty ? other() : this.get();
75
- }
76
-
77
- /**
78
- * Returns the option's value if the option is nonempty, otherwise return other.
79
- */
80
- getOrReturn<B>(other: B): A | B {
81
- return this.isEmpty ? other : this.get();
82
- }
83
-
84
- /**
85
- * Returns the option's value if the option is nonempty, otherwise returns undefined.
86
- */
87
- getOrUndefined(): A | void {
88
- return this.isEmpty ? undefined : this.get();
89
- }
90
-
91
- /**
92
- * Compares the option's value with other option's value and returns true when they match. None always matches other None.
93
- */
94
- equals<B>(other: Option<B>): boolean {
95
- return this.isDefined && other.isDefined ? this.get() === other.get() : this === other;
96
- }
97
-
98
- /**
99
- * Returns value if present, null otherwise. If value contains a method `toJSON`,
100
- * returns the result of method call.
101
- */
102
- toJSON(): mixed {
103
- let value = this.getOrReturn(null);
104
-
105
- if (value != null && typeof value.toJSON === 'function') {
106
- // $FlowFixMe
107
- return value.toJSON();
108
- } else {
109
- return value;
110
- }
111
- }
112
-
113
- /**
114
- * An Option factory which creates Some(x) if the argument is not null, and None if it is null.
115
- */
116
- static of<V>(value?: ?V): Option<V> {
117
- return value == null ? None : Some(value);
118
- }
119
-
120
- /**
121
- * The empty None object
122
- */
123
- static None: Option<empty>;
124
-
125
- /**
126
- * Creates Some(x). Note that Some(null) is valid.
127
- */
128
- static Some: <A>(value: A) => Option<A>;
129
- }
130
-
131
- class $None extends Option<empty> {
132
- get() {
133
- throw new Error('No such element');
134
- }
135
-
136
- get isEmpty(): boolean {
137
- return true;
138
- }
139
- }
140
-
141
- /**
142
- * The empty None object.
143
- */
144
- export const None: Option<empty> = new $None(PrivateToken);
145
-
146
- Option.None = None;
147
-
148
- class $Some<A> extends Option<A> {
149
- _value: A;
150
-
151
- constructor(value: A) {
152
- super(PrivateToken);
153
- this._value = value;
154
- }
155
-
156
- get(): A {
157
- return this._value;
158
- }
159
-
160
- get isEmpty(): boolean {
161
- return false;
162
- }
163
- }
164
-
165
- /**
166
- * Creates Some(x). Note that Some(null) is valid.
167
- */
168
- export function Some<+A>(value: A): Option<A> {
169
- return new $Some(value);
170
- }
171
-
172
- Option.Some = Some;