mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-03-14 02:59:42 +01:00
seperate them
This commit is contained in:
parent
8dd36a1a9c
commit
b693b3bc58
@ -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));
|
@ -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");
|
5
src/experimental/assoc_del.scad
Normal file
5
src/experimental/assoc_del.scad
Normal 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));
|
3
src/experimental/assoc_lookup.scad
Normal file
3
src/experimental/assoc_lookup.scad
Normal file
@ -0,0 +1,3 @@
|
||||
function assoc_lookup(array, key) =
|
||||
let(idx = search([key], array)[0])
|
||||
array[idx][1];
|
6
src/experimental/assoc_put.scad
Normal file
6
src/experimental/assoc_put.scad
Normal 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));
|
Loading…
x
Reference in New Issue
Block a user