1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-03-14 19:19:47 +01:00

seperate them

This commit is contained in:
Justin Lin 2020-03-27 15:30:39 +08:00
parent 8dd36a1a9c
commit b693b3bc58
5 changed files with 14 additions and 23 deletions

View File

@ -1,14 +0,0 @@
use <util/slice.scad>;
function _assoc_get(array, key) =
let(idx = search([key], array)[0])
array[idx][1];
function _assoc_put(array, key, value) =
let(idx = search([key], array)[0])
idx == [] ? concat(array, [[key, value]]) :
concat(slice(array, 0, idx), [[key, value]], slice(array, idx + 1));
function _assoc_remove(array, key) =
let(idx = search([key], array)[0])
idx == [] ? array : concat(slice(array, 0, idx), slice(array, idx + 1));

View File

@ -1,9 +0,0 @@
use <experimental/_impl/_assoc_impl.scad>;
// treat an associative array as a dictionary.
function assoc(array, cmd, key, value) =
is_undef(array) ? [] :
cmd == "put" ? _assoc_put(array, key, value) :
cmd == "get" ? _assoc_get(array, key) :
cmd == "remove" ? _assoc_remove(array, key) : assert("Uknown command");

View File

@ -0,0 +1,5 @@
use <util/slice.scad>;
function assoc_del(array, key) =
let(idx = search([key], array)[0])
idx == [] ? array : concat(slice(array, 0, idx), slice(array, idx + 1));

View File

@ -0,0 +1,3 @@
function assoc_lookup(array, key) =
let(idx = search([key], array)[0])
array[idx][1];

View File

@ -0,0 +1,6 @@
use <util/slice.scad>;
function assoc_put(array, key, value) =
let(idx = search([key], array)[0])
idx == [] ? concat(array, [[key, value]]) :
concat(slice(array, 0, idx), [[key, value]], slice(array, idx + 1));