Last active
June 22, 2023 13:09
-
-
Save thephilip/9e64ec340db26ffc2f4d4b5c3c696fd4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const map = fn => array => array.map(fn); | |
const multiply = x => y => x * y; | |
const pluck = key => object => object[key]; | |
const discount = multiply(0.98); | |
const tax = multiply(1.0925); | |
const custReq = request({ | |
headers: { 'X-Custom': 'mykey' } | |
}); | |
// 3 iterations | |
customReq({ url: '/cart/items' }) | |
.then(map(pluck('price'))) | |
.then(map(discount)) | |
.then(map(tax)); | |
// with composition...1 iteration | |
customReq({ url: '/cart/items' }) | |
.then(map( | |
compose( | |
tax, // 3 | |
discount, // 2 | |
pluck('price') // 1 | |
) | |
)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment