/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-unsafe-member-access */ /* eslint-disable @typescript-eslint/no-unsafe-return */ /* eslint-disable @typescript-eslint/no-unsafe-assignment */ import { getOrUndefined as value, Option } from "@fp-ts/data/Option" export * from "@fp-ts/data/Option" export { Option as Opt } from "@fp-ts/data/Option" /** * @tsplus getter fp-ts/data/Option value */ export const getOrUndefined = value /** * @tsplus static fp-ts/data/Option.Ops omitableToNullable */ export function omitableToNullable(om: Option | undefined) { return om ?? Option.fromNullable(om) } /** * @tsplus static fp-ts/data/Option.Ops toBool */ export const toBool = Option.$.match( () => false, () => true ) /** * @tsplus static fp-ts/data/Option.Ops fromBool */ export const fromBool = (b: boolean) => (b ? Option.some(true) : Option.none) /** * Access property, unwrapping Options along the path */ export function p>>( k: K ): (v: Option) => Option<_A> export function p(k: K): (v: Option) => Option export function p(k: any) { return (v: Option) => v.flatMap(a => convert(a[k])) } function convert(a: any) { return Option.$.isSome(a) || Option.$.isNone(a) ? a : Option.fromNullable(a) } export type _A = A extends Some ? Y : never type KeysMatching = { [K in keyof T]: T[K] extends V ? K : never }[keyof T] export const PartialExceptionTypeId = Symbol() export type PartialExceptionTypeId = typeof PartialExceptionTypeId export class PartialException { readonly _typeId: PartialExceptionTypeId = PartialExceptionTypeId } function raisePartial(): X { throw new PartialException() } /** * Simulates a partial function * @tsplus static fp-ts/data/Option.Ops partial */ export function partial( f: (miss: () => X) => (...args: ARGS) => A ): (...args: ARGS) => Option { return (...args) => { try { return Option.some(f(raisePartial)(...args)) } catch (e) { if (e instanceof PartialException) { return Option.none } throw e } } }