<const A, Input = unknown>(value: A): Filter<
Input,
A,
EqualsWith<Input, A, A, Exclude<Input, A>>
>Creates a filter that only passes values equal to the specified value using structural equality.
When to use
Use to accept inputs that are structurally equal to a known expected value
while staying in a composable Filter / Result pipeline.
Details
Delegates to Equal.equals. On success it returns Result.succeed(value);
on failure it returns Result.fail(input).
export const const equals: <A, Input = unknown>(
value: A
) => Filter<
Input,
A,
EqualsWith<Input, A, A, Exclude<Input, A>>
>
Creates a filter that only passes values equal to the specified value using structural equality.
When to use
Use to accept inputs that are structurally equal to a known expected value
while staying in a composable Filter / Result pipeline.
Details
Delegates to Equal.equals. On success it returns Result.succeed(value);
on failure it returns Result.fail(input).
equals =
<const function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A, function (type parameter) Input in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>Input = unknown>(value: const Avalue: function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A): interface Filter<in Input, out Pass = Input, out Fail = Input>Represents a filter function that can transform inputs to outputs or filter them out.
Details
A filter takes an input value and either returns a boxed pass value or the
special fail type to indicate the value should be filtered out.
Example (Defining a positive number filter)
import { Filter, Result } from "effect"
// A filter that only passes positive numbers
const positiveFilter: Filter.Filter<number> = (n) => n > 0 ? Result.succeed(n) : Result.fail(n)
console.log(positiveFilter(5)) // Result.succeed(5)
console.log(positiveFilter(-3)) // Result.fail(-3)
Filter<function (type parameter) Input in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>Input, function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A, type EqualsWith<A, B, Y, N> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B ? 1 : 2 ? Y : NDetermines if two types are equal, returning custom types for each case.
When to use
Use when you need a type-level if/else based on type equality.
Details
Returns Y when A and B are equal, N otherwise.
Example (Choosing a conditional type based on equality)
import type { Types } from "effect"
type R1 = Types.EqualsWith<string, string, "same", "diff"> // "same"
type R2 = Types.EqualsWith<string, number, "same", "diff"> // "diff"
EqualsWith<function (type parameter) Input in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>Input, function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A, function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A, type Exclude<T, U> = T extends U
? never
: T
Exclude from T those types that are assignable to U
Exclude<function (type parameter) Input in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>Input, function (type parameter) A in <const A, Input = unknown>(value: A): Filter<Input, A, EqualsWith<Input, A, A, Exclude<Input, A>>>A>>> => (u: Input = unknownu) =>
import EqualEqual.equals(u: Input = unknownu, value: const Avalue) ? import ResultResult.const succeed: <A>(right: A) => Result<A>Creates a Result holding a Success value.
Details
- Use when you have a value and want to lift it into the
Result type
- The error type
E defaults to never
Example (Wrapping a value)
import { Result } from "effect"
const result = Result.succeed(42)
console.log(Result.isSuccess(result))
// Output: true
succeed(value: const Avalue) : import ResultResult.const fail: <E>(
left: E
) => Result<never, E>
Creates a Result holding a Failure value.
When to use
Use to represent a failed Result with a typed failure value.
Details
- The success type
A defaults to never
Example (Creating a failure)
import { Result } from "effect"
const result = Result.fail("Something went wrong")
console.log(Result.isFailure(result))
// Output: true
fail(u: Input = unknownu as any)