If maplist/tails, why not inits as well?

Prelude GOA Data.List> inits [1,2,3]
[[],[1],[1,2],[1,2,3]]

I've also found haskell's unfold useful:

(defn expand ;; since Clojure has "reduce" and not "foldl"
  [f seed]
  (lazy-seq (when-let [[a b] (f seed)] (cons a (expand f b)))))

As with maplist it can be implemented in terms of iterate, though I
think that implementation is unattractive. (And iterate can be
implemented in terms of it),

On Sun, Sep 30, 2012 at 7:51 AM, Marc Dzaebel <mdzae...@web.de> wrote:
> I often have the need to lazily iterate over rests of lists rather than
> elements. I frequently saw discussions about this topic. In CL it's called
> maplist, in Haskell it's tails (Scala missing?). Of course there are several
> methods to do this, e.g. (take-while identity (iterate next S)), but if you
> use them recursivly, code reads badly. So my proposal would be to have a
> kind of following function in the core:
>
> (defn maplist
>   ([s] (maplist identity s))
>   ([f s] (when-let [s (seq s)] (lazy-seq (cons (f s) (maplist f (next
> s)))))))
> ;(maplist [1 2 3]) -> ((1 2 3) (2 3) (3))
>
> Questions:
>
> Would such a method help more developers?
> Is there a conceptional reason, to omit a maplist equivalent in Clojure?
>
> Thanks, Marc
>
> --
> 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



-- 
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

-- 
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