Skip to content

lazy ​

DDataParser.lazy(() => parser) lets you describe recursive structures (trees, categories, menus, etc.) by deferring parser resolution. The getter is evaluated only at runtime, which avoids circular references.

Interactive example ​

Parameters ​

  • getter: function that returns the real parser (often an object that itself contains the lazy).
  • checkers: checkerRefine applied on the complete structure (e.g. limit depth, check global invariants).
  • errorMessage: custom message if the input does not match the resolved schema.

Return value ​

A DataParserLazy. schema.parse(data) returns DEither.success<Output> when the value satisfies the resolved parser, otherwise DEither.error<DataParserError> with the exact path even in recursion cases.

Other examples ​

Extended mode ​

See also ​

  • object - Parser for objects
  • bigint - Parser for bigint integers

Released under the MIT license.