Skip to main content
Code Review

Return to Question

edited tags
Link
dfhwze
  • 14.1k
  • 3
  • 40
  • 101
Bumped by Community user
added 238 characters in body
Source Link

UPDATE: Will probably just do this:

 insert(parent, id)
 .yield_self { |obj| update(@set, obj, @set[parent][1] + 1) }
 .yield_self { |updated_set| @set.merge!(updated_set) }

UPDATE: Will probably just do this:

 insert(parent, id)
 .yield_self { |obj| update(@set, obj, @set[parent][1] + 1) }
 .yield_self { |updated_set| @set.merge!(updated_set) }
Tweeted twitter.com/StackCodeReview/status/1124735583627239424
deleted 265 characters in body; edited tags; edited title; edited tags
Source Link
200_success
  • 145.6k
  • 22
  • 190
  • 479

Is there Adding an item to a better syntax for thishierarchical data transformation on a series of objects (functional programming)?structure

I'm trying to find a better way to write this particular line of code in a class I'm writing. What I need to do is create a new object, modify it using a recursive function, then merge it with another object, and do this all in such a way that the values of the new object take precedence over the values in the object I'm merging it with.

Currently, my code works, but I'd like to have more readable code for, particularly this statement for the add operation.:

@set.merge!(
 update(@set, insert(parent, id), @set[parent][1] + 1)
)

I've already refactored quite a bit, but I feel like there's a functional way, or at least more readable way, to write what I current have.

This is the line I want it to be something like: new object → update it → merge it.

#I want it to be something like: new object -> update it -> merge it.
@set.merge!(update(@set, insert(parent, id), @set[parent][1] + 1))
#update, #insert are defined below:

All the tests pass, and I'm aware that there are other questions this code probably brings up, so I'm just looking for better syntax at this point.

Is there a better syntax for this data transformation on a series of objects (functional programming)?

I'm trying to find a better way to write this particular line of code in a class I'm writing. What I need to do is create a new object, modify it using a recursive function, then merge it with another object, and do this all in such a way that the values of the new object take precedence over the values in the object I'm merging it with. Currently, my code works, but I'd like to have more readable code for this operation.

I've already refactored quite a bit, but I feel like there's a functional way, or at least more readable way, to write what I current have.

This is the line

#I want it to be something like: new object -> update it -> merge it.
@set.merge!(update(@set, insert(parent, id), @set[parent][1] + 1))
#update, #insert are defined below:

All the tests pass, and I'm aware that there are other questions this code probably brings up, so I'm just looking for better syntax at this point.

Adding an item to a hierarchical data structure

What I need to do is create a new object, modify it using a recursive function, then merge it with another object, and do this all in such a way that the values of the new object take precedence over the values in the object I'm merging it with.

Currently, my code works, but I'd like to have more readable code, particularly this statement for the add operation:

@set.merge!(
 update(@set, insert(parent, id), @set[parent][1] + 1)
)

I've already refactored quite a bit, but I feel like there's a functional way, or at least more readable way, to write what I current have. I want it to be something like: new object → update it → merge it.

Source Link
Loading
lang-rb

AltStyle によって変換されたページ (->オリジナル) /