#elisp (apply-maybe)
Execute a function with a certain probability.
(defun my/apply-maybe (f probability &rest args)
"Apply function F with a certain PROBABILITY [0-1)."
(if (< (random 100) (* probability 100))
(apply f args)
'my/not-applied))
My use-case is to export a (large) #orgmode file to PDF only once in ~10 saves with an after-save-hook. So I automatically get a more-or-less up to date PDF without having to wait.
I’m aware of async exports but for some reason it’s quite a hassle to get right. apply-maybe
provides a good trade-off for the time being.
Curious if you can come up with other use-cases.
#emacs