mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-06 14:56:47 +02:00
add zipper param
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
function _zipAll_sub(lists, list_to, elem_to, i = 0) =
|
_identity = function(elems) elems;
|
||||||
i > elem_to ? [] :
|
|
||||||
concat([[for(j = [0:list_to]) lists[j][i]]], _zipAll_sub(lists, list_to, elem_to, i + 1));
|
|
||||||
|
|
||||||
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
|
* @copyright Justin Lin, 2020
|
||||||
* @license https://opensource.org/licenses/lgpl-3.0.html
|
* @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>;
|
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/zip.scad>;
|
||||||
|
use <util/sum.scad>;
|
||||||
|
|
||||||
module test_zip() {
|
module test_zip() {
|
||||||
echo("==== test_zip ====");
|
echo("==== test_zip ====");
|
||||||
@@ -8,6 +9,9 @@ module test_zip() {
|
|||||||
zs = [2.5, 7.5, 12.4];
|
zs = [2.5, 7.5, 12.4];
|
||||||
|
|
||||||
assert(zip([xs, ys, zs]) == [[10, 5, 2.5], [20, 15, 7.5], [30, 25, 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();
|
test_zip();
|
Reference in New Issue
Block a user