-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.js
2778 lines (2636 loc) · 79.6 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* ___ ______
/ /\ / ___/\
______/ / / _______ __/ /___\/
/ ___ / / / ___ \ /_ __/\
/ /\_/ / / / /__/ /\ \/ /\_\/
/ / // / / / ______/ / / / /
/ /_// / / / /______\/ / / /
\_______/ / \_______/\ /__/ /
\______\/ \______\/ \__*/
//. # sanctuary-def
//.
//. sanctuary-def is a run-time type system for JavaScript. It facilitates
//. the definition of curried JavaScript functions that are explicit about
//. the number of arguments to which they may be applied and the types of
//. those arguments.
//.
//. It is conventional to import the package as `$`:
//.
//. ```javascript
//. const $ = require ('sanctuary-def');
//. ```
//.
//. [`def`][] is a function for defining functions. For example:
//.
//. ```javascript
//. // add :: Number -> Number -> Number
//. const add =
//. $.def ('add') // name
//. ({}) // type-class constraints
//. ([$.Number, $.Number, $.Number]) // input and output types
//. (x => y => x + y); // implementation
//. ```
//.
//. `[$.Number, $.Number, $.Number]` specifies that `add` takes two arguments
//. of type `Number`, one at a time, and returns a value of type `Number`.
//.
//. Applying `add` to two arguments, one at a time, gives the expected result:
//.
//. ```javascript
//. add (2) (2);
//. // => 4
//. ```
//.
//. Applying `add` to multiple arguments at once results in an exception being
//. thrown:
//.
//. ```javascript
//. add (2, 2, 2);
//. // ! TypeError: ‘add’ applied to the wrong number of arguments
//. //
//. // add :: Number -> Number -> Number
//. // ^^^^^^
//. // 1
//. //
//. // Expected one argument but received three arguments:
//. //
//. // - 2
//. // - 2
//. // - 2
//. ```
//.
//. Applying `add` to one argument produces a function awaiting the remaining
//. argument. This is known as partial application. Partial application allows
//. more specific functions to be defined in terms of more general ones:
//.
//. ```javascript
//. // inc :: Number -> Number
//. const inc = add (1);
//.
//. inc (7);
//. // => 8
//. ```
//.
//. JavaScript's implicit type coercion often obfuscates the source of type
//. errors. Consider the following function:
//.
//. ```javascript
//. // _add :: Number -> Number -> Number
//. const _add = x => y => x + y;
//. ```
//.
//. The type signature indicates that `_add` takes arguments of type `Number`,
//. but this is not enforced. This allows type errors to be silently ignored:
//.
//. ```javascript
//. _add ('2') ('2');
//. // => '22'
//. ```
//.
//. `add`, on the other hand, throws if applied to arguments of the wrong
//. types:
//.
//. ```javascript
//. add ('2') ('2');
//. // ! TypeError: Invalid value
//. //
//. // add :: Number -> Number -> Number
//. // ^^^^^^
//. // 1
//. //
//. // 1) "2" :: String
//. //
//. // The value at position 1 is not a member of ‘Number’.
//. ```
//.
//. Type checking is performed as arguments are provided (rather than once all
//. arguments have been provided), so type errors are reported early:
//.
//. ```javascript
//. add ('X');
//. // ! TypeError: Invalid value
//. //
//. // add :: Number -> Number -> Number
//. // ^^^^^^
//. // 1
//. //
//. // 1) "X" :: String
//. //
//. // The value at position 1 is not a member of ‘Number’.
//. ```
//.
//. `add` is monomorphic: its input types and output type are fixed. Some
//. functions are polymorphic: they can operate on values of any type.
//.
//. The identity function is the simplest polymorphic function:
//.
//. ```javascript
//. // id :: a -> a
//. const id = x => x;
//. ```
//.
//. One would need a [type variable][] to define the identity function.
//. Type variables are refined at run-time as input and output values are
//. observed during an application of a function. This works by initially
//. associating the set of all possible types with each of the function's
//. distinct type variables. Each time a value is observed in the position
//. of a type variable, the associated set of types is filtered: each type
//. that does not include the value as a member is removed from the set.
//.
//. This raises the question of what is the set of all possible types,
//. known henceforth as the environment. Although the environment is a
//. set conceptually, it is represented as an array, [`config.env`][],
//. which initially comprises all the built-in JavaScript [types][].
//.
//. One is free to define custom types and add these to the environment:
//.
//. ```javascript
//. $.config.env.push (Foo, Bar);
//. ```
//.
//. This would make members of the `Foo` and `Bar` types compatible with
//. polymorphic functions.
//.
//. Type constructors such as `List :: Type -> Type` cannot be included in
//. the environment as they're not of the correct type. One could, though,
//. use a type constructor to define a fixed number of concrete types:
//.
//. ```javascript
//. $.config.env.push (
//. List ($.Number), // :: Type
//. List ($.String), // :: Type
//. List (List ($.Number)), // :: Type
//. List (List ($.String)), // :: Type
//. List (List (List ($.Number))), // :: Type
//. List (List (List ($.String))), // :: Type
//. );
//. ```
//.
//. Not only would this be tedious, but one could never enumerate all possible
//. types as there are infinitely many. Instead, one should use [`Unknown`][]:
//.
//. ```javascript
//. $.config.env.push (List ($.Unknown));
//. ```
import E from 'sanctuary-either';
import show from 'sanctuary-show';
import Z from 'sanctuary-type-classes';
import type from 'sanctuary-type-identifiers';
const {hasOwnProperty, toString} = globalThis.Object.prototype;
const {Left, Right} = E;
// complement :: (a -> Boolean) -> a -> Boolean
const complement = pred => x => !(pred (x));
// isPrefix :: Array a -> Array a -> Boolean
const isPrefix = candidate => xs => {
if (candidate.length > xs.length) return false;
for (let idx = 0; idx < candidate.length; idx += 1) {
if (candidate[idx] !== xs[idx]) return false;
}
return true;
};
// toArray :: Foldable f => f a -> Array a
const toArray = foldable => (
globalThis.Array.isArray (foldable)
? foldable
: Z.reduce ((xs, x) => ((xs.push (x), xs)), [], foldable)
);
// stripNamespace :: TypeClass -> String
const stripNamespace = ({name}) => name.slice (name.indexOf ('/') + 1);
const _test = x => function recur(t) {
return t.supertypes.every (recur) && t.test (x);
};
const Type$prototype = {
'@@type': 'sanctuary-def/Type@1',
'@@show': function() {
return this.format (s => s, k => s => s);
},
'validate': function(x) {
if (!(_test (x) (this))) return Left ({value: x, propPath: []});
for (let idx = 0; idx < this.keys.length; idx += 1) {
const k = this.keys[idx];
const t = this.types[k];
const ys = this.extractors[k] (x);
for (let idx2 = 0; idx2 < ys.length; idx2 += 1) {
const result = t.validate (ys[idx2]);
if (result.isLeft) {
return Left ({value: result.value.value,
propPath: [k, ...result.value.propPath]});
}
}
}
return Right (x);
},
'fantasy-land/equals': function(other) {
return (
Z.equals (this.type, other.type) &&
Z.equals (this.name, other.name) &&
Z.equals (this.url, other.url) &&
Z.equals (this.supertypes, other.supertypes) &&
this.keys.length === other.keys.length &&
this.keys.every (k => other.keys.includes (k)) &&
Z.equals (this.types, other.types)
);
},
};
// _Type :: ... -> Type
const _Type = (
type, // :: String
name, // :: String
url, // :: String
arity, // :: NonNegativeInteger
format,
// :: Nullable ((String -> String, String -> String -> String) -> String)
supertypes, // :: Array Type
test, // :: Any -> Boolean
tuples // :: Array (Array3 String (a -> Array b) Type)
) => globalThis.Object.assign (
globalThis.Object.create (Type$prototype, {
_extractors: {
value: tuples.reduce ((extractors, [k, e]) => ((
extractors[k] = e,
extractors
)), {}),
},
extractors: {
value: tuples.reduce ((extractors, [k, e]) => ((
extractors[k] = x => toArray (e (x)),
extractors
)), {}),
},
format: {
value: format || ((outer, inner) =>
outer (name) +
Z.foldMap (
globalThis.String,
([k, , t]) => (
t.arity > 0
? outer (' ') + outer ('(') + inner (k) (show (t)) + outer (')')
: outer (' ') + inner (k) (show (t))
),
tuples
)
),
},
test: {
value: test,
},
}),
{
arity, // number of type parameters
keys: tuples.map (([k]) => k),
name,
supertypes,
type,
types: tuples.reduce ((types, [k, , t]) => ((types[k] = t, types)), {}),
url,
}
);
const BINARY = 'BINARY';
const FUNCTION = 'FUNCTION';
const INCONSISTENT = 'INCONSISTENT';
const NO_ARGUMENTS = 'NO_ARGUMENTS';
const NULLARY = 'NULLARY';
const RECORD = 'RECORD';
const UNARY = 'UNARY';
const UNKNOWN = 'UNKNOWN';
const VARIABLE = 'VARIABLE';
// Inconsistent :: Type
const Inconsistent = _Type (
INCONSISTENT,
'',
'',
0,
(outer, inner) => '???',
[],
null,
[]
);
// NoArguments :: Type
const NoArguments = _Type (
NO_ARGUMENTS,
'',
'',
0,
(outer, inner) => '()',
[],
null,
[]
);
// functionUrl :: String -> String
const functionUrl = name => {
const version = '0.22.0'; // updated programmatically
return (
`https://github.com/sanctuary-js/sanctuary-def/tree/v${version}#${name}`
);
};
const NullaryTypeWithUrl = name => supertypes => test => (
_NullaryType (name) (functionUrl (name)) (supertypes) (test)
);
const UnaryTypeWithUrl = name => supertypes => test => _1 => (
_def (name)
({})
([Type, Type])
(_UnaryType (name) (functionUrl (name)) (supertypes) (test) (_1))
);
const BinaryTypeWithUrl = name => supertypes => test => _1 => _2 => (
_def (name)
({})
([Type, Type, Type])
(_BinaryType (name) (functionUrl (name)) (supertypes) (test) (_1) (_2))
);
//# def :: String -> StrMap (Array TypeClass) -> Array Type -> Function -> Function
//.
//. Wraps a function to produce an equivalent function that checks the
//. types of its inputs and output each time it is applied.
//.
//. Takes a name, an object specifying type-class constraints, an array
//. of types, and a function. Returns the type-checked equivalent of the
//. given function.
const _def = name => constraints => types => impl => {
const typeInfo = {
name,
constraints,
types: types.length === 1 ? [NoArguments, ...types] : types,
};
return withTypeChecking (typeInfo, impl);
};
export const config = ((
$checkTypes = true,
$env = [],
) => ({
get checkTypes() {
return $checkTypes;
},
set checkTypes(checkTypes) {
if (typeof checkTypes !== 'boolean') {
throw new TypeError (
"Value of 'checkTypes' property must be either true or false"
);
}
$checkTypes = checkTypes;
},
get env() {
return $env;
},
})) ();
//. ### Types
//.
//. Conceptually, a type is a set of values. One can think of a value of
//. type `Type` as a function of type `Any -> Boolean` that tests values
//. for membership in the set (though this is an oversimplification).
//# Type :: Type
//.
//. Type comprising every `Type` value.
export const Type = NullaryTypeWithUrl
('Type')
([])
(x => type (x) === 'sanctuary-def/Type@1');
//# NonEmpty :: Type -> Type
//.
//. Constructor for non-empty types. `$.NonEmpty ($.String)`, for example, is
//. the type comprising every [`String`][] value except `''`.
//.
//. The given type must satisfy the [Monoid][] and [Setoid][] specifications.
export const NonEmpty = UnaryTypeWithUrl
('NonEmpty')
([])
(x => Z.Monoid.test (x) &&
Z.Setoid.test (x) &&
!(Z.equals (x, Z.empty (x.constructor))))
(monoid => [monoid]);
//# Unknown :: Type
//.
//. Type used to represent missing type information. The type of `[]`,
//. for example, is `Array ???`.
//.
//. May be used with type constructors when defining environments. Given a
//. type constructor `List :: Type -> Type`, one could use `List ($.Unknown)`
//. to include an infinite number of types in an environment:
//.
//. - `List Number`
//. - `List String`
//. - `List (List Number)`
//. - `List (List String)`
//. - `List (List (List Number))`
//. - `List (List (List String))`
//. - `...`
export const Unknown = _Type (
UNKNOWN,
'',
'',
0,
(outer, inner) => 'Unknown',
[],
x => true,
[]
);
//# Void :: Type
//.
//. Uninhabited type.
//.
//. May be used to convey that a type parameter of an algebraic data type
//. will not be used. For example, a future of type `Future Void String`
//. will never be rejected.
export const Void = NullaryTypeWithUrl
('Void')
([])
(x => false);
//# Any :: Type
//.
//. Type comprising every JavaScript value.
export const Any = NullaryTypeWithUrl
('Any')
([])
(x => true);
//# AnyFunction :: Type
//.
//. Type comprising every Function value.
export const AnyFunction = NullaryTypeWithUrl
('Function')
([])
(x => typeof x === 'function');
//# Arguments :: Type
//.
//. Type comprising every [`arguments`][arguments] object.
export const Arguments = NullaryTypeWithUrl
('Arguments')
([])
(x => type (x) === 'Arguments');
//# Array :: Type -> Type
//.
//. Constructor for homogeneous Array types.
export const Array = UnaryTypeWithUrl
('Array')
([])
(x => type (x) === 'Array')
(array => array);
//# Array0 :: Type
//.
//. Type whose sole member is `[]`.
export const Array0 = NullaryTypeWithUrl
('Array0')
([Array (Unknown)])
(array => array.length === 0);
//# Array1 :: Type -> Type
//.
//. Constructor for singleton Array types.
export const Array1 = UnaryTypeWithUrl
('Array1')
([Array (Unknown)])
(array => array.length === 1)
(array1 => array1);
//# Array2 :: Type -> Type -> Type
//.
//. Constructor for heterogeneous Array types of length 2. `['foo', true]` is
//. a member of `Array2 String Boolean`.
export const Array2 = BinaryTypeWithUrl
('Array2')
([Array (Unknown)])
(array => array.length === 2)
(array2 => [array2[0]])
(array2 => [array2[1]]);
//# Boolean :: Type
//.
//. Type comprising `true` and `false`.
export const Boolean = NullaryTypeWithUrl
('Boolean')
([])
(x => typeof x === 'boolean');
//# Buffer :: Type
//.
//. Type comprising every [Buffer][] object.
export const Buffer = NullaryTypeWithUrl
('Buffer')
([])
(x => globalThis.Buffer != null && globalThis.Buffer.isBuffer (x));
//# Date :: Type
//.
//. Type comprising every Date value.
export const Date = NullaryTypeWithUrl
('Date')
([])
(x => type (x) === 'Date');
//# ValidDate :: Type
//.
//. Type comprising every [`Date`][] value except `new Date (NaN)`.
export const ValidDate = NullaryTypeWithUrl
('ValidDate')
([Date])
(date => !(globalThis.Number.isNaN (date.valueOf ())));
//# Descending :: Type -> Type
//.
//. [Descending][] type constructor.
export const Descending = UnaryTypeWithUrl
('Descending')
([])
(x => type (x) === 'sanctuary-descending/Descending@1')
(descending => descending);
//# Either :: Type -> Type -> Type
//.
//. [Either][] type constructor.
export const Either = BinaryTypeWithUrl
('Either')
([])
(x => type (x) === 'sanctuary-either/Either@1')
(either => either.isLeft ? [either.value] : [])
(either => either.isLeft ? [] : [either.value]);
//# Error :: Type
//.
//. Type comprising every Error value, including values of more specific
//. constructors such as [`SyntaxError`][] and [`TypeError`][].
export const Error = NullaryTypeWithUrl
('Error')
([])
(x => type (x) === 'Error');
//# Fn :: Type -> Type -> Type
//.
//. Binary type constructor for unary function types. `$.Fn (I) (O)`
//. represents `I -> O`, the type of functions that take a value of
//. type `I` and return a value of type `O`.
export const Fn = _def
('Fn')
({})
([Type, Type, Type])
($1 => $2 => Function ([$1, $2]));
//# Function :: NonEmpty (Array Type) -> Type
//.
//. Constructor for Function types.
//.
//. Examples:
//.
//. - `$.Function ([$.Date, $.String])` represents the `Date -> String`
//. type; and
//. - `$.Function ([a, b, a])` represents the `(a, b) -> a` type.
export const Function = _def
('Function')
({})
([NonEmpty (Array (Type)), Type])
(types =>
_Type (
FUNCTION,
'',
'',
types.length,
(outer, inner) => {
const repr = (
types
.slice (0, -1)
.map ((t, idx) =>
t.type === FUNCTION
? outer ('(') + inner (`$${idx + 1}`) (show (t)) + outer (')')
: inner (`$${idx + 1}`) (show (t))
)
.join (outer (', '))
);
return (
(types.length === 2 ? repr : outer ('(') + repr + outer (')')) +
outer (' -> ') +
inner (`$${types.length}`)
(show (types[types.length - 1]))
);
},
[AnyFunction],
x => true,
types.map ((t, idx) => [`$${idx + 1}`, x => [], t])
));
//# HtmlElement :: Type
//.
//. Type comprising every [HTML element][].
export const HtmlElement = NullaryTypeWithUrl
('HtmlElement')
([])
(x => /^\[object HTML.*Element\]$/.test (toString.call (x)));
//# Identity :: Type -> Type
//.
//. [Identity][] type constructor.
export const Identity = UnaryTypeWithUrl
('Identity')
([])
(x => type (x) === 'sanctuary-identity/Identity@1')
(identity => identity);
//# JsMap :: Type -> Type -> Type
//.
//. Constructor for native Map types. `$.JsMap ($.Number) ($.String)`,
//. for example, is the type comprising every native Map whose keys are
//. numbers and whose values are strings.
export const JsMap = BinaryTypeWithUrl
('JsMap')
([])
(x => toString.call (x) === '[object Map]')
(jsMap => globalThis.Array.from (jsMap.keys ()))
(jsMap => globalThis.Array.from (jsMap.values ()));
//# JsSet :: Type -> Type
//.
//. Constructor for native Set types. `$.JsSet ($.Number)`, for example,
//. is the type comprising every native Set whose values are numbers.
export const JsSet = UnaryTypeWithUrl
('JsSet')
([])
(x => toString.call (x) === '[object Set]')
(jsSet => globalThis.Array.from (jsSet.values ()));
//# Maybe :: Type -> Type
//.
//. [Maybe][] type constructor.
export const Maybe = UnaryTypeWithUrl
('Maybe')
([])
(x => type (x) === 'sanctuary-maybe/Maybe@1')
(maybe => maybe);
//# Module :: Type
//.
//. Type comprising every ES module.
export const Module = NullaryTypeWithUrl
('Module')
([])
(x => toString.call (x) === '[object Module]');
//# Null :: Type
//.
//. Type whose sole member is `null`.
export const Null = NullaryTypeWithUrl
('Null')
([])
(x => type (x) === 'Null');
//# Nullable :: Type -> Type
//.
//. Constructor for types that include `null` as a member.
export const Nullable = UnaryTypeWithUrl
('Nullable')
([])
(x => true)
// eslint-disable-next-line eqeqeq
(nullable => nullable === null ? [] : [nullable]);
//# Number :: Type
//.
//. Type comprising every primitive Number value (including `NaN`).
export const Number = NullaryTypeWithUrl
('Number')
([])
(x => typeof x === 'number');
const nonZero = x => x !== 0;
const nonNegative = x => x >= 0;
const positive = x => x > 0;
const negative = x => x < 0;
//# PositiveNumber :: Type
//.
//. Type comprising every [`Number`][] value greater than zero.
export const PositiveNumber = NullaryTypeWithUrl
('PositiveNumber')
([Number])
(positive);
//# NegativeNumber :: Type
//.
//. Type comprising every [`Number`][] value less than zero.
export const NegativeNumber = NullaryTypeWithUrl
('NegativeNumber')
([Number])
(negative);
//# ValidNumber :: Type
//.
//. Type comprising every [`Number`][] value except `NaN`.
export const ValidNumber = NullaryTypeWithUrl
('ValidNumber')
([Number])
(complement (globalThis.Number.isNaN));
//# NonZeroValidNumber :: Type
//.
//. Type comprising every [`ValidNumber`][] value except `0` and `-0`.
export const NonZeroValidNumber = NullaryTypeWithUrl
('NonZeroValidNumber')
([ValidNumber])
(nonZero);
//# FiniteNumber :: Type
//.
//. Type comprising every [`ValidNumber`][] value except `Infinity` and
//. `-Infinity`.
export const FiniteNumber = NullaryTypeWithUrl
('FiniteNumber')
([ValidNumber])
(isFinite);
//# NonZeroFiniteNumber :: Type
//.
//. Type comprising every [`FiniteNumber`][] value except `0` and `-0`.
export const NonZeroFiniteNumber = NullaryTypeWithUrl
('NonZeroFiniteNumber')
([FiniteNumber])
(nonZero);
//# PositiveFiniteNumber :: Type
//.
//. Type comprising every [`FiniteNumber`][] value greater than zero.
export const PositiveFiniteNumber = NullaryTypeWithUrl
('PositiveFiniteNumber')
([FiniteNumber])
(positive);
//# NegativeFiniteNumber :: Type
//.
//. Type comprising every [`FiniteNumber`][] value less than zero.
export const NegativeFiniteNumber = NullaryTypeWithUrl
('NegativeFiniteNumber')
([FiniteNumber])
(negative);
//# Integer :: Type
//.
//. Type comprising every integer in the range
//. [[`Number.MIN_SAFE_INTEGER`][min] .. [`Number.MAX_SAFE_INTEGER`][max]].
export const Integer = NullaryTypeWithUrl
('Integer')
([ValidNumber])
(x => Math.floor (x) === x &&
x >= globalThis.Number.MIN_SAFE_INTEGER &&
x <= globalThis.Number.MAX_SAFE_INTEGER);
//# NonZeroInteger :: Type
//.
//. Type comprising every [`Integer`][] value except `0` and `-0`.
export const NonZeroInteger = NullaryTypeWithUrl
('NonZeroInteger')
([Integer])
(nonZero);
//# NonNegativeInteger :: Type
//.
//. Type comprising every non-negative [`Integer`][] value (including `-0`).
//. Also known as the set of natural numbers under ISO 80000-2:2009.
export const NonNegativeInteger = NullaryTypeWithUrl
('NonNegativeInteger')
([Integer])
(nonNegative);
//# PositiveInteger :: Type
//.
//. Type comprising every [`Integer`][] value greater than zero.
export const PositiveInteger = NullaryTypeWithUrl
('PositiveInteger')
([Integer])
(positive);
//# NegativeInteger :: Type
//.
//. Type comprising every [`Integer`][] value less than zero.
export const NegativeInteger = NullaryTypeWithUrl
('NegativeInteger')
([Integer])
(negative);
//# Object :: Type
//.
//. Type comprising every "plain" Object value. Specifically, values
//. created via:
//.
//. - object literal syntax;
//. - [`Object.create`][]; or
//. - the `new` operator in conjunction with `Object` or a custom
//. constructor function.
export const Object = NullaryTypeWithUrl
('Object')
([])
(x => type (x) === 'Object');
//# Pair :: Type -> Type -> Type
//.
//. [Pair][] type constructor.
export const Pair = BinaryTypeWithUrl
('Pair')
([])
(x => type (x) === 'sanctuary-pair/Pair@1')
(pair => [pair.fst])
(pair => [pair.snd]);
//# RegExp :: Type
//.
//. Type comprising every RegExp value.
export const RegExp = NullaryTypeWithUrl
('RegExp')
([])
(x => type (x) === 'RegExp');
//# GlobalRegExp :: Type
//.
//. Type comprising every [`RegExp`][] value whose `global` flag is `true`.
//.
//. See also [`NonGlobalRegExp`][].
export const GlobalRegExp = NullaryTypeWithUrl
('GlobalRegExp')
([RegExp])
(regexp => regexp.global);
//# NonGlobalRegExp :: Type
//.
//. Type comprising every [`RegExp`][] value whose `global` flag is `false`.
//.
//. See also [`GlobalRegExp`][].
export const NonGlobalRegExp = NullaryTypeWithUrl
('NonGlobalRegExp')
([RegExp])
(regexp => !regexp.global);
//# StrMap :: Type -> Type
//.
//. Constructor for homogeneous Object types.
//.
//. `{foo: 1, bar: 2, baz: 3}`, for example, is a member of `StrMap Number`;
//. `{foo: 1, bar: 2, baz: 'XXX'}` is not.
export const StrMap = UnaryTypeWithUrl
('StrMap')
([Object])
(x => true)
(strMap => strMap);
//# String :: Type
//.
//. Type comprising every primitive String value.
export const String = NullaryTypeWithUrl
('String')
([])
(x => typeof x === 'string');
//# RegexFlags :: Type
//.
//. Type comprising the RegExp flags *accepted by the runtime*.
//. Repeated characters are not permitted. Invalid combinations
//. (such as `'uv'`) are not permitted.
export const RegexFlags = NullaryTypeWithUrl
('RegexFlags')
([String])
(s => {
try { globalThis.RegExp ('', s); } catch { return false; }
return true;
});
//# Symbol :: Type
//.
//. Type comprising every Symbol value.
export const Symbol = NullaryTypeWithUrl
('Symbol')
([])
(x => typeof x === 'symbol');
//# TypeClass :: Type
//.
//. Type comprising every [`TypeClass`][] value.
export const TypeClass = NullaryTypeWithUrl
('TypeClass')
([])
(x => type (x) === 'sanctuary-type-classes/TypeClass@1');
//# Undefined :: Type
//.
//. Type whose sole member is `undefined`.
export const Undefined = NullaryTypeWithUrl
('Undefined')
([])
(x => type (x) === 'Undefined');
//# config.checkTypes :: Boolean
//.
//. Run-time type checking is not free; one may wish to pay the performance
//. cost during development but not in production. Setting `config.checkTypes`
//. to `false` disables type checking, even for functions already defined.
//.
//. One may choose to use an environment variable to control type checking:
//.
//. ```javascript
//. $.config.checkTypes = process.env.NODE_ENV === 'development';
//. ```
//# config.env :: Array Type
//.
//. An array of [types][]:
//.
//. - <code>[AnyFunction](#AnyFunction)</code>
//. - <code>[Arguments](#Arguments)</code>
//. - <code>[Array](#Array) ([Unknown][])</code>
//. - <code>[Array2](#Array2) ([Unknown][]) ([Unknown][])</code>
//. - <code>[Boolean](#Boolean)</code>
//. - <code>[Buffer](#Buffer)</code>
//. - <code>[Date](#Date)</code>
//. - <code>[Descending](#Descending) ([Unknown][])</code>
//. - <code>[Either](#Either) ([Unknown][]) ([Unknown][])</code>
//. - <code>[Error](#Error)</code>
//. - <code>[Fn](#Fn) ([Unknown][]) ([Unknown][])</code>
//. - <code>[HtmlElement](#HtmlElement)</code>
//. - <code>[Identity](#Identity) ([Unknown][])</code>
//. - <code>[JsMap](#JsMap) ([Unknown][]) ([Unknown][])</code>
//. - <code>[JsSet](#JsSet) ([Unknown][])</code>
//. - <code>[Maybe](#Maybe) ([Unknown][])</code>
//. - <code>[Module](#Module)</code>
//. - <code>[Null](#Null)</code>
//. - <code>[Number](#Number)</code>
//. - <code>[Object](#Object)</code>
//. - <code>[Pair](#Pair) ([Unknown][]) ([Unknown][])</code>
//. - <code>[RegExp](#RegExp)</code>
//. - <code>[StrMap](#StrMap) ([Unknown][])</code>
//. - <code>[String](#String)</code>
//. - <code>[Symbol](#Symbol)</code>
//. - <code>[Type](#Type)</code>
//. - <code>[TypeClass](#TypeClass)</code>
//. - <code>[Undefined](#Undefined)</code>
config.env.push (
AnyFunction,
Arguments,
Array (Unknown),
Array2 (Unknown) (Unknown),
Boolean,
Buffer,
Date,
Descending (Unknown),
Either (Unknown) (Unknown),
Error,
Fn (Unknown) (Unknown),
HtmlElement,
Identity (Unknown),