2bdkid / refinement

Convenient creation of type-safe refinement types.
18 stars 4 forks source link

`Refinement.to_inner` misleading name and documentation #8

Open koutheir opened 1 year ago

koutheir commented 1 year ago

The implementation of the method Refinement.to_inner() has two problems:

  1. It implicitly performs a (potentially expensive) self.clone(), and
  2. It provides a clone of the stored value.

Currently, the documentation of the method says:

Retrieve the underlying value without consuming self.

First, the returned value is not the underlying value, but a clone of that value. Second, the inner value is cloned, without any indication of that happening, neither in the name nor in the documentation.

I suggest renaming the method to clone_inner(), and changing the documentation to:

Returns a clone of the underlying value without consuming self.