This commit is contained in:
JOLIMAITRE Matthieu 2024-08-07 10:17:45 +02:00
commit 8c18398ae4
6 changed files with 111 additions and 0 deletions

21
lib/extractor.ts Normal file
View file

@ -0,0 +1,21 @@
export class Extractor<O> {
private extract: (text: string) => O | null;
public constructor(extract: (text: string) => O | null) {
this.extract = extract;
}
public get(text: string) {
return this.extract(text);
}
public or<T>(other: Extractor<T>) {
const this_extract = this.extract;
return new Extractor(text => {
const r1 = this_extract(text);
if (r1 !== null) return r1;
else return other.extract(text);
});
}
}