Fork me on GitHub
#beginners
<
2018-07-11
>
eggsyntax01:07:30

@klaus.azesberger you may want to try adding expound to your project; it'll make those giant spec errors much more readable. https://github.com/bhb/expound

martin_rdz10:07:46

Hello everybody, a beginner question regarding clojurescript tooling: What is the difference between figwheel and figwheel-main? Which one would you recommend? Thanks in advance!

delaguardo11:07:11

Pick up figwheel if you are using leiningen or boot for building cljs. figwheel-main is mostly for tools.deps utility which is new and still in alpha

martin_rdz11:07:05

Ok, thanks for the advice 🙂 Is there any overview on best practice configuration of leiningen for cljs dev and build? I mean apart from the various templates (eg reagent-figwheel, figwheel, mies) which differ quite alot in structure and complexity?

delaguardo11:07:36

There is no silver bullet, unfortunately. I can suggest to play with compiler options and find out the best configuration for yourself. Templates can be a good starting point on that way) For myself I usually starting with basic minimum (just cljs-build) and add complex tools only when I have some problems, like need to reload webpage often to reload source code or need to connect my IDE with running program.

delaguardo11:07:48

It is not the simplest way but as long as you following it will give you a lot in terms of understanding what is going on and how to solve it

martin_rdz11:07:05

maybe doing it manually is the best path anyways. thanks a lot!

matan14:07:07

mind blank: I got a function that initializes a certain specialized data structure, and a function that adds an element to it. Any reason not to bundle them into an object? or what would be the most idiomatic way to provide users with an easy way to use instances of this duo?

donaldball15:07:27

I would look to bundle them into an object myself. If it’s a persistent data structure, implementing IPersistentCollection would be a way to hook into familiar clojure.core fns.

matan18:07:27

Oh, nice tip about IPersistentCollection

matan18:07:06

Any recommendation from within this group of alternative paths for implementing an interface? https://clojure.org/reference/java_interop#_implementing_interfaces_and_extending_classes

donaldball18:07:06

For implementing a data structure, I would look to deftype or reify

👍 4
matan18:07:16

Thanks @donaldball anyway, is there a purely functional counterpart to this?

matan18:07:17

I guess not; just making all those functions that work on my specialized data structure sit in their own namespace, leaving it to users to abuse them on the wrong data types

Mario C.18:07:46

Question: Is there a way I can pattern match on map keys? For example, say I have a map with many different keys and I'd like to filter out some of those based on their key-name. Something along the lines of (dissoc my-map (regex that matches on key name))

Mario C.18:07:59

Another way to put it is that I want to filter out any keys that may contain the word password or phrase pass.

noisesmith18:07:05

I would do this via reduce-kv - there's no solution that isn't a linear scan on all keys

Mario C.18:07:50

But is there a way I can check if a key contains a word/phrase?

noisesmith19:07:57

what's the type of the key? if it's a keyword name gives you a string not including (optional) namespace

noisesmith19:07:11

str gives you the actual string representation of course

Mario C.19:07:18

(filter (fn [[key val]] (= nil (re-find #"pass" (str key)))) my-map)

Mario C.19:07:40

I was able to get it done using that. But I don't understand why I get a vector back?

Mario C.19:07:37

If the input is this {:example "value-a" :sql-pass "abc123" :my-password "hunter2"}

Mario C.19:07:54

The result I get is ([:example "value-a"])

Mario C.19:07:46

Nevermind. That is actually expected

noisesmith19:07:53

you can use into with the filter transducer here

noisesmith19:07:15

(into {} (filter f?) m)

noisesmith19:07:22

where f? is your fn above

Mario C.19:07:26

Yea thats what I ended up doing

noisesmith19:07:37

note that m is outside the filter call

noisesmith19:07:13

the other way works too, but filter's transducer is preferable in cases like this where it can be used

Mario C.19:07:07

Why is it preferable?

noisesmith19:07:37

it directly filters the values going into the hash-map, instead of making a lazy-seq and then putting that into a hash-map

noisesmith19:07:59

also (filter f) can be composed directly with other transformations

noisesmith19:07:27

but maybe you don't need this in #beginners 😄

Mario C.19:07:21

:thumbsup: :thumbsup:

Ivan_Romanof19:07:09

How will this code look like on Clojure

const func  = (x, y) => f => f(x, y)
?

dpsutton19:07:47

(defn func [x y] (fn [f] (f x y)))

noisesmith19:07:46

that fn could equivalently be #(% x y)

Rachna22:07:48

Hello everyone, I need help in printing the cell data of column A and Column B in REPL. How can I print it? This is what I coded till now: (defn sheet "Return all the sheet [sheet] from file [file-path]" [file-path sheet-name] (->> (load-workbook file-path) (select-sheet sheet-name) (select-columns {:A :col1, :B :col2}) ) )

mfikes23:07:51

@rachna.rajput99 If you’d like a nice tabular printout clojure.pprint/print-table is nice.