summaryrefslogtreecommitdiff
path: root/core.fnl
diff options
context:
space:
mode:
authorAndrey Orst <andreyorst@gmail.com>2020-10-29 19:55:31 +0300
committerAndrey Orst <andreyorst@gmail.com>2020-10-29 20:00:19 +0300
commit946378510f1dd542cc2f30efe22a16da69749840 (patch)
treeeca6e0703908d8266d65d7abc978e20e0749c5b8 /core.fnl
parente31bc3dcfebe994f41d0ccc8f784adfec568fdcb (diff)
feature: functions to access table values
Diffstat (limited to 'core.fnl')
-rw-r--r--core.fnl20
1 files changed, 20 insertions, 0 deletions
diff --git a/core.fnl b/core.fnl
index b993863..d151c77 100644
--- a/core.fnl
+++ b/core.fnl
@@ -397,4 +397,24 @@ oppisite truth value."
(set (i k) (next kvs i)))
tbl))
+(fn& core.get
+ "Get value from the table by accessing it with a `key'.
+Accepts additional `not-found' as a marker to return if value wasn't
+found in the table."
+ ([tbl key] (get tbl key nil))
+ ([tbl key not-found]
+ (if-some [res (. tbl key)]
+ res
+ not-found)))
+
+(fn& core.get-in
+ "Get value from nested set of tables by providing key sequence.
+Accepts additional `not-found' as a marker to return if value wasn't
+found in the table."
+ ([tbl keys] (get-in tbl keys nil))
+ ([tbl keys not-found]
+ (if-some [res (. tbl (. keys 1))]
+ (get-in tbl [(unpack tbl 2)] not-found)
+ not-found)))
+
core