🧠
Funkcia Docs
🧠
Funkcia Docs
  • Welcome
  • Data types
    • Option
      • Error Propagation
      • Do Notation
    • Result
      • Error Propagation
      • Do Notation
    • OptionAsync
      • Error Propagation
      • Do Notation
    • ResultAsync
      • Error Propagation
      • Do Notation
  • Modules
    • Exceptions
    • Functions
    • JSON
    • Predicate
    • URI
    • URL
Powered by GitBook
On this page

Was this helpful?

Edit on GitHub
  1. Modules

Predicate

The Predicate module provides utilities for type-safe predicate functions in TypeScript.

not

Returns a new function that will return the opposite boolean value of the original predicate.

import { not } from 'funkcia/predicate';

const isString = (value: unknown) => typeof value === 'string';
const isNotString = not(isString);

Predicate<A>

Represents a function that tests a value and returns a boolean.

import { Predicate } from 'funkcia/predicate';

const isPositive: Predicate.Predicate<number> = (n) => n > 0;

Guard<A, B extends A>

Represents a type guard function that refines a type A to a more specific type B.

import { Predicate } from 'funkcia/predicate';

const isString: Predicate.Guard<unknown, string> = (value) =>
  typeof value === 'string';

Guarded<Guard>

Utility type that extracts the refined type B from a Guard<A, B>.

import { Predicate } from 'funkcia/predicate';

type StringGuard = Predicate.Guard<unknown, string>;
type Refined = Predicate.Guarded<StringGuard>;
//      ^? string

Unguarded<A, B extends A>

Utility type that computes the type that was excluded by the type guard refinement.

import { Predicate } from 'funckia/predicate';

type Shape = Circle | Square | Triangle;
type UnguardedShape = Predicate.Unguarded<Shape, Circle>;
//        ^? Square | Triangle

PreviousJSONNextURI

Last updated 3 months ago

Was this helpful?