Skip to content

Conversation

igas
Copy link
Contributor

@igas igas commented Jan 20, 2015

No description provided.

@josevalim
Copy link
Member

Thank you! Do you have a use case for this particular function or other languages that provide it?

@igas
Copy link
Contributor Author

igas commented Jan 20, 2015

Sure, currently I work on slim and ast for it, and I need many other enums also, this is first one. I have structure like this:

[{1, binary1}, {2, binary2}, {1, binary3}, {2, binary4}, {3, binary5}, {4, binary6}, {2, binary7}, {1, binary8}, {2, binary9}]

and I need something like this:

[
  {binary1, [
    {binary2, []}
  ]},
  {binary3, [
    {binary4, [
      {binary5, [
        {binary6, []}
      ]}
    ]},
    {binary7, []}
  ]},
  {binary8, [{binary9, []}]}
]

With plain recursion it's tricky for me to go back for more than 1 level of nesting.

other languages that provide it?

Ruby for example http://ruby-doc.org/core-2.2.0/Enumerable.html#method-i-slice_before

@josevalim
Copy link
Member

Thanks. I am not a fan of the name slice_before. It doesn't fit with our use of slice. The closest thing to it is chunk_by which is similar but does not seem to fit your use case. split_on would make more sense in my opinion but I am not sure too.

@igas
Copy link
Contributor Author

igas commented Jan 20, 2015

Yep, I renamed it couple of times =) split also was in my list, and chunk was prototype of this function, but as I know English split is slice of 2 pieces. Also it's close to splitWhen in Haskell https://hackage.haskell.org/package/split-0.1.1/docs/Data-List-Split.html but it drops element.

@igas
Copy link
Contributor Author

igas commented Jan 20, 2015

@josevalim what do you think about chunk_when?

@josevalim
Copy link
Member

I think naming it chunk_* is going to be more confusing because it is very hard to make a distinction between it and chunk_by. :S

@lexmag
Copy link
Member

lexmag commented Jan 20, 2015

I think split_on a good candidate to the Enum.split... family.
As a reference, today we have:

  • Enum.chunk... - breaking collection into multiple chunks
  • Enum.partition... - partitioning by fun
  • Enum.split... - splitting collection in two pieces
  • Enum.slice... - taking only a slice of collection

@igas
Copy link
Contributor Author

igas commented Jan 20, 2015

@lexmag as you said, split splitting collection in two pieces, but this one more like chunk. Without limit on pieces.

@lexmag
Copy link
Member

lexmag commented Jan 20, 2015

I see, then it definitely looks like a chunk-style behaviour.

@igas
Copy link
Contributor Author

igas commented Jan 25, 2015

@josevalim do you have any ideas about name?

@josevalim
Copy link
Member

No, sorry. :(

@josevalim
Copy link
Member

I am closing this unfortunately due to lack of progress in naming. :( Thanks @igas!

@josevalim josevalim closed this Aug 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants