當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript transducers-js.map函數代碼示例

本文整理匯總了TypeScript中transducers-js.map函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript map函數的具體用法?TypeScript map怎麽用?TypeScript map使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了map函數的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: transduceExample

function transduceExample() {
  const { completing, transduce, wrap } = t;
  const stringAppendFn = (acc: string, x: number) => acc + x;
  const stringAppendTransformer = wrap(stringAppendFn);
  const stringAppendThenLengthTransformer = completing(
    stringAppendFn,
    s => s.length,
  );
  const lengthsString1: string = transduce(
    t.map((s: string) => s.length),
    stringAppendFn,
    "",
    ["a", "b"],
  );
  const lengthsString2: string = transduce(
    t.map((s: string) => s.length),
    stringAppendTransformer,
    "",
    ["a", "b"],
  );
  const lengthsStringLength: number = transduce(
    t.map((s: string) => s.length),
    stringAppendThenLengthTransformer,
    "",
    ["a", "b"],
  );
}
開發者ID:MrBigDog2U,項目名稱:DefinitelyTyped,代碼行數:27,代碼來源:transducers-js-tests.ts

示例2: intoExample

function intoExample () {
  var inc = function(n: number) { return n+1; };
  var isEven = function(n: number) { return n % 2 == 0; };
  var apush = function(arr: number[], x: number) { arr.push(x); return arr; };
  var xf = t.comp(t.map(inc),t.filter(isEven));
  t.into([], xf, [1,2,3,4]); // [2,4]
}
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:7,代碼來源:transducers-js-tests.ts

示例3: advancedIntoExample

function advancedIntoExample() {
  const array: number[] = into([], t.map((s: string) => s.length), [
    "a",
    "b",
  ]);
  const string: string = into("", t.map((s: string) => s + s), ["a", "b"]);
  const object1: { [key: string]: number } = into(
    {},
    t.map((s: string) => [s, s.length] as [string, number]),
    ["a", "b"],
  );
  const object2: { [key: string]: boolean } = into(
    {},
    t.map((kv: [string, number]) => [kv[0], true] as [string, boolean]),
    { a: 1, b: 2 }
  );
}
開發者ID:MrBigDog2U,項目名稱:DefinitelyTyped,代碼行數:17,代碼來源:transducers-js-tests.ts

示例4: catExample

function catExample () {
  var reverse = function(arr: number[]) {
    var arr: number[] = Array.prototype.slice.call(arr, 0);
    arr.reverse();
    return arr;
  };
  var xf = t.comp(t.map(reverse), t.cat);
  t.into([], xf, [[3,2,1],[6,5,4]]); // [1,2,3,4,5,6]
}
開發者ID:ArtemZag,項目名稱:DefinitelyTyped,代碼行數:9,代碼來源:transducers-js-tests.ts

示例5: it

 it('transduces Stack without initial values', () => {
   let s = Stack.of(1, 2, 3, 4);
   let xform = t.comp(
     t.filter(x => x % 2 === 0),
     t.map(x => x + 1),
   );
   let s2 = t.transduce(xform, Stack(), s);
   expect(s.toArray()).toEqual([1, 2, 3, 4]);
   expect(s2.toArray()).toEqual([5, 3]);
 });
開發者ID:philipp-spiess,項目名稱:immutable-js,代碼行數:10,代碼來源:transformerProtocol.ts

示例6: it

 it('transduces Stack with initial values', () => {
   const v1 = Stack.of(1, 2, 3);
   const v2 = Stack.of(4, 5, 6, 7);
   const xform = t.comp(
     t.filter(x => x % 2 === 0),
     t.map(x => x + 1),
   );
   const r = t.transduce(xform, Stack(), v1, v2);
   expect(v1.toArray()).toEqual([1, 2, 3]);
   expect(v2.toArray()).toEqual([4, 5, 6, 7]);
   expect(r.toArray()).toEqual([7, 5, 1, 2, 3]);
 });
開發者ID:skeet70,項目名稱:immutable-js,代碼行數:12,代碼來源:transformerProtocol.ts


注:本文中的transducers-js.map函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。