( f: (...a: A) => B )
| 970 | * @since 2.0.0 |
| 971 | */ |
| 972 | export const liftThrowable = <A extends ReadonlyArray<unknown>, B>( |
| 973 | f: (...a: A) => B |
| 974 | ): (...a: A) => Option<B> => |
| 975 | (...a) => { |
| 976 | try { |
| 977 | return some(f(...a)) |
| 978 | } catch { |
| 979 | return none() |
| 980 | } |
| 981 | } |
| 982 | |
| 983 | /** |
| 984 | * Extracts the value from a `Some`, or throws a custom error for `None`. |