This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-02-03
Channels
- # announcements (2)
- # atom-editor (1)
- # babashka (6)
- # beginners (49)
- # calva (39)
- # clj-kondo (20)
- # clojure (41)
- # clojure-australia (1)
- # clojure-europe (33)
- # clojure-germany (8)
- # clojure-italy (2)
- # clojure-losangeles (1)
- # clojure-norway (3)
- # clojure-spec (5)
- # clojure-uk (48)
- # clojurescript (147)
- # conjure (24)
- # core-logic (1)
- # datahike (6)
- # datomic (14)
- # emacs (10)
- # events (1)
- # fulcro (11)
- # garden (1)
- # girouette (2)
- # honeysql (16)
- # jobs (3)
- # kaocha (3)
- # malli (5)
- # meander (7)
- # off-topic (49)
- # pathom (50)
- # portal (3)
- # reagent (4)
- # reitit (7)
- # rewrite-clj (3)
- # ring (3)
- # sci (4)
- # shadow-cljs (46)
- # spacemacs (10)
- # sql (3)
- # tools-deps (57)
How do we interop following Java Class in Clojure?
GoogleIdTokenVerifier verifier =
new GoogleIdTokenVerifier.Builder(new NetHttpTransport(), new JacksonFactory());
I tried following which does not work.
(. GoogleIdTokenVerifier/Builder (NetHttpTransport.) (JacksonFactory.))
From the source code here https://github.com/googleapis/google-api-java-client/blob/master/google-api-client/src/main/java/com/google/api/client/googleapis/auth/oauth2/GoogleIdTokenVerifier.java
I can see Builder
is a class in that file.
It looks like Builder
is in the namespace GoogleIdTokenVerifier
.What's your import line like ?
maybe this will help https://livebook.manning.com/book/clojure-in-action-second-edition/chapter-5/73 maybe 20% down the page... hopefully someone more experienced with interop can chime in ^.^
https://clojure.org/reference/java_interop#_class_access
you can see how to access nested classes here. I would try
(GoogleIdTokenVerifier$Builder. (NetHttpTransport.) (JacksonFactory.))
@U3ES97LAC The import statements are given below
(:import com.google.api.client.http.javanet.NetHttpTransport
com.google.api.client.json.jackson2.JacksonFactory
com.google.api.client.googleapis.auth.oauth2.GoogleIdTokenVerifier))
@U11BV7MTK I have tried it before but unfortunately does not work It throws following error
Caused by: java.lang.IllegalArgumentException: Unable to resolve classname: GoogleIdTokenVerifier$Builder
You need to import GoogleIdTokenVerifier$Builder
or use it fully-qualified
@U04V70XH6 Wow it worked.
Nested classes in Java aren't really "nested", they're more like "siblings".
@U1CQ2GB3M maybe Im too late, but that is useful (google api) https://gist.github.com/arohner/8d94ee5704b1c0c1b206186525d9f7a7
Hmm I think you are very close...
Hello again fellow beginners! Yesterday I started my journey into learning Clojure Spec, which is a really interesting tool for making assertions about data. I don't know so much about it yet, but I've gotten my feet wet with it. In my livestream today we're going to be continuing with the "name validator" coding challenge from Eric Normand's newsletter, which seems like a great use case for Spec and a good way to learn it: https://purelyfunctional.tv/issues/purelyfunctional-tv-newsletter-412-module-depth-is-bogus/ If you'd like to watch some guy with about four weeks of Clojure under his belt bungle his way through and learn a few things along the way, feel free to join! Coding challenge should start around 9:40-ish AM EST: https://www.twitch.tv/a_fry_
Maybe this is a stupid question, but I was wondering how much of the syntax in Clojure is set in stone.
(defn testfunc1 [a b] (+ a b))
(defn testfunc2 (vec a b) (+ a b))
The second one does not work, I thought the [a b] is just another way to say (vec ab). Is this because def is a special form?its looking for a vector which is how arguments are supplied. macros takes forms and return forms. so there's a difference between the literal [a b]
and a form that will evaluate to the same form (vec a b)
You can write a macro that would contain an expression like (vec a b)
that takes some expression as input, and constructs and returns an expression that looks like your first expression, but it would operate upon the symbols and other syntactic elements of the input expression given to the macro, not the "run-time" values of a and b.
Hi there. I have a bit of a question regarding how to do things the "Clojure" way. So let's say I have a Java class Foo
with a bunch of methods that return void
like setBar
or calculateBaz
. Is there a way where I can do something like this:
(-> newFoo
.setBar
.setBar
.calculateBaz)
and return newFoo
by the end?I thought doto
would only be your friend if you have methods that return the object they mutate?
Oh, never mind me. Forgetting things.
From the clojuredoc
;; Note that even though println returns nil, doto still returns the HashMap object
(doto (java.util.HashMap.)
(.put "a" 1)
(.put "b" 2)
(println))
Also to add another question on top of that, I've seen a utility library floating around somewhere which allows me to ->
but with certain position within each form. Can anyone remember what it is?
there's a library
that provides lots of arrow or threading functions. you might be able to use as->
. Or I find it often better to figure out why the "position" changes and build forms that acknowledge that. a let binding or perhaps (->> (-> x foo bar) ...)
can solve the "mismatch" problem many times
as a correction, ->
needs to be on the outside, all the other arrows work inside it by design
that's valid there. its threading that single form through the thread last versions. You are talking about a different kinda pattern
ahh - I see what you are doing OK
that said, (-> x foo bar (->> ...))
does the same thing, and is more flexible
I'd call it the "canonical" version
fair. when the thread last form does the majority of the work or is longer i prefer my version as its a bit more clear to me
DAE use babashka? I know borkdude is in here. Iām looking for some reason to use clojure more (get more practice day to day doing real things) and I am pretty good at python/bash one liners, so this might be it
@grazfather There's also a #babashka channel with 400+ people
Yep, I just joined š
after I wrote that I figured Iād check š
Hi, iam trying to find date difference in days, currently using [java-time :as jt] namespace. I have something which yields me difference between two dates in months. (.toTotalMonths(jt/period ?start-date ?end-date)) I want to extend this further and see what is the difference in days between these two dates. Is there any toDays method which will yield difference in days ?
(ns
(:import (java.time LocalDate)
(java.time.temporal ChronoUnit)))
(let [d1 (LocalDate/parse "2016-04-02")
d2 (LocalDate/parse "2016-05-25")]
(-> (ChronoUnit/DAYS) (.between d1 d2)))
=> 53
I think this works to get total number of days.
Or with ..
(let [d1 (LocalDate/parse "2016-04-02")
d2 (LocalDate/parse "2016-05-25")]
(.. ChronoUnit/DAYS (between d1 d2)))
=> 53
(a lot of times it's not worth using a wrapper for Java Time stuff, although clojure.java-time
does make some type conversions easier)