Skip to content

Repository files navigation

All your favorite functions that act on maps/hashes in clojure, but for ruby like:

  • assoc_in
  • update_in
  • update
  • get_in

NOTE:

These functions all return a new hash, they do not modify the original hash

Usage

  • assoc_in
RLC.assoc_in({a: 1},[:b],3)# => {a: 1, b: 3}
RLC.assoc_in({a: 1},[:b,:c],3)# => {a: 1, b: {c: 3}}
  • update_in
RLC.update_in({},[:a,:b]){ |other| (other || 0) + 2}# => { a: { b: 2 } }
RLC.update_in({a: {b: 1}},[:a,:b]){ |other| (other || 0) + 2}# => { a: { b: 3 } }
  • update
RLC.update({},:a){ |other| (other || 0) + 2}# => { a: 2 }
RLC.update({a: 1},:a){ |other| (other || 0) + 2}# => { a: 3 }
  • get_in
RLC.get_in({a: 1},[:a])# => 1
RLC.get_in({a: [1,3]},[:a,1])# => 3
RLC.get_in({a: {b: 2}},[:a,:c])# => nil
RLC.get_in({a: {b: 2}},[:a,:c],4)# => 4
my_report_hash.then{RLC.update_in(_1,%w[reportsgroup1], &method(:fill_in_things))}.then{RLC.update_in(_1,%w[reportsgroup2], &method(:add_things))}# => new my_report_hash
Feel free to suggest other functions we can implement in ruby that you miss in clojure

About

A project that brings Clojure features to Ruby for manipulating maps like assoc_in, update_in, update and get_in

Resources

Code of conduct

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages