File tree Expand file tree Collapse file tree 3 files changed +42
-16
lines changed Expand file tree Collapse file tree 3 files changed +42
-16
lines changed Original file line number Diff line number Diff line change
1
+ import { listFrom , listOf } from './list.factory'
2
+
3
+ describe ( 'List Factory' , ( ) => {
4
+ describe ( listFrom . name , ( ) => {
5
+ it ( 'should' , ( ) => {
6
+ const sut = listFrom ( [ 1 , 2 ] ) . filter ( a => a > 1 )
7
+
8
+ expect ( sut . toArray ( ) ) . toEqual ( [ 2 ] )
9
+ } )
10
+
11
+ it ( 'should handle undefined' , ( ) => {
12
+ const sut = listFrom < number > ( ) . filter ( a => a > 1 )
13
+
14
+ expect ( sut . toArray ( ) ) . toEqual ( [ ] )
15
+ } )
16
+ } )
17
+
18
+ describe ( listOf . name , ( ) => {
19
+ it ( 'should handle nominal' , ( ) => {
20
+ const sut = listOf ( 1 , 2 ) . filter ( a => a > 1 )
21
+
22
+ expect ( sut . toArray ( ) ) . toEqual ( [ 2 ] )
23
+ } )
24
+
25
+ it ( 'should handle undefined' , ( ) => {
26
+ const sut = listOf < number > ( ) . filter ( a => a > 1 )
27
+
28
+ expect ( sut . toArray ( ) ) . toEqual ( [ ] )
29
+ } )
30
+ } )
31
+ } )
32
+
Original file line number Diff line number Diff line change 1
1
import { List } from './list'
2
2
3
3
export function listOf < T > ( ...args : T [ ] ) {
4
- return List . of ( args )
4
+ return List . of < T > ( ... args )
5
5
}
6
6
7
- // export function listFrom<T>(value?: T) {
8
- // return List.from<T>()
9
- // }
10
-
11
- // export function none<T>() {
12
- // return Maybe.none<T>()
13
- // }
14
-
15
- // export function some<T>(value: T) {
16
- // return maybe(value)
17
- // }
7
+ export function listFrom < T > ( value ?: Iterable < T > ) {
8
+ return List . from < T > ( value )
9
+ }
Original file line number Diff line number Diff line change @@ -30,10 +30,12 @@ export class List<T> {
30
30
} , args . length )
31
31
}
32
32
33
- public static from < T > ( iterable : Iterable < T > ) : List < T > {
34
- return new List ( function * ( ) {
35
- yield * iterable as any
36
- } as any , ( iterable as any ) . length )
33
+ public static from < T > ( iterable ?: Iterable < T > ) : List < T > {
34
+ return iterable
35
+ ? new List ( function * ( ) {
36
+ yield * iterable as any
37
+ } as any , ( iterable as any ) . length )
38
+ : List . empty ( )
37
39
}
38
40
39
41
public static range ( start : number , end : number , step = 1 ) : List < number > {
You can’t perform that action at this time.
0 commit comments