typelevel / spire

Powerful new number types and numeric abstractions for Scala.
http://typelevel.org/spire/
MIT License
1.77k stars 243 forks source link

Proposal: `andThen` for Polynomial? #1337

Open windymelt opened 5 months ago

windymelt commented 5 months ago

Current Spire has compose for Polynomial[A]:

(f.compose(g).compose(h))(x) // => process h, then g, then f; that's result

But it has no andThen method for Polynomial.

In business context, People prefer more intuitive syntax ---- "Discount, then apply another discount, then add tax".

So implementing andThen alike function is reasonable choice for devs including newcomers.

Please tell me your opinions!

armanbilge commented 3 months ago

Thanks for the idea! The compose method for Polynomial relates to this mathematical concept.

https://en.wikipedia.org/wiki/Polynomial#Composition

What is the mathematical formulation for andThen?