-
Notifications
You must be signed in to change notification settings - Fork 2
Add second
selector for arrays
#51
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
Comments
There's already the |
Oh really? So given my example I could do: people = [{ name: 'Amy' }, { name: 'Bob' }]
get(:people, :first, :name) #=> 'Amy'
get(:people, at(1), :name) #=> 'Bob'
people = [{ name: 'Amy' }]
get(:people, :first, :name) #=> 'Amy'
get(:people, at(1), :name) #=> nil That would indeed solve my problem. In that case, having |
Yes, that should work. First and last are just syntax sugar for at(n). You can easily add "second" your self if you look at the code. It would be good practice if you want to extend the DSL in the future. Just make sure to add some tests if you decide to create a pull request ツ |
Oh yeah, that's actually very neat and should be easy. Well, thank you so much! I will consider this solved then! If I add it in the future, I'll make sure to make a PR :) Thank you for your help! |
There's already
first
,last
, andall
. For me, it would often be beneficial to also have asecond
selector. If you have two elements that need to be mapped differently, then usinglast
also works -- unless the second element doesn't always exist.So:
Would it be possible to add something like this?
The text was updated successfully, but these errors were encountered: