From 230c4bbb3e9f44875d6593a7c6cb0ca33bb63805 Mon Sep 17 00:00:00 2001 From: William Carroll Date: Fri, 29 Jul 2022 11:15:17 -0700 Subject: feat(wpcarro/emacs): Package maybe.el (Temporarily) remove dependency on list.el in favor of dash, which I'm not thrilled about. Change-Id: Ic4348ee72582dee63ba07a183f3bda65baa7e2d6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/5999 Reviewed-by: wpcarro Autosubmit: wpcarro Tested-by: BuildkiteCI --- users/wpcarro/emacs/.emacs.d/wpc/buffer.el | 1 + users/wpcarro/emacs/.emacs.d/wpc/math.el | 9 ++-- users/wpcarro/emacs/.emacs.d/wpc/maybe.el | 78 ------------------------------ 3 files changed, 6 insertions(+), 82 deletions(-) delete mode 100644 users/wpcarro/emacs/.emacs.d/wpc/maybe.el (limited to 'users/wpcarro/emacs/.emacs.d') diff --git a/users/wpcarro/emacs/.emacs.d/wpc/buffer.el b/users/wpcarro/emacs/.emacs.d/wpc/buffer.el index fa98393df82f..ede3d3e68d05 100644 --- a/users/wpcarro/emacs/.emacs.d/wpc/buffer.el +++ b/users/wpcarro/emacs/.emacs.d/wpc/buffer.el @@ -33,6 +33,7 @@ (require 'struct) (require 'ts) (require 'general) +(require 'list) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Library diff --git a/users/wpcarro/emacs/.emacs.d/wpc/math.el b/users/wpcarro/emacs/.emacs.d/wpc/math.el index 4013ce3be21d..dbc527928a30 100644 --- a/users/wpcarro/emacs/.emacs.d/wpc/math.el +++ b/users/wpcarro/emacs/.emacs.d/wpc/math.el @@ -13,6 +13,7 @@ ;; Dependencies ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(require 'dash) (require 'maybe) (require 'cl-lib) @@ -31,13 +32,13 @@ ;; Int -> Int -> Int -> Boolean (cl-defun math-triangle-of-power (&key base power result) (cond - ((maybe-somes? base power result) + ((-all? #'maybe-some? (list base power result)) (error "All three arguments should not be set")) - ((maybe-somes? power result) + ((-all? #'maybe-some? (list power result)) (message "power and result")) - ((maybe-somes? base result) + ((-all? #'maybe-some? (list base result)) (log result base)) - ((maybe-somes? base power) + ((-all? #'maybe-some? (list base power)) (expt base power)) (t (error "Two of the three arguments must be set")))) diff --git a/users/wpcarro/emacs/.emacs.d/wpc/maybe.el b/users/wpcarro/emacs/.emacs.d/wpc/maybe.el deleted file mode 100644 index ef92e5a4c15c..000000000000 --- a/users/wpcarro/emacs/.emacs.d/wpc/maybe.el +++ /dev/null @@ -1,78 +0,0 @@ -;;; maybe.el --- Library for dealing with nil values -*- lexical-binding: t -*- - -;; Author: William Carroll -;; Version: 0.0.1 -;; Package-Requires: ((emacs "24")) - -;;; Commentary: -;; Inspired by Elm's Maybe library. -;; -;; For now, a Nothing value will be defined exclusively as a nil value. I'm -;; uninterested in supported falsiness in this module even at risk of going -;; against the LISP grain. -;; -;; I'm avoiding introducing a struct to handle the creation of Just and Nothing -;; variants of Maybe. Perhaps this is a mistake in which case this file would -;; be more aptly named nil.el. I may change that. Because of this limitation, -;; functions in Elm's Maybe library like andThen, which is the monadic bind for -;; the Maybe type, doesn't have a home here since we cannot compose multiple -;; Nothing or Just values without a struct or some other construct. -;; -;; Possible names for the variants of a Maybe. -;; None | Some -;; Nothing | Something -;; None | Just -;; Nil | Set -;; -;; NOTE: In Elisp, values like '() (i.e. the empty list) are aliases for nil. -;; What else in Elisp is an alias in this way? -;; Examples: -;; TODO: Provide examples of other nil types in Elisp. - -;;; Code: - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Dependencies -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(require 'list) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Constants -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defvar maybe--run-tests? t - "When t, run the test suite defined herein.") - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Library -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(defun maybe-nil? (x) - "Return t if X is nil." - (eq nil x)) - -(defun maybe-some? (x) - "Return t when X is non-nil." - (not (maybe-nil? x))) - -(defun maybe-nils? (&rest xs) - "Return t if all XS are nil." - (list-all? #'maybe-nil? xs)) - -(defun maybe-somes? (&rest xs) - "Return t if all XS are non-nil." - (list-all? #'maybe-some? xs)) - -(defun maybe-default (default x) - "Return DEFAULT when X is nil." - (if (maybe-nil? x) default x)) - -(defun maybe-map (f x) - "Apply F to X if X is not nil." - (if (maybe-some? x) - (funcall f x) - x)) - -(provide 'maybe) -;;; maybe.el ends here -- cgit 1.4.1