Hi all,
I've been working on a fast immutable list for JavaScript with a functional API. The library is designed to be used together with other functional libraries and replace the usage of arrays. Currently, the
library includes a wrapper that makes the it work seamlessly with Ramda. I would like to do something similar for Sanctuary. I've opened this issue to hear if there's any interest in that and get feedback on how best to do it.
The two primary reasons for using List together with Sanctuary would be:
-
Safety. JavaScript arrays are inherently mutable. When using arrays in functional code the only thing that prevents us from mutating them is our own self-discipline. In my experience, this is sometimes not good enough and can be a source of bugs, especially on teams. Immutable data structures, on the other hand, guarantees that mutations don't happen.
-
Performance. Immutable data structures can give better performance. For instance, S.init on arrays take O(n) time, L.init on List takes constant time. S.concat on arrays takes O(n + m) time but L.concat on List takes O(log(n)) time. Furthermore, List has been carefully optimized such that the constants are also low.
To make List work smoothly with Sanctuary I think the following could be done in a Sanctuary specific export:
- Export all List function wrapped with sanctuary-def. This would give Sanctuary currying and run-time type checking.
- All List functions that can return
undefined (at, head, etc.) should instead return a Sanctuary Maybe.
- Maybe provide Sanctuary aliases. For instance, List has
includes which is elem in Sanctuary.
I'd love to hear what you all think about the idea and if there's any interest in this? Is there anything that could be done in addition to the above?
Hi all,
I've been working on a fast immutable list for JavaScript with a functional API. The library is designed to be used together with other functional libraries and replace the usage of arrays. Currently, the
library includes a wrapper that makes the it work seamlessly with Ramda. I would like to do something similar for Sanctuary. I've opened this issue to hear if there's any interest in that and get feedback on how best to do it.
The two primary reasons for using List together with Sanctuary would be:
Safety. JavaScript arrays are inherently mutable. When using arrays in functional code the only thing that prevents us from mutating them is our own self-discipline. In my experience, this is sometimes not good enough and can be a source of bugs, especially on teams. Immutable data structures, on the other hand, guarantees that mutations don't happen.
Performance. Immutable data structures can give better performance. For instance,
S.initon arrays takeO(n)time,L.initon List takes constant time.S.concaton arrays takesO(n + m)time butL.concaton List takesO(log(n))time. Furthermore, List has been carefully optimized such that the constants are also low.To make List work smoothly with Sanctuary I think the following could be done in a Sanctuary specific export:
undefined(at,head, etc.) should instead return a SanctuaryMaybe.includeswhich iselemin Sanctuary.I'd love to hear what you all think about the idea and if there's any interest in this? Is there anything that could be done in addition to the above?