diff --git a/kutils.lisp b/kutils.lisp index 8a411e6..9ea4857 100644 --- a/kutils.lisp +++ b/kutils.lisp @@ -133,3 +133,20 @@ contain any additional keyword arguments to @c(assoc)." (cons x y)) b)) a))) + +(defun empty-or-nil-p (arg) + "Is @c(arg) null, or does it represent an empty sequence? Returns +NIL if @c(arg) is not a nil or a sequence." + (cond ((null arg) t) + ((stringp arg) (string-equal "" arg)) + ((vectorp arg) (zerop (length arg))) + ((listp arg) (null (rest arg))) + (t nil))) + +(defun effector (&rest fns) + "An effector returns a function that calls all the functions +supplied to @c(effector) on its input. This is usually useful for +effectful code, such as logging." + (lambda (&rest args) + (dolist (fn fns) + (apply fn args)))) diff --git a/package.lisp b/package.lisp index c52c2c7..1200b88 100644 --- a/package.lisp +++ b/package.lisp @@ -28,6 +28,8 @@ #:extend-vector #:assoc-val #:cartprod2 + #:empty-or-nil-p + #:effector ;; kutils-hash-tables.lisp #:enable-hash-table-reader