<A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>Creates a Filter from a function that returns an Option; Some(value)
passes with value, and None fails with the original input.
export const const fromPredicateOption: <A, B>(
predicate: (a: A) => Option.Option<B>
) => Filter<A, B>
Creates a Filter from a function that returns an Option; Some(value)
passes with value, and None fails with the original input.
fromPredicateOption = <function (type parameter) A in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>A, function (type parameter) B in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>B>(predicate: (a: A) => Option.Option<B>predicate: (a: Aa: function (type parameter) A in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>A) => 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) B in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>B>): 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) A in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>A, function (type parameter) B in <A, B>(predicate: (a: A) => Option.Option<B>): Filter<A, B>B> => (input: Ainput) => {
const const o: Option.Option<B>o = predicate: (a: A) => Option.Option<B>predicate(input: Ainput)
return const o: Option.Option<B>o._tag: "None" | "Some"_tag === "None" ? 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(input: Ainput) : 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(const o: Option.Some<B>const o: {
_tag: "Some";
_op: "Some";
value: A;
valueOrUndefined: A;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
o.Some<B>.value: Bvalue)
}