Welcome! Please see the About page for a little more info on how this works.

+1 vote
in Transducers by

Discussion: https://groups.google.com/d/topic/clojure-dev/NaAuBz6SpkY/discussion

It comes up when I would otherwise use (take-while pred coll), but I need to include the first item for which (pred item) is false.

(take-while pos? [1 2 0 3]) => (1 2) (take-until zero? [1 2 0 3]) => (1 2 0)

Patch: clj-1451.patch

  • Includes transducer arity of take-until
  • Includes inclusion in transducer generative tests

21 Answers

0 votes
by

Comment made by: alexmiller

Patch welcome (w/tests).

0 votes
by

Comment made by: ataggart

Impl and tests for take-until and drop-until, one patch for each.

0 votes
by

Comment made by: wagjo

Please change :added metadata to "1.7".

0 votes
by

Comment made by: ataggart

Updated to :added "1.7"

0 votes
by

Comment made by: jbm

I'd like to propose {{take-through}} and {{drop-through}} as alternative names. I think "through" communicates more clearly how these differ from {{take-while}} and {{drop-while}}.

0 votes
by

Comment made by: jafingerhut

Both patches CLJ-1451-drop-until.patch and CLJ-1451-take-until.patch dated Jun 20 2014 no longer apply cleanly to latest Clojure master due to some changes committed earlier today. I haven't checked whether they are straightforward to update, but would guess that they merely require updating a few lines of diff context.

See the section "Updating stale patches" at http://dev.clojure.org/display/community/Developing Patches for suggestions on how to update patches.

0 votes
by

Comment made by: gshayban

Would be nice to cover the transducer case too.

0 votes
by

Comment made by: michaelblume

rerolled patches

0 votes
by

Comment made by: michaelblume

Covered transducer case =)

0 votes
by

Comment made by: michaelblume

Actually I like take/drop-through as well

0 votes
by

Comment made by: gshayban

Michael, no volatile/state is necessary in the transducer, like take-while. Just wrap in 'reduced to terminate

0 votes
by

Comment made by: michaelblume

a) you're clearly right about take-until

b) seriously I don't know what I was thinking with my take-until implementation, I'm going to claim lack of sleep.

c) I'm confused about how to make drop-until work without a volatile

0 votes
by

Comment made by: michaelblume

Ghadi and I discussed this and couldn't think of a use case for drop-until. Are there any?

Here's a new take-until patch, generative tests included.

Open questions:

Is take-until a good name? My biggest concern is that take-until makes it sound like a slight modification of take, but this function reverses the sense of the predicate relative to take.

0 votes
by

Comment made by: jafingerhut

Michael, while JIRA can handle multiple attachments for the same ticket with the same name, it can get confusing for people trying to determine which one with the same name is meant. Could you remove or rename one of your identically-named attachments? Instructions for deleting patches are in the "Removing patches" section on this wiki page: http://dev.clojure.org/display/community/Developing Patches

0 votes
by

Comment made by: alexmiller

The patch was slightly stale so I updated to apply to master, but it's almost identical. Attribution retained.

Marked as prescreened.

...