Fork me on GitHub
#beginners
<
2016-03-15
>
puppybits01:03:09

Is there a way to get previous items in a seq when iterating over it?

puppybits01:03:28

For instance if I have a sort list of timestamps and want to count how many timestamps have previously been recorded for the same date.

eggsyntax02:03:15

@puppybits: Often you don’t want to think about iterating over it, but rather transforming it into something that gives you what you want. In your case it sounds like you probably want partition-by (https://clojuredocs.org/clojure.core/partition-by) or take-while (https://clojuredocs.org/clojure.core/take-while). Or if those aren’t what you’re looking for, can you say a bit more fully what you’re trying to do?

danmidwood02:03:22

Not really, but take a look at group-by using a function to get the date

danmidwood02:03:46

It will return a map of date->[item], and from there you can count the items for each date

eggsyntax02:03:46

Or (frequencies (map date-of timestamps)) (where timestamps is your list of timestamps, and date-of is a function that takes a timestamp and returns the date part of it).

puppybits03:03:22

Yeah I was thinking about the 'group-by' & 'partition-by' it sounds like I need to separate it out first and then run the operation on an entire group.

mariogintili14:03:37

I've just finished the clojure-koans and I'm really happy with it

mariogintili14:03:51

I'd like to practice a bit more clojure, anyone recommend any resources?

mariogintili14:03:59

I'm looking to implement a pet project rather than anything else

clojuregeek14:03:19

you could do the small problems here http://exercism.io/

clojuregeek14:03:37

but yes, a great way is it just dive in and work on a real project.

jsteve121214:03:26

we’ve got a high of 93*F in Austin today 😛

yogidevbear15:03:54

@mariogintili: You could try http://www.codewars.com/ (I haven't delved into it yet, but they do have Clojure listed on the homepage)