-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
4072 lines (3884 loc) · 211 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Sanctuary</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Fira+Code:400,500,700&display=swap">
<link rel="stylesheet" href="style.css">
<link rel="shortcut icon" href="favicon.png">
<link rel="mask-icon" href="mask-icon.svg" color="#080">
</head>
<body spellcheck="false">
<div id="css-header">
<p>
Join the Sanctuary community on
<a href="https://github.com/sanctuary-js/sanctuary">GitHub</a>,
<a href="https://gitter.im/sanctuary-js/sanctuary">Gitter</a>, and
<a href="https://stackoverflow.com/questions/tagged/sanctuary">Stack Overflow</a>
</p>
</div>
<div id="css-main">
<h1 id="sanctuary">Sanctuary <small>v3.1.0</small></h1>
<p id="tagline">Refuge from unsafe JavaScript</p>
<ul id="toc">
<li>
<a href="#section:overview">Overview</a>
</li>
<li>
<a href="#section:sponsors">Sponsors</a>
</li>
<li>
<a href="#section:folktale">Folktale</a>
</li>
<li>
<a href="#section:ramda">Ramda</a>
<ul>
<li>
<a href="#section:totality">Totality</a>
</li>
<li>
<a href="#section:information-preservation">Information preservation</a>
</li>
<li>
<a href="#section:invariants">Invariants</a>
</li>
<li>
<a href="#section:currying">Currying</a>
</li>
<li>
<a href="#section:variadic-functions">Variadic functions</a>
</li>
<li>
<a href="#section:implicit-context">Implicit context</a>
</li>
<li>
<a href="#section:transducers">Transducers</a>
</li>
<li>
<a href="#section:modularity">Modularity</a>
</li>
</ul>
</li>
<li>
<a href="#section:types">Types</a>
</li>
<li>
<a href="#section:type-checking">Type checking</a>
</li>
<li>
<a href="#section:installation">Installation</a>
</li>
<li>
<a href="#section:api">API</a>
<ul>
<li>
<details>
<summary><a href="#section:configure">Configure</a></summary>
<ul>
<li>
<a href="#create"><code><b>create</b> :: { checkTypes :: Boolean, env :: Array Type } -> Module</code></a>
</li>
<li>
<a href="#env"><code><b>env</b> :: Array Type</code></a>
</li>
<li>
<a href="#unchecked"><code><b>unchecked</b> :: Module</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:classify">Classify</a></summary>
<ul>
<li>
<a href="#type"><code><b>type</b> :: Any -> { namespace :: Maybe String, name :: String, version :: NonNegativeInteger }</code></a>
</li>
<li>
<a href="#is"><code><b>is</b> :: Type -> Any -> Boolean</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:showable">Showable</a></summary>
<ul>
<li>
<a href="#show"><code><b>show</b> :: Any -> String</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:fantasy-land">Fantasy Land</a></summary>
<ul>
<li>
<a href="#equals"><code><b>equals</b> :: Setoid a => a -> a -> Boolean</code></a>
</li>
<li>
<a href="#lt"><code><b>lt</b> :: Ord a => a -> a -> Boolean</code></a>
</li>
<li>
<a href="#lte"><code><b>lte</b> :: Ord a => a -> a -> Boolean</code></a>
</li>
<li>
<a href="#gt"><code><b>gt</b> :: Ord a => a -> a -> Boolean</code></a>
</li>
<li>
<a href="#gte"><code><b>gte</b> :: Ord a => a -> a -> Boolean</code></a>
</li>
<li>
<a href="#min"><code><b>min</b> :: Ord a => a -> a -> a</code></a>
</li>
<li>
<a href="#max"><code><b>max</b> :: Ord a => a -> a -> a</code></a>
</li>
<li>
<a href="#clamp"><code><b>clamp</b> :: Ord a => a -> a -> a -> a</code></a>
</li>
<li>
<a href="#id"><code><b>id</b> :: Category c => TypeRep c -> c</code></a>
</li>
<li>
<a href="#concat"><code><b>concat</b> :: Semigroup a => a -> a -> a</code></a>
</li>
<li>
<a href="#empty"><code><b>empty</b> :: Monoid a => TypeRep a -> a</code></a>
</li>
<li>
<a href="#invert"><code><b>invert</b> :: Group g => g -> g</code></a>
</li>
<li>
<a href="#filter"><code><b>filter</b> :: Filterable f => (a -> Boolean) -> f a -> f a</code></a>
</li>
<li>
<a href="#reject"><code><b>reject</b> :: Filterable f => (a -> Boolean) -> f a -> f a</code></a>
</li>
<li>
<a href="#map"><code><b>map</b> :: Functor f => (a -> b) -> f a -> f b</code></a>
</li>
<li>
<a href="#flip"><code><b>flip</b> :: Functor f => f (a -> b) -> a -> f b</code></a>
</li>
<li>
<a href="#bimap"><code><b>bimap</b> :: Bifunctor f => (a -> b) -> (c -> d) -> f a c -> f b d</code></a>
</li>
<li>
<a href="#mapLeft"><code><b>mapLeft</b> :: Bifunctor f => (a -> b) -> f a c -> f b c</code></a>
</li>
<li>
<a href="#promap"><code><b>promap</b> :: Profunctor p => (a -> b) -> (c -> d) -> p b c -> p a d</code></a>
</li>
<li>
<a href="#alt"><code><b>alt</b> :: Alt f => f a -> f a -> f a</code></a>
</li>
<li>
<a href="#zero"><code><b>zero</b> :: Plus f => TypeRep f -> f a</code></a>
</li>
<li>
<a href="#reduce"><code><b>reduce</b> :: Foldable f => (b -> a -> b) -> b -> f a -> b</code></a>
</li>
<li>
<a href="#reduce_"><code><b>reduce_</b> :: Foldable f => (a -> b -> b) -> b -> f a -> b</code></a>
</li>
<li>
<a href="#traverse"><code><b>traverse</b> :: (Applicative f, Traversable t) => TypeRep f -> (a -> f b) -> t a -> f (t b)</code></a>
</li>
<li>
<a href="#sequence"><code><b>sequence</b> :: (Applicative f, Traversable t) => TypeRep f -> t (f a) -> f (t a)</code></a>
</li>
<li>
<a href="#ap"><code><b>ap</b> :: Apply f => f (a -> b) -> f a -> f b</code></a>
</li>
<li>
<a href="#lift2"><code><b>lift2</b> :: Apply f => (a -> b -> c) -> f a -> f b -> f c</code></a>
</li>
<li>
<a href="#lift3"><code><b>lift3</b> :: Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d</code></a>
</li>
<li>
<a href="#apFirst"><code><b>apFirst</b> :: Apply f => f a -> f b -> f a</code></a>
</li>
<li>
<a href="#apSecond"><code><b>apSecond</b> :: Apply f => f a -> f b -> f b</code></a>
</li>
<li>
<a href="#of"><code><b>of</b> :: Applicative f => TypeRep f -> a -> f a</code></a>
</li>
<li>
<a href="#chain"><code><b>chain</b> :: Chain m => (a -> m b) -> m a -> m b</code></a>
</li>
<li>
<a href="#join"><code><b>join</b> :: Chain m => m (m a) -> m a</code></a>
</li>
<li>
<a href="#chainRec"><code><b>chainRec</b> :: ChainRec m => TypeRep m -> (a -> m (Either a b)) -> a -> m b</code></a>
</li>
<li>
<a href="#extend"><code><b>extend</b> :: Extend w => (w a -> b) -> w a -> w b</code></a>
</li>
<li>
<a href="#duplicate"><code><b>duplicate</b> :: Extend w => w a -> w (w a)</code></a>
</li>
<li>
<a href="#extract"><code><b>extract</b> :: Comonad w => w a -> a</code></a>
</li>
<li>
<a href="#contramap"><code><b>contramap</b> :: Contravariant f => (b -> a) -> f a -> f b</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:combinator">Combinator</a></summary>
<ul>
<li>
<a href="#I"><code><b>I</b> :: a -> a</code></a>
</li>
<li>
<a href="#K"><code><b>K</b> :: a -> b -> a</code></a>
</li>
<li>
<a href="#T"><code><b>T</b> :: a -> (a -> b) -> b</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:function">Function</a></summary>
<ul>
<li>
<a href="#curry2"><code><b>curry2</b> :: ((a, b) -> c) -> a -> b -> c</code></a>
</li>
<li>
<a href="#curry3"><code><b>curry3</b> :: ((a, b, c) -> d) -> a -> b -> c -> d</code></a>
</li>
<li>
<a href="#curry4"><code><b>curry4</b> :: ((a, b, c, d) -> e) -> a -> b -> c -> d -> e</code></a>
</li>
<li>
<a href="#curry5"><code><b>curry5</b> :: ((a, b, c, d, e) -> f) -> a -> b -> c -> d -> e -> f</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:composition">Composition</a></summary>
<ul>
<li>
<a href="#compose"><code><b>compose</b> :: Semigroupoid s => s b c -> s a b -> s a c</code></a>
</li>
<li>
<a href="#pipe"><code><b>pipe</b> :: Foldable f => f (Any -> Any) -> a -> b</code></a>
</li>
<li>
<a href="#pipeK"><code><b>pipeK</b> :: (Foldable f, Chain m) => f (Any -> m Any) -> m a -> m b</code></a>
</li>
<li>
<a href="#on"><code><b>on</b> :: (b -> b -> c) -> (a -> b) -> a -> a -> c</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:pair">Pair</a></summary>
<ul>
<li>
<a href="#Pair"><code><b>Pair</b> :: a -> b -> Pair a b</code></a>
</li>
<li>
<a href="#pair"><code><b>pair</b> :: (a -> b -> c) -> Pair a b -> c</code></a>
</li>
<li>
<a href="#fst"><code><b>fst</b> :: Pair a b -> a</code></a>
</li>
<li>
<a href="#snd"><code><b>snd</b> :: Pair a b -> b</code></a>
</li>
<li>
<a href="#swap"><code><b>swap</b> :: Pair a b -> Pair b a</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:maybe">Maybe</a></summary>
<ul>
<li>
<a href="#Maybe"><code><b>Maybe</b> :: TypeRep Maybe</code></a>
</li>
<li>
<a href="#Nothing"><code><b>Nothing</b> :: Maybe a</code></a>
</li>
<li>
<a href="#Just"><code><b>Just</b> :: a -> Maybe a</code></a>
</li>
<li>
<a href="#isNothing"><code><b>isNothing</b> :: Maybe a -> Boolean</code></a>
</li>
<li>
<a href="#isJust"><code><b>isJust</b> :: Maybe a -> Boolean</code></a>
</li>
<li>
<a href="#maybe"><code><b>maybe</b> :: b -> (a -> b) -> Maybe a -> b</code></a>
</li>
<li>
<a href="#maybe_"><code><b>maybe_</b> :: (() -> b) -> (a -> b) -> Maybe a -> b</code></a>
</li>
<li>
<a href="#fromMaybe"><code><b>fromMaybe</b> :: a -> Maybe a -> a</code></a>
</li>
<li>
<a href="#fromMaybe_"><code><b>fromMaybe_</b> :: (() -> a) -> Maybe a -> a</code></a>
</li>
<li>
<a href="#justs"><code><b>justs</b> :: (Filterable f, Functor f) => f (Maybe a) -> f a</code></a>
</li>
<li>
<a href="#mapMaybe"><code><b>mapMaybe</b> :: (Filterable f, Functor f) => (a -> Maybe b) -> f a -> f b</code></a>
</li>
<li>
<a href="#maybeToNullable"><code><b>maybeToNullable</b> :: Maybe a -> Nullable a</code></a>
</li>
<li>
<a href="#maybeToEither"><code><b>maybeToEither</b> :: a -> Maybe b -> Either a b</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:either">Either</a></summary>
<ul>
<li>
<a href="#Either"><code><b>Either</b> :: TypeRep Either</code></a>
</li>
<li>
<a href="#Left"><code><b>Left</b> :: a -> Either a b</code></a>
</li>
<li>
<a href="#Right"><code><b>Right</b> :: b -> Either a b</code></a>
</li>
<li>
<a href="#isLeft"><code><b>isLeft</b> :: Either a b -> Boolean</code></a>
</li>
<li>
<a href="#isRight"><code><b>isRight</b> :: Either a b -> Boolean</code></a>
</li>
<li>
<a href="#either"><code><b>either</b> :: (a -> c) -> (b -> c) -> Either a b -> c</code></a>
</li>
<li>
<a href="#fromLeft"><code><b>fromLeft</b> :: a -> Either a b -> a</code></a>
</li>
<li>
<a href="#fromRight"><code><b>fromRight</b> :: b -> Either a b -> b</code></a>
</li>
<li>
<a href="#fromEither"><code><b>fromEither</b> :: b -> Either a b -> b</code></a>
</li>
<li>
<a href="#lefts"><code><b>lefts</b> :: (Filterable f, Functor f) => f (Either a b) -> f a</code></a>
</li>
<li>
<a href="#rights"><code><b>rights</b> :: (Filterable f, Functor f) => f (Either a b) -> f b</code></a>
</li>
<li>
<a href="#tagBy"><code><b>tagBy</b> :: (a -> Boolean) -> a -> Either a a</code></a>
</li>
<li>
<a href="#encase"><code><b>encase</b> :: Throwing e a b -> a -> Either e b</code></a>
</li>
<li>
<a href="#eitherToMaybe"><code><b>eitherToMaybe</b> :: Either a b -> Maybe b</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:logic">Logic</a></summary>
<ul>
<li>
<a href="#and"><code><b>and</b> :: Boolean -> Boolean -> Boolean</code></a>
</li>
<li>
<a href="#or"><code><b>or</b> :: Boolean -> Boolean -> Boolean</code></a>
</li>
<li>
<a href="#not"><code><b>not</b> :: Boolean -> Boolean</code></a>
</li>
<li>
<a href="#complement"><code><b>complement</b> :: (a -> Boolean) -> a -> Boolean</code></a>
</li>
<li>
<a href="#boolean"><code><b>boolean</b> :: a -> a -> Boolean -> a</code></a>
</li>
<li>
<a href="#ifElse"><code><b>ifElse</b> :: (a -> Boolean) -> (a -> b) -> (a -> b) -> a -> b</code></a>
</li>
<li>
<a href="#when"><code><b>when</b> :: (a -> Boolean) -> (a -> a) -> a -> a</code></a>
</li>
<li>
<a href="#unless"><code><b>unless</b> :: (a -> Boolean) -> (a -> a) -> a -> a</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:array">Array</a></summary>
<ul>
<li>
<a href="#array"><code><b>array</b> :: b -> (a -> Array a -> b) -> Array a -> b</code></a>
</li>
<li>
<a href="#head"><code><b>head</b> :: Foldable f => f a -> Maybe a</code></a>
</li>
<li>
<a href="#last"><code><b>last</b> :: Foldable f => f a -> Maybe a</code></a>
</li>
<li>
<a href="#tail"><code><b>tail</b> :: (Applicative f, Foldable f, Monoid (f a)) => f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#init"><code><b>init</b> :: (Applicative f, Foldable f, Monoid (f a)) => f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#take"><code><b>take</b> :: (Applicative f, Foldable f, Monoid (f a)) => Integer -> f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#drop"><code><b>drop</b> :: (Applicative f, Foldable f, Monoid (f a)) => Integer -> f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#takeLast"><code><b>takeLast</b> :: (Applicative f, Foldable f, Monoid (f a)) => Integer -> f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#dropLast"><code><b>dropLast</b> :: (Applicative f, Foldable f, Monoid (f a)) => Integer -> f a -> Maybe (f a)</code></a>
</li>
<li>
<a href="#takeWhile"><code><b>takeWhile</b> :: (a -> Boolean) -> Array a -> Array a</code></a>
</li>
<li>
<a href="#dropWhile"><code><b>dropWhile</b> :: (a -> Boolean) -> Array a -> Array a</code></a>
</li>
<li>
<a href="#size"><code><b>size</b> :: Foldable f => f a -> NonNegativeInteger</code></a>
</li>
<li>
<a href="#all"><code><b>all</b> :: Foldable f => (a -> Boolean) -> f a -> Boolean</code></a>
</li>
<li>
<a href="#any"><code><b>any</b> :: Foldable f => (a -> Boolean) -> f a -> Boolean</code></a>
</li>
<li>
<a href="#none"><code><b>none</b> :: Foldable f => (a -> Boolean) -> f a -> Boolean</code></a>
</li>
<li>
<a href="#append"><code><b>append</b> :: (Applicative f, Semigroup (f a)) => a -> f a -> f a</code></a>
</li>
<li>
<a href="#prepend"><code><b>prepend</b> :: (Applicative f, Semigroup (f a)) => a -> f a -> f a</code></a>
</li>
<li>
<a href="#joinWith"><code><b>joinWith</b> :: String -> Array String -> String</code></a>
</li>
<li>
<a href="#elem"><code><b>elem</b> :: (Setoid a, Foldable f) => a -> f a -> Boolean</code></a>
</li>
<li>
<a href="#find"><code><b>find</b> :: Foldable f => (a -> Boolean) -> f a -> Maybe a</code></a>
</li>
<li>
<a href="#intercalate"><code><b>intercalate</b> :: (Monoid m, Foldable f) => m -> f m -> m</code></a>
</li>
<li>
<a href="#foldMap"><code><b>foldMap</b> :: (Monoid m, Foldable f) => TypeRep m -> (a -> m) -> f a -> m</code></a>
</li>
<li>
<a href="#unfoldr"><code><b>unfoldr</b> :: (b -> Maybe (Pair a b)) -> b -> Array a</code></a>
</li>
<li>
<a href="#range"><code><b>range</b> :: Integer -> Integer -> Array Integer</code></a>
</li>
<li>
<a href="#groupBy"><code><b>groupBy</b> :: (a -> a -> Boolean) -> Array a -> Array (Array a)</code></a>
</li>
<li>
<a href="#reverse"><code><b>reverse</b> :: (Applicative f, Foldable f, Monoid (f a)) => f a -> f a</code></a>
</li>
<li>
<a href="#sort"><code><b>sort</b> :: (Ord a, Applicative m, Foldable m, Monoid (m a)) => m a -> m a</code></a>
</li>
<li>
<a href="#sortBy"><code><b>sortBy</b> :: (Ord b, Applicative m, Foldable m, Monoid (m a)) => (a -> b) -> m a -> m a</code></a>
</li>
<li>
<a href="#zip"><code><b>zip</b> :: Array a -> Array b -> Array (Pair a b)</code></a>
</li>
<li>
<a href="#zipWith"><code><b>zipWith</b> :: (a -> b -> c) -> Array a -> Array b -> Array c</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:object">Object</a></summary>
<ul>
<li>
<a href="#prop"><code><b>prop</b> :: String -> a -> b</code></a>
</li>
<li>
<a href="#props"><code><b>props</b> :: Array String -> a -> b</code></a>
</li>
<li>
<a href="#get"><code><b>get</b> :: (Any -> Boolean) -> String -> a -> Maybe b</code></a>
</li>
<li>
<a href="#gets"><code><b>gets</b> :: (Any -> Boolean) -> Array String -> a -> Maybe b</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:strmap">StrMap</a></summary>
<ul>
<li>
<a href="#value"><code><b>value</b> :: String -> StrMap a -> Maybe a</code></a>
</li>
<li>
<a href="#singleton"><code><b>singleton</b> :: String -> a -> StrMap a</code></a>
</li>
<li>
<a href="#insert"><code><b>insert</b> :: String -> a -> StrMap a -> StrMap a</code></a>
</li>
<li>
<a href="#remove"><code><b>remove</b> :: String -> StrMap a -> StrMap a</code></a>
</li>
<li>
<a href="#keys"><code><b>keys</b> :: StrMap a -> Array String</code></a>
</li>
<li>
<a href="#values"><code><b>values</b> :: StrMap a -> Array a</code></a>
</li>
<li>
<a href="#pairs"><code><b>pairs</b> :: StrMap a -> Array (Pair String a)</code></a>
</li>
<li>
<a href="#fromPairs"><code><b>fromPairs</b> :: Foldable f => f (Pair String a) -> StrMap a</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:number">Number</a></summary>
<ul>
<li>
<a href="#negate"><code><b>negate</b> :: ValidNumber -> ValidNumber</code></a>
</li>
<li>
<a href="#add"><code><b>add</b> :: FiniteNumber -> FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#sum"><code><b>sum</b> :: Foldable f => f FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#sub"><code><b>sub</b> :: FiniteNumber -> FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#mult"><code><b>mult</b> :: FiniteNumber -> FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#product"><code><b>product</b> :: Foldable f => f FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#div"><code><b>div</b> :: NonZeroFiniteNumber -> FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#pow"><code><b>pow</b> :: FiniteNumber -> FiniteNumber -> FiniteNumber</code></a>
</li>
<li>
<a href="#mean"><code><b>mean</b> :: Foldable f => f FiniteNumber -> Maybe FiniteNumber</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:integer">Integer</a></summary>
<ul>
<li>
<a href="#even"><code><b>even</b> :: Integer -> Boolean</code></a>
</li>
<li>
<a href="#odd"><code><b>odd</b> :: Integer -> Boolean</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:parse">Parse</a></summary>
<ul>
<li>
<a href="#parseDate"><code><b>parseDate</b> :: String -> Maybe ValidDate</code></a>
</li>
<li>
<a href="#parseFloat"><code><b>parseFloat</b> :: String -> Maybe Number</code></a>
</li>
<li>
<a href="#parseInt"><code><b>parseInt</b> :: Radix -> String -> Maybe Integer</code></a>
</li>
<li>
<a href="#parseJson"><code><b>parseJson</b> :: (Any -> Boolean) -> String -> Maybe a</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:regexp">RegExp</a></summary>
<ul>
<li>
<a href="#regex"><code><b>regex</b> :: RegexFlags -> String -> RegExp</code></a>
</li>
<li>
<a href="#regexEscape"><code><b>regexEscape</b> :: String -> String</code></a>
</li>
<li>
<a href="#test"><code><b>test</b> :: RegExp -> String -> Boolean</code></a>
</li>
<li>
<a href="#match"><code><b>match</b> :: NonGlobalRegExp -> String -> Maybe { match :: String, groups :: Array (Maybe String) }</code></a>
</li>
<li>
<a href="#matchAll"><code><b>matchAll</b> :: GlobalRegExp -> String -> Array { match :: String, groups :: Array (Maybe String) }</code></a>
</li>
</ul>
</details>
</li>
<li>
<details>
<summary><a href="#section:string">String</a></summary>
<ul>
<li>
<a href="#toUpper"><code><b>toUpper</b> :: String -> String</code></a>
</li>
<li>
<a href="#toLower"><code><b>toLower</b> :: String -> String</code></a>
</li>
<li>
<a href="#trim"><code><b>trim</b> :: String -> String</code></a>
</li>
<li>
<a href="#stripPrefix"><code><b>stripPrefix</b> :: String -> String -> Maybe String</code></a>
</li>
<li>
<a href="#stripSuffix"><code><b>stripSuffix</b> :: String -> String -> Maybe String</code></a>
</li>
<li>
<a href="#words"><code><b>words</b> :: String -> Array String</code></a>
</li>
<li>
<a href="#unwords"><code><b>unwords</b> :: Array String -> String</code></a>
</li>
<li>
<a href="#lines"><code><b>lines</b> :: String -> Array String</code></a>
</li>
<li>
<a href="#unlines"><code><b>unlines</b> :: Array String -> String</code></a>
</li>
<li>
<a href="#splitOn"><code><b>splitOn</b> :: String -> String -> Array String</code></a>
</li>
<li>
<a href="#splitOnRegex"><code><b>splitOnRegex</b> :: GlobalRegExp -> String -> Array String</code></a>
</li>
</ul>
</details>
</li>
</ul>
</li>
</ul>
<a class="pilcrow h2" href="#section:overview">¶</a>
<h2 id="section:overview">Overview</h2>
<p>Sanctuary is a JavaScript functional programming library inspired by
<a href="https://www.haskell.org/">Haskell</a> and <a href="http://www.purescript.org/">PureScript</a>. It's stricter than <a href="https://ramdajs.com/">Ramda</a>, and
provides a similar suite of functions.</p>
<p>Sanctuary promotes programs composed of simple, pure functions. Such
programs are easier to comprehend, test, and maintain – they are
also a pleasure to write.</p>
<p>Sanctuary provides two data types, <a href="#section:maybe">Maybe</a> and <a href="#section:either">Either</a>, both of
which are compatible with <a href="https://github.com/fantasyland/fantasy-land/tree/v4.0.1">Fantasy Land</a>. Thanks to these data types
even Sanctuary functions that may fail, such as <a href="#head"><code>head</code></a>, are
composable.</p>
<p>Sanctuary makes it possible to write safe code without null checks.
In JavaScript it's trivial to introduce a possible run-time type error.</p>
<p>Try changing <code>words</code> to <code>[]</code> in the REPL below. Hit <em>return</em> to re-evaluate.</p>
<div class="examples">
<form>
<input value="words = ['foo', 'bar', 'baz']">
<div class="output">["foo", "bar", "baz"]</div>
</form>
<form>
<input value="words[0].toUpperCase()">
<div class="output">"FOO"</div>
</form>
<form>
<input value="S.map (S.toUpper) (S.head (words))">
<div class="output">Just ("FOO")</div>
</form>
</div>
<p>Sanctuary is designed to work in Node.js and in ES5-compatible browsers.</p>
<a class="pilcrow h2" href="#section:sponsors">¶</a>
<h2 id="section:sponsors">Sponsors</h2>
<p>Development of Sanctuary is funded by the following community-minded
<strong>partners</strong>:</p>
<ul>
<li><p>
<a id="logo-fink" href="https://www.fink.no/">
<svg viewBox="0 0 100 44" xmlns="http://www.w3.org/2000/svg">
<path d="M 13.5 13.9872 H 33.25 V 44 H 25.5 V 19.7397 H 13.5 V 44 H 5.75 V 19.7397 H 0 V 13.9872 H 5.75 C 5.75 9.73544 7 6.48405 9.25 4.2331 C 11.5 1.98214 15 0.731606 19.5 0.4815 H 22.25 L 22.5 6.23395 H 19.5 C 17.5 6.48405 15.75 6.98427 14.75 7.98469 C 14 8.98512 13.5 10.4858 13.5 12.4866 V 13.9872 Z M 63 16.2382 C 64.75 18.2391 65.75 21.4904 65.75 25.4921 V 44 H 58 V 25.9924 C 58 23.7414 57.5 21.9907 56.75 20.9902 C 55.75 19.9898 54.5 19.4896 52.5 19.4896 C 50.25 19.4896 48.5 20.2399 47.25 21.4904 C 46 22.9911 45.25 24.7418 45.25 26.9928 V 44 H 37.5 V 13.9873 H 45 V 18.4892 C 46 16.7384 47.5 15.4879 49 14.7376 C 50.75 13.7371 52.75 13.487 54.75 13.487 C 58.75 13.2369 61.25 14.2374 63 16.2382 Z M 100 44 H 90.5 L 77.5 30.2441 V 44 H 70 V 0.731592 H 77.5 V 27.2429 L 89.5 14.2373 H 98.75 L 85.25 28.7435 L 100 44 Z" />
</svg>
</a>
is a small, friendly, and passionate gang of IT consultants.
We love what we do, which is mostly web and app development,
including graphic design, interaction design, back-end and
front-end coding, and ensuring the stuff we make works as intended.
Our company is entirely employee-owned; we place great importance on
the well-being of every employee, both professionally and personally.
</p></li>
</ul>
<p>Development of Sanctuary is further encouraged by the following generous
<strong>supporters</strong>:</p>
<ul>
<li><a href="https://github.com/voxbono">@voxbono</a></li>
<li><a href="https://github.com/syves">@syves</a></li>
<li><a href="https://github.com/Avaq">@Avaq</a></li>
<li><a href="https://gitlab.com/kabo">@kabo</a></li>
<li><a href="https://github.com/o0th">@o0th</a></li>
<li><a href="https://github.com/identinet">@identinet</a></li>
</ul>
<p><a href="https://github.com/sponsors/davidchambers">Become a sponsor</a> if you would like
the Sanctuary ecosystem to grow even stronger.</p>
<a class="pilcrow h2" href="#section:folktale">¶</a>
<h2 id="section:folktale">Folktale</h2>
<p><a href="https://folktale.origamitower.com/">Folktale</a>, like Sanctuary, is a standard library for functional
programming in JavaScript. It is well designed and well documented.
Whereas Sanctuary treats JavaScript as a member of the ML language
family, Folktale embraces JavaScript's object-oriented programming
model. Programming with Folktale resembles programming with Scala.</p>
<a class="pilcrow h2" href="#section:ramda">¶</a>
<h2 id="section:ramda">Ramda</h2>
<p><a href="https://ramdajs.com/">Ramda</a> provides several functions that return problematic values
such as <code>undefined</code>, <code>Infinity</code>, or <code>NaN</code> when applied to unsuitable
inputs. These are known as <a href="https://en.wikipedia.org/wiki/Partial_function">partial functions</a>. Partial functions
necessitate the use of guards or null checks. In order to safely use
<code>R.head</code>, for example, one must ensure that the array is non-empty:</p>
<pre><code>if (R.isEmpty (xs)) {
// ...
} else {
return f (R.head (xs));
}
</code></pre>
<p>Using the Maybe type renders such guards (and null checks) unnecessary.
Changing functions such as <code>R.head</code> to return Maybe values was proposed
in <a href="https://github.com/ramda/ramda/issues/683">ramda/ramda#683</a>, but was considered too much of a stretch for
JavaScript programmers. Sanctuary was released the following month,
in January 2015, as a companion library to Ramda.</p>
<p>In addition to broadening in scope in the years since its release,
Sanctuary's philosophy has diverged from Ramda's in several respects.</p>
<a class="pilcrow h3" href="#section:totality">¶</a>
<h3 id="section:totality">Totality</h3>
<p>Every Sanctuary function is defined for every value that is a member of
the function's input type. Such functions are known as <a href="https://en.wikipedia.org/wiki/Partial_function#Total_function">total functions</a>.
Ramda, on the other hand, contains a number of <a href="https://en.wikipedia.org/wiki/Partial_function">partial functions</a>.</p>
<a class="pilcrow h3" href="#section:information-preservation">¶</a>
<h3 id="section:information-preservation">Information preservation</h3>
<p>Certain Sanctuary functions preserve more information than their Ramda
counterparts. Examples:</p>
<pre><code>|> R.tail ([]) |> S.tail ([])
[] Nothing
|> R.tail (['foo']) |> S.tail (['foo'])
[] Just ([])
|> R.replace (/^x/) ('') ('abc') |> S.stripPrefix ('x') ('abc')
'abc' Nothing
|> R.replace (/^x/) ('') ('xabc') |> S.stripPrefix ('x') ('xabc')
'abc' Just ('abc')
</code></pre>
<a class="pilcrow h3" href="#section:invariants">¶</a>
<h3 id="section:invariants">Invariants</h3>
<p>Sanctuary performs rigorous <a href="#section:type-checking">type checking</a> of inputs and outputs, and
throws a descriptive error if a type error is encountered. This allows bugs
to be caught and fixed early in the development cycle.</p>
<p>Ramda operates on the <a href="https://en.wikipedia.org/wiki/Garbage_in,_garbage_out">garbage in, garbage out</a> principle. Functions
are documented to take arguments of particular types, but these invariants
are not enforced. The problem with this approach in a language as
permissive as JavaScript is that there's no guarantee that garbage input
will produce garbage output (<a href="https://github.com/ramda/ramda/issues/1413">ramda/ramda#1413</a>). Ramda performs ad hoc
type checking in some such cases (<a href="https://github.com/ramda/ramda/pull/1419">ramda/ramda#1419</a>).</p>
<p>Sanctuary can be configured to operate in garbage in, garbage out mode.
Ramda cannot be configured to enforce its invariants.</p>
<a class="pilcrow h3" href="#section:currying">¶</a>
<h3 id="section:currying">Currying</h3>
<p>Sanctuary functions are curried. There is, for example, exactly one way to
apply <code>S.reduce</code> to <code>S.add</code>, <code>0</code>, and <code>xs</code>:</p>
<ul>
<li><code>S.reduce (S.add) (0) (xs)</code></li>
</ul>
<p>Ramda functions are also curried, but in a complex manner. There are four
ways to apply <code>R.reduce</code> to <code>R.add</code>, <code>0</code>, and <code>xs</code>:</p>
<ul>
<li><code>R.reduce (R.add) (0) (xs)</code></li>
<li><code>R.reduce (R.add) (0, xs)</code></li>
<li><code>R.reduce (R.add, 0) (xs)</code></li>
<li><code>R.reduce (R.add, 0, xs)</code></li>
</ul>
<p>Ramda supports all these forms because curried functions enable partial
application, one of the library's tenets, but <code>f(x)(y)(z)</code> is considered
too unfamiliar and too unattractive to appeal to JavaScript programmers.</p>
<p>Sanctuary's developers prefer a simple, unfamiliar construct to a complex,
familiar one. Familiarity can be acquired; complexity is intrinsic.</p>
<p>The lack of breathing room in <code>f(x)(y)(z)</code> impairs readability. The simple
solution to this problem, proposed in <a href="https://github.com/sanctuary-js/sanctuary/issues/438">#438</a>, is to include a space when
applying a function: <code>f (x) (y) (z)</code>.</p>
<p>Ramda also provides a special placeholder value, <a href="https://ramdajs.com/docs/#__"><code>R.__</code></a>, that removes
the restriction that a function must be applied to its arguments in order.
The following expressions are equivalent:</p>
<ul>
<li><code>R.reduce (R.__, 0, xs) (R.add)</code></li>
<li><code>R.reduce (R.add, R.__, xs) (0)</code></li>
<li><code>R.reduce (R.__, 0) (R.add) (xs)</code></li>
<li><code>R.reduce (R.__, 0) (R.add, xs)</code></li>
<li><code>R.reduce (R.__, R.__, xs) (R.add) (0)</code></li>
<li><code>R.reduce (R.__, R.__, xs) (R.add, 0)</code></li>
</ul>
<a class="pilcrow h3" href="#section:variadic-functions">¶</a>
<h3 id="section:variadic-functions">Variadic functions</h3>
<p>Ramda provides several functions that take any number of arguments. These
are known as <a href="https://en.wikipedia.org/wiki/Variadic_function">variadic functions</a>. Additionally, Ramda provides several
functions that take variadic functions as arguments. Although natural in
a dynamically typed language, variadic functions are at odds with the type
notation Ramda and Sanctuary both use, leading to some indecipherable type
signatures such as this one:</p>
<pre><code>R.lift :: (*... -> *...) -> ([*]... -> [*])
</code></pre>
<p>Sanctuary has no variadic functions, nor any functions that take variadic
functions as arguments. Sanctuary provides two "lift" functions, each with
a helpful type signature:</p>
<pre><code>S.lift2 :: Apply f => (a -> b -> c) -> f a -> f b -> f c
S.lift3 :: Apply f => (a -> b -> c -> d) -> f a -> f b -> f c -> f d
</code></pre>
<a class="pilcrow h3" href="#section:implicit-context">¶</a>
<h3 id="section:implicit-context">Implicit context</h3>
<p>Ramda provides <a href="https://ramdajs.com/docs/#bind"><code>R.bind</code></a> and <a href="https://ramdajs.com/docs/#invoker"><code>R.invoker</code></a> for working with methods.
Additionally, many Ramda functions use <code>Function#call</code> or <code>Function#apply</code>
to preserve context. Sanctuary makes no allowances for <code>this</code>.</p>
<a class="pilcrow h3" href="#section:transducers">¶</a>
<h3 id="section:transducers">Transducers</h3>
<p>Several Ramda functions act as transducers. Sanctuary provides no support
for transducers.</p>
<a class="pilcrow h3" href="#section:modularity">¶</a>
<h3 id="section:modularity">Modularity</h3>
<p>Whereas Ramda has no dependencies, Sanctuary has a modular design:
<a href="https://github.com/sanctuary-js/sanctuary-def/tree/v0.22.0">sanctuary-def</a> provides type checking, <a href="https://github.com/sanctuary-js/sanctuary-type-classes/tree/v12.1.0">sanctuary-type-classes</a>
provides Fantasy Land functions and type classes, <a href="https://github.com/sanctuary-js/sanctuary-show/tree/v2.0.0">sanctuary-show</a>
provides string representations, and algebraic data types are provided
by <a href="https://github.com/sanctuary-js/sanctuary-either/tree/v2.1.0">sanctuary-either</a>, <a href="https://github.com/sanctuary-js/sanctuary-maybe/tree/v2.1.0">sanctuary-maybe</a>, and <a href="https://github.com/sanctuary-js/sanctuary-pair/tree/v2.1.0">sanctuary-pair</a>.
Not only does this approach reduce the complexity of Sanctuary itself,
but it allows these components to be reused in other contexts.</p>
<a class="pilcrow h2" href="#section:types">¶</a>
<h2 id="section:types">Types</h2>
<p>Sanctuary uses Haskell-like type signatures to describe the types of
values, including functions. <code>'foo'</code>, for example, is a member of <code>String</code>;
<code>[1, 2, 3]</code> is a member of <code>Array Number</code>. The double colon (<code>::</code>) is used
to mean "is a member of", so one could write:</p>
<pre><code>'foo' :: String
[1, 2, 3] :: Array Number
</code></pre>
<p>An identifier may appear to the left of the double colon:</p>
<pre><code>Math.PI :: Number
</code></pre>
<p>The arrow (<code>-></code>) is used to express a function's type:</p>
<pre><code>Math.abs :: Number -> Number
</code></pre>
<p>That states that <code>Math.abs</code> is a unary function that takes an argument
of type <code>Number</code> and returns a value of type <code>Number</code>.</p>
<p>Some functions are parametrically polymorphic: their types are not fixed.
Type variables are used in the representations of such functions:</p>
<pre><code>S.I :: a -> a
</code></pre>
<p><code>a</code> is a type variable. Type variables are not capitalized, so they
are differentiable from type identifiers (which are always capitalized).
By convention type variables have single-character names. The signature
above states that <code>S.I</code> takes a value of any type and returns a value of
the same type. Some signatures feature multiple type variables:</p>
<pre><code>S.K :: a -> b -> a
</code></pre>
<p>It must be possible to replace all occurrences of <code>a</code> with a concrete type.
The same applies for each other type variable. For the function above, the
types with which <code>a</code> and <code>b</code> are replaced may be different, but needn't be.</p>
<p>Since all Sanctuary functions are curried (they accept their arguments
one at a time), a binary function is represented as a unary function that
returns a unary function: <code>* -> * -> *</code>. This aligns neatly with Haskell,
which uses curried functions exclusively. In JavaScript, though, we may
wish to represent the types of functions with arities less than or greater
than one. The general form is <code>(<input-types>) -> <output-type></code>, where
<code><input-types></code> comprises zero or more comma–space (<code>, </code>)
-separated type representations:</p>
<ul>
<li><code>() -> String</code></li>
<li><code>(a, b) -> a</code></li>
<li><code>(a, b, c) -> d</code></li>
</ul>
<p><code>Number -> Number</code> can thus be seen as shorthand for <code>(Number) -> Number</code>.</p>
<p>Sanctuary embraces types. JavaScript doesn't support algebraic data types,
but these can be simulated by providing a group of data constructors that
return values with the same set of methods. A value of the Either type, for
example, is created via the Left constructor or the Right constructor.</p>
<p>It's necessary to extend Haskell's notation to describe implicit arguments
to the <em>methods</em> provided by Sanctuary's types. In <code>x.map(y)</code>, for example,
the <code>map</code> method takes an implicit argument <code>x</code> in addition to the explicit
argument <code>y</code>. The type of the value upon which a method is invoked appears
at the beginning of the signature, separated from the arguments and return
value by a squiggly arrow (<code>~></code>). The type of the <code>fantasy-land/map</code> method
of the Maybe type is written <code>Maybe a ~> (a -> b) -> Maybe b</code>. One could
read this as:</p>
<p><em>When the <code>fantasy-land/map</code> method is invoked on a value of type <code>Maybe a</code>
(for any type <code>a</code>) with an argument of type <code>a -> b</code> (for any type <code>b</code>),
it returns a value of type <code>Maybe b</code>.</em></p>
<p>The squiggly arrow is also used when representing non-function properties.
<code>Maybe a ~> Boolean</code>, for example, represents a Boolean property of a value
of type <code>Maybe a</code>.</p>
<p>Sanctuary supports type classes: constraints on type variables. Whereas
<code>a -> a</code> implicitly supports every type, <code>Functor f => (a -> b) -> f a -> f b</code> requires that <code>f</code> be a type that satisfies the requirements of the
Functor type class. Type-class constraints appear at the beginning of a
type signature, separated from the rest of the signature by a fat arrow
(<code>=></code>).</p>
<a class="pilcrow h2" href="#section:type-checking">¶</a>
<h2 id="section:type-checking">Type checking</h2>
<p>Sanctuary functions are defined via <a href="https://github.com/sanctuary-js/sanctuary-def/tree/v0.22.0">sanctuary-def</a> to provide run-time
type checking. This is tremendously useful during development: type errors
are reported immediately, avoiding circuitous stack traces (at best) and
silent failures due to type coercion (at worst). For example:</p>
<div class="examples">
<form>
<input value="S.add (2) (true)">
<div class="output" data-error="true">! Invalid value
add :: FiniteNumber -> FiniteNumber -> FiniteNumber
^^^^^^^^^^^^
1
1) true :: Boolean
The value at position 1 is not a member of ‘FiniteNumber’.
See https://github.com/sanctuary-js/sanctuary-def/tree/v0.22.0#FiniteNumber for information about the FiniteNumber type.
</div>
</form>
</div>
<p>Compare this to the behaviour of Ramda's unchecked equivalent:</p>
<div class="examples">