Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

ewok
Copy link

@ewok ewok commented Jul 23, 2024

No description provided.

(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)
Copy link
Author

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

Copy link

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

Copy link
Author

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.

Copy link

@Ivana- Ivana- left a 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)))
Copy link

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))))

Copy link
Author

@ewok ewok Jul 23, 2024

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)
Copy link

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]))
Copy link

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

Copy link
Author

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))))))
Copy link

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"]]
Copy link

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. ...
...
"

Copy link
Author

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)
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants