import type { Either } from "../Either";
import type { Lazy } from "../Function";
import { fromNullable, none, some } from "./constructors";
import { isNone } from "./guards";
import type { Option } from "./model";
/*
* -------------------------------------------
* Option Combinators
* -------------------------------------------
*/
/**
* mapNullable_ :: Maybe m => (m a, (a -> ?b)) -> m b
* Map over a Maybe with a function that returns a nullable value
*
* @category Combinators
* @since 1.0.0
*/
export const mapNullable_ = (fa: Option, f: (a: A) => B | null | undefined): Option =>
isNone(fa) ? none() : fromNullable(f(fa.value));
/**
* mapNullable :: Maybe m => (a -> ?b) -> m a -> m b
* Map over a Maybe with a function that returns a nullable value
*
* @category Combinators
* @since 1.0.0
*/
export const mapNullable: (f: (a: A) => B | null | undefined) => (fa: Option) => Option = (f) => (fa) =>
mapNullable_(fa, f);
/**
* orElse_ :: Maybe m => (m a, () -> m b) -> m (a | b)
* Evaluate and return alternate optional value if empty
*
* @category Combinators
* @since 1.0.0
*/
export const orElse_ = (fa: Option, onNothing: Lazy