clojure.core/halt-when¶
Returns a transducer that ends transduction when pred returns true for an input. When retf is supplied it must be a fn of 2 arguments - it will be passed the (completed) result so far and the input that triggered the predicate, and its return value (if it does not throw an exception) will be the return value of the transducer. If retf is not supplied, the input that triggered the predicate will be returned. If the predicate never returns true the transduction is unaffected.
Examples¶
Note by glts¶
halt-when is an odd transducer in that it is supposed to be used with transduce, but not in other transducible contexts like sequence or into.
Says Alex Miller at https://dev.clojure.org/jira/browse/CLJ-1451: ‘Yeah, halt-when is a little tricky to use in transducible contexts other than transduce.’ Some more discussion at https://groups.google.com/d/msg/clojure/6HvmJIUsXKk/gLqUsfcnAwAJ.
Note by holyjak¶
Not anymore, as pointed out above, at least into works fine under Clojure 1.11
See also¶
Content from the matching ClojureDocs page, with authors credited on each contribution.