/**
* The `Option` module provides a type-safe way to represent values that may or
* may not exist. An `Option` is either `Some` (containing a value) or
* `None` (representing absence).
*
* **Mental model**
*
* - `Option` is a discriminated union: `None | Some`
* - `None` represents the absence of a value (like `null`/`undefined`, but type-safe)
* - `Some` wraps a present value of type `A`, accessed via `.value`
* - `Option` is a monad: chain operations with {@link flatMap}, compose pipelines with `pipe`
* - All operations are pure and return new `Option` values; the input is never mutated
* - `Option` is yieldable in `Effect.gen`, producing the inner value or short-circuiting with `NoSuchElementError`
*
* **Common tasks**
*
* - Create from a value: {@link some}, {@link none}
* - Create from nullable: {@link fromNullishOr}, {@link fromNullOr}, {@link fromUndefinedOr}
* - Create from iterable: {@link fromIterable}
* - Create from Result: {@link getSuccess}, {@link getFailure}
* - Transform: {@link map}, {@link flatMap}, {@link andThen}
* - Unwrap: {@link getOrElse}, {@link getOrNull}, {@link getOrUndefined}, {@link getOrThrow}
* - Pattern match: {@link match}
* - Fallbacks: {@link orElse}, {@link orElseSome}, {@link firstSomeOf}
* - Filter: {@link filter}, {@link filterMap}
* - Combine multiple: {@link all}, {@link zipWith}, {@link product}
* - Generator syntax: {@link gen}
* - Do notation: {@link Do}, {@link bind}, {@link let_ let}
* - Check contents: {@link isSome}, {@link isNone}, {@link contains}, {@link exists}
*
* **Gotchas**
*
* - `Option.some(null)` is a valid `Some`; use {@link fromNullishOr} to treat `null`/`undefined` as `None`
* - {@link filterMap} uses a `Filter` callback that returns `Result`
* - {@link getOrThrow} throws a generic `Error`; prefer {@link getOrThrowWith} for custom errors
* - `None` is a singleton; compare with {@link isNone}, not `===`
* - When yielded in `Effect.gen`, a `None` becomes a `NoSuchElementError` defect
*
* **Quickstart**
*
* **Example** (Working with optional values)
*
* ```ts
* import { Option } from "effect"
*
* const name = Option.some("Alice")
* const age = Option.none()
*
* // Transform
* const upper = Option.map(name, (s) => s.toUpperCase())
*
* // Unwrap with fallback
* console.log(Option.getOrElse(upper, () => "unknown"))
* // Output: "ALICE"
*
* console.log(Option.getOrElse(age, () => 0))
* // Output: 0
*
* // Combine multiple options
* const both = Option.all({ name, age })
* console.log(Option.isNone(both))
* // Output: true
* ```
*
* **See also**
*
* - {@link some} / {@link none} for creating values
* - {@link map} / {@link flatMap} for transforming values
* - {@link match} for pattern matching
* - {@link gen} for generator-based syntax
*
* @since 2.0.0
* @module
*/
import * as Combiner from "./Combiner.ts"
import * as Equal from "./Equal.ts"
import * as Equivalence from "./Equivalence.ts"
import type * as Filter from "./Filter.ts"
import type { LazyArg } from "./Function.ts"
import { constNull, constUndefined, dual, identity } from "./Function.ts"
import type { TypeLambda } from "./HKT.ts"
import type { Inspectable } from "./Inspectable.ts"
import * as doNotation from "./internal/doNotation.ts"
import * as option from "./internal/option.ts"
import * as result from "./internal/result.ts"
import type { Order } from "./Order.ts"
import * as order from "./Order.ts"
import type { Pipeable } from "./Pipeable.ts"
import type { Predicate, Refinement } from "./Predicate.ts"
import { isFunction } from "./Predicate.ts"
import * as Reducer from "./Reducer.ts"
import type { Result } from "./Result.ts"
import type { Covariant, NoInfer, NotFunction } from "./Types.ts"
import type * as Unify from "./Unify.ts"
import type * as Gen from "./Utils.ts"
const TypeId = "~effect/data/Option"
/**
* The `Option` data type represents optional values. An `Option` is either
* `Some`, containing a value of type `A`, or `None`, representing absence.
*
* **When to use**
*
* - Representing initial values that may not yet exist
* - Returning from partial functions (not defined for all inputs)
* - Managing optional fields in data structures
*
* **Example** (Creating and matching Options)
*
* ```ts
* import { Option } from "effect"
*
* const someValue: Option.Option = Option.some(42)
* const noneValue: Option.Option = Option.none()
*
* const result = Option.match(someValue, {
* onNone: () => "No value",
* onSome: (value) => `Value is ${value}`
* })
*
* console.log(result)
* // Output: "Value is 42"
* ```
*
* @see {@link some} for creating a `Some`
* @see {@link none} for creating a `None`
* @see {@link match} for pattern matching
*
* @category Models
* @since 2.0.0
*/
export type Option = None | Some
/**
* Represents the absence of a value within an {@link Option}.
*
* **When to use**
*
* - Use as a type guard target when narrowing via {@link isNone}
*
* **Behavior**
*
* - `_tag` is always `"None"`
* - Implements `Pipeable`, `Inspectable`, and structural equality
*
* @see {@link isNone} to check if an `Option` is `None`
* @see {@link none} to construct a `None`
*
* @category Models
* @since 2.0.0
*/
export interface None extends Pipeable, Inspectable {
readonly _tag: "None"
readonly _op: "None"
readonly valueOrUndefined: undefined
readonly [TypeId]: {
readonly _A: Covariant
}
[Symbol.iterator](): OptionIterator