Hey Elixir-Lang-Talk!


I have a question about dealing with complicated API requests in a 
functional way. If we are given a JSON response that looks something like 
this:


{ 

   “room_id1”: { 
      “date1”: { 
        “id”: "3", 
        “other_variables”: 1, 
        “other_variables”: 2, 
        “important_stuff”: { 
          “id”: “2342”, 
          “child_id1”: { 
            “var1”: 1, 
            “var2”: 1, 
            “var3”: true, 

          }, 

          “child_id2”: { 
            “var1”: 2, 
            “var2”: 2, 
            “var3”: true, 

          },…

  } 

}



and we want to take information held in the keys and place it in the inner 
most object (i’ve called it important stuff).  Such that the final data 
looks like this:


 [{

   room_id: “room_id1”, 
   date: “date1”, 
   child_id: “child_id1”, 
   var1: 1, 
   var2: 1, 
   var3: true 

}, 
 
 { 

   room_id: “room_id2”, 
   date: “date2”, 
   child_id: “child_id2”, 
   var1: 2, 
   var2: 2, 
   var3: true 

}] 




How might we manage this in a functional way, without side effects? At the 
moment,  I have triple nested Enums, building the object which is then 
inserted directly into a database via Ecto. I would really like to separate 
the transforming of the API data with the inserting of that data in the 
database.

Thanks,
Sam

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-talk/ac6dd923-d2b5-47de-99d0-f4db00ce97ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to