-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interest for some-> and some->> threading macros? #5
Comments
What do they do? |
It is a builtin threading macro in clojure, along with https://clojuredocs.org/clojure.core/some-%3E If a form evaluates to Eg.
and
|
I'd support putting it in a |
I'm OK with having a fairly large core, but it has to have things that actually get used a lot, like Clojure's core. It's a pain to import these things every time. I'd support putting most of Clojure's core macros in Hy core. I'd also support putting most of Clojure's core functions in Hy extra or even Hy core if they're sufficiently important. That said, I think a large core can make Hy harder to learn, because new users can't find the absolute essentials inside all the other useful stuff. Clojure had the same problem. The solution is probably better documentation highlighting these rather than more nested namespaces. We do have |
This is exasperated by
I see your point with core functions like I'd argue that |
I am reconsidering the current macro namespace implementation. hylang/hy#1416, we might be able to get transitivity by adding to the In the meantime, couldn't you write a macro that expands to all your require statements? Then you'd only have to require that (and invoke it). I haven't actually tried this, but I think it would work. |
Yes I realized that while writing that comment. It's a bit funny to have such a macro though. |
For anyone arriving at this Issue expecting to see Hylang's (defmacro some->> [expr #* forms]
"When expr is not None, thread it to the first form (via ->>)
and then when the result is not None, through the next, and so on."
(setv g (gensym))
(setv steps (map (fn [step] `(if (is ~g None)
(setv ~g None)
(setv ~g (->> ~g ~step))))
(if (is forms None)
[]
forms)))
`(do
(setv ~g ~expr)
~@steps
~g)) This implementation is tested using the REPL: => (assert (= 1 (some->> 1)))
=> (assert (= None (some->> None)))
=> (assert (= 1 (some->> 1 (- 2))))
=> (assert (= None (some->> 1 ((fn [x] None)) (- 2)))) |
Is there still any objection to add |
No, there isn't. |
|
I have just finished implementing and writing tests for
some->
andsome->>
threading macros for personal use.Is there interest in adding these macros to
hy.core.macros
, before I PR?I've found myself wanting for them often, even
toolz
has a PR open for asome
thread.The text was updated successfully, but these errors were encountered: