Skip to content

Commit

Permalink
Use Clojure 1.12.0-alpha12 FI interop in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
eerohele committed May 24, 2024
1 parent 52fcf50 commit d905be8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
2 changes: 1 addition & 1 deletion deps.edn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{:aliases {:dev {:extra-paths ["dev/src"]
:extra-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha11"}
:extra-deps {org.clojure/clojure {:mvn/version "1.12.0-alpha12"}
com.cognitect/transcriptor {:mvn/version "0.1.5"}
criterium/criterium {:mvn/version "0.4.6"}
org.clojure/test.check {:mvn/version "1.1.1"}}}
Expand Down
11 changes: 3 additions & 8 deletions doc/INDEX.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,11 @@ You can [`deref`](https://clojure.github.io/clojure/clojure.core-api.html#clojur
Or, if you need to, you can take advantage of the CompletableFuture API:

```clojure
;; Until functional interface interop lands in Clojure 1.12.
user=> (defn as-fn
[f]
(reify java.util.function.Function
(apply [_ arg]
(f arg))))
#'user/as-fn
;; (Presuming Clojure 1.12.0-alpha12 or newer for functional interface interop.)
;;
;; Have Redis increment a number, then Clojure -- asynchronously, of course,
;; because that's extremely useful.
user=> (-> (redis [:INCR "n"]) (.thenApplyAsync (as-fn inc)) (.get))
user=> (-> (redis [:INCR "n"]) (.thenApplyAsync inc) (.get))
2
```

Expand Down
18 changes: 5 additions & 13 deletions examples/compression.repl
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,11 @@

(assert (= edn *1))

;; Do the same thing, but using CompletableFuture APIs.

;; Until functional interface interop lands in Clojure 1.12.
(defn as-fn
[f]
(reify java.util.function.Function
(apply [_ arg]
(f arg))))

;; Presuming Clojure 1.12.0-alpha12 or newer.
(->
(redis [:GET "data"])
(.thenApply (as-fn inflate))
(.thenApply (as-fn json/read-str))
(.thenApply inflate)
(.thenApply json/read-str)
(.get))

(assert (= edn *1))
Expand All @@ -90,6 +82,6 @@

(->
(redis [:GET "data"])
(.thenApplyAsync (as-fn inflate) executor)
(.thenApplyAsync (as-fn json/read-str) executor)
(.thenApplyAsync inflate executor)
(.thenApplyAsync json/read-str executor)
(.get))

0 comments on commit d905be8

Please sign in to comment.