rebolred-lang

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?


Solution

  • 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.