Skip to content
// EFFECT DAYS 2026

PathFilter unstable

Decides which /-separated, root-relative paths to keep with an ordered list of exclusion and inclusion rules, without accessing the file system. Pass a PathFilter, a pattern or a list of patterns and rules to FileSystem.glob to find the paths it keeps, or build one from ignore files with IgnoreFile.

Details

Every rule applies to the paths strictly below its scope directory and matches them relative to it. When several rules match a path, the last one wins, except that nothing inside a directory decided by a barrier exclusion can be included again. A rule's subtree says what matching a directory means for the paths inside it:

  • barrier: if the rule decides the directory, every path inside is excluded by it, as with Git exclusions.
  • inherit: if the match changed the directory's result at that point in rule order, it also counts for every path inside, and later rules can still override it, as with Docker rules. A match that repeats the result so far, such as the second d in d, !d/keep, d, does not.
  • self: the paths inside are left to their own rules, as with Git ! inclusions.

A path no rule decides gets the filter's default. Filters built from rules or ignore files keep such paths; select builds a selection, which drops them. restrict combines a selection with ignore rules, so that a path must pass both.

Gotchas

match treats every ancestor of a path as a directory. FileSystem.glob uses each entry's own type instead, so there a link to a directory never matches a directoryOnly rule.

18 exports Since v4.0.0 Source

Combining

concat

unstable
Since v4.0.0

Combines the rules of two filters, with the rules of that taking precedence.

Details

Either side may be any Input. Both must have the same default, which the result keeps, so two selections combine into one selection.

Gotchas

Combining filters with different defaults, or a filter that has restrictions, is a defect. Use restrict to remove ignored paths from a selection; in a single list, an ignore file's ! lines would add paths to it.

Signature

declare const concat: {
(that: Input): (self: Input) => PathFilter;
(self: Input, that: Input): PathFilter;
}

Example Layering a nested filter

import { PathFilter } from "effect"
const root = PathFilter.make([PathFilter.exclude("**/*.log")])
const nested = PathFilter.make([PathFilter.include("keep.log", { scope: "logs" })])
const filter = PathFilter.concat(root, nested)
PathFilter.excludes(filter, "logs/keep.log") // => false
PathFilter.excludes(filter, "keep.log") // => true

restrict

unstable
Since v4.0.0

Keeps the paths that self keeps and by does not exclude.

Details

Either side may be any Input. The two are evaluated separately, so an inclusion in by, such as a !keep.log line in an ignore file, cannot add a path self drops. Restrictions nest: every one of them must keep a path. The curried form is restrict(by)(self).

See

  • select for building a selection

Signature

declare const restrict: {
(by: Input): (self: Input) => PathFilter;
(self: Input, by: Input): PathFilter;
}

Example Selecting files that are not ignored

import { IgnoreFile, PathFilter } from "effect"
const ignored = IgnoreFile.gitignore("*.log\n!keep.log\n")
const filter = PathFilter.restrict("**/*.ts", ignored)
PathFilter.excludes(filter, "src/index.ts") // => false
PathFilter.excludes(filter, "keep.log") // => true

Constructors

empty

unstable
Since v4.0.0

A filter without rules, which keeps every path.

Signature

declare const empty: PathFilter

exclude

unstable
Since v4.0.0

Creates a rule that excludes the paths matching a pattern.

Details

A string pattern uses Glob syntax and is anchored at the scope, so *.log matches only directly inside it and **/*.log at any depth. Wildcards match names that start with . unless dot is false. A PathMatcher is used as is, and dot does not apply to it.

scope is a /-separated directory relative to the root, defaulting to the root. subtree defaults to "barrier", so nothing inside an excluded directory can be included again; use "inherit" to allow later inclusions there, or "self" to leave the paths inside undecided.

Gotchas

An absolute pattern, a pattern with a .. segment or an escaped /, and a scope with an empty, . or .. segment are defects. A pattern naming only the root, such as ., never matches.

See

Signature

declare const exclude: {
(pattern: PathMatcher, options?: RuleOptions<"inherit" | "barrier" | "self">): ExcludeRule;
(pattern: string | PathMatcher, options?: RuleOptions<"inherit" | "barrier" | "self">): ExcludeRule;
}

Example Choosing what an excluded directory means for its contents

import { PathFilter } from "effect"
const keep = PathFilter.include("logs/keep.log")
const barrier = PathFilter.make([PathFilter.exclude("logs"), keep])
const inherit = PathFilter.make([PathFilter.exclude("logs", { subtree: "inherit" }), keep])
PathFilter.excludes(barrier, "logs/keep.log") // => true
PathFilter.excludes(inherit, "logs/keep.log") // => false
PathFilter.excludes(inherit, "logs/debug.log") // => true

fromInput

unstable
Since v4.0.0

Converts an Input into a PathFilter.

Details

Filters are returned unchanged, keeping their default. Strings become include rules, whose wildcards skip names that start with ., or exclude rules after a leading !, which match those names; write \! for a literal !. An input with at least one including string drops the paths no rule decides, as with select. Any other input keeps them, as with make.

Gotchas

An invalid pattern is a defect, as in exclude.

Signature

declare function fromInput(input: Input): PathFilter

Example Converting patterns and rules

import { PathFilter } from "effect"
const sources = PathFilter.fromInput(["src/**/*.ts", "!**/*.test.ts"])
const ignored = PathFilter.fromInput([PathFilter.exclude("dist")])
PathFilter.excludes(sources, "README.md") // => true
PathFilter.excludes(ignored, "README.md") // => false
PathFilter.fromInput(ignored) === ignored // => true

include

unstable
Since v4.0.0

Creates a rule that includes the paths matching a pattern, overriding earlier rules.

Details

Patterns, scope and dot work as in exclude. subtree defaults to "self", so including a directory does not include the paths inside it. With "inherit", they are included too if the inclusion changed the directory's result, unless a later rule overrides it; including a directory that was already included passes nothing down.

Gotchas

An inclusion cannot override a barrier exclusion of an ancestor directory. An absolute pattern, a pattern with a .. segment or an escaped /, and a scope with an empty, . or .. segment are defects.

See

Signature

declare const include: {
(pattern: PathMatcher, options?: RuleOptions<"inherit" | "self">): IncludeRule;
(pattern: string | PathMatcher, options?: RuleOptions<"inherit" | "self">): IncludeRule;
}

make

unstable
Since v4.0.0

Creates a filter from rules, with later rules taking precedence.

Details

Paths no rule decides are kept.

Signature

declare function make(rules: Iterable<Rule>): PathFilter

Example Including a file inside an excluded directory

import { PathFilter } from "effect"
const filter = PathFilter.make([
PathFilter.exclude("dist", { subtree: "inherit" }),
PathFilter.include("dist/index.d.ts")
])
PathFilter.excludes(filter, "dist/index.js") // => true
PathFilter.excludes(filter, "dist/index.d.ts") // => false

select

unstable
Since v4.0.0

Creates a filter that keeps only the paths its rules include.

Details

A path no rule decides is excluded. Strings are patterns that include paths, or exclude them after a leading !; write \! for a literal !. dot says whether the wildcards of include strings match names that start with ., and defaults to false. ! strings and rules match those names unless built with dot: false.

See

  • restrict for removing ignored paths from a selection

Signature

declare function select(rules: string | Iterable<string | Rule, any, any>, options?: {
readonly dot?: boolean;
}): PathFilter

Example Selecting source files

import { PathFilter } from "effect"
const sources = PathFilter.select(["src/**/*.ts", "!**/*.test.ts"])
PathFilter.excludes(sources, "src/index.ts") // => false
PathFilter.excludes(sources, "src/index.test.ts") // => true
PathFilter.excludes(sources, "README.md") // => true
PathFilter.excludes(sources, "src/.cache/x.ts") // => true

Getters

match

unstable
Since v4.0.0

Evaluates a /-separated path relative to the root and returns the rule that decides it.

Details

None means no rule decided the path, which then gets the filter's default. For a restricted filter, the last restriction that excludes the path decides it, even through its default, and otherwise the filter itself does.

Empty and . segments are dropped, so a trailing / does not mark a directory; pass directory: true instead. Every ancestor of the path is treated as a directory.

Gotchas

A path with a .. segment is a defect.

See

Signature

declare const match: {
(path: string, options?: {
readonly directory?: boolean;
}): (self: PathFilter) => Match;
(self: PathFilter, path: string, options?: {
readonly directory?: boolean;
}): Match;
}

Example Finding the deciding rule

import { PathFilter } from "effect"
const logs = PathFilter.exclude("**/*.log")
const keep = PathFilter.include("logs/keep.log")
const filter = PathFilter.make([logs, keep])
PathFilter.match(filter, "logs/debug.log") // => { _tag: "Exclude", rule: logs }
PathFilter.match(filter, "logs/keep.log") // => { _tag: "Include", rule: keep }
PathFilter.match(filter, "src/index.ts") // => { _tag: "None" }

Guards

Since v4.0.0

Checks whether a value is a PathFilter.

Signature

declare function isPathFilter(u: unknown): u is PathFilter

Models

ExcludeRule

interface unstable
Since v4.0.0

A rule that excludes the paths its matcher accepts.

Details

directoryOnly restricts the rule to directories, scope holds the segments of the directory the rule applies below, and subtree says what matching a directory means for the paths inside it.

See

Signature

interface ExcludeRule {
readonly _tag: "Exclude";
readonly directoryOnly: boolean;
readonly matcher: PathMatcher;
readonly scope: readonly Array<string>;
readonly subtree: "inherit" | "barrier" | "self";
}

IncludeRule

interface unstable
Since v4.0.0

A rule that includes the paths its matcher accepts, overriding earlier rules.

Details

The fields mean the same as on ExcludeRule. An inclusion cannot be a barrier.

See

Signature

interface IncludeRule {
readonly _tag: "Include";
readonly directoryOnly: boolean;
readonly matcher: PathMatcher;
readonly scope: readonly Array<string>;
readonly subtree: "inherit" | "self";
}

Input

type unstable
Since v4.0.0

Values accepted wherever a filter is expected: a filter, a pattern, or a list of patterns and rules.

Details

A string is a pattern that includes paths, or excludes them after a leading !. As soon as an input holds one including string it is a selection, which drops the paths no rule decides; otherwise it keeps them.

See

Signature

type Input = PathFilter | string | Iterable<string | Rule>

Match

type unstable
Since v4.0.0

The result of evaluating a path: None when no rule decides it, otherwise the deciding rule as it was passed in.

See

  • match for computing one

Signature

type Match = {
readonly _tag: "None";
} | {
readonly _tag: "Exclude";
readonly rule: Rule;
} | {
readonly _tag: "Include";
readonly rule: Rule;
}

PathFilter

interface unstable
Since v4.0.0

An ordered list of rules that decides which paths to exclude.

Details

Later rules take precedence, subject to ancestor barriers, and default decides the paths no rule matches. restrictions holds the further filters added by restrict, which a path must also pass. Test paths with match or excludes, or pass the filter to FileSystem.glob.

See

  • make for building a filter from rules
  • select for building a selection
  • concat for combining rules
  • restrict for intersecting filters

Signature

interface PathFilter extends Pipeable, Inspectable {
readonly "~effect/PathFilter": "~effect/PathFilter";
readonly default: "include" | "exclude";
readonly restrictions: readonly Array<PathFilter>;
readonly rules: readonly Array<Rule>;
}

PathMatcher

interface unstable
Since v4.0.0

Decides whether a rule matches a path relative to the rule's scope.

Details

match receives a /-separated path without empty or . segments, and whether the path is a directory. matchesBelow is an optional hint for skipping directories: returning false for a directory, given without a trailing / and as "" for the scope itself, promises that match accepts no strict descendant of it, file or directory. Without the hint, every directory may contain a match.

Gotchas

Both functions must be deterministic, and a hint must never return false where a descendant matches; otherwise FileSystem.glob may skip results.

Signature

interface PathMatcher {
readonly match: (path: string, directory: boolean) => boolean;
readonly matchesBelow?: (directory: string) => boolean;
}

Rule

type unstable
Since v4.0.0

An exclusion or inclusion rule of a PathFilter.

Signature

type Rule = ExcludeRule | IncludeRule

Predicates

excludes

unstable
Since v4.0.0

Tests whether a filter excludes a /-separated path relative to the root.

Details

A path is excluded when the filter or one of its restrictions excludes it, applying each one's default to paths no rule decides. Paths are read as in match: pass directory: true for a directory, and every ancestor is treated as a directory.

See

  • match for the deciding rule

Signature

declare const excludes: {
(path: string, options?: {
readonly directory?: boolean;
}): (self: PathFilter) => boolean;
(self: PathFilter, path: string, options?: {
readonly directory?: boolean;
}): boolean;
}

Example Testing directories

import { PathFilter, pipe } from "effect"
const filter = PathFilter.make([PathFilter.exclude("build", { directoryOnly: true })])
PathFilter.excludes(filter, "build") // => false
PathFilter.excludes(filter, "build", { directory: true }) // => true
pipe(filter, PathFilter.excludes("build/out.js")) // => true