Fork me on GitHub
#beginners
<
2016-03-17
>
samueldev16:03:02

@bronsa: is correct, some is what I wanted

lmergen19:03:36

ok, i'm confused. i need to map, but at the same time, also keep track of a counter and increment it by one

lmergen19:03:01

for can iterate over two lists at the same time, but is like two nested for loops

lmergen19:03:40

what is the name of the function i'm looking for? or do i really need to start using recursion for this?

edbond19:03:39

@lmergen: map-indexed maybe

noisesmith19:03:33

lmergen: a cool trick is (for [[i x] (map list (range) coll)] ...) so you get the numeric index and the value for each item

lmergen19:03:26

map-indexed sounds like what i need

lmergen19:03:58

and well... i like that trick, but it decreased the readability of my code a lot simple_smile

noisesmith19:03:00

d'oh, reading comprehension fail, you mentioned map not for as your first choice, right

lmergen19:03:02

yes, well, actually, i just need to iterate over a lazy sequence, apply a function with side effects on it, but i don't care about the results

lmergen19:03:07

oh yeah, and i also need that counter

noisesmith19:03:42

oh, in that case use (dorun (map-indexed ...))

lmergen19:03:55

yeah, that's what i'm doing

noisesmith19:03:06

or (doseq [[i x] (map list (range) coll)] ...)

lmergen19:03:08

i wondered whether there was some doseq-indexed simple_smile

noisesmith19:03:57

lmergen: it would totally be worth it to implement run-indexed! - run! is like map but side effects only

lmergen19:03:26

but, but... where would i put that function

lmergen19:03:36

i'm not starting my own clojure semi-standard library simple_smile

noisesmith19:03:14

=> (defn run-indexed! [f coll] (reduce (fn [i x] (f i x) (inc i)) 0 coll))
#'run-indexed!
=> (run-indexed! println [:a :b :c])
0 :a
1 :b
2 :c
3

lmergen19:03:05

is there some semi-standard filename where people put their "algorithms" or their own custom handy functions?

noisesmith19:03:49

lmergen: there's user.clj I guess, but I think it's normal for a given dev or organization to have their own "util" lib that they habitually pull in

lmergen19:03:35

right, we actually have that already, but it's usually a little bit less abstract

Chris O’Donnell20:03:02

Design question. For internal application code, how do you decide between throwing an exception and returning error data, eg. {:error info}?

noisesmith20:03:38

codonnell: I do the compromise of the two, and I throw an instance of ex-info

noisesmith20:03:54

being able to throw reduces the number of branches in the code, and it's nice to be able to keep the flow for unexceptional cases clearer

noisesmith20:03:10

*visible branches - of course each throw is really a goto

Chris O’Donnell20:03:51

I hadn't thought of it in terms of code flow. That's a really good point.

roberto21:03:16

I think this is an interesting way of handling errors and exceptions also http://docs.caudate.me/hara/hara-event.html

jreedmoore21:03:06

not really sure if this is a 'beginners' topic, but... I'm trying to get a Clojure REPL in an existing Java/maven monolith project that leans heavily on Spring and AspectJ and ilk

jreedmoore21:03:24

wondering what pitfalls await me

lmergen21:03:00

that sounds ambitious

jreedmoore21:03:51

so, there's a small set of classes that I want to interact with. They don't really need to be integrated with all this Spring/AspectJ nonsense

jreedmoore21:03:01

but I'm also trying to avoid having to pull them out into a separate artifact