Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
functional ruby
users_url = URI('https://jsonplaceholder.typicode.com/users')
calls = -> method_name, *args {
-> object {
object.public_send(method_name, *args)
}
}
gets_value = -> key_name { calls[:[], key_name] }
email_ends_with = -> what {
gets_value['email'] >> calls[:end_with?, what]
}
extracts = -> *keys {
-> object { object.slice(*keys) }
}
Net::HTTP.get(users_url)
.then(&JSON.method(:parse))
.select(&email_ends_with['biz'])
.map(&extracts['name', 'email'])
=> [{"name"=>"Leanne Graham", "email"=>"Sincere@april.biz"},
{"name"=>"Kurtis Weissnat", "email"=>"Telly.Hoeger@billy.biz"},
{"name"=>"Clementina DuBuque", "email"=>"Rey.Padberg@karina.biz"}]
-------------------
https://medium.com/@baweaver/mf-abusing-rubys-operator-precedence-ccf3f071bad8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.