@YuriMostardeiro Hey. You're asking two questions here:
atomand not a
@fileA/myDef. Or maybe don't use an atom at all, if you don't need to change its value
reversebefore you reduce it: https://clojuredocs.org/clojure.core/reverse
Hi everyone, I'm new to clojure, appreciate if you can point out how shall I implement this
I want to format byte size into human-friendly format.
But I feel
reduce isn't the right approach if the list is huge (I call
format-size on a large list), is there a way to early return (without using exception) ?
One approach I can think of is to use recursive function with, so I can stop iteration, but then I'll have to urgly decompose in each loop, like
(first c) and (first (rest c))
@beenotung There's no need for iteration at all. If you prepend an empty string to the vector of units, the index of that vector becomes a corresponding power of 1024 that corresponds to that unit (1024^0 - no unit, 1024^1 - KB, and so on).
So, you need to just get the logarithm of the input number to the base of 1024, round it down, and get the unit from the units vector.
Of course, you can still use iteration to actually find the logarithm. Or you could use the built-in math function.
On a side note - you can stop a reduction early by using
set!the var created by a
defat the NS scope or you can use a dynamic variable if that makes sense. More details: https://clojure.org/reference/vars
metabase.util/prog1macro which defines that symbol: https://github.com/metabase/metabase/blob/master/src/metabase/util.clj#L173
Hey everyone, I'm trying to create a function that will download stuff based on the link its given. I wonder if its better to use multimethod over protocols.
Req: I want to extend that function in the future, each link has its unique process and set of argument as well as the output it produces.
(= 1 1.0)returns false. I don't understand the claim in the documentation.
Immutableclasses. Long story short, I noticed that
ImmutableList<T>is a binary tree. I've read that Clojure uses an N-ary tree for immutable lists/arrays and this gives an almost O(1) access time.