# byenull > A lightweight, tree-shakable Option type library for type-safe nullable handling in TypeScript. ## Guide - [Introduction](/guide/start/introduction.md): Learn how byenull represents absent values with Option, composes synchronous and asynchronous work, and converts to and from @praha/byethrow Results. - [Why byenull?](/guide/start/why.md): Decide when Option pipelines are useful, what byenull leaves explicit, and when a @praha/byethrow Result is the better return type. - [Quick start](/guide/start/quick.md): Install byenull and learn the core workflow: create Options with some and none, wrap nullable lookups with fn, compose steps with pipe, map, and andThen, recover with orElse, and handle async lookups. - [Tutorial](/guide/tutorial/index.md): The byenull tutorial: build a type-safe profile lookup step by step, from the Option type through pipelines to byethrow interop. - [Option type](/guide/tutorial/basics/option-type.md): The structure of Option: the Some and None union, OptionAsync for async operations, and utility types such as OptionMaybeAsync, InferSome, and OptionFor. - [Creating Options](/guide/tutorial/basics/creating-options.md): Creating Options with some and none, wrapping nullable-returning functions with fn and maybe, and normalizing nullish values into None. - [Checking Options](/guide/tutorial/basics/checking-options.md): Checking Options with isSome, isNone, and isOption: narrowing the type so value access is safe, and verifying unknown values. - [Pipe basics](/guide/tutorial/transforming/pipe-basics.md): How Option.pipe chains operations from top to bottom instead of nested calls or intermediate variables, how a None short-circuits a pipeline, and how async steps are handled. - [Mapping options](/guide/tutorial/transforming/mapping-options.md): Transform values inside Options with map, including nullish normalization, asynchronous inputs, and the difference between map and andThen. - [Chaining options](/guide/tutorial/transforming/chaining-options.md): Chain Option-returning steps with andThen, including sequential lookups, asynchronous work, and None short-circuiting. - [Recovering options](/guide/tutorial/transforming/recovering-options.md): Recover from None with orElse by supplying a fallback Option, continuing the pipeline, and using asynchronous fallbacks. - [Inspecting options](/guide/tutorial/transforming/inspecting-options.md): Run side effects such as logging at any step of a pipeline with inspect and inspectNone, without changing the Option that flows through it. - [Unwrapping options](/guide/tutorial/resolving/unwrapping-options.md): Extract a plain value from an Option with unwrap, provide a default for None, and unwrap asynchronous Options at application boundaries. - [Converting to Results](/guide/tutorial/resolving/converting-to-results.md): Convert between byenull Options and byethrow Results with toResult and fromResult, including asynchronous values and error handling. - [How-to guides](/guide/how-to/index.md): Task-oriented guides for real-world byenull work: imports, nullish sources, async pipelines, Result conversion, and testing. - [How to choose an import style](/guide/how-to/importing-option.md): The two import styles of byenull, the Option namespace and the O shorthand alias, how both support tree-shaking, and how to keep a codebase on one style. - [How to handle nullish values](/guide/how-to/handling-nullish-values.md): Recipes for turning nullish-returning APIs into Options that compose: Array.find, Map.get, DOM queries, environment variables, and third-party SDKs. - [How to mix sync and async Options](/guide/how-to/writing-async-pipelines.md): How to mix synchronous and asynchronous Options in one pipeline: wrap async APIs with fn, let andThen carry the Promise, and await the final result. - [How to convert between Option and Result](/guide/how-to/converting-between-option-and-result.md): How to cross the boundary between byenull Options and @praha/byethrow Results: convert absence into a Failure with toResult, and drop the error with fromResult. - [How to test Options](/guide/how-to/testing-options.md): Assert Options in Vitest and Jest with the byenull-testing matchers toBeSome and toBeNone: setup, typed value callbacks, and the .not caveat. - [Explanation](/guide/explanation/index.md): Why Options beat nullish checks, absence versus failure, the sync/async model, and the decisions behind byenull. - [Option vs null and undefined](/guide/explanation/option-vs-nullish.md): When an Option helps compose dependent operations, when nullish values are clearer, and what information both representations leave out. - [Option vs Result](/guide/explanation/option-vs-result.md): How to choose between absence without a reason, anticipated failures with typed errors, and unexpected exceptions, plus where to convert between Option and Result. - [Sync and async Options](/guide/explanation/sync-and-async.md): How Promise-aware Option operations dispatch at runtime, how OptionFor types mixed unions, and why unwrap can return either a value or a Promise. - [Design principles](/guide/explanation/design-principles.md): Why byenull uses plain objects, data-last functions, nullish-normalizing constructors, two namespace aliases, and shared sync and async combinators. ## API Reference - [byenull](/api/index.md) - [Namespace: Option](/api/modules/Option.md): Re-exports core Option-handling utilities under two convenient namespaces: - [Type Alias: InferSome](/api/types/Option.InferSome.md): Infers the Some value type `T` from an Option or a function returning an Option. - [Type Alias: None](/api/types/Option.None.md): The variant of an Option that holds no value. - [Type Alias: NonNullableValue](/api/types/Option.NonNullableValue.md): A value that is neither `null` nor `undefined`. - [Type Alias: Option](/api/types/Option.Option.md): A union type representing either a Some or a None. - [Type Alias: OptionAsync](/api/types/Option.OptionAsync.md): An asynchronous variant of Option, wrapped in a `Promise`. - [Type Alias: OptionFor](/api/types/Option.OptionFor.md): Resolves to the appropriate Option type (sync or async) based on the input type. - [Type Alias: OptionMaybeAsync](/api/types/Option.OptionMaybeAsync.md): An option that may be either synchronous or asynchronous. - [Type Alias: Some](/api/types/Option.Some.md): The variant of an Option that holds a value. - [Function: andThen()](/api/functions/Option.andThen.md): Chains the next computation using the value of an Option or OptionAsync. If the input is a None, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. - [Function: fn()](/api/functions/Option.fn.md): Wraps a function and returns a new function that returns an Option or OptionAsync. - [Function: fromResult()](/api/functions/Option.fromResult.md): Converts a Result from @praha/byethrow into an Option or OptionAsync. A `Success` becomes a Some; a `Failure` becomes a None, discarding the error. - [Function: inspect()](/api/functions/Option.inspect.md): Executes a side effect function on the value of a Some in an Option or OptionAsync, without modifying the original option. This is useful for debugging, logging, or performing other side effects while maintaining the original value. - [Function: inspectNone()](/api/functions/Option.inspectNone.md): Executes a side effect function when an Option or OptionAsync is a None, without modifying the original option. This is useful for debugging, logging, or performing other side effects while maintaining the original value. - [Function: isNone()](/api/functions/Option.isNone.md): Type guard to check if an Option is a None. - [Function: isOption()](/api/functions/Option.isOption.md): Type guard to check if a value is an Option. - [Function: isSome()](/api/functions/Option.isSome.md): Type guard to check if an Option is a Some. - [Function: map()](/api/functions/Option.map.md): Applies a transformation function to the value of an Option or OptionAsync. If the input is a None, it is returned unchanged. - [Function: maybe()](/api/functions/Option.maybe.md): Executes a function and wraps its result in an Option or OptionAsync. - [Function: none()](/api/functions/Option.none.md): Creates a None: an `Option` that holds no value. - [Function: orElse()](/api/functions/Option.orElse.md): Chains a fallback computation for an Option or OptionAsync. If the input is a Some, it is returned unchanged. Otherwise, the provided function is called, and its result is returned as-is. - [Function: pipe()](/api/functions/Option.pipe.md): Applies a sequence of functions to a value, from left to right. - [Function: some()](/api/functions/Option.some.md): Creates a Some from a given value. Passing `null` or `undefined` returns None instead. - [Function: toResult()](/api/functions/Option.toResult.md): Converts an Option or OptionAsync into a Result from @praha/byethrow. A Some becomes a `Success`; a None becomes a `Failure` containing `err`. - [Function: unwrap()](/api/functions/Option.unwrap.md): Extracts the value from an Option or OptionAsync. If the input is a None, the default value is returned.