Skip to content
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

Implement SortedSet#update_in and List#update_in #192

Open
xaviershay opened this issue Aug 15, 2015 · 3 comments
Open

Implement SortedSet#update_in and List#update_in #192

xaviershay opened this issue Aug 15, 2015 · 3 comments

Comments

@xaviershay
Copy link
Contributor

Seems desirable for consistency with Hash and Vector?

@xaviershay xaviershay changed the title Implement SortedSet#update_in Implement SortedSet#update_in and List#update_in Aug 15, 2015
@dubek
Copy link
Contributor

dubek commented Oct 29, 2015

Nowadays #update_in is part of the Associable module:

  # Including `Associable` in your container class gives it an `update_in`
  # method.
  #
  # To mix in `Associable`, your class must implement two methods:
  #
  # * `fetch(index, default = (missing_default = true))`
  # * `put(index, item = yield(get(index)))`
  #
  # See {Vector#fetch}, {Vector#put}, {Hash#fetch}, and {Hash#put} for examples.

So for List we can implement #fetch (in terms of #at) and probably make some not-really-efficient #put.

As for Set and SortedSet, I'm not sure what these operations (fetch/put) mean. What is the index? What is the item's value?

@alexdowad
Copy link
Contributor

For SortedSet, the index is integral, starting from the far "left" of the tree. For Set, you could say that each item is its own index, but I don't know how useful that will actually be. Probably Set will not have #update_in.

@dubek
Copy link
Contributor

dubek commented Oct 29, 2015

Indeed there's already SortedSet#fetch(index, default = (missing_default = true)) so this side is OK.

As for #put, it'll be something like #delete and then #add. Of course it's very weird because in the SortedSet ["a", "b", "c", "d"] if your perform s.put(2, "z") you'll get ["a", "b", "d", "z"], so a subsequent s.fetch(2) will return "d"...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants