Which of two settings wins, and what to do when they disagree: the precedence every moonbitstack library shares. Not a configuration loader; that is moonconf.
library preset < the record passed in < this call's argument of the same name| Variant | Result | Says |
|---|---|---|
| Ignore | what wins chose | nothing |
| Warn(f) | what wins chose | one line to f |
| Panic | aborts | the message |
| Handle(f) | what f returns | f gets a Clash[T]: the names, the base, the merged value |
struct Options {
timeout : Int32
retries : Int32
}
let options : Options = { timeout: 30, retries: 3 }
fn connect(
options~ : Options = options,
timeout? : Int32,
retries? : Int32,
wins~ : @moonknob.Wins = Extra,
clash~ : @moonknob.OnClash[Options] = Ignore,
) -> Options {
let merge = @moonknob.Merge::new(wins)
let merged = {
timeout: merge.pick("timeout", options.timeout, timeout),
retries: merge.pick("retries", options.retries, retries),
}
merge.settle(clash, options, merged, "connect: options and arguments")
}let mine = { timeout: 5, retries: 1 }
let a = connect(options=mine, timeout=10)
let b = connect(options=mine, timeout=10, wins=Base)
let c = connect(options=mine, timeout=10, clash=Warn(line => println(line)))
let d = connect(
options=mine,
timeout=10,
retries=9,
clash=Handle(seen => { ..seen.merged, retries: seen.base.retries }),
)type Merge let merge = @moonknob.Merge::new(wins)
let merged = {
..policy,
leeway: merge.pick("leeway", policy.leeway, leeway),
expiry: merge.pick("expiry", policy.expiry, expiry),
}
merge.settle(clash, policy, merged, "jwt.verify: policy and arguments")Install
Download zipWhich of two settings wins, and what to do when they disagree: the precedence every moonbitstack library shares. Not a configuration loader; that is moonconf.