Skip to content

Commit

Permalink
fix(maybe): restrict mapped fmap value from being nullable in resul…
Browse files Browse the repository at this point in the history
…ting type
  • Loading branch information
drizzer14 committed Nov 24, 2022
1 parent 6ee5d6d commit 95895eb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/maybe/operators/fmap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { isJust } from './guards'
*/
export default function fmap<Value, NextValue>(
map: Map<Value, NextValue>
): (monad: Maybe<Value>) => Maybe<NextValue>
): (monad: Maybe<Value>) => Maybe<NonNullable<NextValue>>

/**
* Maps the value of the provided `monad` through the `transition` function
Expand All @@ -26,7 +26,7 @@ export default function fmap<Value, NextValue>(
export default function fmap<Value, NextValue>(
monad: Maybe<Value>,
map: Map<Value, NextValue>
): Maybe<NextValue>
): Maybe<NonNullable<NextValue>>

export default function fmap (...args: [any, any?]): any {
return permutation2(
Expand Down
7 changes: 7 additions & 0 deletions typetests/maybe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ const c2: Maybe<string> = tacit(
maybe(1)
)

const c3: Maybe<string> = fmap(
maybe(1),
(v) => {
return v > 0 ? `${v}` : null
}
)

// endregion

// region fold
Expand Down

0 comments on commit 95895eb

Please sign in to comment.