matchigo - v1.0.2
    Preparing search index...

    Function compile

    • Compiles rules once and returns a callable dispatcher. Use this when you want to separate compile-time from call-time, or when the rules array identity changes per call but its content doesn't (match() keys its cache on array identity, so a rebuilt array misses it — compile() doesn't care).

      Type Parameters

      • T
      • R

      Parameters

      Returns CompiledFn<T, R>

      import { P, compile } from "matchigo";

      const classify = compile<number, string>([
      { with: 0, then: () => "zero" },
      { with: P.negative, then: () => "negative" },
      { with: P.positive, then: () => "positive" },
      ]);

      classify(-3); // "negative"