-
-
Notifications
You must be signed in to change notification settings - Fork 504
/
NonEmptyArray.ts
107 lines (83 loc) · 2.56 KB
/
NonEmptyArray.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
import * as _ from '../../src/NonEmptyArray'
import { Ord } from '../../src/Ord'
import { pipe } from '../../src/function'
declare const neas: _.NonEmptyArray<string>
declare const nens: _.NonEmptyArray<number>
declare const netns: _.NonEmptyArray<[number, string]>
//
// zip
//
_.zip(nens, neas) // $ExpectType NonEmptyArray<[number, string]>
_.zip(neas) // $ExpectType <A>(as: NonEmptyArray<A>) => NonEmptyArray<[A, string]>
//
// zipWith
//
_.zipWith(nens, neas, (n, s) => [n, s] as const) // $ExpectType NonEmptyArray<readonly [number, string]>
//
// unzip
//
_.unzip(netns) // $ExpectType [NonEmptyArray<number>, NonEmptyArray<string>]
pipe(netns, _.unzip) // $ExpectType [NonEmptyArray<number>, NonEmptyArray<string>]
//
// cons
//
_.cons(1, []) // $ExpectType NonEmptyArray<1>
_.cons(1, [2, 3]) // $ExpectType NonEmptyArray<number>
//
// sort
//
declare const ordSubX: Ord<{ readonly a: string }>
interface X {
readonly a: string
readonly b: number
}
declare const xs: Array<X>
declare const nexs: _.NonEmptyArray<X>
_.sort(ordSubX)(nexs) // $ExpectType NonEmptyArray<X>
pipe(nexs, _.sort(ordSubX)) // $ExpectType NonEmptyArray<X>
//
// group
//
_.group(ordSubX)(xs) // $ExpectType NonEmptyArray<X>[]
pipe(xs, _.group<X>(ordSubX)) // $ExpectType NonEmptyArray<X>[]
_.group(ordSubX)(nexs) // $ExpectType NonEmptyArray<NonEmptyArray<X>>
// TODO pipe(nexs, _.group<X>(ordSubX)) // $ExpectType NonEmptyArray<NonEmptyArray<X>>
//
// groupSort
//
_.groupSort(ordSubX)(xs) // $ExpectType NonEmptyArray<X>[]
pipe(xs, _.groupSort<X>(ordSubX)) // $ExpectType NonEmptyArray<X>[]
_.groupSort(ordSubX)(nexs) // $ExpectType NonEmptyArray<NonEmptyArray<X>>
// TODO pipe(nexs, _.groupSort<X>(ordSubX)) // $ExpectType NonEmptyArray<NonEmptyArray<X>>
//
// groupBy
//
_.groupBy((x: { readonly a: string }) => x.a)(xs) // $ExpectType Record<string, NonEmptyArray<{ readonly a: string; }>>
// $ExpectType Record<string, NonEmptyArray<X>>
pipe(
xs,
_.groupBy((x) => x.a)
)
//
// Do
//
// $ExpectType NonEmptyArray<{ 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: _.NonEmptyArray<string | number>
// $ExpectType Option<NonEmptyArray<number>>
pipe(neasn, _.filter(isNumber1))
// $ExpectType Option<NonEmptyArray<number>>
_.filter(isNumber1)(neasn)
// $ExpectType Option<NonEmptyArray<number>>
pipe(neasn, _.filter(isNumber2))
// $ExpectType Option<NonEmptyArray<number>>
_.filter(isNumber2)(neasn)