Documentation states that Empty allowed only as a root of the tree. Both performance and functions (e. g. binarySetOpWithKey) depends on this invariant. But, now it is not checked by tests at all.
Unfortunately, there is no way to write such check function using public API only.
AFAIU there are two ways to solve this problem:
- Make one of the API functions (e.g. toList) to check this. This check will cost just a one call on the root tree.
- Provide special check function in the API.
I think first variant is better.