Fork me on GitHub
#beginners
<
2017-01-12
>
gadfly36107:01:54

If i have (def foo ["A" "B" "C"]) and (def bar [1 2 3]) ... is there a clean way where i can get [ ["A" 1] ["A" 2] ["A" 3] ["B" 1] ["B" 2] ["B" 3] ["C" 1] ["C" 2] ["C" 3] ] (order of resulting vector elements doesnt have to match as written). i can do it in a few lines, but i felt like there is a function that does this somwehere, maybe i am mistaken tho

rauh08:01:17

@gadfly361 Outer product can be done with for.

gadfly36108:01:50

I suppose this would work (mapcat #(for [x foo] (vector % x)) bar)

rauh08:01:58

@gadfly361

(for [a ["a" "b"]
      b [0 1]]
  [a b])

rauh08:01:55

Sorry, probably should've been more clear

gadfly36108:01:51

@rauh thank you for clarifying, that is exactly what i was hoping for! 🍻

sb10:01:08

Somebody have an idea what is the problem with that?

(assoc (ring.util.response/redirect "/addpass") :flash "Passwords don't match!”)
how can I add multi-params for this or how can I handle the best this flow in clojure?

sb10:01:34

(or just with cookie - session handling?)

gregnwosu14:01:16

trying to java interop onto a method defined in the java inherited parent class , but clojure claims the method is not there

gregnwosu14:01:55

(.withRegion  client [”eu-west-1”])

gregnwosu14:01:11

\am i doing interop wrong?

abarylko14:01:51

@gregnwosu what's the type of client ?

abarylko14:01:17

Not sure about the parameter you are passing

abarylko14:01:49

I see withRegion(Region ...) and withRegion(Regions ....)

gregnwosu15:01:27

(def secrets
  (let [
        provider (DefaultAWSCredentialsProviderChain.)
        client (AmazonDynamoDBClient. provider)
        region (Region/getRegion (Regions/EU_WEST_1))
        client-opts {
                                        ;
                     :access-key "someTest"
                     :secret-key "someTest"
                     }
        ]

    (.setRegion client [region])
    client))

kamillelonek16:01:04

is there any way to use local dependencies (project) for my Clojure project?

kamillelonek16:01:55

.
├── README.md
├── project.clj
├── repo
├── src
├── target
├── libraries
│   └── my-project
└── test

kamillelonek16:01:06

and how to add my-project as a dependency?

zzamboni16:01:32

Woohoo, I finished all the 4clojure problems 🙂

ballpointcarrot17:01:39

@kamillelonek if you’re “my-project” is built as a jar, you can add it to the :resource-paths in your project.clj

ballpointcarrot17:01:03

(saves you from building your own private Maven repo 😄 )

kamillelonek17:01:05

what if it's just a regular directory with the project

ballpointcarrot17:01:51

is it its own, separately managed project (has it’s own project.clj, builds on its own, etc)?

kamillelonek17:01:59

it's a library

kamillelonek17:01:08

regular Clojure library project

ballpointcarrot17:01:44

that’s fine - from a dep mgmt perspective, you shouldn’t be mixing your project sources though - they should be managed as two separate projects, and the artifacts from the build of the library should be brought in. You’re mixing them together, which actually makes it more difficult.

kamillelonek17:01:34

> you shouldn’t be mixing your project sources though - they should be managed as two separate projects

kamillelonek17:01:44

they have their own repositories

kamillelonek17:01:11

I just want to use my library in my application

kamillelonek17:01:16

in the simplest possible way

ballpointcarrot17:01:39

build a jar of the lib; add it to the resource-paths in the consuming project

kamillelonek17:01:26

lein2 doesn't support that

ballpointcarrot17:01:26

I mean, that does leave using a local maven repo, but ¯\(ツ)

kamillelonek17:01:35

I could use local maven repository, but lein deps doesn't seem to look at it at all

mruzekw17:01:46

I’m doing an exercise to learn clojure(script) which is basically a list of counters. You can add and remove counters as well as inc and dec the individual counters. I wondered if the following was a sound data model:

(def counters (atom [{:id 0
:amount 0}]))
as opposed to

mruzekw17:01:24

(def counters (atom {0 0}))

schmee17:01:29

maybe (def counters {0 (atom 0)})?

schmee17:01:57

so you can update the counters individually

mruzekw17:01:25

I currently pass an index to inc and dec individually.

manutter5117:01:50

I would probably start with an empty list: (def counters (atom []))

mruzekw17:01:21

And then make a vector of numbers/amounts?

manutter5118:01:38

Sorry, called away suddenly

manutter5118:01:27

Anyway, I was starting to say you should think about how you want to refer to your counters. If you’re just going to refer to “the first one” and “the second one” and so on, then you can just use an array of values

manutter5118:01:47

but that might cause problems because you said you want to add and remove counters, so if you have 3 counters [18 14 6], and you remove the first counter, you have to remember that the 14 is now the first counter, etc.

mruzekw18:01:29

Cool, makes sense. In my project you would always remove from the end of the list allowing use of subvec

manutter5119:01:39

sounds good. If you want to attach a specific ID to each different counter, I’d just us a map of id -> current-count, so something like {:a-counter 12, :b-counter 8}. It’ll be easier to work with than an array of objects

manutter5119:01:17

though with a plain map I think you might lose the ordering.