<< Back to previous view

[CLJ-863] interleave should accept 1 or 0 arguments Created: 24/Oct/11  Updated: 24/May/13  Resolved: 24/May/13

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3
Fix Version/s: Release 1.6

Type: Enhancement Priority: Trivial
Reporter: Joe Gallo Assignee: Unassigned
Resolution: Completed Votes: 5
Labels: None

Attachments: Text File 0001-make-interleave-handle-odd-arugments-in-the-same-man.patch     Text File clj-863-make-interleave-handle-odd-args-like-concat-patch-v1.txt    
Patch: Code and Test
Approval: Ok

 Description   

interleave should handle 0 and 1 arguments in the same way that concat does (i.e., 0 args --> empty seq, 1 args --> identity).



 Comments   
Comment by Rich Hickey [ 15/Jun/12 9:31 AM ]

(lazy-seq nil) should be ()

Comment by Joe Gallo [ 15/Jun/12 10:13 AM ]

Hey Rich, if you're talking about the first line of the diff:

+ ([] (lazy-seq nil))

Then that's the implementation, not the tests – given an empty vector of arguments, return (lazy-seq nil), which I just copied from the existing definition of concat.

Cheers,
Joe

Comment by Marc Dzaebel [ 03/Oct/12 1:19 PM ]

(defn interleave [& s] (apply mapcat list s))

Comment by Matthew O. Smith [ 03/Oct/12 8:47 PM ]

Marc's definition doesn't work for no arguments. Maybe:

(defn interleave
([] ())
([& s] (apply mapcat list s)))

Comment by Marc Dzaebel [ 05/Oct/12 1:07 PM ]

Yes, but my solution is too slow, as it uses "apply".

Comment by Andy Fingerhut [ 01/Jan/13 11:54 AM ]

Patch clj-863-make-interleave-handle-odd-args-like-concat-patch-v1.txt dated Jan 1 2013 is identical to Joe Gallo's 0001-make-interleave-handle-odd-arugments-in-the-same-man.patch patch dated Oct 24 2011, except it returns () instead of (lazy-seq nil) as per Rich's comment. If concat should also return () instead of (lazy-seq nil), perhaps another ticket should be created to fix that. Also presumptuously changing ticket state from Incomplete back to Vetted, since the reason it was marked Incomplete should now be addressed, and it was Screened before.

Generated at Thu Apr 17 22:32:13 CDT 2014 using JIRA 4.4#649-r158309.