/**
* Defines composable checks that can also transform values.
*
* A `Filter` receives an input and returns a `Result`.
* Success means the value passed the filter, and failure means the value was
* filtered out. Filters may also narrow or transform the passing value. This
* module includes constructors from predicates, options, and effects, built-in
* filters for common JavaScript values and tags, helpers for combining filters,
* and conversions to predicates, options, and results.
*
* @stability stable
* @since 4.0.0
*/
import type { Effect } from "./Effect.ts";
import * as Option from "./Option.ts";
import * as Predicate from "./Predicate.ts";
import * as Result from "./Result.ts";
import type { EqualsWith, ExcludeTag, ExtractReason, ExtractTag, ReasonTags, Tags } from "./Types.ts";
/**
* 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)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* // A filter that only passes positive numbers
* const positiveFilter: Filter.Filter = (n) => n > 0 ? Result.succeed(n) : Result.fail(n)
*
* positiveFilter(5) // => Result.succeed(5)
* positiveFilter(-3) // => Result.fail(-3)
* ```
*
* @stability stable
* @category models
* @since 4.0.0
*/
export interface Filter {
(input: Input): Result.Result;
}
/**
* Represents an effectful filter function that can produce Effects.
*
* **Details**
*
* Similar to a regular `Filter`, but the filtering operation itself can be
* effectful, allowing for asynchronous operations, error handling, and
* dependency injection.
*
* **Example** (Defining an effectful user filter)
*
* ```ts import.meta.vitest
* import { Effect, Filter, Result } from "effect"
*
* // An effectful filter that validates user data
* type User = { id: string; isActive: boolean }
* type ValidationError = { message: string }
*
* const validateUser: Filter.FilterEffect<
* string,
* User,
* User,
* ValidationError,
* never
* > = (id) =>
* Effect.gen(function*() {
* const user: User = { id, isActive: id.length > 0 }
* return user.isActive ? Result.succeed(user) : Result.fail(user)
* })
*
* await Effect.runPromise(validateUser("alice")) // => Result.succeed({ id: "alice", isActive: true })
* await Effect.runPromise(validateUser("")) // => Result.fail({ id: "", isActive: false })
* ```
*
* @stability stable
* @category models
* @since 4.0.0
*/
export interface FilterEffect {
(input: Input): Effect, E, R>;
}
/**
* Creates a Filter from a function that returns either a `pass` or `fail` value.
*
* **Details**
*
* This is the primary constructor for creating custom filters. The function
* should return either `Result.succeed(value)` or `Result.fail(value)`.
*
* **Example** (Creating custom filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* // Create a filter for positive numbers
* const positiveFilter = Filter.make((n: number) => n > 0 ? Result.succeed(n) : Result.fail(n))
*
* // Create a filter that transforms strings to uppercase
* const uppercaseFilter = Filter.make((s: string) =>
* s.length > 0 ? Result.succeed(s.toUpperCase()) : Result.fail(s)
* )
* positiveFilter(1) // => Result.succeed(1)
* uppercaseFilter("ok") // => Result.succeed("OK")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const make: (f: (input: Input) => Result.Result) => Filter;
/**
* Creates an effectful Filter from a function that returns an Effect.
*
* **Details**
*
* This constructor is used when the filtering operation needs to perform
* effectful computations, such as async operations, error handling, or accessing
* services from the environment.
*
* **Example** (Creating effectful filters)
*
* ```ts import.meta.vitest
* import { Effect, Filter, Result } from "effect"
*
* // Create an effectful filter that validates async
* const asyncValidate = Filter.makeEffect((id: string) =>
* Effect.gen(function*() {
* const isValid = yield* Effect.succeed(id.length > 0)
* return isValid ? Result.succeed(id) : Result.fail(id)
* })
* )
*
* await Effect.runPromise(asyncValidate("id")) // => Result.succeed("id")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const makeEffect: (f: (input: Input) => Effect, E, R>) => FilterEffect;
/**
* Transforms the failure value produced by a `Filter`, leaving successful
* results unchanged.
*
* @stability stable
* @category mapping
* @since 4.0.0
*/
export declare const mapFail: {
/**
* Transforms the failure value produced by a `Filter`, leaving successful
* results unchanged.
*
* @stability stable
* @category mapping
* @since 4.0.0
*/
(f: (fail: Fail) => Fail2): (self: Filter) => Filter;
/**
* Transforms the failure value produced by a `Filter`, leaving successful
* results unchanged.
*
* @stability stable
* @category mapping
* @since 4.0.0
*/
(self: Filter, f: (fail: Fail) => Fail2): Filter;
};
declare const try_: (f: (input: Input) => Output) => Filter;
export {
/**
* Creates a Filter that tries to apply a function and returns `fail` on
* error.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
try_ as try };
/**
* Creates a Filter from a predicate or refinement function.
*
* **Details**
*
* This is a convenient way to create filters from boolean-returning functions.
* When the predicate returns true, the input value is passed through unchanged.
* When it returns false, the `fail` type is returned.
*
* **Example** (Creating filters from predicates)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* // Create filter from predicate
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const nonEmptyStrings = Filter.fromPredicate((s: string) => s.length > 0)
*
* // Type refinement
* const isString = Filter.fromPredicate((x: unknown): x is string =>
* typeof x === "string"
* )
* positiveNumbers(1) // => Result.succeed(1)
* nonEmptyStrings("") // => Result.fail("")
* isString("ok") // => Result.succeed("ok")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const fromPredicate: {
/**
* Creates a Filter from a predicate or refinement function.
*
* **Details**
*
* This is a convenient way to create filters from boolean-returning functions.
* When the predicate returns true, the input value is passed through unchanged.
* When it returns false, the `fail` type is returned.
*
* **Example** (Creating filters from predicates)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* // Create filter from predicate
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const nonEmptyStrings = Filter.fromPredicate((s: string) => s.length > 0)
*
* // Type refinement
* const isString = Filter.fromPredicate((x: unknown): x is string =>
* typeof x === "string"
* )
* positiveNumbers(1) // => Result.succeed(1)
* nonEmptyStrings("") // => Result.fail("")
* isString("ok") // => Result.succeed("ok")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(refinement: Predicate.Refinement): Filter>>;
/**
* Creates a Filter from a predicate or refinement function.
*
* **Details**
*
* This is a convenient way to create filters from boolean-returning functions.
* When the predicate returns true, the input value is passed through unchanged.
* When it returns false, the `fail` type is returned.
*
* **Example** (Creating filters from predicates)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* // Create filter from predicate
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const nonEmptyStrings = Filter.fromPredicate((s: string) => s.length > 0)
*
* // Type refinement
* const isString = Filter.fromPredicate((x: unknown): x is string =>
* typeof x === "string"
* )
* positiveNumbers(1) // => Result.succeed(1)
* nonEmptyStrings("") // => Result.fail("")
* isString("ok") // => Result.succeed("ok")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(predicate: Predicate.Predicate): Filter;
};
/**
* Creates a `Filter` from a function that returns an `Option`; `Some(value)`
* passes with `value`, and `None` fails with the original input.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const fromPredicateOption: (predicate: (a: A) => Option.Option) => Filter;
/**
* Converts a Filter into a predicate function.
*
* **When to use**
*
* Use to reuse a `Filter` with APIs that accept only boolean predicates when
* the pass and fail payloads are not needed.
*
* @see {@link toOption} for keeping passed values and discarding failure values
* @see {@link toResult} for preserving both pass and failure values
*
* @stability stable
* @category converting
* @since 4.0.0
*/
export declare const toPredicate: (self: Filter) => Predicate.Predicate;
/**
* A predefined filter that only passes through string values.
*
* **Example** (Filtering strings)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* Filter.string("hello") // => Result.succeed("hello")
* Filter.string(42) // => Result.fail(42)
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const string: Filter;
/**
* Creates a `Filter` that passes only values strictly equal to the specified
* value using JavaScript `===` comparison.
*
* **When to use**
*
* Use when you need a `Filter` that accepts only the exact primitive value or
* object reference using JavaScript strict equality in a `Filter` / `Result`
* pipeline.
*
* **Gotchas**
*
* `NaN` never passes, even when the expected value is `NaN`, and objects pass
* only when they are the same reference.
*
* @see {@link equals} for structural equality when distinct values with equal
* contents should pass
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const equalsStrict: (value: A) => Filter>>;
/**
* 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.
*
* @see {@link fromPredicate} for custom predicate filters or inputs without a
* `has` method
* @see {@link Predicate.hasProperty} for guarding property presence instead of
* calling an input's `has` method
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const has: (key: K) => boolean;
}>(input: Input) => Result.Result;
/**
* Creates a filter that only passes instances of the given constructor.
*
* **When to use**
*
* Use to narrow unknown input to values created by a specific JavaScript
* constructor while keeping the result in the `Filter` / `Result` pipeline.
*
* **Details**
*
* The filter succeeds when the input satisfies `instanceof constructor`.
* Otherwise it fails with the original input.
*
* **Gotchas**
*
* This uses JavaScript `instanceof` semantics, including prototype-chain and
* realm behavior.
*
* @see {@link fromPredicate} for custom predicate-based narrowing
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const instanceOf: any>(constructor: K) => (u: Input) => Result.Result, Exclude>>;
/**
* A predefined filter that only passes through number values.
*
* **Example** (Filtering numbers)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* Filter.number(42) // => Result.succeed(42)
* Filter.number("42") // => Result.fail("42")
* ```
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const number: Filter;
/**
* A predefined filter that only passes through boolean values.
*
* **When to use**
*
* Use when accepting an unknown input only if it is already a boolean and you
* want a `Filter` result rather than a plain predicate result.
*
* **Details**
*
* Implemented with `fromPredicate(Predicate.isBoolean)`, so `true` and `false`
* succeed and non-booleans fail with the original input.
*
* @see {@link Predicate.isBoolean} for the underlying guard
* @see {@link fromPredicate} for custom predicate-based filters
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const boolean: Filter;
/**
* A predefined filter that only passes through `bigint` primitive values.
*
* **When to use**
*
* Use to keep primitive big integer values from unknown input while staying in
* the composable `Filter` / `Result` pipeline.
*
* **Details**
*
* Implemented with `fromPredicate(Predicate.isBigInt)`, so values where
* `typeof input === "bigint"` succeed and all other inputs fail with the
* original input.
*
* **Gotchas**
*
* This filter does not coerce numbers or strings; `1n` passes while `1` fails.
*
* @see {@link number} for JavaScript `number` values
* @see {@link Predicate.isBigInt} for the underlying guard
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const bigint: Filter;
/**
* A predefined filter that only passes through Symbol values.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const symbol: Filter;
/**
* A predefined filter that only passes through Date objects.
*
* **When to use**
*
* Use when you need to narrow unknown input to JavaScript `Date` instances with
* a reusable `Filter`.
*
* **Details**
*
* Implemented with `fromPredicate(Predicate.isDate)`, so passing values return
* `Result.succeed(input)` and failing values return `Result.fail(input)`.
*
* **Gotchas**
*
* The check uses `instanceof Date`, so invalid `Date` objects still pass; the
* filter does not validate the timestamp.
*
* @see {@link Predicate.isDate} for the underlying guard
* @see {@link instanceOf} for constructor-based filtering
* @see {@link fromPredicate} for custom date checks
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const date: Filter;
/**
* Creates a filter that checks if an input is tagged with a specific tag.
*
* **When to use**
*
* Use to keep only the matching member of a `_tag`-discriminated union while
* staying in a composable `Filter` / `Result` pipeline.
*
* **Details**
*
* The filter succeeds when `Predicate.isTagged(input, tag)` returns `true`.
* Otherwise it fails with the original input.
*
* **Gotchas**
*
* This only checks `_tag`; it does not validate the rest of the variant fields.
*
* @see {@link Predicate.isTagged} for the underlying boolean guard when a
* `Filter` result is not needed
* @see {@link reason} for extracting a nested reason variant from tagged errors
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const tagged: {
/**
* Creates a filter that checks if an input is tagged with a specific tag.
*
* **When to use**
*
* Use to keep only the matching member of a `_tag`-discriminated union while
* staying in a composable `Filter` / `Result` pipeline.
*
* **Details**
*
* The filter succeeds when `Predicate.isTagged(input, tag)` returns `true`.
* Otherwise it fails with the original input.
*
* **Gotchas**
*
* This only checks `_tag`; it does not validate the rest of the variant fields.
*
* @see {@link Predicate.isTagged} for the underlying boolean guard when a
* `Filter` result is not needed
* @see {@link reason} for extracting a nested reason variant from tagged errors
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(): >(tag: Tag) => Filter, ExcludeTag>;
/**
* Creates a filter that checks if an input is tagged with a specific tag.
*
* **When to use**
*
* Use to keep only the matching member of a `_tag`-discriminated union while
* staying in a composable `Filter` / `Result` pipeline.
*
* **Details**
*
* The filter succeeds when `Predicate.isTagged(input, tag)` returns `true`.
* Otherwise it fails with the original input.
*
* **Gotchas**
*
* This only checks `_tag`; it does not validate the rest of the variant fields.
*
* @see {@link Predicate.isTagged} for the underlying boolean guard when a
* `Filter` result is not needed
* @see {@link reason} for extracting a nested reason variant from tagged errors
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
>(tag: Tag): Filter, ExcludeTag>;
/**
* Creates a filter that checks if an input is tagged with a specific tag.
*
* **When to use**
*
* Use to keep only the matching member of a `_tag`-discriminated union while
* staying in a composable `Filter` / `Result` pipeline.
*
* **Details**
*
* The filter succeeds when `Predicate.isTagged(input, tag)` returns `true`.
* Otherwise it fails with the original input.
*
* **Gotchas**
*
* This only checks `_tag`; it does not validate the rest of the variant fields.
*
* @see {@link Predicate.isTagged} for the underlying boolean guard when a
* `Filter` result is not needed
* @see {@link reason} for extracting a nested reason variant from tagged errors
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(tag: Tag): (input: Input) => Result.Result, ExcludeTag>;
};
/**
* Creates a filter that extracts a reason from a tagged error.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const reason: {
/**
* Creates a filter that extracts a reason from a tagged error.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(): , const ReasonTag extends ReasonTags>>(tag: Tag, reasonTag: ReasonTag) => Filter, ReasonTag>, Input>;
/**
* Creates a filter that extracts a reason from a tagged error.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
, const ReasonTag extends ReasonTags>>(tag: Tag, reasonTag: ReasonTag): Filter, ReasonTag>, Input>;
/**
* Creates a filter that extracts a reason from a tagged error.
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
(tag: Tag, reasonTag: ReasonTag): (input: Input) => Result.Result, ReasonTag>, Input>;
};
/**
* 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)`.
*
* @see {@link equalsStrict} for JavaScript `===` matching instead of structural
* equality
* @see {@link Equal.equals} for the underlying structural equality semantics
*
* @stability stable
* @category constructors
* @since 4.0.0
*/
export declare const equals: (value: A) => Filter>>;
/**
* Combines two filters with logical OR semantics.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const or: {
/**
* Combines two filters with logical OR semantics.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(that: Filter): (self: Filter) => Filter;
/**
* Combines two filters with logical OR semantics.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(self: Filter, that: Filter): Filter;
};
/**
* Combines two filters and applies a function to their results.
*
* **When to use**
*
* Use to combine two filters with a custom function to merge their outputs.
*
* **Details**
*
* Both filters must succeed (not return `fail`) for the combination to succeed.
* If both filters pass, their outputs are combined using the provided function.
*
* @see {@link zip} for combining two filters into a tuple
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const zipWith: {
/**
* Combines two filters and applies a function to their results.
*
* **When to use**
*
* Use to combine two filters with a custom function to merge their outputs.
*
* **Details**
*
* Both filters must succeed (not return `fail`) for the combination to succeed.
* If both filters pass, their outputs are combined using the provided function.
*
* @see {@link zip} for combining two filters into a tuple
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter, f: (left: PassL, right: PassR) => A): (left: Filter) => Filter;
/**
* Combines two filters and applies a function to their results.
*
* **When to use**
*
* Use to combine two filters with a custom function to merge their outputs.
*
* **Details**
*
* Both filters must succeed (not return `fail`) for the combination to succeed.
* If both filters pass, their outputs are combined using the provided function.
*
* @see {@link zip} for combining two filters into a tuple
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter, f: (left: PassL, right: PassR) => A): Filter;
};
/**
* Combines two filters into a tuple of their results.
*
* **Details**
*
* Both filters must succeed for the combination to succeed. If both pass, their
* outputs are combined into a tuple.
*
* **Example** (Zipping filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveAndEven = Filter.zip(positiveNumbers, evenNumbers)
* positiveAndEven(2) // => Result.succeed([2, 2])
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const zip: {
/**
* Combines two filters into a tuple of their results.
*
* **Details**
*
* Both filters must succeed for the combination to succeed. If both pass, their
* outputs are combined into a tuple.
*
* **Example** (Zipping filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveAndEven = Filter.zip(positiveNumbers, evenNumbers)
* positiveAndEven(2) // => Result.succeed([2, 2])
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter): (left: Filter) => Filter;
/**
* Combines two filters into a tuple of their results.
*
* **Details**
*
* Both filters must succeed for the combination to succeed. If both pass, their
* outputs are combined into a tuple.
*
* **Example** (Zipping filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveAndEven = Filter.zip(positiveNumbers, evenNumbers)
* positiveAndEven(2) // => Result.succeed([2, 2])
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter): Filter;
};
/**
* Combines two filters but only returns the result of the left filter.
*
* **Example** (Keeping the left filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveEven = Filter.andLeft(positiveNumbers, evenNumbers)
* positiveEven(2) // => Result.succeed(2)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const andLeft: {
/**
* Combines two filters but only returns the result of the left filter.
*
* **Example** (Keeping the left filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveEven = Filter.andLeft(positiveNumbers, evenNumbers)
* positiveEven(2) // => Result.succeed(2)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter): (left: Filter) => Filter;
/**
* Combines two filters but only returns the result of the left filter.
*
* **Example** (Keeping the left filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const evenNumbers = Filter.fromPredicate((n: number) => n % 2 === 0)
*
* const positiveEven = Filter.andLeft(positiveNumbers, evenNumbers)
* positiveEven(2) // => Result.succeed(2)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter): Filter;
};
/**
* Combines two filters but only returns the result of the right filter.
*
* **Example** (Keeping the right filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const doubleNumbers = Filter.make((n: number) =>
* n > 0 ? Result.succeed(n * 2) : Result.fail(n)
* )
*
* const positiveDoubled = Filter.andRight(positiveNumbers, doubleNumbers)
* positiveDoubled(2) // => Result.succeed(4)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const andRight: {
/**
* Combines two filters but only returns the result of the right filter.
*
* **Example** (Keeping the right filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const doubleNumbers = Filter.make((n: number) =>
* n > 0 ? Result.succeed(n * 2) : Result.fail(n)
* )
*
* const positiveDoubled = Filter.andRight(positiveNumbers, doubleNumbers)
* positiveDoubled(2) // => Result.succeed(4)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter): (left: Filter) => Filter;
/**
* Combines two filters but only returns the result of the right filter.
*
* **Example** (Keeping the right filter result)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const positiveNumbers = Filter.fromPredicate((n: number) => n > 0)
* const doubleNumbers = Filter.make((n: number) =>
* n > 0 ? Result.succeed(n * 2) : Result.fail(n)
* )
*
* const positiveDoubled = Filter.andRight(positiveNumbers, doubleNumbers)
* positiveDoubled(2) // => Result.succeed(4)
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter): Filter;
};
/**
* Composes two filters sequentially, feeding the output of the first into the second.
*
* **Example** (Composing filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const stringFilter = Filter.string
* const nonEmptyUpper = Filter.make((s: string) =>
* s.length > 0 ? Result.succeed(s.toUpperCase()) : Result.fail(s)
* )
*
* const stringToUpper = Filter.compose(stringFilter, nonEmptyUpper)
* stringToUpper("hello") // => Result.succeed("HELLO")
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const compose: {
/**
* Composes two filters sequentially, feeding the output of the first into the second.
*
* **Example** (Composing filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const stringFilter = Filter.string
* const nonEmptyUpper = Filter.make((s: string) =>
* s.length > 0 ? Result.succeed(s.toUpperCase()) : Result.fail(s)
* )
*
* const stringToUpper = Filter.compose(stringFilter, nonEmptyUpper)
* stringToUpper("hello") // => Result.succeed("HELLO")
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter): (left: Filter) => Filter;
/**
* Composes two filters sequentially, feeding the output of the first into the second.
*
* **Example** (Composing filters)
*
* ```ts import.meta.vitest
* import { Filter, Result } from "effect"
*
* const stringFilter = Filter.string
* const nonEmptyUpper = Filter.make((s: string) =>
* s.length > 0 ? Result.succeed(s.toUpperCase()) : Result.fail(s)
* )
*
* const stringToUpper = Filter.compose(stringFilter, nonEmptyUpper)
* stringToUpper("hello") // => Result.succeed("HELLO")
* ```
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter): Filter;
};
/**
* Composes two filters sequentially, passing the successful output of the first
* filter to the second.
*
* **Details**
*
* If either filter fails, the returned filter fails with the original input
* instead of the intermediate failure value.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
export declare const composePassthrough: {
/**
* Composes two filters sequentially, passing the successful output of the first
* filter to the second.
*
* **Details**
*
* If either filter fails, the returned filter fails with the original input
* instead of the intermediate failure value.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(right: Filter): (left: Filter) => Filter;
/**
* Composes two filters sequentially, passing the successful output of the first
* filter to the second.
*
* **Details**
*
* If either filter fails, the returned filter fails with the original input
* instead of the intermediate failure value.
*
* @stability stable
* @category combinators
* @since 4.0.0
*/
(left: Filter, right: Filter): Filter;
};
/**
* Converts a `Filter` into a function that returns `Some` for passed values
* and `None` for filtered-out values.
*
* **When to use**
*
* Use when adapting a `Filter` to `Option`-based code where passed values
* become `Some` and filtered-out inputs become `None`.
*
* @see {@link toResult} for keeping the filter failure value
* @see {@link toPredicate} for plain boolean pass/fail checks
*
* @stability stable
* @category converting
* @since 4.0.0
*/
export declare const toOption: (self: Filter) => (input: A) => Option.Option;
/**
* Converts a `Filter` into a function that returns the underlying
* `Result.Result` for each input.
*
* **When to use**
*
* Use to adapt a `Filter` to APIs that expect a plain function returning
* `Result`, while preserving both the pass value and the failure value.
*
* @see {@link toOption} for keeping only passed values
* @see {@link toPredicate} for plain boolean pass/fail checks
*
* @stability stable
* @category converting
* @since 4.0.0
*/
export declare const toResult: (self: Filter) => (input: A) => Result.Result;
//# sourceMappingURL=Filter.d.ts.map