インスタントカレー


今日はMethoと一緒に料理をするcurry .

成分
  • 1 xmetho - あなたのローカルNPMで利用できる
  • 1 xFunction プロトタイプ
  • 1 xcurry 関数(一般的です.
  • あなたの選択の1つのx機能
  • JS知識のピンチ

  • 方法
  • 追加するmetho ボウルに:
  • import * as Metho from "metho"
    
  • 「カレー」ソースを作るにはcurry 関数とFunction Methooを結合するプロトタイプです.
  • const target = Function.prototype
    
    function curry(func) {
      return function curried(...args) {
        if (args.length >= func.length) {
          return func.apply(this, args)
        } else {
          return function(...args2) {
            return curried.apply(this, args.concat(args2))
          }
        }
      }
    }
    
    const curried = Metho.add(
      target,
      function() {
        return curry(this)
      }
    )
    
  • おいしい組合せのためにあなたの選ばれた機能にソースを加えてください!
  • function myAdd(a, b) {
      return a + b
    }
    
    // without 'curried' sauce - kinda bland
    console.log(myAdd(2, 3))   // 5
    
    // with sauce - tasty!
    const add2 = myAdd[curried](2)
    console.log(add2(3))   // 5
    
    // versatile! map it with an array
    console.log([2, 4, 6].map(myAdd[curried](11)))   // [13, 15, 17]
    

    代替法
    主な成分はまた、ご利用いただけます中古ミックスmetho-function - また、すべての良いNPMで利用できます.単にインポートcurried パケットから直接ソースを作り、前に続けます.
    import { curried } from 'metho-function'
    ...
    

    以上です.
    あなたがこのレシピが好きであるか、それを改善する方法についてのどんな考えも持っているならば、ここで、または、Metho Cookery学校で私に線を降ろしてください.

    jonrandy / metho
    新しい方法

    jonrandy / metho-function
    機能プロトタイプ拡張