Hyperlinkv0.8.0-beta.28

Match

Match.nonEmptyStringconsteffect/Match.ts:1203
SafeRefinement<string, never>

Matches non-empty strings.

When to use

Use to match strings whose length is greater than zero.

Details

This predicate matches any string that contains at least one character, effectively filtering out empty strings ("").

Example (Matching non-empty strings)

import { Match } from "effect"

const processInput = Match.type<string>()
  .pipe(
    Match.when(Match.nonEmptyString, (str) => `Valid input: ${str}`),
    Match.orElse(() => "Input cannot be empty")
  )

console.log(processInput("hello"))
// Output: "Valid input: hello"

console.log(processInput(""))
// Output: "Input cannot be empty"

console.log(processInput("   "))
// Output: "Valid input:    " (whitespace-only strings are considered non-empty)
predicatesstring
Source effect/Match.ts:12031 lines
export const nonEmptyString: SafeRefinement<string, never> = internal.nonEmptyString