marpple / FxTS

A functional programming library for TypeScript/JavaScript
https://fxts.dev
Apache License 2.0
862 stars 63 forks source link

fxts flatMap causes 'Maximum call stack size exceeded' #256

Closed flex-junhyuk closed 4 months ago

flex-junhyuk commented 4 months ago

Bug Report

When there is array with objects with 3000+ items,

fxts flatMap causes 'Maximum call stack size exceeded'.

💻 Code

Array with objects are looks like this..

export const people1 = [
  {
    idHash: "B1bpoJ9WOa",
    userIdHash: "EDjELJvboY",
    a: "HC00000",
    b: "lee",
    c: "880818-2020201",
    d: "level",
    e: "something",
    f: "abc",
    g: "aaaaa",
    h: "",
    i: "nominal",
    remarks: ["remark1", "remark2"],
    j: "cdcc",
    k: "2020-01-01",
    l: "common"
  },
  ...3000

And I want to process this array into something..

  const res: BB[] = pipe(
    people1,
    // fxts flatMap causes Maximum call stack size exceeded
    flatMap((item) => item.remarks ?? []),
    toArray
  );

These one causes error, but

  const people = people1.flatMap((item) => item.remarks ?? []);
  const res2: BB[] = pipe(people, toArray);

These one is ok.

https://codesandbox.io/p/sandbox/fxts-flatmap-forked-zmpp79

Take a look my code snippet.

🙁 Actual behavior

fxts flatMap causes 'Maximum call stack size exceeded'.

🙂 Expected behavior

fxts flatMap should working good as native flatMap.


Version Information

@fxts/core 0.25.0

ppeeou commented 4 months ago

@flex-junhyuk Thank you for reporting the error. Issue resolved in 0.26.0 :)