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 11import { List } from './list'
22
33export function listOf < T > ( ...args : T [ ] ) {
4- return List . of ( args )
4+ return List . of < T > ( ... args )
55}
66
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> {
3030 } , args . length )
3131 }
3232
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 ( )
3739 }
3840
3941 public static range ( start : number , end : number , step = 1 ) : List < number > {
You can’t perform that action at this time.
0 commit comments