emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/dash e07cef6 196/439: Adding -first-item and -last-item


From: Phillip Lord
Subject: [elpa] externals/dash e07cef6 196/439: Adding -first-item and -last-item. [magnars/dash.el#17]
Date: Tue, 04 Aug 2015 20:27:54 +0000

branch: externals/dash
commit e07cef640bf48e5adaf58e08aed5f6c694dddc98
Author: Wilfred Hughes <address@hidden>
Commit: Wilfred Hughes <address@hidden>

    Adding -first-item and -last-item. [magnars/dash.el#17]
    
    `-first-item` is a trivial alias to `car`, so I used `defalias` so
    there isn't the additional overhead of a function call. This has
    broken `create_docs.sh`.
    
    It seems that `defexamples` expects `symbol-function` to return an
    elisp function definition, but `car` is implemented in C.
---
 dash.el         |    7 +++++++
 dev/examples.el |    8 ++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/dash.el b/dash.el
index 31e9a83..1107c21 100644
--- a/dash.el
+++ b/dash.el
@@ -27,6 +27,13 @@
 
 ;;; Code:
 
+(defalias '-first-item 'car
+  "Returns the first item of LIST, or nil on an empty list.")
+
+(defun -last-item (list)
+  "Returns the first item of LIST, or nil on an empty list."
+  (car (last list)))
+
 (defmacro !cons (car cdr)
   "Destructive: Sets CDR to the cons of CAR and CDR."
   `(setq ,cdr (cons ,car ,cdr)))
diff --git a/dev/examples.el b/dev/examples.el
index e035320..2f13ae1 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -9,6 +9,14 @@
 (defun square (num) (* num num))
 (defun three-letters () '("A" "B" "C"))
 
+(defexamples -first-item
+  (-first-item '(1 2 3)) => 1
+  (-first-item nil => nil))
+
+(defexamples -last-item
+  (-last-item '(1 2 3)) => 3
+  (-last-item nil => nil))
+
 (defexamples -map
   (-map (lambda (num) (* num num)) '(1 2 3 4)) => '(1 4 9 16)
   (-map 'square '(1 2 3 4)) => '(1 4 9 16)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]