<K>(key: K): <Input extends { readonly has: (key: K) => boolean }>(
input: Input
) => Result.Result<Input, Input>Creates a Filter that passes inputs whose has(key) method returns
true for the specified key.
When to use
Use to keep inputs that expose a has method, such as Set or Map, when
they contain a required key.
export const const has: <K>(
key: K
) => <
Input extends {
readonly has: (key: K) => boolean
}
>(
input: Input
) => Result.Result<Input, Input>
Creates a Filter that passes inputs whose has(key) method returns
true for the specified key.
When to use
Use to keep inputs that expose a has method, such as Set or Map, when
they contain a required key.
has =
<function (type parameter) K in <K>(key: K): <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input) => Result.Result<Input, Input>
K>(key: Kkey: function (type parameter) K in <K>(key: K): <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input) => Result.Result<Input, Input>
K) => <function (type parameter) Input in <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input): Result.Result<Input, Input>
Input extends { readonly has: (key: K) => booleanhas: (key: Kkey: function (type parameter) K in <K>(key: K): <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input) => Result.Result<Input, Input>
K) => boolean }>(input: Input extends { readonly has: (key: K) => boolean; }input: function (type parameter) Input in <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input): Result.Result<Input, Input>
Input): import ResultResult.type Result<A, E = never> = Result.Success<A, E> | Result.Failure<A, E>A value that is either Success<A, E> or Failure<A, E>.
When to use
Use when both success and failure should remain available as data and
Option would lose failure information.
Details
- Use
succeed
/
fail
to construct
- Use
match
to fold both branches
- Use
isSuccess
/
isFailure
to narrow the type
E defaults to never, so Result<number> means a result that cannot fail.
Example (Creating and matching a Result)
import { Result } from "effect"
const success = Result.succeed(42)
const failure = Result.fail("something went wrong")
const message = Result.match(success, {
onSuccess: (value) => `Success: ${value}`,
onFailure: (error) => `Error: ${error}`
})
console.log(message)
// Output: "Success: 42"
Namespace containing type-level utilities for extracting the inner types
of a Result.
Example (Extracting inner types)
import type { Result } from "effect"
type R = Result.Result<number, string>
// number
type A = Result.Result.Success<R>
// string
type E = Result.Result.Failure<R>
Result<function (type parameter) Input in <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input): Result.Result<Input, Input>
Input, function (type parameter) Input in <Input extends {
readonly has: (key: K) => boolean;
}>(input: Input): Result.Result<Input, Input>
Input> =>
input: Input extends { readonly has: (key: K) => boolean; }input.has: (key: K) => booleanhas(key: Kkey) ? 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(input: Input extends { readonly has: (key: K) => boolean; }input) : 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: Input extends { readonly has: (key: K) => boolean; }input)