Skip to content

Commit

Permalink
feat(optional): add the asOptional function
Browse files Browse the repository at this point in the history
This wraps a function to make it return an Optional
  • Loading branch information
dancrumb committed May 25, 2024
1 parent 221567f commit 2985dea
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ export const makeNonOptional =
<T>(f: (o: Optional<T>) => unknown) =>
(v: T) =>
f(Optional.of(v));

/**
* Take function that returns a value and make that return an Optional
*/
export const asOptional = <A extends any[], R>(f: (...args: A) => R) => {
return (...args: A) => Optional.of<R>(f(...args))
}

0 comments on commit 2985dea

Please sign in to comment.