Skip to content

Commit ccd7098

Browse files
fix: FlatMapAuto uses NonNullable<T> (#142)
1 parent 267b5a3 commit ccd7098

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/maybe/maybe.interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export interface IMaybe<T> extends IMonad<T> {
9696
/**
9797
* Combine multiple Maybe, automatically wrapping predicate
9898
*/
99-
flatMapAuto<R>(fn: (v: T) => R): IMaybe<NonNullable<R>>
99+
flatMapAuto<R>(fn: (v: NonNullable<T>) => R): IMaybe<NonNullable<R>>
100100

101101
/**
102102
* Apply a predicate which if met, continues the Maybe chain,

src/maybe/maybe.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,17 @@ describe('Maybe', () => {
456456

457457
expect(maybeAString).toBeUndefined()
458458
})
459+
460+
it('should be nonnullable value outlet', () => {
461+
const imgWidth = maybe('url.com')
462+
.flatMapAuto(imgUrl => /width=[0-9]*/.exec(imgUrl))
463+
.flatMapAuto(a => a[0].split('=')[1])
464+
.map(a => +a)
465+
.valueOr(0)
466+
467+
expect(imgWidth).toEqual(0)
468+
})
469+
459470
})
460471

461472
describe('isSome', () => {

0 commit comments

Comments
 (0)