lambdaisland / uri

A pure Clojure/ClojureScript URI library
Mozilla Public License 2.0
243 stars 21 forks source link

Add compatibility with babashka/sci (with some caveats) #22

Closed plexus closed 3 years ago

plexus commented 3 years ago

From the README:

Babashka-specific caveats (also applies to SCI)

Instances of URI implement the toString method, so calling (str uri) gives you the URI back as a string. They also implement the IFn interfaces so they are callable the way maps are.

On babashka implementing interfaces or overriding Object methods is not supported. As an alternative to clojure.core/str you can use lambdaisland.uri/uri-str. As an alternative to using the URI as a function, use the keyword as a function, or use clojure.core/get

;; clojure / clojurescript
(str uri) ;; "https://example.com"
(uri :domain) ;; "example.com"

;; bb
(str uri) ;; "{:scheme "https", :domain "example.com", :path ...}"
(uri :domain) ;; nil

(uri/uri-str uri) ;; "https://example.com"
(:domain uri) ;; "example.com"
(get uri :domain) ;; "example.com"
plexus commented 3 years ago

Released in

[lambdaisland/uri "1.4.74"]
{lambdaisland/uri {:mvn/version "1.4.74"}}
borkdude commented 2 years ago

@plexus The newest bb now supports overriding Object toString on defrecords.

plexus commented 2 years ago

@borkdude I still need to guard the IFn invoke implementation, correct?

borkdude commented 2 years ago

@plexus Correct. Currently SCI records only support implementing protocol functions. Now there is a special case for Object/toString per your issue.

plexus commented 2 years ago

Cool, toString support for babashka is now available in

[lambdaisland/uri "1.12.89"]
{lambdaisland/uri {:mvn/version "1.12.89"}}