map function for objects (instead of arrays)
map function for objects (instead of arrays)
map function for objects (instead of arrays)
I needed this as well so I just took the source code from b93 and put it in a “util” class. I had to modify it slightly to work with the current API. For reference here’s the working code (take it at your own risk…): public static<A, B, C> Stream<C> zip(Stream<? extends A> a, Stream<? … Read more
2016 update: Here’s a snazzier Ecmascript 6 version: zip= rows=>rows[0].map((_,c)=>rows.map(row=>row[c])) Illustration equiv. to Python{zip(*args)}: > zip([[‘row0col0’, ‘row0col1’, ‘row0col2’], [‘row1col0’, ‘row1col1’, ‘row1col2’]]); [[“row0col0″,”row1col0”], [“row0col1″,”row1col1”], [“row0col2″,”row1col2”]] (and FizzyTea points out that ES6 has variadic argument syntax, so the following function definition will act like python, but see below for disclaimer… this will not be its own inverse … Read more
Currying is when you break down a function that takes multiple arguments into a series of functions that each take only one argument. Here’s an example in JavaScript: function add (a, b) { return a + b; } add(3, 4); // returns 7 This is a function that takes two arguments, a and b, and … Read more
What is tail recursion?
Most likely no difference at all. The compiler will inline the function just as much as it inlines the macro. Since macros are much harder to use in a debugger, use a function. And as I always say in case of “which performs better”, you should always benchmark the different options, since differences in compilers … Read more
The fundamental algorithm is the same as your vertical shift function, since String is also a list of characters, [Char]. You can generalize your algorithm to a move function since the code for moveVer really only requires a list and has no dependency on Img: move :: Int -> [a] -> [a] move n xs … Read more
1> L_tup = [ 1> {“Caerus1”, “Ramses Refiner”}, 1> {“Caerus1”, “Jupiter Refiner”}, 1> {“Caerus1”, “Jupiter Other”}, 1> {“Caerus1”, “Trader 13”}, 1> {“Caerus1”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Cathode Supplier 4”}, 1> {“Dionysus3”, “Ramses Refiner”}, 1> {“Dionysus3”, “Trader 13”}, 1> {“Dionysus3”, “Jupiter Refiner”}, 1> {“Dionysus3”, “Jupiter Other”}, 1> {“Prometheus2”, “Jupiter Other”}, 1> {“Prometheus2”, “Ramses Refiner”}, 1> … Read more
uint num=/* your input */; // that’s the number of digits required to print // num in base 10; uint ceil_log10 = 1; for(uint i = 10; num > 10; i = i*10) { num -= (num % i); ceil_log10++; } Any number < 10 needs one digit. Any number >= 10 will enter the … Read more