Thursday, December 17, 2009

Proposal for 1.2 : New Seq Utilities

Time to brainstorm everyone!

I've been trying to come up with new sequence functions. Of course, there's nothing really new about these at all. They just aren't in core or c.c.seq-utils. Do any of these belong in contrib or core?

alternate [pred coll]
returns an alternating collection. Similar to a regex partition.

split [pred coll]
returns a collection of collection, split by matching the predicate.

take-last [n coll]
The mirror of drop-last

take-until [pred coll]
Returns a lazy sequence of successive items from coll while (pred item) returns false. pred must be free of side-effects.

drop-until [pred coll]
Returns a lazy sequence of the items in coll starting from the first item for which (pred item) returns true.

rotate [n coll]
Take a collection and left rotates it n steps. If n is negative, the collection is rotated right. Executes in O(n) time.

rotate-while [pred coll]
Rotates a collection left while (pred item) is true. Will return a unrotated sequence if (pred item) is never true. Executes in O(n) time.

rotate-until [pred coll]
Rotates a collection left while (pred item) is nil. Will return a unrotated sequence if (pred item) is always true. Executes in O(n) time.

Anyway, I define all of these functions and more here:


Do others have ideas for missing seq utilities?

No comments:

Post a Comment