List with nested maps - Part Deux

(Please not: Elixir Experience Level: Beginner so please Eli5)

Given:

items = 

[
  %{
    __type: "pair",
    amountAsset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
    data: %{
      firstPrice: 44536,
      high: 44536,
      lastPrice: 44536,
      low: 44536,
      quoteVolume: 0.44001568,
      txsCount: 1,
      volume: 9.88e-6,
      volumeWaves: 14839431.7405322,
      weightedAveragePrice: 44536
    },
    priceAsset: "4uK8i4ThRGbehENwa6MxyLtxAjAo1Rj9fduborGExarC"
  },
  %{
    __type: "pair",
    amountAsset: "bPWkA3MNyEr1TuDchWgdpqJZhGhfPXj7dJdr3qiW2kD",
    data: %{
      firstPrice: 0.0052531,
      high: 0.00679851,
      lastPrice: 0.00675602,
      low: 0.00490054,
      quoteVolume: 63536.722011126, 
      txsCount: 2380,
      volume: 10812543.1748219,
      volumeWaves: 63536.722011126,
      weightedAveragePrice: 0.00587620516134242
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "3QvxP6YFBKpWJSMAfYtL8Niv8KmmKsnpb9uQwQpg8QN2",
    data: %{
      firstPrice: 0.3065,
      high: 0.43999798,
      lastPrice: 0.34350851,
      low: 0.24500001,
      quoteVolume: 63261.4660060131,
      txsCount: 7322,
      volume: 174946.61,
      volumeWaves: 63261.4660060131,
      weightedAveragePrice: 0.361604411803195
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "WAVES",
    data: %{
      firstPrice: 1.025e-4,
      high: 1.033e-4,
      lastPrice: 1.0244e-4,
      low: 1.0157e-4,
      quoteVolume: 5.03931474051697,
      txsCount: 1124,
      volume: 49249.97965736,
      volumeWaves: 49249.97965736,
      weightedAveragePrice: 1.0232115374618e-4
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
    data: %{
      firstPrice: 0.17,
      high: 0.17666,
      lastPrice: 0.16100007,
      low: 0.16000001,
      quoteVolume: 38051.4832098366,
      txsCount: 931,
      volume: 231101.80792578,
      volumeWaves: 38051.4832098366,
      weightedAveragePrice: 0.164652468759816
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "7x5Efh41w4k2Q2ikxHQtAa9uR91qnmGQMVkqcb2SPfde",
    data: %{
      firstPrice: 2.5e-5,
      high: 6.179e-5,
      lastPrice: 5.555e-5,
      low: 1.0e-5,
      quoteVolume: 25846.6374654418,
      txsCount: 92,
      volume: 1104249380.479,
      volumeWaves: 25846.6374654418,
      weightedAveragePrice: 2.34065220432635e-5
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    data: %{
      firstPrice: 212.71233783,
      high: 216,
      lastPrice: 212.39506719,
      low: 210.3,
      quoteVolume: 14705.1765571804,
      txsCount: 547,
      volume: 68.75927238,
      volumeWaves: 14705.1765571804,
      weightedAveragePrice: 213.864633062314
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "6GqtM59Cx2mEoCAi2Fo3o2E8USi15UBsifoCcTZWBTm8",
    data: %{
      firstPrice: 50,
      high: 190,
      lastPrice: 190,
      low: 0.01,
      quoteVolume: 13933.11,
      txsCount: 826,
      volume: 246.500000000003,
      volumeWaves: 13933.11,
      weightedAveragePrice: 56.5237728194719
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
    data: %{
      firstPrice: 35794,
      high: 35794,
      lastPrice: 35794,
      low: 35794,
      quoteVolume: 3.5794e-4,
      txsCount: 1,
      volume: 1.0e-8, 
      volumeWaves: 12071.4475384288,
      weightedAveragePrice: 35794
    },
    priceAsset: "725Yv9oceWsB4GsYwyy4A52kEwyVrL5avubkeChSnL46"
  },
  %{
    __type: "pair",
    amountAsset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
    data: %{
      firstPrice: 35284,
      high: 35284,
      lastPrice: 35284,
      low: 35284,
      quoteVolume: 3.5284e-4,
      txsCount: 1,
      volume: 1.0e-8,
      volumeWaves: 11899.4511634889,
      weightedAveragePrice: 35284
    },
    priceAsset: "5dJj4Hn9t2Ve3tRpNGirUHy4yBK6qdJRAJYV21yPPuGz"
  },
  %{
    __type: "pair",
    amountAsset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
    data: %{
      firstPrice: 34263,
      high: 34263,
      lastPrice: 34263,
      low: 34263,
      quoteVolume: 3.4263e-4,
      txsCount: 1,
      volume: 1.0e-8,
      volumeWaves: 11555.1211658151,
      weightedAveragePrice: 34263
    },
    priceAsset: "7FzrHF1pueRFrPEupz6oiVGTUZqe8epvC7ggWUx8n1bd"
  },
  %{
    __type: "pair",
    amountAsset: "WAVES",
    data: %{
      firstPrice: 0.88,
      high: 0.9,
      lastPrice: 0.88,
      low: 0.87,
      quoteVolume: 8872.4500004216,
      txsCount: 130,
      volume: 9983.59760124,
      volumeWaves: 9983.59760124,
      weightedAveragePrice: 0.88870268562503
    },
    priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
  },
  %{
    __type: "pair",
    amountAsset: "DHgwrRvVyqJsepd32YbBqUeDH4GJ1N984X8QoekjgH8J",
    data: %{
      firstPrice: 0.13700044,
      high: 0.14377,
      lastPrice: 0.14163503,
      low: 0.13600411,
      quoteVolume: 9866.64988827234,
      txsCount: 2738,
      volume: 69677.2799999998,
      volumeWaves: 9866.64988827234,
      weightedAveragePrice: 0.141604980680537
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "3y48VYf9gSWAVRqvemHWv5gqz5cYhJWTVkkvxw7RGA1f",
    data: %{
      firstPrice: 0.0001,
      high: 0.0001,
      lastPrice: 0.0001,
      low: 0.0001,
      quoteVolume: 8696.81623000006,
      txsCount: 612,
      volume: 86968162.2999999,
      volumeWaves: 8696.81623000006,
      weightedAveragePrice: 1.00000000000001e-4
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "GSFvcF6ycBfXwPJLLKMExRsHWnvVdZQFHtGiYu4A2kZP",
    data: %{
      firstPrice: 20,
      high: 22,
      lastPrice: 22,
      low: 20,
      quoteVolume: 81305.0000002,
      txsCount: 3,
      volume: 3921.5909091,
      volumeWaves: 8130.50000002,
      weightedAveragePrice: 20.7326572008143
    },
    priceAsset: "5f1txDysSx2fVDjgXMdNpuprpdgXKjoHPtebL3SrMGzE"
  },
  %{
    __type: "pair",
    amountAsset: "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy",
    data: %{
      firstPrice: 252.89779012,
      high: 265.47052766,
      lastPrice: 264.02684869,
      low: 30,
      quoteVolume: 7616.35625664231,
      txsCount: 594,
      volume: 44.74142363,
      volumeWaves: 7616.35625664231,
      weightedAveragePrice: 170.230529981067
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "3k6vM987VAEVKJdD1J9eaXB2qi48Q7iYTEct7g9DMmtv",
    data: %{
      firstPrice: 1.31,
      high: 1.31,
      lastPrice: 1.31,
      low: 0.6,
      quoteVolume: 6883.3816362296,
      txsCount: 35,
      volume: 5265.07723608,
      volumeWaves: 6883.3816362296,
      weightedAveragePrice: 1.30736574746897
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
    data: %{
      firstPrice: 0.00658588,
      high: 0.00658588, 
      lastPrice: 0.00653156,
      low: 0.0064829,
      quoteVolume: 0.61191169120525,
      txsCount: 43,
      volume: 93.44377064,
      volumeWaves: 5980.30484217536,
      weightedAveragePrice: 0.00654844819525414
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
    data: %{
      firstPrice: 65.74801226,
      high: 66.44335158,
      lastPrice: 65.7,
      low: 65.09807853,
      quoteVolume: 5772.91091562858,
      txsCount: 262,
      volume: 87.8685564000001,
      volumeWaves: 5772.91091562858,
      weightedAveragePrice: 65.6993940966642 
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "ACyZADnLf1ZR4oRMAGPYxwpjyFFU52oVtMqX3kBP9dBc",
    data: %{
      firstPrice: 1010000,
      high: 1010000,
      lastPrice: 1010000,
      low: 1010000,
      quoteVolume: 4714.478,
      txsCount: 6,
      volume: 0.0046678,
      volumeWaves: 4714.478,
      weightedAveragePrice: 1010000
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS",
    data: %{
      firstPrice: 8619.99,
      high: 8798.99,
      lastPrice: 8700.01,
      low: 8540,
      quoteVolume: 3986.3031071937,
      txsCount: 81,
      volume: 0.46352701,
      volumeWaves: 4485.5306185894,
      weightedAveragePrice: 8599.93705047242
    },
    priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
  },
  %{
    __type: "pair",
    amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    data: %{
      firstPrice: 0.0216993,
      high: 0.02210443,
      lastPrice: 0.0218268,
      low: 0.02169366,
      quoteVolume: 0.421822669698145,
      txsCount: 87,
      volume: 19.22409271,
      volumeWaves: 4122.53629141563,
      weightedAveragePrice: 0.0219423967654256
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "5ZPuAVxAwYvptbCgSVKdTzeud9dhbZ7vvxHVnZUoxf4h",
    data: %{
      firstPrice: 2.7e-4,
      high: 2.7001e-4,
      lastPrice: 2.5e-4,
      low: 2.5e-4,
      quoteVolume: 0.410684830004633,
      txsCount: 6,
      volume: 1581.76743926,
      volumeWaves: 4013.68451164444,
      weightedAveragePrice: 2.59636669595857e-4
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
    data: %{
      firstPrice: 0.57733991,
      high: 0.58499999,
      lastPrice: 0.57692439,
      low: 0.57,
      quoteVolume: 4012.25994843018,
      txsCount: 1135,
      volume: 6949.8783,
      volumeWaves: 4012.25994843018,
      weightedAveragePrice: 0.577313698921919
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "4LHHvYGNKJUg5hj65aGD5vgScvCBmLpdRFtjokvCjSL8",
    data: %{
      firstPrice: 1.727e-5,
      high: 1.774e-5,
      lastPrice: 1.624e-5,
      low: 1.622e-5,
      quoteVolume: 0.288214440204845,
      txsCount: 2998,
      volume: 16782.72349761,
      volumeWaves: 2816.7630021041,
      weightedAveragePrice: 1.71732818124478e-5
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "7uncmN7dZfV3fYVvNdYTngrrbamPYMgwpDnYG1bGy6nA",
    data: %{
      firstPrice: 5.7e-7,
      high: 7.5e-7,
      lastPrice: 7.0e-7,
      low: 4.4e-7,
      quoteVolume: 2558.9974401,
      txsCount: 38,
      volume: 4756780445,
      volumeWaves: 2558.9974401,
      weightedAveragePrice: 5.37968373711644e-7
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "GSFvcF6ycBfXwPJLLKMExRsHWnvVdZQFHtGiYu4A2kZP",
    data: %{
      firstPrice: 10,
      high: 11,
      lastPrice: 11,
      low: 10,
      quoteVolume: 23000,
      txsCount: 2,
      volume: 2250,
      volumeWaves: 2300,
      weightedAveragePrice: 10.2222222222222
    },
    priceAsset: "FP2rjWYBQfqBpdLCDBaZvCtzikMozEyDbxsKyaWA76oB"
  },
  %{
    __type: "pair",
    amountAsset: "zMFqXuoyrn5w17PFurTqxB7GsS71fp9dfk6XFwxbPCy",
    data: %{
      firstPrice: 0.02634439,
      high: 0.02713558,
      lastPrice: 0.02713558,
      low: 0.017183,
      quoteVolume: 0.168655701505049,
      txsCount: 157,
      volume: 6.67307467,
      volumeWaves: 1648.29749597449,
      weightedAveragePrice: 0.0252740617849327
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "EYz8Zvs62D4d7F5ZgXHCWuzuFaZg63FYnfVQrTWQoLSK",
    data: %{
      firstPrice: 5.954e-5,
      high: 6.013e-5,
      lastPrice: 5.92e-5,
      low: 5.813e-5,
      quoteVolume: 0.156342559483,
      txsCount: 105,
      volume: 2645.003,
      volumeWaves: 1527.95931006433,
      weightedAveragePrice: 5.91086510990724e-5
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "AYRiZmXipTgtBn62MraFByqKc7Sr4hH1QagEMc89jX2s",
    data: %{ 
      firstPrice: 1000,
      high: 2000,
      lastPrice: 2000,
      low: 1000,
      quoteVolume: 5704744,
      txsCount: 13,
      volume: 5149.872,
      volumeWaves: 1443.94505243608,
      weightedAveragePrice: 1107.74481385168
    },
    priceAsset: "2pxjVMm7pm5uTtZAkRA8ggVJfcFsD2LkBCrDD5zFqF7X"
  },
  %{
    __type: "pair",
    amountAsset: "HZk1mbfuJpmxU1Fs4AX5MWLVYtctsNcg6e2C6VKqK8zk",
    data: %{
      firstPrice: 0.00673136,
      high: 0.00678454,
      lastPrice: 0.00672508,
      low: 0.00668768,
      quoteVolume: 0.122834901093841,
      txsCount: 36,
      volume: 18.23315524,
      volumeWaves: 1200.48393315177,
      weightedAveragePrice: 0.0067368976722342
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "3f2XzwnKvnjXp45G3PBcKGze9L6AXasKae7UyiW7AJRV",
    data: %{
      firstPrice: 0.01222,
      high: 0.013,
      lastPrice: 0.013,
      low: 0.0112,
      quoteVolume: 1165.962290928,
      txsCount: 24,
      volume: 90439.13884,
      volumeWaves: 1165.962290928,
      weightedAveragePrice: 0.0128922312384106
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "Fabm95cy9YLd19SAeL8rGg5zue58XavaHQCbqbmBY2TY",
    data: %{
      firstPrice: 0.66,
      high: 0.72,
      lastPrice: 0.72,
      low: 0.66,
      quoteVolume: 1026,
      txsCount: 36,
      volume: 1466,
      volumeWaves: 1154.49184141759,
      weightedAveragePrice: 0.699863574351978
    },
    priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
  },
  %{
    __type: "pair",
    amountAsset: "5WvPKSJXzVE2orvbkJ8wsQmmQKqTv9sGBPksV4adViw3",
    data: %{
      firstPrice: 64.24312324,
      high: 64.5655486,
      lastPrice: 63.47760676,
      low: 62.97198573,
      quoteVolume: 1091.80557732329,
      txsCount: 77,
      volume: 17.04574521,
      volumeWaves: 1091.80557732329,
      weightedAveragePrice: 64.0515016429304
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "EbLVSrAi6vS3AkLwBinzZCvAXP2yYiFJEzj1MBVHcwZ5",
    data: %{
      firstPrice: 4.16e-6,
      high: 4.28e-6,
      lastPrice: 4.17e-6,
      low: 4.01e-6,
      quoteVolume: 0.0994919300002917,
      txsCount: 19,
      volume: 24675.61580259,
      volumeWaves: 972.349571498123,
      weightedAveragePrice: 4.03199380296109e-6
    },
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "5b3UGNZXX5srkHUQWnEWEiaVtnNWmg5aLo5uZMdjWupH",
    data: %{
      firstPrice: 66.05,
      high: 66.05,
      lastPrice: 66.05,
      low: 66.05,
      quoteVolume: 950.2879991935,
      txsCount: 21,
      volume: 14.38740347,
      volumeWaves: 950.2879991935,
      weightedAveragePrice: 66.05
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "51LxAtwBXapvvTFSbbh4nLyWFxH6x8ocfNvrXxbTChze",
    data: %{
      firstPrice: 7.2e-4,
      high: 9.7956e-4,
      lastPrice: 7.1999e-4,
      low: 0.0006,
      quoteVolume: 944.367934615773,
      txsCount: 155,
      volume: 1239006.084085,
      volumeWaves: 944.367934615773,
      weightedAveragePrice: 7.62197980095622e-4
    },
    priceAsset: "WAVES"
  },
  %{ 
    __type: "pair",
    amountAsset: "EFmBdhoQDy2vkpkC2am33ANwxBFLGeJwAmWGvJeVmWmE",
    data: %{
      firstPrice: 0.01,
      high: 0.01,
      lastPrice: 0.01,
      low: 0.01,
      quoteVolume: 712.61,
      txsCount: 4,
      volume: 71261,
      volumeWaves: 801.8542213573,
      weightedAveragePrice: 0.01
    },
    priceAsset: "Ft8X1v1LTa1ABafufpaCWyVj8KkaxUWE6xBhW6sNFJck"
  },
  %{
    __type: "pair",
    amountAsset: "291eANuyaSj9NiZTkMTXhktUudhFuYvR714BfqrshAWa",
    data: %{
      firstPrice: 0.97077668,
      high: 0.99554432,
      lastPrice: 0.99554432,
      low: 0.1,
      quoteVolume: 771.00327731197,
      txsCount: 55,
      volume: 833.03026391,
      volumeWaves: 771.00327731197,
      ...
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H",
    data: %{
      firstPrice: 81.15855529,
      high: 85.72778187,
      lastPrice: 84.39180534,
      low: 81.15855529,
      quoteVolume: 729.623153462685,
      txsCount: 69,
      volume: 8.83535252,
      ...
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "4vPcbA5yiwpWBVPALPGXus6fNdGEuYTpe4hAeSxM9Kj4",
    data: %{
      firstPrice: 6.55e-6,
      high: 8.77e-6,
      lastPrice: 8.77e-6,
      low: 6.55e-6,
      quoteVolume: 709.581911090001,
      txsCount: 20,
      ...
    },
    priceAsset: "WAVES" 
  },
  %{
    __type: "pair",
    amountAsset: "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
    data: %{
      firstPrice: 42.6,
      high: 43.41760658,
      lastPrice: 43.41760658,
      low: 42.01402619,
      quoteVolume: 689.589114917919,
      ...
    },
    priceAsset: "WAVES"
  },
  %{
    __type: "pair",
    amountAsset: "WAVES",
    data: %{firstPrice: 0.81, high: 0.83, lastPrice: 0.83, low: 0.81, ...},
    priceAsset: "Gtb1WRznfchDnTh37ezoDTJ4wcoKaRsKqKjJjy7nm2zU"
  },
  %{
    __type: "pair",
    amountAsset: "knZe9t5sZRqe9khJjWQXKnScaN4WEyY4zM1mCmvvuUB",
    data: %{firstPrice: 1.5e-6, high: 1.55e-6, lastPrice: 1.55e-6, ...},
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "BrjUWjndUanm5VsJkbUip8VRYy6LWJePtxya3FNv4TQa",
    data: %{firstPrice: 0.00435974, high: 0.00442668, ...},
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "B3uGHFRpSUuGEDWjqB9LWWxafQj8VTvpMucEyoxzws5H",
    data: %{firstPrice: 0.00838007, ...},
    priceAsset: "8LQW8f7P5d5PZM7GtZEBgaqRPGSzS3DfPuiXrURJ4AJS"
  },
  %{
    __type: "pair",
    amountAsset: "98sW4fRVsMN7tRcngeL2zWSzUFkHsabsRqXe18GX7bzQ",
    data: %{...},
    ...
  },
  %{
    __type: "pair",
    amountAsset: "474jTeYx2r2Va35794tCScAXWJG9hU2HcgxzMowaZUnu",
    ...
  },
  %{__type: "pair", ...},
  %{...},
  ...
]

    

Goal:

flattened = 
[
  %{
         asset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
         priced_in: "4uK8i4ThRGbehENwa6MxyLtxAjAo1Rj9fduborGExarC",
         last: 44536,
         volume: 14839431.7405322
      }, 

  %{
      asset: "bPWkA3MNyEr1TuDchWgdpqJZhGhfPXj7dJdr3qiW2kD",
      priced_in: "WAVES",
      last: 0.00675602,
      volume: 63536.722011126
      }
]

and so on and so forth.

My attempt: (based on: List with nested maps)

iex(1)> items |> Enum.map(fn {_, amountAsset, data, priceAsset} = flattened -> %{asset: amountAsset, priced_in: priceAsset, last: Map.get(data, "lastPrice"), volume: Map.get(data, "volumeWaves")} end)

Resulting error:

    
    The following arguments were given to :erl_eval."-inside-an-interpreted-fun-"/1:
    
        # 1
        %{
          __type: "pair",
          amountAsset: "84LtkQrCByMYGS8K8XaRkWxtHDAxDfyRCJpABxFcSLt4",
          data: %{
            firstPrice: 44536,
            high: 44536,
            lastPrice: 44536,
            low: 44536,
            quoteVolume: 0.44001568,
            txsCount: 1,
            volume: 9.88e-6,
            volumeWaves: 14839431.7405322,
            weightedAveragePrice: 44536
          },
          priceAsset: "4uK8i4ThRGbehENwa6MxyLtxAjAo1Rj9fduborGExarC"
        }
    
    (stdlib) :erl_eval."-inside-an-interpreted-fun-"/1
    (stdlib) erl_eval.erl:829: :erl_eval.eval_fun/6
    (elixir) lib/enum.ex:1327: Enum."-map/2-lists^map/1-0-"/2

Where did I go wrong? (Please Eli5, thanks! :slight_smile: )

I don’t see any lists here. To go from your input to your desired output can be done in a straightforward way:

flattened = %{
  asset: items.amountAsset,
  priced_in: items.priceAsset,
  last: items.data.lastPrice,
  volume: items.data.volumeWaves
}

If you truly do have a list of items, then you’d want to do that inside an Enum.map.

Also, you should not use upper case keys in your maps. Those are reserved for module names and will cause you some problems.

edit: I see you made items a list while I was posing

Enum.map(items, fn item ->
  %{
    asset: item.amountAsset,
    priced_in: item.priceAsset,
    last: item.data.lastPrice,
    volume: item.data.volumeWaves
  }
end)
2 Likes

I think your main conceptual problem is trying to destructure a map in more of a Javascript way rather than pattern matching in an Elixir way. You could use pattern matching here, though I find it less readable than my previous example:

Enum.map(items, fn %{amountAsset: asset, priceAsset: priced_in, data: %{lastPrice: last, volumeWaves: volume}} ->
  %{asset: asset, priced_in: priced_in, last: last, volume: volume}
end)
2 Likes

Please revisit the re-edited OP and thank you for your response :slight_smile:

1 Like

Here is a simple and easily configurable example:

defmodule Example do
  @keys [
    Asset: [:amountAsset],
    Last: [:data, :lastPrice],
    Priced_in: [:priceAsset],
    Volume: [:data, :volumeWaves]
  ]

  def sample(list) when is_list(list), do: Enum.map(list, &do_sample/1)

  defp do_sample(element), do: Enum.reduce(@keys, %{}, &do_sample(&1, &2, element))

  defp do_sample({key, value}, acc, element), do: Map.put_new(acc, key, get_in(element, value))
end

Helpful resources:

  1. Enum.map/2
  2. Enum.reduce/3
  3. Map.put_new/3
  4. get_in/2
  5. is_list/1
2 Likes

Thank you!! Thank you!! Thank you!!

:slight_smile: :slight_smile: :slight_smile:

(P.S. I don’t know JavaScript, lol :slight_smile: )

1 Like

Just to be clear (we were doing some simultaneous edits which complicated things) My first response is really the one I would recommend because I find it both simpler and easier to read:

Enum.map(items, fn item ->
  %{
    asset: item.amountAsset,
    priced_in: item.priceAsset,
    last: item.data.lastPrice,
    volume: item.data.volumeWaves
  }
end)

This only danger to it (and one of the things @Eiji 's more abstracted approach handles) is the chance that the data key might be missing or have a nil value. If that’s something you need to protect against, I’d modify my recommended solution slightly to use get_in

Enum.map(items, fn item ->
  %{
    asset: item.amountAsset,
    priced_in: item.priceAsset,
    last: get_in(item, [:data, :lastPrice]),
    volume: get_in(item, [:data, :volumeWaves])
  }
end)

If you go with the pattern matching approach you marked as the solution, you will have errors if any of the required keys are not present in any of the items. In some cases that might be what you want, to fail fast (and presumably let some supervision restart a process). But that decision can only be made in the larger context of the system you are building.

3 Likes