Skip to content

Conversation

@holyjak
Copy link

@holyjak holyjak commented Mar 28, 2025

This knowledge is quite useful and has been missing from the guide.

This knowledge is quite useful and has been missing from the guide.
@seancorfield
Copy link
Contributor

That page already has two sections where Clojure 1.12's functional interface support is mentioned and code examples given (pretty much identical to what's in your new section).

@seancorfield
Copy link
Contributor

The first, from line 517 in the source:

In Clojure 1.12, a Java interface that is declared @FunctionalInterface can
be inferred from from the context and can be satisfied with a regular Clojure
function. java.io.FilenameFilter is such an interface, so you can pass a
Clojure function directly to a Java method that expects a FilenameFilter:

(seq (.list (java.io.File. ".") #(str/starts-with? %2 ".")))
;;⇒ (".cpcache" ".portal" ".clj-kondo" ".lsp" ".calva")

The second, from line 587 in the source:

As above, in Clojure 1.12, because java.io.FilenameFilter is a functional interface, you can pass a Clojure function directly:

(import java.io.File)

;; a file filter implementation that keeps only .edn files
(let [^java.io.FilenameFilter
      f  (fn [_dir name]
           (str/ends-with? name ".edn"))
    dir  (File. "/home/sean/oss/clojure-doc.github.io/")]
  (into [] (.listFiles dir f)))

Note: we need the type hint on f here because .listFiles has multiple overloads for the same arity, and we need to distinguish a FilenameFilter from a FileFilter.

@holyjak
Copy link
Author

holyjak commented Apr 3, 2025

Hi, I see 😅

The thing is that I have not read the document in detail, I have scanned the sections for anything that looked relevant, and did not see anything. I on purpose skipped the reify sections, b/c I knew I did not want/need to use reify.

Would it still make sense, to add the section as proposed, and instead adjust the two existing place that you pointed out to link to this section? I can update the draft if you think that could work...

@seancorfield
Copy link
Contributor

Sure, if you want to update the PR to add links / adjust wording in those existing places, as well as adding that new section, I'd appreciate that. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants