Skip to content

Latest commit

 

History

History
33 lines (21 loc) · 1.01 KB

prsc.filterundefined.md

File metadata and controls

33 lines (21 loc) · 1.01 KB

Home > prsc > filterUndefined

filterUndefined() function

Creates a parser that discards undefined values from the array produced by the given parser.

Useful in combination with star, or and consume:

const a: Parser<string> = token('a');
const b: Parser<void> = consume(token('b'));
const abs: Parser<(string | void)[]> = star(or<string | void>([a, b]));
const as: Parser<string[]> = filterUndefined(abs);

Signature:

export declare function filterUndefined<T>(parser: Parser<(T | void)[]>): Parser<T[]>;

Parameters

Parameter Type Description
parser Parser<(T | void)[]> Parser to apply, should produce an array that may contain undefined entries.

Returns:

Parser<T[]>