Welcome! Please see the About page for a little more info on how this works.

+3 votes
in Clojure by

The CLJS version of shuffle accepts arrays, but the CLJ version does not.
The CLJS version of shuffle accepts nil, but the CLJ version does not.

This behavior could be unified.

Proposal:

  • Add support for arrays in CLJ
  • Add support for nil in CLJ and return nil or ().
  • The behavior of the CLJS version on nil should be made the same as CLJ: do not return an empty vector, since nil does not pun as an empty vector.
  • The CLJS version supports a shuffle of string, but this can be considered undefined behavior.

The attached patch CLJ-2470 adds support for nil (also returns nil) and Java arrays.
Patch CLJ-2470-2 adds a better error message.

Patch: CLJ-2470-2.patch
Prescreened by: Alex Miller

5 Answers

0 votes
by

Comment made by: borkdude

Patch attached.

0 votes
by

Comment made by: borkdude

Alex:

CLJS also supports:

`(shuffle (eduction (map inc) [1 2 3]))`

Should it and if so, should we support it in CLJ? Probably not, since it's not a collection?

0 votes
by

Comment made by: alexmiller

That seems weird to me, so I'd say no.

0 votes
by

Comment made by: alexyakushev

Drive-by comment, I think that (shuffle nil) should return an empty collection, same as sort, map, filter, partition... etc.

0 votes
by
Reference: https://clojure.atlassian.net/browse/CLJ-2470 (reported by borkdude)
...