-
-
Notifications
You must be signed in to change notification settings - Fork 95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Immutable list for Sanctuary #485
Comments
Creating something like this has been on my personal TODO list for a long time. I'm glad that someone has actually done it. It looks very nice, @paldepind! |
@CrossEye Thank's a lot Scott. It's great to hear that you feel that way. Let me know how your experience is if/when you get a chance to try the library. |
This is very exciting, Simon!
👍
👍
One thing that would be interesting to consider is whether |
😄
One can implement Foldable has a bit of a dilemma. In theory, you can derive a lot of useful things from just Haskell has a decent solution to the dilemma. Their Foldable type class includes a lot of derivable methods. Thanks to Haskell's support for default method implementations implementors of Foldable can optionally override these with performant versions for their data structure. Thus Haskell's Foldable can be used for additional things without being prohibitively expensive. This stands in contrast to the Foldable in Fantasy Land and Purescript (PureScript doesn't support default methods implementations so they can't use the Haskell solution) which is essentially only good for Haskell's solution could be mimicked in JavaScript by defining a Foldable with a bunch of methods and then offering a mixin function that installs default method implementations. The problem is that how many methods to include in such a Foldable becomes arbitrary (there are methods that could've been included in Haskell's Foldable but which are not). A second downside is that it makes the Foldable definition a lot bulkier. I suspect that due to these issues proposing such a thing for Fantasy Land would be controversial. fantasyland/fantasy-land#224 would have made it possible to define By taking the same approach as what I've done for Ramda using List and Sanctuary together would mean that people would be able to do import * as S from "sanctuary";
import * as L from "list/sanctuary"; And then rely on the fact that for every
IMO this is quite nice but the downside is, of course, that it isn't actualy polymorphism so one can't write code that works for both lists and arrays at the same time. |
Your proposal sounds good to me, Simon. How would you like to proceed? Would you like the project to live in the @funkia account, the @sanctuary-js account, or some other account? I don't mind. If it's to live in the @sanctuary-js account I would like it to be written in ES5 in accordance with the conventions adopted for other Sanctuary projects. ;) |
Good question. I think there are a few options:
Number 1 is what I've currently done for Ramda. There is a file for Ramda that users can import by doing I'm thinking number 2 may be the best option. Having it in a single repository makes it easy to keep things in synchrony. For instance I have a test in place that ensures that the curried Ramda file has all the functions that the main file has. This ensures that I don't add a new function and forget to add it in the Ramda file. What do you think? |
It makes sense to me for the Sanctuary wrapper to be handled in the same way as the Ramda wrapper. The peer dependency (
I agree. Would you do the same for the Ramda wrapper, or do you see significant differences between the two wrappers which warrant different treatment? |
You're right,
I agree with you that it makes sense to do the same thing for both Ramda and Sanctuary. I've looked at a tool call Lerna which looks like it would make it possible to manage option number 2 with very little overhead. The core list, the Ramda wrapper and the Sanctuary rapper would each live in a directory in the same repo. Lerna would make it easy to run tests for them all at once and to publish new package versions in sync.
That is fine for me 😄 Are the conventions documented or should I just look at the existing code? |
I was thinking of the peer dependency from the perspective of one of your users. You claim that the API of your wrapper matches that of Ramda, but you must qualify this claim. If
👍
@sanctuary-js projects all use sanctuary-style, but since this project will live in the @funkia account it should follow Funkia conventions rather than Sanctuary conventions. :) |
I usually use |
@davidchambers You're right that there need to be some sort of documentation about which version of List goes with which version of Ramda. But I'm not sure if the @Avaq Good suggestion! That's definitely better than my idea 😄 |
Thanks a lot for the feedback in this thread 😄 I'll probably start working on this in a week or so. I'll let you know when I've got something to share. |
I've realized that I'd like to offer a curried variant of List that doesn't depend on Ramda for people who want currying but doesn't want the dependency on Ramda. I've then decided that it's not worth it to maintain two near-identical curried variants. Ramda users can easily use the dependency-free one. Therefore the Ramda integration no longer has to be a separate package and then using Lerna doesn't seem like it's worth the additional complexity. I was, therefore, thinking that a separate What do you think? |
Sounds good to me, Simon. I have created sanctuary-list and granted you write access. Please create a branch named |
Is this still happening? |
I have needed |
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 takeO(n)
time,L.init
on List takes constant time.S.concat
on arrays takesO(n + m)
time butL.concat
on 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
.includes
which iselem
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?
The text was updated successfully, but these errors were encountered: