File tree 3 files changed +6
-5
lines changed
3 files changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ export interface IMaybe<T> extends IMonad<T> {
76
76
/**
77
77
* Map output of non-empty data to a new value
78
78
*/
79
- map < R > ( f : ( t : T ) => R ) : IMaybe < R >
79
+ map < R > ( f : ( t : T ) => NonNullable < R > ) : IMaybe < R >
80
80
81
81
/**
82
82
* Returns true if value is not empty
Original file line number Diff line number Diff line change @@ -199,14 +199,15 @@ describe('Maybe', () => {
199
199
const maybeNotSomeSome2 = maybe ( sut )
200
200
. map ( _str => getUserService < string > ( 0 ) )
201
201
. valueOr ( 'fallback' )
202
+
202
203
const maybeNotSomeSome3 = maybe ( sut )
203
- . map ( _str => getUserService < string > ( '' ) )
204
+ . map ( _str => 'sut' )
204
205
. valueOr ( 'fallback' )
205
206
206
207
expect ( maybeSomeString ) . toEqual ( 'initial input mapped' )
207
208
expect ( maybeNotSomeSomeString ) . toEqual ( 'fallback' )
208
209
expect ( maybeNotSomeSome2 ) . toEqual ( 0 )
209
- expect ( maybeNotSomeSome3 ) . toEqual ( '' )
210
+ expect ( maybeNotSomeSome3 ) . toEqual ( 'sut ' )
210
211
} )
211
212
212
213
it ( 'should handle undefined input' , ( ) => {
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ export class Maybe<T> implements IMaybe<T> {
74
74
: [ this . value as NonNullable < T > ]
75
75
}
76
76
77
- public map < R > ( fn : ( t : NonNullable < T > ) => R ) : IMaybe < R > {
77
+ public map < R > ( fn : ( t : NonNullable < T > ) => NonNullable < R > ) : IMaybe < R > {
78
78
return this . isSome ( )
79
79
? new Maybe < R > ( fn ( this . value as NonNullable < T > ) )
80
80
: new Maybe < R > ( )
@@ -98,7 +98,7 @@ export class Maybe<T> implements IMaybe<T> {
98
98
: new Maybe < T > ( )
99
99
}
100
100
101
- public apply < R > ( fab : IMaybe < ( v : T ) => R > ) : IMaybe < R > {
101
+ public apply < R > ( fab : IMaybe < ( v : T ) => NonNullable < R > > ) : IMaybe < R > {
102
102
return this . flatMap ( b => fab . map ( fn => fn ( b ) ) )
103
103
}
104
104
}
You can’t perform that action at this time.
0 commit comments