-
-
Notifications
You must be signed in to change notification settings - Fork 504
/
ReadonlyNonEmptyArray.ts
108 lines (84 loc) · 3.03 KB
/
ReadonlyNonEmptyArray.ts
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
import * as _ from '../../src/ReadonlyNonEmptyArray'
import { pipe } from '../../src/function'
import { Ord } from '../../src/Ord'
declare const ras: ReadonlyArray<string>
declare const rneas: _.ReadonlyNonEmptyArray<string>
declare const rnens: _.ReadonlyNonEmptyArray<number>
declare const rnetns: _.ReadonlyNonEmptyArray<[number, string]>
//
// zip
//
_.zip(rnens, rneas) // $ExpectType ReadonlyNonEmptyArray<readonly [number, string]>
_.zip(rneas) // $ExpectType <A>(as: ReadonlyNonEmptyArray<A>) => ReadonlyNonEmptyArray<readonly [A, string]>
//
// zipWith
//
_.zipWith(rnens, rneas, (n, s) => [n, s] as const) // $ExpectType ReadonlyNonEmptyArray<readonly [number, string]>
//
// unzip
//
_.unzip(rnetns) // $ExpectType readonly [ReadonlyNonEmptyArray<number>, ReadonlyNonEmptyArray<string>]
pipe(rnetns, _.unzip) // $ExpectType readonly [ReadonlyNonEmptyArray<number>, ReadonlyNonEmptyArray<string>]
//
// cons
//
_.cons(1, []) // $ExpectType ReadonlyNonEmptyArray<1>
_.cons(1, [2, 3]) // $ExpectType ReadonlyNonEmptyArray<number>
//
// sort
//
declare const ordSubX: Ord<{ readonly a: string }>
interface X {
readonly a: string
readonly b: number
}
declare const xs: ReadonlyArray<X>
declare const nexs: _.ReadonlyNonEmptyArray<X>
_.sort(ordSubX)(nexs) // $ExpectType ReadonlyNonEmptyArray<X>
pipe(nexs, _.sort(ordSubX)) // $ExpectType ReadonlyNonEmptyArray<X>
//
// group
//
_.group(ordSubX)(nexs) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
pipe(xs, _.group<X>(ordSubX)) // $ExpectType ReadonlyArray<ReadonlyNonEmptyArray<X>>
_.group(ordSubX)(nexs) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
// TODO pipe(nexs, _.group<X>(ordSubX)) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
//
// groupSort
//
_.groupSort(ordSubX)(nexs) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
pipe(xs, _.groupSort<X>(ordSubX)) // $ExpectType ReadonlyArray<ReadonlyNonEmptyArray<X>>
_.groupSort(ordSubX)(nexs) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
// TODO pipe(nexs, _.groupSort<X>(ordSubX)) // $ExpectType ReadonlyNonEmptyArray<ReadonlyNonEmptyArray<X>>
//
// groupBy
//
_.groupBy((x: { readonly a: string }) => x.a)(xs) // $ExpectType Readonly<Record<string, ReadonlyNonEmptyArray<{ readonly a: string; }>>>
// $ExpectType Readonly<Record<string, ReadonlyNonEmptyArray<X>>>
pipe(
xs,
_.groupBy((x) => x.a)
)
//
// Do
//
// $ExpectType ReadonlyNonEmptyArray<{ a: number; b: string; }>
pipe(
_.Do,
_.bind('a', () => _.of(1)),
_.bind('b', () => _.of('b'))
)
//
// filter
//
declare const isNumber1: (sn: string | number) => sn is number
declare const isNumber2: (sn: unknown) => sn is number
declare const neasn: _.ReadonlyNonEmptyArray<string | number>
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
pipe(neasn, _.filter(isNumber1))
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
_.filter(isNumber1)(neasn)
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
pipe(neasn, _.filter(isNumber2))
// $ExpectType Option<ReadonlyNonEmptyArray<number>>
_.filter(isNumber2)(neasn)