Skip to content

count on strings and binary #4228

Closed
Closed

Description

@danielmewes

Follow up from #264 and #1146

The proposal is to make count work on strings and binary data in addition to arrays.
On binary data it would count the number of bytes, and on string data I propose it would count the number of UTF-8 code points.

Scheduling for 2.2.

Activity

  1. danielmewes commented on May 13, 2015

    @danielmewes
    MemberAuthor

    An alternative is to introduce another term length for strings. I would prefer re-using count.

  2. coffeemug commented on May 16, 2015

    @coffeemug
    Contributor

    Obligatory reminder that count already works on binary blobs:

    > r.http('https://2.gravatar.com/avatar/767fc9c115a1b989744c755db47feb60?s=132&d=wavatar').count()
    7223
  3. added this to the 2.2 milestone on Jun 2, 2015
  4. carbureted commented on Jun 29, 2015

    @carbureted

    Would be awesome to see this!

  5. andreis commented on Jul 22, 2015

    @andreis

    I need to measure the byte size of documents, currently I'm doing

    .coerceTo('string').coerceTo('binary').count()
    

    Is that good enough?

  6. mlucy commented on Jul 23, 2015

    @mlucy
    Member

    @andreis -- yeah, that should get you the size of the JSON representation of the document.

  7. marshall007 commented on Jul 23, 2015

    @marshall007
    Contributor

    Not sure if this belongs in a separate issue, but I also think <object>.count() should return the number of keys. Basically a shortcut to <object>.keys().count() or <object>.coerceTo('array').count().

  8. danielmewes commented on Jul 24, 2015

    @danielmewes
    MemberAuthor

    @marshall007 Ah that's an interesting idea. I quite like that (though I haven't thought about it too deeply yet).

  9. mlucy commented on Aug 27, 2015

    @mlucy
    Member

    So the current proposal is just to define count on strings? That seems obviously good to me, so +1.

  10. mlucy commented on Aug 27, 2015

    @mlucy
    Member

    I would like to propose that we also define count on objects and have it count the number of fields. I think most languages that have a common function that works on arrays and strings also define that function on objects.

  11. VeXocide commented on Aug 27, 2015

    @VeXocide
    Member

    +1 for extending it to support both strings and objects

  12. deontologician commented on Aug 27, 2015

    @deontologician
    Contributor

    +1 for objects as well

  13. danielmewes commented on Aug 27, 2015

    @danielmewes
    MemberAuthor

    Sounds reasonable. 👍 for:
    object.count() to count the number of fields and
    string.count() to count Unicode code points

  14. coffeemug commented on Aug 27, 2015

    @coffeemug
    Contributor

    👍

  15. danielmewes commented on Sep 3, 2015

    @danielmewes
    MemberAuthor

    Marking as settled as described (object.count() and string.count()).

  16. modified the milestones: 2.2, 2.3 on Oct 5, 2015
  17. encryptio commented on Dec 4, 2015

    @encryptio
    Contributor

    In CR 3389

  18. added a commit that references this issue on Aug 7, 2026
    0364154
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions