Un-optioning an optioned Option
It’s a shame that flatten doesn’t exist. It should. Flatten does exist now. As before, s getOrElse None (in addition to the other answers) will also do the same thing.
It’s a shame that flatten doesn’t exist. It should. Flatten does exist now. As before, s getOrElse None (in addition to the other answers) will also do the same thing.
The Iterables.concat method satisfies that requirement: public static <T> Iterable<T> concat(Iterable<? extends Iterable<? extends T>> inputs)
List has the flatten method. Why not use it? List(List(1,2), List(3,4)).flatten > List(1,2,3,4)
Use Object.assign: let merged = Object.assign(…arr); // ES6 (2015) syntax var merged = Object.assign.apply(Object, arr); // ES5 syntax Note that Object.assign is not yet implemented in many environment and you might need to polyfill it (either with core-js, another polyfill or using the polyfill on MDN). You mentioned lodash, so it’s worth pointing out it … Read more
Here is a solution in Java that gives you both: from 3D to 1D from 1D to 3D Below is a graphical illustration of the path I chose to traverse the 3D matrix, the cells are numbered in their traversal order: Conversion functions: public int to1D( int x, int y, int z ) { return … Read more
You can use Array.concat like bellow:- var arr = [[‘object1’, ‘object2’],[‘object1’],[‘object1′,’object2′,’object3’]]; var flattened = [].concat.apply([],arr); flattened will be your expected array. ES 2020 gives the flat, also flatMap if you want to iterate over, to flat lists of lists: [[‘object1’], [‘object2’]].flat() // [‘object1’, ‘object2’]
You can use jQuery.map, which is the way to go if you have the jQuery Library already loaded. $.map( [1, 2, [3, 4], [5, 6], 7], function(n){ return n; }); Returns [1, 2, 3, 4, 5, 6, 7]
Here’s a non-jQuery version: function toQueryString(obj) { var parts = []; for (var i in obj) { if (obj.hasOwnProperty(i)) { parts.push(encodeURIComponent(i) + “=” + encodeURIComponent(obj[i])); } } return parts.join(“&”); }
Here’s a solution using json_normalize() again by using a custom function to get the data in the correct format understood by json_normalize function. import ast from pandas.io.json import json_normalize def only_dict(d): ”’ Convert json string representation of dictionary to a python dict ”’ return ast.literal_eval(d) def list_of_dicts(ld): ”’ Create a mapping of the tuples formed … Read more