private static FSharpFunc <CharStream <Unit>, Reply <double> > MathFunc(FSharpFunc <CharStream <Unit>, Reply <double> > term, string key, Func <double, double> func) { var noParenthesis = Pipe(StringP(key).And(WS), term, (_, d) => func(d)); var withParenthesis = Pipe(StringP(key).And(WS), CharP('(').And(WS), term.And(WS), CharP(')'), (_, pl, d, pr) => func(d)); return(noParenthesis.Or(withParenthesis)); }