Open HunSeol opened 3 weeks ago
@ppeeou It needs to determine if the case where toArray is not used constitutes a bug.
@HunSeol Thank you for reporting the issue.
This is not a bug.
Because you have consumed all of the Iterator in optionIdsWithoutArray
In optionNamesWithoutArray
, iterator.next() returns {done:true, value:undefined }
.
If you want to check, change the execution order as follows.
const optionNamesWithoutArray = pipe(
checkedOptionsWithoutArray,
map((option) => option.name),
join('|')
);
const optionIdsWithoutArray = pipe(
checkedOptionsWithoutArray,
map((option) => option.id),
join('|')
);
This is something to be careful of when using the iterator object. To achieve the intended result, you must use fork, but it is still under development. https://github.com/marpple/FxTS/issues/70
To obtain the desired result with the current specification, you can use toArray
to store the iterator result in memory.
be careful of when using the iterator object. you must use fork, but it is still under development.
Thank you for comment. I understood your intention.
To obtain the desired result with the current specification, you can use toArray to store the iterator result in memory.
Could you explain this comment more? How to store in memory using toArray?
I have one more question. As we know, Array.prototype.map is an immutable function because it does not modify the original array. So I think it makes us more confused. Do you have plans to add an immutable map function not fork function?
Could you explain this comment more? How to store in memory using toArray?
@HunSeol You were already using it :)
const checkedOptionsWithArray = pipe(
groups,
flatMap((group) => group.options),
filter((option) => option.checked),
toArray
);
const optionIdsWithArray = pipe(
checkedOptionsWithArray,
map((option) => option.id),
join('|')
);
const optionNamesWithArray = pipe(
checkedOptionsWithArray,
map((option) => option.name),
join('|')
);
I have one more question. As we know, Array.prototype.map is an immutable function because it does not modify the original array. So I think it makes us more confused. Do you have plans to add an immutable map function not fork function?
Not yet, but I'll think about it.
Bug Report
💻 Code
🙁 Actual behavior
When
toArray
is not used afterflatMap
andfilter
, the intermediate values are removed, resulting in an empty string foroptionNames
.optionIds
: "1|3|4"optionNames
: ""🙂 Expected behavior
Both
optionIds
andoptionNames
should correctly display the joined string of IDs and names of checked options, regardless of the use oftoArray
.optionIds
: "1|3|4"optionNames
: "name-1|name-3|name-4"Version Information