I'm having trouble seeing how I should create a lazy sequence of all
Mondays and Thursdays.  Currenty I just generate two sequences, one of
Mondays and one of Wednesdays, but this leaves me with a seq of seqs which
is making future calculations on this sequence more complicated than I'd
like.

Below are the functions I am using currently to create a day of the week
stream. Ex.

  (fact
    (take 3 (day-of-week-stream 1)) => [(DateMidnight. 2011 11 7)
(DateMidnight. 2011 11 14) (DateMidnight. 2011 11 21)])

I'd like to be able to do this:

  (fact
    (take 4 (day-of-week-stream 1 4)) => [(DateMidnight. 2011 11 7)
(DateMidnight. 2011 11 10) (DateMidnight. 2011 11 14) (DateMidnight. 2011
11 17)])


(defn today+all-future-dates []
   (iterate #(.plusDays % 1) (DateMidnight.)))

(defn- next-day-of-week-in-future [day-num]
  (first (filter  #(= day-num (.. % dayOfWeek get))
(today+all-future-dates))))

(defn day-of-week-stream [day-num]
  (iterate #(.plusDays % 7) (next-day-of-week-in-future day-num)))

Any suggestions?

Alex

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to