Home > prsc > filterUndefined
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[]>;
Parameter | Type | Description |
---|---|---|
parser | Parser<(T | void)[]> | Parser to apply, should produce an array that may contain undefined entries. |
Returns:
Parser<T[]>