def swap
import ezmcp@0.1.0.0/src/openapi.bend as Openapiimport Base
1128# a string with its first `pat` replaced by `rep`
1129def swap(text: String, +pat: String, +rep: String) -> String:
1130 match text:
1131 case SNil{}:
1132 SNil{}
1133 case SCon{+ch, +rest}:
1134 swap.at(String.starts_with(SCon{ch, rest}, pat), SCon{ch, rest}, pat, rep,
1135 _u => SCon{ch, swap(rest, pat, rep)})