structurae icon indicating copy to clipboard operation
structurae copied to clipboard

Add unsafeFrom sortedArray initializer?

Open Swoorup opened this issue 2 years ago • 3 comments

When working with web workers, all methods are stripped away during transfer. Is there a way to initialize the sortedArray at the other end, without the end to sort it again? https://github.com/zandaqo/structurae/blob/master/sorted-array.ts#L30

Swoorup avatar May 12 '23 10:05 Swoorup

Looks like you could do.

new SortedArray(...[10,9])`

Is that the preferred solution?

Swoorup avatar May 12 '23 10:05 Swoorup

const sorted = new SortedArray(...array)

Just use the constructor, it doesn't trigger sorting.

EDIT:

Is that the preferred solution?

Yes, at least for now, I have to test how much/and if spreading adds overhead and whether it's worth having a special logic for this situation.

zandaqo avatar May 12 '23 10:05 zandaqo

I heavily use web workers for short bursts of computation,

I could use the native array methods, but the methods in this library are quite useful 😄 to pass up. Thanks for the library.

Swoorup avatar May 12 '23 10:05 Swoorup