Clojure has an abstraction first design (these abstractions can be protocols, interfaces, or multimethods). That is to say, that a function shouldn't generally target a specific datatype, but rather it should operate on some abstraction type, and let any datatype implement that abstraction in order to be used by that function.
Functions in Clojure that work on ordered collections should target clojure.lang.ISeq
. The complication here is that we want to also target native types like String
or Array
or List
, where we cannot add a supertype retroactively. Our solution is to use seq
to get an instance of clojure.lang.ISeq
. It turns out that it is convenient to treat nil
as an empty ISeq
, this simplifies eg. various linked list representations, as it's natural to have a nil
next element for for the last element of the list, and thus to treat nil
as an empty list.