effect-io-ai

Package: effect
Module: Match

Match.nonEmptyString

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)

See

Signature

declare const nonEmptyString: SafeRefinement<string, never>

Source

Since v4.0.0