mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-04-20 22:21:52 +02:00
add zipper param
This commit is contained in:
parent
387bd8fe4a
commit
f6ea7fa328
@ -1,5 +1,7 @@
|
||||
function _zipAll_sub(lists, list_to, elem_to, i = 0) =
|
||||
i > elem_to ? [] :
|
||||
concat([[for(j = [0:list_to]) lists[j][i]]], _zipAll_sub(lists, list_to, elem_to, i + 1));
|
||||
_identity = function(elems) elems;
|
||||
|
||||
function _zipAll(lists) = _zipAll_sub(lists, len(lists) - 1, len(lists[0]) - 1);
|
||||
function _zipAll_sub(lts, list_to, elem_to, zipper, i = 0) =
|
||||
i > elem_to ? [] :
|
||||
concat([zipper([for(j = [0:list_to]) lts[j][i]])], _zipAll_sub(lts, list_to, elem_to, zipper, i + 1));
|
||||
|
||||
function _zipAll(lts, zipper = _identity) = _zipAll_sub(lts, len(lts) - 1, len(lts[0]) - 1, zipper);
|
@ -4,10 +4,10 @@
|
||||
* @copyright Justin Lin, 2020
|
||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||
*
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-zip.html
|
||||
* @see https://openhome.cc/eGossip/OpenSCAD/lib3x-zip.html
|
||||
*
|
||||
**/
|
||||
|
||||
use <_impl/_zip_impl.scad>;
|
||||
|
||||
function zip(lts) = _zipAll(lts);
|
||||
function zip(lts, zipper) = is_function(zipper) ? _zipAll(lts, zipper) : _zipAll(lts);
|
@ -1,4 +1,5 @@
|
||||
use <util/zip.scad>;
|
||||
use <util/sum.scad>;
|
||||
|
||||
module test_zip() {
|
||||
echo("==== test_zip ====");
|
||||
@ -8,6 +9,9 @@ module test_zip() {
|
||||
zs = [2.5, 7.5, 12.4];
|
||||
|
||||
assert(zip([xs, ys, zs]) == [[10, 5, 2.5], [20, 15, 7.5], [30, 25, 12.4]]);
|
||||
|
||||
sum_up = function(elems) sum(elems);
|
||||
assert(zip([xs, ys, zs], sum_up) == [17.5, 42.5, 67.4]);
|
||||
}
|
||||
|
||||
test_zip();
|
Loading…
x
Reference in New Issue
Block a user