-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
Fixes issue #555 #608
Fixes issue #555 #608
Conversation
boot/core/src/boot/core.clj
Outdated
->file #(if (tmp? %) (io/file (tmp-path %)) (io/file %)) | ||
pred (apply juxt (mapv mkpred criteria))] | ||
(filter-files #(pred (->file %)) files negate?)))) | ||
(if (empty? criteria) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works, but a more idiomatic way would be:
(when (seq criteria))
....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would that not result in a nil
return if the seq was empty? I'm still new to Clojure and Boot, so I may be missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep it returns nil
.
I have been thought that you should always check using (seq coll)
if the collection contains stuff (wonderfully in The Joy of Clojure). This has to do with how lazy sequences where implemented in Clojure and it is very different from how things are done in other Lisps (you can google nil punning
and nil punning next rest in Clojure
).
Huh, I just noticed that #600 fixed this issue as well. hit023 said for me to do ahead and fix it, and I hadn't thought about checking pull requests. Anyway, this does have the advantage of passing the tests. |
1b4bed0
to
601cd23
Compare
@arichiardi Updated it to match your suggestions. |
You know I have been thinking about this and I was wondering whether it is a good idea to filter all the items if no criterias are given...Maybe this is why the behavior was to crash..Is The least surprising thing is maybe to return all the files in case of empty criteria, maybe, thoughts? |
Though I assume you were asking that as a more general, question, I'll still put my thoughts down. This is basically a divide by zero situation. Does nothing match anything? More concretely, my suggest would to be return |
But ok, so if the behavior is undefined, maybe it is better to throw the error then, this is my biggest doubt. |
Soooo, what do we want to do with this? |
Seeking advice? 😀 The undefined behavior above that you describe is good, but I still think |
I was partially seeking those other opinions :) |
How about
Or something like that. Perhaps added to all the What do you think? |
I came to like the idea of an error actually there, so an assertion makes total sense to me. To all functions in order to specify what's missing. Totally.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
|
@DonyorM what do you think? Shall we finish this off? 😁 |
601cd23
to
63edf19
Compare
@arichiardi @martinklepsch Updated the commit. Let me know if I should ask anything else. |
63edf19
to
4a51c1c
Compare
boot/core/src/boot/core.clj
Outdated
@@ -1218,6 +1218,7 @@ | |||
"A file filtering function factory. FIXME: more documenting here." | |||
[mkpred] | |||
(fn [criteria files & [negate?]] | |||
(assert (seq criteria) "file-filet (called from by-*) requires a list of matching paths, if you want all files use boot.core/ls") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a lil' typo there and I would drop the if you want ...
because if you call it from by-ext
is a weird message back...my proposal:
boot.core/file-filter requires a list of criteria but null was passed in, make sure your `by-*` calls are passing them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Just pushed a new commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still don't see it, GitHub seems a bit slow today
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whoops, sorry, somehow didn't commit the changes.
de783e4
to
9d8446f
Compare
A part for Changelog and better working ( I am using to pass twice there lol) I think this is finally good to go 😀 |
9d8446f
to
f9213f1
Compare
@arichiardi Added changes.md. I put this under improved, since it's kind of new behavior |
Thanks a lot @DonyorM and sorry for this long conversation, I maybe swayed you a bit from the final solution but I see this is an improvement. I spent myself quite some time trying to figure out what the failure was and opened the issue in frustration 😁😁 this will avoid the trouble for other folks 👍 Good job! |
@arichiardi No problem. It wasn't simple to figure out the best way to do this. Thanks for your help! |
Anything else I need to do for this? |
No 👍 I think @alandipert or @micha will merge it eventually. |
👍 |
boot/core/src/boot/core.clj
Outdated
@@ -1218,6 +1218,7 @@ | |||
"A file filtering function factory. FIXME: more documenting here." | |||
[mkpred] | |||
(fn [criteria files & [negate?]] | |||
(assert (seq criteria) "boot.core/file-filter requires a list of criteria but null was passed in, make sure your `by-*` calls are passing them.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually null
could be nil
here but not too important haha :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
haha, I was stuck in java land there. Just pushed an update to change it.
This modifies the file-filter function so that if the criteria seq is empty, it throws an error.
f9213f1
to
c3046ac
Compare
This fixes issue #555
This modifies the file-filter function so that if the criteria seq is
empty, it simply returns an empty list.
An empty list was chosen instead of simply returning nil because an empty list allows seq functions (
conj
,cons
, etc.) to continue to work.