This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-15
Channels
- # beginners (16)
- # cljs-dev (12)
- # clojure (9)
- # clojure-berlin (5)
- # clojure-russia (16)
- # clojure-uk (26)
- # clojurescript (48)
- # community-development (2)
- # cursive (1)
- # data-science (10)
- # datomic (7)
- # emacs (27)
- # figwheel-main (31)
- # fulcro (6)
- # hoplon (47)
- # immutant (1)
- # jobs (1)
- # jobs-discuss (33)
- # off-topic (3)
- # onyx (34)
- # protorepl (5)
- # re-frame (26)
- # reagent (1)
- # reitit (1)
- # shadow-cljs (80)
- # spacemacs (44)
- # specter (4)
- # testing (1)
- # tools-deps (4)
I’m trying to call Google Cloud Language (sentiment analysis, categorization service) from Clojure, using their offical Java client. The Java tutorial says,
// Imports the Google Cloud client library
import com.google.cloud.language.v1.Document;
import com.google.cloud.language.v1.Document.Type;
import com.google.cloud.language.v1.LanguageServiceClient;
import com.google.cloud.language.v1.Sentiment;
I’ve translated this to
(ns exp.language
(:import [com.google.cloud.language.v1
Document
LanguageServiceClient
Sentiment]))
But Document.Type
eludes me. Putting Document.Type
among the imports leads to a ClassNotFoundException
. What is Type
, and how do I import it?Document$Type
worked, thank you! So, a nested class according to Java interop documentation.
Is there anything in Clojure standard library similar to with-open
, but for an arbitrary value (say, implementing a particular interface)?
Actually I'm trying to do a multi-step construction of a stateful component, where every step should be rolled back if the next one fails. I have come up with the following monstrous construction, is there way to make it better?
(defn open []
(let [a (open-a)]
(try
(let [b (open-b a)]
(try
(let [c (open-c a b)]
{:a a :b b :c c})
(catch Exception e
(close {:a a :b b})
(throw e)))
(catch Exception e
(close {:a a})
(throw e)))))
(defn close [{:keys [a b c]}]
(when c
(close-c c))
(when b
(close-b b))
(when a
(close-a a)))
;; usage
(let [session (open)]
(try
(do-some-stuff session)
(finally
(close session))))