(some) returns first truthy predicate result, not first truthy item
iacore opened this issue · comments
repl:40:> (doc some)
function
boot.janet on line 2160, column 1
(some pred ind & inds)
Returns nil if (pred item) is false or nil for every item in ind.
Otherwise, returns the first truthy result encountered.
Is this intended? The return value isn't very useful this way.
I found find
to do what I wanted. No idea if there is a function that maps to (all)
.
I agree that the docstring doesn't seem to match the actual behavior depending on specific arguments.
But I don't know what you mean by "return value isn't very useful":
$ janet
Janet 1.32.1-9142f38c linux/x64/gcc - '(doc)' for help
repl:1:> (some neg? [1 2 3 8])
nil
repl:2:> (some neg? [1 2 3 8 -1])
true
Doesn't this tell you something that was not necessarily known before the call?
But I don't know what you mean by "return value isn't very useful":
I mean (some ...)
can easily just return true
or false
.
If the language was starting from scratch, may be a different choice might have been nicer.
Not so clear what the implications of changing behavior are at this point. But who knows...
how do i move this to /discussions/
I don't know -- I don't see an option in my view of this issue.
Perhaps it's reserved for some folks (like members of the janet-lang org)?