aboutsummaryrefslogtreecommitdiff
path: root/stack-core.el
diff options
context:
space:
mode:
authorSean Allred <allred.sean@gmail.com>2014-11-02 09:26:38 -0500
committerSean Allred <allred.sean@gmail.com>2014-11-02 09:26:38 -0500
commit6766f1175ac3fad1a2928ff1f798e9c11caf465d (patch)
tree4377a39ec2cd28162cbd3db9ce6cd5bb515783b7 /stack-core.el
parent796937d412f79c5caf964cc26f81f60e130d035e (diff)
parent39ec0ba8a34b3764fcf46f0e5deb1133b0e70e2c (diff)
Merge pull request #5 from vermiculus/convenience-functions
Add a convenience function to sort through large data structures. Also move tests to test/ and add sample data for real use-case tests later.
Diffstat (limited to 'stack-core.el')
-rw-r--r--stack-core.el32
1 files changed, 32 insertions, 0 deletions
diff --git a/stack-core.el b/stack-core.el
index d48c873..9a535cd 100644
--- a/stack-core.el
+++ b/stack-core.el
@@ -92,6 +92,10 @@ recent call. Set by `stack-core-make-request'.")
number, `stack-core-make-request' will begin printing out the
number of requests left every time it finishes a call.")
+(defcustom stack-core-silent-requests
+ t
+ "When `t', requests default to being silent.")
+
;;; Keyword Arguments
@@ -151,6 +155,7 @@ optional KEYWORD-ARGUMENTS. If no KEYWORD-ARGUMENTS are given,
entire response as a complex alist."
(let ((url-automatic-caching stack-core-cache-requests)
(url-inhibit-uncompression t)
+ (silent (or silent stack-core-silent-requests))
(call
(stack-core-build-request
method
@@ -209,5 +214,32 @@ entire response as a complex alist."
stack-core-remaining-api-requests))
(cdr (assoc 'items response))))))))
+(defun stack-core-filter-data (data desired-tree)
+ "Filters DATA and returns the DESIRED-TREE"
+ (if (vectorp data)
+ (apply #'vector
+ (mapcar (lambda (entry)
+ (stack-core-filter-data
+ entry desired-tree))
+ data))
+ (delq
+ nil
+ (mapcar (lambda (cons-cell)
+ ;; TODO the resolution of `f' is O(2n) in the worst
+ ;; case. It may be faster to implement the same
+ ;; functionality as a `while' loop to stop looking the
+ ;; list once it has found a match. Do speed tests.
+ ;; See edfab4443ec3d376c31a38bef12d305838d3fa2e.
+ (let ((f (or (memq (car cons-cell) desired-tree)
+ (assoc (car cons-cell) desired-tree))))
+ (when f
+ (if (and (sequencep (cdr cons-cell))
+ (sequencep (elt (cdr cons-cell) 0)))
+ (cons (car cons-cell)
+ (stack-core-filter-data
+ (cdr cons-cell) (cdr f)))
+ cons-cell))))
+ data))))
+
(provide 'stack-core)
;;; stack-core.el ends here