interleave should accept 1 or 0 arguments

Description

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

Environment

None

Attachments

2

Activity

Show:

Andy Fingerhut January 1, 2013 at 5:54 PM

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.

import October 5, 2012 at 7:07 PM

Comment made by: mdzaebel

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

Matthew Smith October 4, 2012 at 2:47 AM

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

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

import October 3, 2012 at 7:19 PM

Comment made by: mdzaebel

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

Joseph Gallo June 15, 2012 at 4:13 PM

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

Completed

Details

Assignee

Reporter

Approval

Ok

Patch

Code and Test

Priority

Affects versions

Fix versions

Created October 24, 2011 at 8:50 PM
Updated May 24, 2013 at 1:55 PM
Resolved May 24, 2013 at 1:55 PM