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

+1 vote
in Clojure by
It is not possible to check whether a value is reducible (can be passed
to {{reduce}}).

One can try to cobble something together using {{clojure.lang.IReduce}}
and {{clojure.core.protocols/CollReduce}} but this is not satisfactory:
the {{CollReduce}} protocol is extended to {{java.lang.Object}}, so
{{(satisfies? CollReduce x)}} always returns true, even for values that
will throw an exception when reduced.

It seems to me that the extension of {{CollReduce}} to {{Object}} may be
problematic.

Note that ClojureScript has a working {{reduceable?}}, so doesn't seem
to suffer from this problem.

4 Answers

0 votes
by
_Comment made by: glts_

I cannot edit the description, but would add that the same problem applies to ‘foldable’ values and the {{clojure.core.reducers/CollFold}} protocol. It is not possible to check whether a value is foldable.
0 votes
by

Comment made by: gshayban

I'd like to know what the surrounding use-case is.

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