Skip to content

Instantly share code, notes, and snippets.

@hesan-aminiloo
Created August 31, 2022 16:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hesan-aminiloo/f5d8d95ea6081833db20010bb22ce01a to your computer and use it in GitHub Desktop.
Save hesan-aminiloo/f5d8d95ea6081833db20010bb22ce01a to your computer and use it in GitHub Desktop.
const withIntroAndDownload = (base = '') => `معرفی و دانلود ${base}`;
const withIntroAndPurchase = (base) => `معرفی، خرید و دانلود ${base}`;
const withFreeContent = (base) => `رایگان ${base}`;
const withBook = (base) => `کتاب ${base}`;
const withAudioBook = (base) => `کتاب صوتی ${base}`;
const withPodcast = (base) => `پادکست ${base}`;
const compose = (...fns) => (param) =>
fns.reduceRight((y, f) => f(y), param);
console.log(
compose(withIntroAndPurchase, withBook)('ملت عشق')
); // معرفی، خرید و دانلود کتاب ملت عشق
console.log(
compose(withIntroAndDownload, withFreeContent, withBook)('ملت عشق')
); // معرفی و دانلود رایگان کتاب ملت عشق
console.log(
compose(withIntroAndDownload, withFreeContent, withAudioBook)('ملت عشق')
); // معرفی و دانلود رایگان کتاب صوتی ملت عشق
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment