1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-06 06:47:46 +02:00

refactor to zip

This commit is contained in:
Justin Lin
2020-03-19 20:32:09 +08:00
parent d5720ddf5d
commit cc9bcc6e9d
4 changed files with 16 additions and 4 deletions

View File

@@ -0,0 +1,11 @@
function _zip2(lt1, lt2) =
[for(i = [0:len(lt1) - 1]) [lt1[i], lt2[i]]];
function _zip3(lt1, lt2, lt3) =
[for(i = [0:len(lt1) - 1]) [lt1[i], lt2[i], lt3[i]]];
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));
function _zipAll(lists) = _zipAll_sub(lists, len(lists) - 1, len(lists[0]) - 1);

View File

@@ -0,0 +1,5 @@
use <experimental/_impl/_zip_impl.scad>;
function zip(lt, lt2, lt3) =
is_undef(lt2) ? _zipAll(lt) :
is_undef(lt3) ? _zip2(lt, lt2) : _zip3(lt, lt2, lt3);

View File

@@ -1,2 +0,0 @@
function zip2(lt1, lt2) =
[for(i = [0:len(lt1) - 1]) [lt1[i], lt2[i]]];

View File

@@ -1,2 +0,0 @@
function zip3(lt1, lt2, lt3) =
[for(i = [0:len(lt1) - 1]) [lt1[i], lt2[i]. lt3[i]]];