diff --git a/gists.org b/gists.org index 1769fed..59f7bdd 100644 --- a/gists.org +++ b/gists.org @@ -527,6 +527,16 @@ It turns out it didn't work as well as I hoped, paredit steals the RET binding s :post-process-template #'my/dwim-shell-command/convert-path-cygwin)) #+end_src +* Apply maybe + +#+begin_src elisp :tangle gists/apply-maybe.el + (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)) +#+end_src + * Meta ** License diff --git a/gists/apply-maybe.el b/gists/apply-maybe.el new file mode 100644 index 0000000..2614c48 --- /dev/null +++ b/gists/apply-maybe.el @@ -0,0 +1,5 @@ +(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))