diff --git a/src/uncomplicate/commons/core.clj b/src/uncomplicate/commons/core.clj index 363e9db..f9ed012 100644 --- a/src/uncomplicate/commons/core.clj +++ b/src/uncomplicate/commons/core.clj @@ -141,8 +141,20 @@ " (release [this] "Releases all resources held by this object.")) +(let [obj-impl (delay (find-protocol-impl Releaseable (Object.)))] + "Checks whether the implementation of Releaseable for `this` isn't + identical to the catch-all implementations for `nil` and `Object`." + (defn nontrivially-releaseable? + [this] + (and + (some? this) + (not (identical? @obj-impl (find-protocol-impl Releasable this)))))) + (defn releaseable? - "Checks whether this is releaseable (in terms of Releaseable protocol)." + "Checks whether this is releaseable (in terms of Releaseable protocol). + + Note: pending redefinitions of the `Releaseable` protocol, this function always returns true. + consider `nontrivially-releaseable?` for checking for non-default implementations." [this] (satisfies? Releaseable this))