lyl
lyl

Reputation: 293

How to prevent "collect/keep" function from flatting its result

>> a: [[1 2] "a" a [3 3]]
== [[1 2] "a" a [3 3]]
>> collect [foreach x a [if block? x [keep x]]]
== [1 2 3 3]

But what I want is [[1 2] [3 3]]. It seems that collect/keep would flat the result(in term of block). How to prevent it?

Upvotes: 1

Views: 58

Answers (1)

9214
9214

Reputation: 2193

Use keep/only. FYI, keep has almost the same semantics as append (barring a few refinements) with an implicit block that collect provides internally: see ?? collect for the details.

Upvotes: 2

Related Questions