Upgrade to Pro — share decks privately, control downloads, hide ads and more …

20241128 カリー化

Avatar for saka saka
December 23, 2025
2

20241128 カリー化

Avatar for saka

saka

December 23, 2025

Transcript

  1. // ੜ੒ let calc = (x: number, y: number): number

    => x + y; console.log(calc(3, 4)); // ݁Ռ: 7
  2. // ୅ೖ calc = (x: number, y: number): number =>

    x - y; // ड͚౉͠ const diffLength = (a: string, b: string, fn: (x: number, y: number) => number): number => { return fn(a.length, b.length); }; console.log(diffLength('aaa', 'a', calc)); // 2
  3. const add = (a: number, b: number) => a +

    b; // ෦෼ద༻Ͱʮa = 2ʯΛݻఆ const add2 = (b: number) => add(2, b); console.log(add2(3)); // 5
  4. // ௨ৗͷؔ਺ function add(a: number, b: number): number { return

    a + b; } // ΧϦʔԽ͞Εͨؔ਺ const curriedAdd = (a: number) => (b: number) => a + b; console.log(curriedAdd(2)(3)); // 5 const curriedAdd2 = curryAdd(2); const result = curryAdd2(3); // 5