Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/maybe/maybe.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export interface IMaybe<T> extends IMonad<T> {
/**
* Map output of non-empty data to a new value
*/
map<R>(f: (t: T) => R): IMaybe<R>
map<R>(f: (t: T) => NonNullable<R>): IMaybe<R>

/**
* Returns true if value is not empty
Expand Down
5 changes: 3 additions & 2 deletions src/maybe/maybe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,15 @@ describe('Maybe', () => {
const maybeNotSomeSome2 = maybe(sut)
.map(_str => getUserService<string>(0))
.valueOr('fallback')

const maybeNotSomeSome3 = maybe(sut)
.map(_str => getUserService<string>(''))
.map(_str => 'sut')
.valueOr('fallback')

expect(maybeSomeString).toEqual('initial input mapped')
expect(maybeNotSomeSomeString).toEqual('fallback')
expect(maybeNotSomeSome2).toEqual(0)
expect(maybeNotSomeSome3).toEqual('')
expect(maybeNotSomeSome3).toEqual('sut')
})

it('should handle undefined input', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/maybe/maybe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Maybe<T> implements IMaybe<T> {
: [this.value as NonNullable<T>]
}

public map<R>(fn: (t: NonNullable<T>) => R): IMaybe<R> {
public map<R>(fn: (t: NonNullable<T>) => NonNullable<R>): IMaybe<R> {
return this.isSome()
? new Maybe<R>(fn(this.value as NonNullable<T>))
: new Maybe<R>()
Expand All @@ -98,7 +98,7 @@ export class Maybe<T> implements IMaybe<T> {
: new Maybe<T>()
}

public apply<R>(fab: IMaybe<(v: T) => R>): IMaybe<R> {
public apply<R>(fab: IMaybe<(v: T) => NonNullable<R>>): IMaybe<R> {
return this.flatMap(b => fab.map(fn => fn(b)))
}
}