I had the second variant in mind, but it doesn’t really matter either way. By “composition”, I mean creating a new conformer by putting several other conformers together in some way. Any of these are tricky to do in a performant way:
- A pattern that represents a heterogeneous group of n sub‐patterns concatenated together.
- A pattern that represents a heterogeneous group of n sub‐patterns that are alternate possibilities.
- A pattern that represents a heterogeneous group of n sub‐patterns that must all be true of the same match at once.
- Anything combining the above by using each other as sub‐patterns.
It is easy to design an API that can do that—and do it fast—for a fixed target collection (i.e. for String
instead of Collection
). It is also easy to design an API that can do that for a generic collection when speed is unimportant. But getting generics to work without severe performance sacrifices is extremely hard—and maybe even impossible without new language features and/or new or better optimizations available to the compiler.
The fact that the closest I have gotten thus far requires conformers to inherit from a common base class demonstrates that such functionality cannot not be feasibly added on from the outside.
Edit: The original posts may have sounded confusing because for some reason I repeatedly wrote homogenous when I meant heterogeneous. I must have been tired that day. I went back and fixed them so they actually make sense.