-
Notifications
You must be signed in to change notification settings - Fork 14
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
homework-06-ataranchiev #8
base: main
Are you sure you want to change the base?
Conversation
(vec (for [line (line-seq f) | ||
:let [result (zipmap schema (string/split line #"[|]"))] | ||
:when (if (some? filter-k) | ||
(string/includes? (get result filter-k nil) filter-v) |
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.
Just got noticed, that here might be a problem if ID is small and may intersect with others as a same sub-string. Will think about it
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.
Didn't get your point. You split string by separator read and then it doesn't matter is ID big or small, as I think
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.
For instance "3" will be caught in ids like "33" "30" and so on. Because "inclides?" will find it as a sub string.
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.
Very good, you included mutability with atoms and some other tricks! Just try to find/google more simple & straightforward solutions when you making some complex & pepeatative parts.
name | ||
address | ||
phoneNumber))] | ||
(println line))) |
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.
Discover full magic of destructuring and avoid that complex nested doseq & for with let :)
(defn display-customers
[]
(doseq [{:keys [name address phoneNumber]} (get-customers)]
(println (format "Name: %s, Address: %s, Phone: %s"
name
address
phoneNumber))))
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.
Hmmm your solution works.... Actually I tried it and it didn't work. Seems that I made another mistake and decided that it is not possible in "for" without "let". Funny =)...
Thanks
(vec (for [line (line-seq f) | ||
:let [result (zipmap schema (string/split line #"[|]"))] | ||
:when (if (some? filter-k) | ||
(string/includes? (get result filter-k nil) filter-v) |
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.
Didn't get your point. You split string by separator read and then it doesn't matter is ID big or small, as I think
(let [customers (into {} | ||
(for [customer (get-customers) | ||
:let [{:keys [custID name]} customer]] | ||
[custID name])) |
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.
You do know zipmap
, I saw it above :)
(let [cs (get-customers)] (zipmap (map :custID cs) (map :name cs)))
But yes, it's a matter of taste
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.
Nice variant thanks 👍🏼
{name sum})) | ||
sales-with-default (if (seq sales) sales {"Not found" 0})] | ||
(doseq [line sales-with-default] | ||
(println (format "Name: %s, Sum: $%s" (key line) (val line)))))) |
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.
Again, the power of destructuring (doseq [[k v] sales-with-default] ...
(clear-screen) | ||
(doseq [menu ["1. Display Customer Table" "2. Display Product Table" | ||
"3. Display Sales Table" "4. Total Sales for Customer" | ||
"5. Total Count for Product" "6. Exit"]] |
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.
Dude, make it readable, split on different lines :)
"1. ...
"2. ...
...
"
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.
I don't know. But auto formatter did that
(defn -main | ||
[& args] | ||
(while true | ||
(condp = (menu) |
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.
case
will look nice here, but it's also a matter of taste
No description provided.