Skip to content

Instantly share code, notes, and snippets.

@AtnNn
Last active December 29, 2015 07:18
Show Gist options
  • Save AtnNn/7634640 to your computer and use it in GitHub Desktop.
Save AtnNn/7634640 to your computer and use it in GitHub Desktop.
r.table('lexi2').insert([
{net:{lo:{tx:1, rx:2}, eth0:{tx:2, rx:4}}},
{net:{lo:{tx:4, rx:6}, wl0ps4:{tx:7, rx:1}}},
{net:{lo:{tx:14, rx:8}, eth0:{tx:1, rx:5}}}])
r.table('lexi2').reduce(
function(left, right){
return { net:
left('net').keys().setUnion(right('net').keys()).map(
function(iface){
return [iface,
{tx: left('net')(iface)('tx').default(0).add(right('net')(iface)('tx').default(0))}]}
).coerceTo('object')}})
@wojons
Copy link

wojons commented Nov 25, 2013

r.table('lexi2').reduce(
  function(left, right){
    return { net:
      left('net').keys().setUnion(right('net').keys()).map(
        function(iface){
          return [iface,
            {tx: left('net')(iface)('tx').default(0).add(right('net')(iface)('tx').default(0))}]}
      ).coerceTo('object')}})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment