Re: [ANN] if-and

2013-06-10 Thread Jean Niklas L'orange
On Monday, June 10, 2013 10:20:20 PM UTC+2, Steven Degutis wrote: > Sometimes I've wanted a function that takes a value and a bunch of tests, > and returns it if it passes every test, otherwise nil. > > Does this seem useful enough to put into core? > > A simpler variant already exists in core,

Re: [ANN] if-and

2013-06-10 Thread Ben Wolfson
On Mon, Jun 10, 2013 at 6:55 PM, Cedric Greevey wrote: > Hmmm? Maybe > > (defn if-and [x & tests] > (if (every? true? (map #(% x) tests)) x)) > > for a version that's a function, would short-circuit but for seq chunking, > and returns nil or x. > Yes, that's why you might as well use this: u

Re: [ANN] if-and

2013-06-10 Thread Cedric Greevey
Hmmm? Maybe (defn if-and [x & tests] (if (every? true? (map #(% x) tests)) x)) for a version that's a function, would short-circuit but for seq chunking, and returns nil or x. Incidentally, I think you can dechunk any seq with (map first (take-while seq (iterate next s))), but haven't tested t

Re: [ANN] if-and

2013-06-10 Thread Jiaqi Liu
you can just use (every? true? '(arg1 arg2 )) or def a simple function . i think the Core is powerful enough. 2013/6/11 Cedric Greevey > There's also the defmacro route: > > (defmacro if-and [test-expr binding & tests] > `(let [~binding ~test-expr] > (and ~@(concat tests [binding])))

Re: [ANN] if-and

2013-06-10 Thread Cedric Greevey
There's also the defmacro route: (defmacro if-and [test-expr binding & tests] `(let [~binding ~test-expr] (and ~@(concat tests [binding] Evaluates test-expr, then evaluates to the result of that if the tests all pass, and to a falsey value otherwise (in fact, the first falsey value ret

Re: [ANN] if-and

2013-06-10 Thread Ben Wolfson
On Mon, Jun 10, 2013 at 1:20 PM, Steven Degutis wrote: > Sometimes I've wanted a function that takes a value and a bunch of tests, > and returns it if it passes every test, otherwise nil. > > So I wrote if-and: > > (if-and "foo" > > string? > #(.startsWith % "f") > #(.cont

[ANN] if-and

2013-06-10 Thread Steven Degutis
Sometimes I've wanted a function that takes a value and a bunch of tests, and returns it if it passes every test, otherwise nil. So I wrote if-and: (if-and "foo" string? #(.startsWith % "f") #(.contains % "oo")) ;; => "foo" (if-and "foo" string? #(.start