Operations like firstOccurrence() and firstInclusion() suffered from several problems:
since they were declared by the covariant type List, they weren't typesafe,
they were required to be implemented by every List, even though they weren't really appropriate for e.g. LinkedList
the implementations on String were inefficient
the actual usecases for these operations called for additional optional parameters, e.g. from indexes
Therefore, they have been factored out to a new invariant interface SearchableList which is implemented by String, Array, and ArrayList. Since all these are invariant types, we've regained typesafety. In addition, optional parameters from and length have been added, and the implementations on String have been made much more efficient.
I have one more small remaining task here which is to decide between:
defining all the operations in terms of occurrences() and inclusions()—making SearchableList easier to implement, or
leaving it as it is, where occurrences() and inclusions() are defined in terms of the other operations of SearchableList—potentially more efficient.
Operations like
firstOccurrence()
andfirstInclusion()
suffered from several problems:List
, they weren't typesafe,List
, even though they weren't really appropriate for e.g.LinkedList
String
were inefficientfrom
indexesTherefore, they have been factored out to a new invariant interface
SearchableList
which is implemented byString
,Array
, andArrayList
. Since all these are invariant types, we've regained typesafety. In addition, optional parametersfrom
andlength
have been added, and the implementations onString
have been made much more efficient.I have one more small remaining task here which is to decide between:
occurrences()
andinclusions()
—makingSearchableList
easier to implement, oroccurrences()
andinclusions()
are defined in terms of the other operations ofSearchableList
—potentially more efficient.