-
-
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
array: add S.size #414
array: add S.size #414
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I mentioned in #413 I think size
or count
would be a more appropriate name given that not all Foldable
structures have a "length" (e.g. sets and trees).
Thanks for raising the question of naming, Gabe. I took the name from Haskell (and Ramda), but we're not forced to follow Haskell's lead. Let's indicate our preferences via emoji:
|
@Avaq? @safareli? @scott-christopher? Do you have preferences? |
Oh - I had cast my vote using a mobile app. Guess it didn't work. I prefer |
e98696c
to
9985ade
Compare
eq(S.size(Nil), 0); | ||
eq(S.size(Cons('foo', Nil)), 1); | ||
eq(S.size(Cons('foo', Cons('bar', Nil))), 2); | ||
eq(S.size(Cons('foo', Cons('bar', Cons('baz', Nil)))), 3); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that #413 has been merged we're able to include tests for lists. :)
the function could also be moved in |
Good point, Irakli! It would be nice to decide upon a rule we can apply to tell us whether a particular function warrants inclusion in sanctuary-type-classes. Does anyone have a suggestion? |
If a function is polymorphic and it's input have some algebraic constraints, maybe. |
It's interesting that given the definition of Though the "size" of a |
I like your suggestion, Irakli. :) I will open a pull request to define |
Superseded by sanctuary-js/sanctuary-type-classes#61 |
This is equivalent to Haskell's
length
function.I quite often find myself using
S.prop('length')
asArray a -> Integer
; it will be convenient to be able to useS.length
S.size
in these situations instead. :)