Fork me on GitHub
#beginners
<
2019-10-08
>
David Pham07:10:52

Is there a reason why filterv does not have the same signature as mapv

penryu08:10:38

@neo2551 I expect it's because filterv only accepts a unary predicate, whereas mapv will accept a transforming function with different arities to map over multiple collections at once.

penryu08:10:38

If the question is "Why doesn't filterv filter over multiple collections at once?" ... I guess I'm not sure what that would look like.

David Pham09:10:12

Thanks! I still wonder why we could not filter with predicates accepting multiple arities though.

David Pham09:10:51

A predicate is a transformation returning a falsy or truthy value from its arguments

David Pham09:10:10

Maybe I miss something.

penryu09:10:59

@neo2551 Yeah, you could consider filter as a special case of map[T,Bool]. Which means you could implement a sort of filter over multiple colls using map

hendore14:10:14

I’ve noticed a convention of adding a ! suffix to function names that have side effects, so I have a few functions that insert/update a database such as create-account! add-booking! etc… This got me thinking, functions that query the database are also not pure functions as the result may be different (if someone was to edit the database) so should functions such as get-booking also share the same convention?

hendore14:10:51

Also, if create-account! is called from a register function, should I also suffix the register function with ! as it has side effects?

hendore14:10:23

I understand it makes no difference at all but would just like to get into good habits whilst learning

danielneal14:10:44

Yep, when I’ve seen this convention, only the side-effecting functions tend be indicated by the !, rather than all impure functions. So get-booking wouldn’t have a ! but register! probably would.

hendore14:10:16

Sweet :thumbsup:

dharrigan14:10:28

I mostly use ! for things that my program modifies, i.e., writing to file, writing to a database, sending data across the wire. Things which I consume, I don't suffix with ! (unless I then modify and write out, external to my application)

☝️ 4
dharrigan14:10:54

that's just my style of doing it

chris_johnson15:10:13

> functions that query the database are also not pure functions as the result may be different (if someone was to edit the database) so should functions such as get-booking also share the same convention

chris_johnson15:10:40

In this case the result of the function isn’t idempotent but it’s not your function that mutates state

chris_johnson15:10:00

! in my understanding means “look out! This function changes state somewhere!”

hendore15:10:41

Thanks for clearing this up @danieleneal @dharrigan @chris_johnson this was all very helpful info.

Michaël Salihi21:10:59

Hi ! I I would like to know if it's possible to populate deps.edn dependencies in command line or some externals tools ? Right now, I use clj-refactor with cljr-add-project-dependency in Emacs but it only works when a REPL is already running.

alexmiller21:10:06

I'm not aware of anything like that right now

Michaël Salihi21:10:53

OK thank you @alexmiller. Is this something that could be useful and above all feasible?

hendore12:10:09

Certainly something I was looking for the other day (coming from other languages that have package managers to install and update deps) I was surprised to find there wasn’t anything like this for clojure.