From 2985dea34dc54093d3ad8ac0cb5b67fc2d3510da Mon Sep 17 00:00:00 2001 From: Dan Rumney Date: Sat, 25 May 2024 09:56:14 -0500 Subject: [PATCH] feat(optional): add the asOptional function This wraps a function to make it return an Optional --- src/index.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/index.ts b/src/index.ts index e6729613..bf2a9aac 100644 --- a/src/index.ts +++ b/src/index.ts @@ -28,3 +28,10 @@ export const makeNonOptional = (f: (o: Optional) => unknown) => (v: T) => f(Optional.of(v)); + +/** + * Take function that returns a value and make that return an Optional + */ +export const asOptional = (f: (...args: A) => R) => { + return (...args: A) => Optional.of(f(...args)) +} \ No newline at end of file