/
clojure.cljc
2356 lines (2079 loc) · 94.2 KB
/
clojure.cljc
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
;; Copyright (c) Ambrose Bonnaire-Sergeant, Rich Hickey & contributors.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; which can be found in the file epl-v10.html at the root of this distribution.
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns ^:no-doc typed.ann.clojure
"Type annotations for the base Clojure distribution."
#?(:cljs (:require-macros [typed.ann-macros.clojure :as macros]))
(:require [clojure.core :as cc]
[typed.clojure :as t]
#?(:clj [typed.ann-macros.clojure :as macros])
#?(:clj typed.ann.clojure.jvm) ;; jvm annotations
#?(:clj clojure.core.typed))
#?(:clj
(:import (clojure.lang PersistentHashSet PersistentTreeSet PersistentList
APersistentMap #_IPersistentCollection
#_ITransientSet
IRef)
(java.util Comparator Collection))))
;; ==========================================
;; Protocol annotations
(t/ann-protocol cc/Inst
-inst-ms [cc/Inst :-> t/Int])
#?(:clj (do
(t/defalias IOFactoryOpts (t/HMap :optional {:append t/Any, :encoding (t/Nilable t/Str)}))
(t/ann-protocol clojure.java.io/IOFactory
make-reader
[clojure.java.io/IOFactory IOFactoryOpts :-> java.io.BufferedReader]
make-writer
[clojure.java.io/IOFactory IOFactoryOpts :-> java.io.BufferedWriter]
make-input-stream
[clojure.java.io/IOFactory IOFactoryOpts :-> java.io.BufferedInputStream]
make-output-stream
[clojure.java.io/IOFactory IOFactoryOpts :-> java.io.BufferedOutputStream])
(t/ann-protocol clojure.java.io/Coercions
as-file
[clojure.java.io/Coercions :-> (t/Nilable java.io.File)]
as-url
[clojure.java.io/Coercions :-> (t/Nilable java.net.URL)])
))
#?(:cljs (do
(t/ann-protocol cljs.core/Fn)
(t/ann-protocol cljs.core/IFn)
(t/ann-protocol cljs.core/ICloneable
-clone [cljs.core/ICloneable :-> t/Any])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IIterable
;; TODO
-iterator [(cljs.core/IIterable x) :-> t/Any #_Object])
(t/ann-protocol cljs.core/ICounted
-count [cljs.core/ICounted :-> t/Num])
(t/ann-protocol cljs.core/IEmptyableCollection
;; :/ TFn param on protocol?
-empty [cljs.core/IEmptyableCollection :-> t/Any])
(t/ann-protocol cljs.core/ICollection
-conj [cljs.core/ICollection t/Any :-> cljs.core/ICollection])
(t/ann-protocol [[x :variance :covariant]] cljs.core/IIndexed
-nth (t/All [y]
(t/IFn [(cljs.core/IIndexed x) t/JSnumber :-> x]
[(cljs.core/IIndexed x) t/JSnumber y :-> (t/U x y)])))
(t/ann-protocol cljs.core/ASeq)
(t/ann-protocol [[x :variance :covariant]] cljs.core/ISeqable)
(t/ann-protocol [[x :variance :covariant]] cljs.core/ISeq
-first [(cljs.core/ISeq x) :-> (t/Nilable x)]
-rest [(cljs.core/ISeq x) :-> (cljs.core/ISeq x)])
;cljs.core/INext [[x :variance :covariant]]
(t/ann-protocol [[v :variance :covariant]] cljs.core/ILookup)
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IAssociative
-contains-key [(cljs.core/IAssociative k v) t/Any :-> t/Bool]
-assoc (t/All [k1 v1] [(cljs.core/IAssociative k v) k1 v1 :->
(cljs.core/IAssociative (t/U k k1) (t/U v v1))]))
(t/ann-protocol cljs.core/IMap
-dissoc [cljs.core/IMap t/Any :-> cljs.core/IMap])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]]
cljs.core/IMapEntry
-key [(cljs.core/IMapEntry k v) :-> k]
-val [(cljs.core/IMapEntry k v) :-> v])
(t/ann-protocol cljs.core/ISet
-disjoin (t/All [s] [s t/Any :-> s]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IStack
-peek [(cljs.core/IStack x) :-> (t/U nil x)]
-pop [(cljs.core/IStack x) :-> (cljs.core/IStack x)])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IVector
-assoc-n (t/All [x1] [(cljs.core/IVector x) t/Num x1
:-> (cljs.core/IVector (t/U x x1))]))
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDeref
-deref [(cljs.core/IDeref x) :-> x])
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IDerefWithTimeout
-deref-with-timeout [(cljs.core/IDerefWithTimeout x) :-> x])
(t/ann-protocol cljs.core/IMeta
-meta [cljs.core/IMeta :-> (t/Nilable (t/Map t/Any t/Any))])
(t/ann-protocol cljs.core/IWithMeta
-with-meta [cljs.core/IWithMeta (t/Nilable (t/Map t/Any t/Any)) :-> cljs.core/IWithMeta])
;TODO
;cljs.core/IReduce [[]]
(t/ann-protocol cljs.core/IKVReduce ;;TODO
-kv-reduce [cljs.core/IKVReduce [t/Any t/Any t/Any :-> t/Any] :-> t/Any])
(t/ann-protocol cljs.core/IList)
(t/ann-protocol cljs.core/IEquiv
-equiv [cljs.core/IEquiv t/Any :-> t/Bool])
(t/ann-protocol cljs.core/IHash
-hash [cljs.core/IHash :-> t/Num])
(t/ann-protocol cljs.core/ISequential)
(t/ann-protocol cljs.core/IRecord)
(t/ann-protocol [[x :variance :covariant]]
cljs.core/IReversible
-rseq [(cljs.core/IReversible x) :-> (t/NilableNonEmptySeq x)])
(t/ann-protocol [[k :variance :covariant]
[v :variance :covariant]] cljs.core/IFind
-find [(cljs.core/IFind k v) t/Any :-> (t/Nilable (cljs.core/IMapEntry k v))]
)
(t/ann-protocol [[x :variance :covariant]]
cljs.core/ISorted
-sorted-seq [(cljs.core/ISorted x) t/Bool :-> (t/Nilable (t/ASeq x))]
;; second arg => comparable?
-sorted-seq-from [(cljs.core/ISorted x) t/Any t/Bool :-> (t/Nilable (t/ASeq x))]
-entry-key [(cljs.core/ISorted x) t/Any :-> t/Any]
-comparator [(cljs.core/ISorted x) :-> [t/Any t/Any :-> t/Num]])
(t/ann-protocol cljs.core/IPending)
;cljs.core/IWriter [[]]
;cljs.core/IPrintWithWriter [[]]
; ;TODO
;;cljs.core/IWatchable [[]]
; ;cljs.core/IEditableCollection [[]]
; ;cljs.core/ITransientCollection [[]]
; ;cljs.core/ITransientAssociative [[]]
; ;cljs.core/ITransientMap [[]]
; ;cljs.core/ITransientVector [[]]
; ;cljs.core/ITransientSet [[]]
;cljs.core/IComparable [[]]
; ;cljs.core/IChunk [[]]
; ;cljs.core/IChunkedSeq [[]]
; ;cljs.core/IChunkedNext [[]]
(t/ann-protocol cljs.core/INamed
-named [cljs.core/INamed :-> t/Str]
-namespace [cljs.core/INamed :-> (t/Nilable t/Str)])
(t/ann-protocol cljs.core/UUID)
))
;; ==========================================
;; Datatypes
#?(:cljs (do
(t/ann-datatype [[w :variance :contravariant]
[r :variance :covariant]]
cljs.core/Atom)
(t/ann-datatype cljs.core/Symbol)
(t/ann-datatype cljs.core/Keyword)
(t/ann-datatype [[x :variance :covariant]] cljs.core/List)
(t/ann-datatype [[x :variance :covariant]] cljs.core/Reduced)
(t/ann-datatype cljs.core/ExceptionInfo)
(t/ann-datatype [[x :variance :covariant]] cljs.core/Delay)
))
;; ==========================================
;; Type aliases
(t/defalias
^{:doc "A type that returns true for clojure.core/integer?"
:forms '[AnyInteger]}
t/AnyInteger
#?(:clj (t/U Integer
Long
clojure.lang.BigInt
BigInteger
Short
Byte)
:cljs t/CLJSInteger))
(t/defalias
^{:doc "A type that returns true for clojure.core/integer?"
:forms '[Int]}
t/Int
t/AnyInteger)
(t/defalias
^{:doc "A type that returns true for clojure.core/number?"
:forms '[Num]}
t/Num
#?(:clj Number
:cljs t/JSnumber))
(t/defalias
^{:doc "A keyword"
:forms '[Keyword]}
t/Keyword
#?(:clj clojure.lang.Keyword
:cljs cljs.core/Keyword))
(t/defalias
^{:doc "A keyword"
:forms '[Kw]}
t/Kw
t/Keyword)
(t/defalias
^{:doc "A symbol"
:forms '[Symbol]}
t/Symbol
#?(:clj clojure.lang.Symbol
:cljs cljs.core/Symbol))
(t/defalias
^{:doc "A symbol"
:forms '[Sym]}
t/Sym
t/Symbol)
(t/defalias
t/Ident
(t/U t/Sym t/Kw))
(t/defalias
^{:doc "A string"
:forms '[Str]}
t/Str
#?(:clj java.lang.String
:cljs t/JSstring))
(t/defalias
t/Named
#?(:clj clojure.lang.Named
:cljs cljs.core/INamed))
(t/defalias
t/Indexed
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.Indexed x)
:cljs (cljs.core/IIndexed x))))
(t/defalias
^{:doc "A boolean"
:forms '[Bool]}
t/Bool
#?(:clj java.lang.Boolean
:cljs t/JSboolean))
(t/defalias
^{:doc "A namespace"
:forms '[Namespace]}
t/Namespace
#?(:clj clojure.lang.Namespace
;; nilable?
:cljs cljs.core/Namespace))
(t/defalias
t/UUID
#?(:clj java.util.UUID
:cljs cljs.core/UUID))
(t/defalias
^{:doc "An atom that can write type w and read type r."
:forms '[(Atom2 t)]}
t/Atom2
(t/TFn [[w :variance :contravariant]
[r :variance :covariant]]
(#?(:clj clojure.lang.Atom :cljs cljs.core/Atom) w r)))
(t/defalias
^{:doc "An atom that can read and write type x."
:forms '[(Atom1 t)]}
t/Atom1
(t/TFn [[x :variance :invariant]]
(t/Atom2 x x)))
(t/defalias
^{:doc "An var that can write type w and read type r."
:forms '[(Var2 w r)]}
t/Var2
(t/TFn [[w :variance :contravariant]
[r :variance :covariant]]
#?(:clj (clojure.lang.Var w r)
:cljs (cljs.core/Var w r))))
(t/defalias
^{:doc "An var that can read and write type x."
:forms '[(Var1 t)]}
t/Var1
(t/TFn [[x :variance :invariant]]
(t/Var2 x x)))
#?(:clj
(t/defalias
^{:doc "A ref that can write type w and read type r."
:forms '[(Ref2 w r)]}
t/Ref2
(t/TFn [[w :variance :contravariant]
[r :variance :covariant]]
(clojure.lang.Ref w r))))
#?(:clj
(t/defalias
^{:doc "A ref that can read and write type x."
:forms '[(Ref1 t)]}
t/Ref1
(t/TFn [[x :variance :invariant]]
(t/Ref2 x x))))
#?(:clj
(t/defalias
^{:doc "An agent that can write type w and read type r."
:forms '[(Agent2 t t)]}
t/Agent2
(t/TFn [[w :variance :contravariant]
[r :variance :covariant]]
(clojure.lang.Agent w r))))
#?(:clj
(t/defalias
^{:doc "An agent that can read and write type x."
:forms '[(Agent1 t)]}
t/Agent1
(t/TFn [[x :variance :invariant]]
(t/Agent2 x x))))
(t/defalias
^{:doc "A union of x and nil."
:forms '[(Option t)]}
t/Option
(t/TFn [[x :variance :covariant]] (t/U nil x)))
(t/defalias
^{:doc "A union of x and nil."
:forms '[(Nilable t)]}
t/Nilable
t/Option)
(t/defalias
^{:doc "The result of re-pattern."
:forms '[t/Regex]}
t/Regex
#?(:clj java.util.regex.Pattern
:cljs js/Regexp))
(t/defalias
^{:doc "The identity function at the type level."
:forms '[Id]}
t/Id
(t/TFn [[x :variance :covariant]] x))
(t/defalias
^{:doc "A type that returns true for clojure.core/seqable?, with members t."
:forms '[(Seqable t)]}
t/Seqable
(t/TFn [[x :variance :covariant]]
(t/Nilable
#?(:clj (clojure.lang.Seqable x)
:cljs (cljs.core/ISeqable x)))))
(t/defalias
t/Counted
#?(:clj clojure.lang.Counted
:cljs cljs.core/ICounted))
(t/defalias
t/URI
#?(:clj java.net.URI
:cljs goog.Uri))
(t/defalias
^{:doc "A type that returns true for clojure.core/coll?, with members t."
:forms '[(Coll t)]}
t/Coll
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IPersistentCollection x)
:cljs (t/I (t/Seqable x)
cljs.core/ICollection
;;cljs.core/ICounted
cljs.core/IEmptyableCollection
;;cljs.core/IEquiv
))))
(t/defalias
^{:doc "The type of all things with count 0. Use as part of an intersection.
eg. See EmptySeqable."
:forms '[EmptyCount]}
t/EmptyCount
(t/ExactCount 0))
(t/defalias
^{:doc "The type of all things with count greater than 0. Use as part of an intersection.
eg. See NonEmptySeq"
:forms '[NonEmptyCount]}
t/NonEmptyCount
(t/CountRange 1))
(t/defalias
^{:doc "A persistent collection with member type x and count greater than 0."
:forms '[(NonEmptyColl t)]}
t/NonEmptyColl
(t/TFn [[x :variance :covariant]]
(t/I (t/Coll x)
t/NonEmptyCount)))
(t/defalias
^{:doc "An associative persistent collection supporting associative operations on keys type k and values type v."
:forms '[(t/Associative k v)]}
t/Associative
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
#?(:clj (clojure.lang.Associative k v)
:cljs (t/I (cljs.core/IAssociative k v)
;; emulate clojure.lang.Associative's ancestors
(t/Coll t/Any)
(cljs.core/ILookup v)))))
(t/defalias
^{:doc "A Clojure reversible collection."
:forms '[(Reversible t)]}
t/Reversible
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.Reversible x)
:cljs (cljs.core/IReversible x))))
(t/defalias
^{:doc "A persistent vector with member type x."
:forms '[(Vec t)]}
t/Vec
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IPersistentVector x)
:cljs (t/I (cljs.core/IVector x)
(t/Associative t/Int x)
(t/Coll x)
(cljs.core/ILookup x)
cljs.core/ISequential
(cljs.core/IStack x)
(t/Reversible x)
(t/Indexed x)))))
(t/defalias
^{:doc "A persistent vector with member type x and count greater than 0."
:forms '[(NonEmptyVec t)]}
t/NonEmptyVec
(t/TFn [[x :variance :covariant]]
(t/I (t/Vec x)
t/NonEmptyCount)))
(t/defalias
^{:doc "A persistent vector returned from clojure.core/vector (and others)"
:forms '[(AVec t)]}
t/AVec
(t/TFn [[x :variance :covariant]]
#?(:clj (t/I ; is this type useful enough? c.l.APV implements a lot more
(t/Vec x)
(java.lang.Iterable x)
(java.util.Collection x)
(java.util.List x)
clojure.lang.IObj)
:cljs (t/I (t/Vec x)
cljs.core/APersistentVector
; TODO cljs equivalent
))))
(t/defalias
^{:doc "A persistent vector returned from clojure.core/vector (and others) and count greater than 0."
:forms '[(NonEmptyAVec t)]}
t/NonEmptyAVec
(t/TFn [[x :variance :covariant]]
(t/I (t/AVec x)
t/NonEmptyCount)))
(t/defalias
t/MapEntry
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
#?(:clj (clojure.lang.IMapEntry k v)
:cljs (cc/IMapEntry k v))))
(t/defalias
t/AMapEntry
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
#?(:clj (clojure.lang.AMapEntry k v)
:cljs (cc/IMapEntry k v))))
(t/defalias
^{:doc "A persistent map with keys k and vals v."
:forms '[(Map t t)]}
t/Map
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
#?(:clj (clojure.lang.IPersistentMap k v)
:cljs (t/I cljs.core/ICloneable
(cljs.core/IIterable (cc/IMapEntry k v))
cljs.core/IWithMeta
cljs.core/IMeta
cc/ICollection
cc/IEmptyableCollection
cljs.core/IEquiv
cljs.core/IHash
(cc/ISeqable (cc/IMapEntry k v))
cc/ICounted
(cc/ILookup v)
(cc/IAssociative k v)
(cc/IFind k v)
cljs.core/IMap
cljs.core/IKVReduce
;; TODO IFn
;; TODO cljs.core/IEditableCollection
))))
(t/defalias
^{:doc "Values that can be conj'ed to a t/Map, adding keys of type k
and vals of type v."}
t/MapConjable
(t/TFn [[k :variance :covariant]
[v :variance :covariant]]
(t/U (t/MapEntry k v)
'[k v]
(t/Seqable (t/MapEntry k v)))))
(t/defalias
^{:doc "A persistent set with member type x"
:forms '[(Set t)]}
t/Set
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IPersistentSet x)
:cljs (t/I cljs.core/ICloneable
(cljs.core/IIterable x)
cljs.core/IWithMeta
cljs.core/IMeta
cljs.core/ICollection
cljs.core/IEmptyableCollection
cljs.core/IEquiv
cljs.core/IHash
(cljs.core/ISeqable x)
cljs.core/ICounted
(cljs.core/ILookup x)
cljs.core/ISet
;; TODO IFn
;; TODO cljs.core/IEditableCollection
))))
(t/defalias
^{:doc "A sorted collection."
:forms '[t/Sorted]}
t/Sorted
(t/TFn [[x :variance :covariant]]
#?(:clj clojure.lang.Sorted
:cljs (cljs.core/ISorted x))))
(t/defalias
^{:doc "A sorted persistent set with member type x"
:forms '[(SortedSet t)]}
t/SortedSet
(t/TFn [[x :variance :covariant]]
(t/I (t/Set x)
(t/Sorted x))))
(t/defalias
^{:doc "A type that can be used to create a sequence of member type x
with count greater than 0."
:forms '[(NonEmptySeqable t)]}
t/NonEmptySeqable
(t/TFn [[x :variance :covariant]]
(t/I (t/Seqable x)
t/NonEmptyCount)))
(t/defalias
^{:doc "A type that can be used to create a sequence of member type x
with count 0."
:forms '[(EmptySeqable t)]}
t/EmptySeqable
(t/TFn [[x :variance :covariant]]
(t/I (t/Seqable x)
t/EmptyCount)))
(t/defalias
^{:doc "A persistent sequence of member type x."
:forms '[(Seq t)]}
t/Seq
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.ISeq x)
:cljs (t/I (cljs.core/ISeq x)
cljs.core/IWithMeta
cljs.core/IMeta
(cljs.core/ISeqable x)
(cljs.core/IIterable x)
;(cljs.core/INext x)
cljs.core/ICollection
cljs.core/IEmptyableCollection
cljs.core/ISequential
cljs.core/IEquiv))))
(t/defalias
^{:doc "A persistent sequence of member type x with count greater than 0."
:forms '[(NonEmptySeq t)]}
t/NonEmptySeq
(t/TFn [[x :variance :covariant]]
(t/I (t/Seq x)
t/NonEmptyCount)))
(t/defalias
^{:doc "A persistent sequence of member type x with count greater than 0, or nil."
:forms '[(NilableNonEmptySeq t)]}
t/NilableNonEmptySeq
(t/TFn [[x :variance :covariant]]
(t/Nilable
(t/NonEmptySeq x))))
(t/defalias
^{:doc "A hierarchy for use with derive, isa? etc."
:forms '[Hierarchy]}
t/Hierarchy
'{:parents (t/Map t/Any t/Any)
:ancestors (t/Map t/Any t/Any)
:descendants (t/Map t/Any t/Any)})
(t/defalias
^{:doc "A Clojure derefable (see clojure.core/deref)."
:forms '[(Deref t)]}
t/Deref
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IDeref x)
;; note: IDerefWithTimeout not used in cljs
:cljs (cljs.core/IDeref x))))
#?(:clj
(t/defalias
^{:doc "A Clojure future (see clojure.core/{future-call,future})."
:forms '[(Future t)]}
t/Future
(t/TFn [[x :variance :covariant]]
(t/I (t/Deref x)
(clojure.lang.IBlockingDeref x)
clojure.lang.IPending
java.util.concurrent.Future))))
#?(:clj
(t/defalias
^{:doc "A Clojure promise (see clojure.core/{promise,deliver})."
:forms '[(Promise t)]}
t/Promise
(t/TFn [[x :variance :invariant]]
(t/I (t/Deref x)
(clojure.lang.IBlockingDeref x)
clojure.lang.IPending
;; FIXME I think this might be an implementation detail.
[x :-> (t/Nilable (t/Promise x))]))))
(t/defalias
^{:doc "A Clojure delay (see clojure.core/{delay,force})."
:forms '[(Delay t)]}
t/Delay
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.Delay x)
:cljs (cljs.core/Delay x))))
(t/defalias
^{:doc "A Clojure blocking derefable (see clojure.core/deref)."
:forms '[(BlockingDeref t)]}
t/BlockingDeref
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IBlockingDeref x)
:cljs (cljs.core/IDerefWithTimeout x))))
(t/defalias
^{:doc "A Clojure persistent list."
:forms '[(List t)]}
t/List
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.IPersistentList x)
:cljs (t/I cljs.core/IList
cljs.core/ICloneable
cljs.core/IWithMeta
cljs.core/IMeta
cljs.core/ASeq
(cljs.core/ISeq x)
cljs.core/ICollection
cljs.core/IEmptyableCollection
cljs.core/ISequential))))
(t/defalias
^{:doc "A Clojure custom exception type."
:forms '[ExInfo]}
t/ExInfo
#?(:clj (t/I clojure.lang.IExceptionInfo
RuntimeException)
:cljs cljs.core/ExceptionInfo))
(t/defalias
^{:doc "A Clojure proxy."
:forms '[Proxy]}
t/Proxy
clojure.lang.IProxy)
(t/defalias
^{:doc "A Clojure stack."
:forms '[(Stack t)]}
t/Stack
(t/TFn [[x :variance :covariant]]
(clojure.lang.IPersistentStack x)))
(t/defalias
^{:doc "A sequential collection."
:forms '[Sequential]}
t/Sequential
#?(:clj clojure.lang.Sequential
:cljs cljs.core/ISequential))
(t/defalias
^{:doc "A sequential, seqable collection. Seq's aren't always Sequential."
:forms '[(SequentialSeqable t)]}
t/SequentialSeqable
(t/TFn [[x :variance :covariant]]
(t/I t/Sequential
(t/Seqable x))))
(t/defalias
^{:doc "A sequential, seqable Clojure collection."
:forms '[(SequentialColl t)]}
t/SequentialColl
(t/TFn [[x :variance :covariant]]
(t/I t/Sequential
(t/Coll x))))
(t/defalias
^{:doc "A Clojure sequential sequence. Seq's aren't always Sequential."
:forms '[(SequentialSeq t)]}
t/SequentialSeq
(t/TFn [[x :variance :covariant]]
(t/I t/Sequential
(t/Seq x))))
(t/defalias
^{:doc "A sequential seq returned from clojure.core/seq"
:forms '[(ASeq t)]}
t/ASeq
(t/TFn [[x :variance :covariant]]
(t/I (t/SequentialSeq x)
#?@(:clj [(Iterable x)
(java.util.Collection x)
(java.util.List x)
clojure.lang.IObj]))))
(t/defalias
^{:doc "A sequential non-empty seq retured from clojure.core/seq"
:forms '[(NonEmptyASeq t)]}
t/NonEmptyASeq
(t/TFn [[x :variance :covariant]]
(t/I (t/ASeq x)
t/NonEmptyCount)))
(t/defalias
^{:doc "The result of clojure.core/seq."
:forms '[(NilableNonEmptyASeq t)]}
t/NilableNonEmptyASeq
(t/TFn [[x :variance :covariant]]
(t/Nilable
(t/NonEmptyASeq x))))
(t/defalias
^{:doc "A type that returns true for clojure.core/fn?"
:forms '[Fn]}
t/Fn
#?(:clj clojure.lang.Fn
:cljs (t/U cljs.core/Fn
js/Function)))
(t/defalias
^{:doc "A Clojure multimethod."
:forms '[Multi]}
t/Multi
clojure.lang.MultiFn)
(t/defalias
^{:doc "A reduced value of type x."
:forms '[(t/Reduced x)]}
t/Reduced
(t/TFn [[x :variance :covariant]]
#?(:clj (clojure.lang.Reduced x)
:cljs (cljs.core/Reduced x))))
(t/defalias
^{:doc "A reducer function with accumulator a and reduces over collections of b"
:forms '[(Reducer a b)]}
t/Reducer
(t/TFn [[a :variance :contravariant]
[b :variance :invariant]]
(t/IFn
;init
[:-> b]
;complete
[b :-> b]
;step
[b a :-> (t/U b (t/Reduced b))])))
(t/defalias
^{:doc "A transducer function that transforms in to out."
:forms '[(Transducer in out)]}
t/Transducer
(t/TFn [[in :variance :contravariant]
[out :variance :covariant]]
;; note: putting t/Transducer in an IFn makes r existential (but only in contravariant position IIUC? need to revisit my notes)
;; Stephen Dolan noted this when I showed him the type of `into`.
;; eg., Simulating Existential Types https://www.cs.cmu.edu/~fp/courses/15312-f04/assignments/asst5.pdf
(t/All [r]
[(t/Reducer out r) :-> (t/Reducer in r)])))
;; ==========================================
;; Var annotations
(macros/anns
#?@(:cljs [] :default [
clojure.core.typed/check-ns (t/IFn [t/Sym :-> t/Any]
[:-> t/Any])
;; Internal annotations
;clojure.core.typed.current-impl/*current-impl* t/Any
clojure.core.typed.current-impl/clojure t/Any
clojure.core.typed.current-impl/clojurescript t/Any
clojure.core.typed/ann* [t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/untyped-var* [t/Any t/Any :-> t/Any]
clojure.core.typed/declare-names* [t/Any :-> t/Any]
clojure.core.typed/typed-deps* [t/Any :-> t/Any]
clojure.core.typed/warn-on-unannotated-vars* [:-> t/Any]
clojure.core.typed/ann-datatype* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-protocol* [t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-record* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/ann-pdatatype* [t/Any t/Any t/Any t/Any :-> t/Any]
clojure.core.typed/declare-datatypes* [t/Any :-> t/Any]
clojure.core.typed/declare-protocols* [t/Any :-> t/Any]
clojure.core.typed/non-nil-return* [t/Any t/Any :-> t/Any]
clojure.core.typed/nilable-param* [t/Any t/Any :-> t/Any]
clojure.core.typed/override-constructor* [t/Any t/Any :-> t/Any]
clojure.core.typed/override-method* [t/Any t/Any :-> t/Any]
clojure.core.typed/typed-deps* [t/Any :-> t/Any]
clojure.core.typed/load-if-needed [:-> t/Any]
clojure.core.typed/*collect-on-eval* t/Any
; should always be special cased
;clojure.core.typed/var>* [t/Any :-> (t/Var2 t/Nothing t/Any)]
])
;; core annotations
cc/*ns* t/Namespace
#?@(:cljs [] :default [
cc/pop-thread-bindings [:-> t/Any]
cc/load [t/Str :* :-> t/Any]
cc/read-string [t/Str :-> t/Any]
cc/read (t/IFn [:-> t/Any]
[java.io.Reader :-> t/Any]
[java.io.Reader t/Bool t/Any :-> t/Any]
[java.io.Reader t/Bool t/Any t/Bool :-> t/Any])
cc/read+string (t/IFn [:-> '[t/Any t/Str]]
[java.io.Reader :-> '[t/Any t/Str]]
[java.io.Reader t/Bool t/Any :-> '[t/Any t/Str]]
[java.io.Reader t/Bool t/Any t/Bool :-> '[t/Any t/Str]])
cc/read-line [:-> (t/U nil t/Str)]
cc/add-classpath [(t/U t/Str java.net.URL) :-> nil]
])
cc/*1 t/Any
cc/*2 t/Any
cc/*3 t/Any
cc/*e #?(:cljs t/Any :default (t/U nil Throwable))
#?@(:cljs [] :default [
cc/*agent* (t/U nil (t/Agent2 t/Nothing t/Any))
cc/*allow-unresolved-vars* t/Any
cc/*data-readers* (t/Map t/Sym (t/Var2 t/Nothing t/Any))
cc/*default-data-reader-fn* (t/U nil [t/Any t/Any :-> t/Any])
cc/*fn-loader* t/Any
cc/*math-context* t/Any
cc/*source-path* t/Str
cc/*use-context-classloader* t/Any
])
cc/*assert* t/Any
cc/alength [(ReadOnlyArray t/Any) :-> t/AnyInteger]
cc/aclone (t/All [x] [(ReadOnlyArray x) :-> (Array x)])
cc/aget (t/All [x]
(t/IFn [(ReadOnlyArray x)
t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray x))
t/AnyInteger t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x)))
t/AnyInteger t/AnyInteger t/AnyInteger :-> x]
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x))))
t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger :-> x]
; don't support unsound cases
[(ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray (ReadOnlyArray x)))))
t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger :-> x]))
cc/aset
(t/All [x]
(t/IFn
[(Array x) t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]
[(Array x) t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger t/AnyInteger x :-> x]))
#?@(:cljs [] :default [
cc/macroexpand-1 [t/Any :-> t/Any]
cc/macroexpand [t/Any :-> t/Any]
cc/create-struct [t/Any :* :-> (t/Map t/Any t/Any)]
])
cc/find-ns [t/Sym :-> (t/Nilable t/Namespace)]
cc/create-ns [t/Sym :-> t/Namespace]
#?@(:cljs [] :default [
cc/remove-ns [t/Sym :-> t/Namespace]
cc/ns-map [(t/U t/Sym t/Namespace) :-> t/Sym]
cc/ns-aliases [(t/U t/Sym t/Namespace) :-> (t/Map t/Sym t/Namespace)]
cc/the-ns [(t/U t/Sym t/Namespace) :-> t/Namespace]
cc/in-ns [t/Sym :-> nil]
cc/import [t/Any :* :-> nil]
])
cc/namespace [(t/U t/Sym t/Keyword) :-> (t/Nilable t/Str)]
cc/ns-name [(t/U t/Sym t/Namespace) :-> t/Sym]
cc/name [(t/U t/Str t/Named) :-> t/Str]
cc/identity (t/All [x] [x :-> x
:filters {:then (! (t/U nil false) 0)
:else (is (t/U nil false) 0)}
:object {:id 0}])
cc/gensym (t/IFn [:-> t/Sym]
[(t/U t/Sym t/Str) :-> t/Sym])
#?@(:cljs [] :default [
cc/intern (t/IFn [(t/U t/Sym t/Namespace) t/Sym :-> (t/Var2 t/Nothing t/Any)]
[(t/U t/Sym t/Namespace) t/Sym t/Any :-> (t/Var2 t/Nothing t/Any)])
])
cc/doall (t/All [[c :< (t/U nil (t/Seqable t/Any))]]
(t/IFn [c :-> c]
[t/AnyInteger c :-> c]))
cc/dorun (t/IFn [(t/Seqable t/Any) :-> nil]
[t/AnyInteger (t/Seqable t/Any) :-> nil])
cc/iterate (t/All [x]
[[x :-> x] x :-> (t/ASeq x)])
cc/memoize (t/All [x y :..]
[[y :.. y :-> x] :-> [y :.. y :-> x]])
cc/key (t/All [x] [(t/MapEntry x t/Any) :-> x])
cc/val (t/All [x] [(t/MapEntry t/Any x) :-> x])
;cc/juxt
;(t/All [b1 :..]
;(t/All [x r b2 :..]
; (Fn [[b1 :.. b1 :-> b2] :.. b2 :-> [b1 :.. b1 :-> '[b2 :.. b2]]]
; [[b1 :.. b1 :-> r] :* :-> [b1 :.. b1 :-> (t/Vec r)]]
; [[x :* :-> b2] :.. b2 :-> [x :* :-> '[b2 :.. b2]]]
; [[x :* :-> r] :* :-> [x :* :-> (t/Vec r)]])))
;TODO flip filters
cc/complement (t/All [x] [[x :-> t/Any] :-> [x :-> t/Bool]])
; should preserve filters
cc/boolean [t/Any :-> t/Bool]
cc/filter (t/All [x y] (t/IFn
[[x :-> t/Any :filters {:then (is y 0)}] (t/Seqable x) :-> (t/ASeq y)]
[[x :-> t/Any :filters {:then (! y 0)}] (t/Seqable x) :-> (t/ASeq (t/I x (t/Not y)))]
[[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
cc/filterv (t/All [x y] (t/IFn
[[x :-> t/Any :filters {:then (is y 0)}] (t/Seqable x) :-> (t/AVec y)]
[[x :-> t/Any] (t/Seqable x) :-> (t/AVec x)]))
cc/remove (t/All [x y] (t/IFn
[[x :-> t/Any :filters {:else (is y 0)}] (t/Seqable x) :-> (t/ASeq y)]
[[x :-> t/Any :filters {:else (! y 0)}] (t/Seqable x) :-> (t/ASeq (t/I x (t/Not y)))]
[[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)]))
cc/take-while (t/All [x y] [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)])
cc/drop-while (t/All [x] [[x :-> t/Any] (t/Seqable x) :-> (t/ASeq x)])
cc/split-with (t/All [x y z] (t/IFn
[[x :-> t/Any :filters {:then (is y 0), :else (is z 0)}] (t/Seqable x) :-> '[(t/ASeq y) (t/ASeq z)]]
[[x :-> t/Any] (t/Seqable x) :-> '[(t/ASeq x) (t/ASeq x)]]))
cc/split-at (t/All [x y z] [t/AnyInteger (t/Seqable x) :-> '[(t/ASeq x) (t/ASeq x)]])
cc/partition-all (t/All [x] (t/IFn [t/Int (t/Seqable x) :-> (t/ASeq (t/ASeq x))]
[t/Int t/Int (t/Seqable x) :-> (t/ASeq (t/ASeq x))]))