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

Add setBy #136

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add setBy #136

wants to merge 1 commit into from

Conversation

vjrasane
Copy link

A utility function for cases that Ive ran into few times now and have had to write it every time so I figured I might as well create a pull request :)

Most often when I use this I need to replace a value in a list by ID or name, so I'd call this by saying:

setBy .id value list

which is much nicer than:

setIf (\item -> item.id == value.id) value list

(or the shorter setIf (.id >> (==) value.id) value list )

Let me know if there are any problems with this or if I've missed some utility that achieves the same.

@Chadtech
Copy link
Collaborator

Hey @vjrasane,

Do you have another use case for this function aside from setting something by id? Ids go along well with other data types like Array and Dict. So if the use case could be better served by those data types and the apis, then I would rather not include functions that make it easier to set specific values inside a List when it really seems like users should be using Array or Dict.

@vjrasane
Copy link
Author

The use cases all do revolve around some identifying value, of course. Quite often its an ID, but I've used it to set a user by their name, a bank account by its IBAN and a financial instrument by its ISIN.

I think the key thing to recognize is that in some cases the order of items is important, so a dictionary would lose that information although it would make lookup by some comparable value easier. Same with Array. since the lookup is done by index. Another consideration is that you might need to set values based on several different values, so using a dictionary wouldn't help.

In any case I do see your point, although personally I have found this function to be useful on several occasions.

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

Successfully merging this pull request may close these issues.

2 participants