<A>(): Prism<Option.Option<A>, undefined>Prism that focuses on Option.None, exposing undefined.
When to use
Use when you want to match or construct None values within an optic chain.
Details
getResultsucceeds withundefinedwhen the option isNone.getResultfails when the option isSome.set(undefined)producesOption.none().
Example (Matching None)
import { Optic, Option, Result } from "effect"
const _none = Optic.id<Option.Option<number>>().compose(Optic.none())
console.log(Result.isSuccess(_none.getResult(Option.none())))
// Output: true
console.log(Result.isFailure(_none.getResult(Option.some(1))))
// Output: trueexport function function none<A>(): Prism<
Option.Option<A>,
undefined
>
Prism that focuses on Option.None, exposing undefined.
When to use
Use when you want to match or construct None values within an optic chain.
Details
getResult succeeds with undefined when the option is None.
getResult fails when the option is Some.
set(undefined) produces Option.none().
Example (Matching None)
import { Optic, Option, Result } from "effect"
const _none = Optic.id<Option.Option<number>>().compose(Optic.none())
console.log(Result.isSuccess(_none.getResult(Option.none())))
// Output: true
console.log(Result.isFailure(_none.getResult(Option.some(1))))
// Output: true
none<function (type parameter) A in none<A>(): Prism<Option.Option<A>, undefined>A>(): interface Prism<in out S, in out A>Focuses on a part A of S that may not be present (e.g. a union
variant or a validated subset).
When to use
Use when the focus is conditional — reading can fail (wrong variant, failed
validation).
- Building a new
S from A does not require the original S.
Details
getResult(s) returns Result.Success<A> when the focus matches, or
Result.Failure<string> with an error message.
set(a) always succeeds and returns a new S.
- Extends
Optional
.
- Composing two Prisms produces a Prism; composing a Prism with a
Example (Narrowing a tagged union)
import { Optic, Result } from "effect"
type Shape =
| { readonly _tag: "Circle"; readonly radius: number }
| { readonly _tag: "Rect"; readonly width: number }
const _circle = Optic.id<Shape>().tag("Circle")
console.log(Result.isSuccess(_circle.getResult({ _tag: "Circle", radius: 5 })))
// Output: true
console.log(Result.isFailure(_circle.getResult({ _tag: "Rect", width: 10 })))
// Output: true
Prism<import OptionOption.type Option<A> = Option.None<A> | Option.Some<A>The Option data type represents optional values. An Option<A> is either
Some<A>, containing a value of type A, or None, representing absence.
When to use
Use to represent initial values that may not yet exist
- Returning from partial functions (not defined for all inputs)
- Managing optional fields in data structures
Namespace containing utility types for Option.
When to use
Use to access type-level helpers associated with Option.
Option<function (type parameter) A in none<A>(): Prism<Option.Option<A>, undefined>A>, undefined> {
const const run: <A>(
e: Option.Option<A>
) => Result.Result<
Option.None<A>,
SchemaIssue.Issue
>
run = function runRefinement<T extends E, E>(
refinement: (e: E) => e is T,
annotations?: Schema.Annotations.Filter
): (e: E) => Result.Result<T, SchemaIssue.Issue>
runRefinement(import OptionOption.const isNone: <A>(
self: Option<A>
) => self is None<A>
Checks whether an Option is None (absent).
When to use
Use when you need to branch on an absent Option before accessing .value.
Details
- Acts as a type guard, narrowing to
None<A>
Example (Checking for None)
import { Option } from "effect"
console.log(Option.isNone(Option.some(1)))
// Output: false
console.log(Option.isNone(Option.none()))
// Output: true
isNone, { Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "a None value" })
return function makePrism<S, A>(
getResult: (s: S) => Result.Result<A, string>,
set: (a: A) => S
): Prism<S, A>
Creates a
Prism
from a fallible getter and an infallible setter.
When to use
Use when reading can fail (the part may not exist in S), but building S
from A always succeeds.
Details
getResult should return Result.fail(message) on mismatch.
Example (Parsing a string to a number)
import { Optic, Result } from "effect"
const numeric = Optic.makePrism<string, number>(
(s) => {
const n = Number(s)
return Number.isNaN(n) ? Result.fail("not a number") : Result.succeed(n)
},
String
)
console.log(Result.isSuccess(numeric.getResult("42")))
// Output: true
console.log(numeric.set(42))
// Output: "42"
makePrism(
(s: Option.Option<A>s) =>
import ResultResult.const mapBoth: {
<E, E2, A, A2>(options: {
readonly onFailure: (left: E) => E2
readonly onSuccess: (right: A) => A2
}): (self: Result<A, E>) => Result<A2, E2>
<E, A, E2, A2>(
self: Result<A, E>,
options: {
readonly onFailure: (left: E) => E2
readonly onSuccess: (right: A) => A2
}
): Result<A2, E2>
}
mapBoth(const run: <A>(
e: Option.Option<A>
) => Result.Result<
Option.None<A>,
SchemaIssue.Issue
>
run(s: Option.Option<A>s), {
onFailure: (left: SchemaIssue.Issue) => stringonFailure: var String: StringConstructorAllows manipulation and formatting of text strings and determination and location of substrings within strings.
String,
onSuccess: (right: Option.None<A>) => undefinedonSuccess: () => var undefinedundefined
}),
() => import OptionOption.const none: <A = never>() => Option<A>Creates an Option representing the absence of a value.
When to use
Use to represent a missing or uninitialized value, such as returning "no
result" from a function.
Details
- Returns
Option<never>, which is a subtype of Option<A> for any A
- Always returns the same singleton instance
Example (Creating an empty Option)
import { Option } from "effect"
// ┌─── Option<never>
// ▼
const noValue = Option.none()
console.log(noValue)
// Output: { _id: 'Option', _tag: 'None' }
none()
)
}