1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-07-31 03:50:27 +02:00

update to 3.0

This commit is contained in:
Justin Lin
2021-02-11 11:50:32 +08:00
parent f6ea7fa328
commit f1382cb7f4
5 changed files with 12 additions and 7 deletions

View File

@@ -150,7 +150,7 @@ These examples incubate dotSCAD and dotSCAD refactors these examples. See [examp
- [util/sub_str](https://openhome.cc/eGossip/OpenSCAD/lib3x-sub_str.html)
- [util/split_str](https://openhome.cc/eGossip/OpenSCAD/lib3x-split_str.html)
- [util/sum](https://openhome.cc/eGossip/OpenSCAD/lib3x-sum.html)
- [util/zip](https://openhome.cc/eGossip/OpenSCAD/lib2x-zip.html)
- [util/zip](https://openhome.cc/eGossip/OpenSCAD/lib3x-zip.html)
### Matrix
- [matrix/m_determinant](https://openhome.cc/eGossip/OpenSCAD/lib2x-m_determinant.html)

View File

@@ -6,7 +6,8 @@ Make a list that aggregates elements from each of the lists. Returns a list of l
## Parameters
- `lts` : a list of lists.
- `lts` : A list of lists.
- `head` : Rather than listing the elements, the elements are combined using the function. **Since:** 3.0
## Examples
@@ -16,4 +17,7 @@ Make a list that aggregates elements from each of the lists. Returns a list of l
ys = [5, 15, 25];
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]);

View File

@@ -8,6 +8,7 @@ dotSCAD 3.0 Dev
- `util/sort`: `by` accepts a function literal.
- `util/bsearch`: only supports `sorted` and `target` parameters. I view it as a new function.
- `util/dedup`: add the `eq` parameter.
- `util/zip`: add the `head` parameter.
New modules/functions

View File

@@ -1,7 +1,7 @@
_identity = function(elems) elems;
function _zipAll_sub(lts, list_to, elem_to, zipper, i = 0) =
function _zipAll_sub(lts, list_to, elem_to, head, 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));
concat([head([for(j = [0:list_to]) lts[j][i]])], _zipAll_sub(lts, list_to, elem_to, head, i + 1));
function _zipAll(lts, zipper = _identity) = _zipAll_sub(lts, len(lts) - 1, len(lts[0]) - 1, zipper);
function _zipAll(lts, head = _identity) = _zipAll_sub(lts, len(lts) - 1, len(lts[0]) - 1, head);

View File

@@ -10,4 +10,4 @@
use <_impl/_zip_impl.scad>;
function zip(lts, zipper) = is_function(zipper) ? _zipAll(lts, zipper) : _zipAll(lts);
function zip(lts, head) = is_function(head) ? _zipAll(lts, head) : _zipAll(lts);