This commit is contained in:
Felix Roos 2022-02-20 20:31:55 +01:00
parent 1de371e944
commit f8df4b485d
9 changed files with 397 additions and 95 deletions

View file

@ -175,6 +175,13 @@ class Pattern {
_withEvents(func) {
return new Pattern((span) => func(this.query(span)));
}
withLocation(location) {
return this.fmap((value) => {
value = typeof value === "object" && !Array.isArray(value) ? value : {value};
const locations = (value.locations || []).concat([location]);
return {...value, locations};
});
}
withValue(func) {
return new Pattern((span) => this.query(span).map((hap) => hap.withValue(func)));
}
@ -312,6 +319,7 @@ class Pattern {
_patternify(func) {
const pat = this;
const patterned = function(...args) {
args = args.map((arg) => arg.constructor?.name === "Pattern" ? arg.fmap((value) => value.value || value) : arg);
const pat_arg = sequence(...args);
return pat_arg.fmap((arg) => func.call(pat, arg)).outerJoin();
};