superruzafa / visual-scala-reference

Visual Scala Reference
https://superruzafa.github.io/visual-scala-reference
269 stars 28 forks source link

Associate andThen and compose so that users can find opposite function #14

Closed exoego closed 2 years ago

exoego commented 5 years ago

These changes will be superseded by #4, but it is good to have as of today.

superruzafa commented 5 years ago

andThen and compose are not "opposed" to each other. They are two ways to express the same calculation but by swapping the two operands.

val f = (x: Int) => x * 10
val g = (x: Int) => x + 10

(f andThen g)(5) // 60
(g compose f)(5) // 60

(g andThen f)(5) // 150
(f compose g)(5) // 150

Also, I prefer the readers to find related functions after have reading the whole article.

exoego commented 5 years ago

Could you suggest a sentence to describe compose?

superruzafa commented 5 years ago

Both andThen and compose are used to combine other input functions. They do the same job but each one swaps the order the other function applies the input functions.

exoego commented 5 years ago

Both andThen and compose are used to combine other input functions. They do the same job but each one swaps the order the other function applies the input functions.

Thans, updated so.

Spanish paragraphs translated by Google, so could be funny... If the added sentences looks good, I will add the corresponding Japanese translation soon.