<commit_before>local fn = {}


-- cond should be a predicate
fn.select = function(tab, cond)
   assert(type(cond) == 'function', 'cond must be a predicate function')
   local insert = table.insert
   local result = {}

   for _,v in pairs(tab) do
      if cond(v) then
         insert(result, v)
      end
   end

   return result
end



return fn

<commit_msg>fixed fn.select to properly iterate over all types of items<commit_after>local insert = table.insert
local fn = {}


local append = function(a, b)
   for _, v in ipairs(b) do
      insert(a, v)
   end
end


fn.select = function(tab, cond)
   assert(type(cond) == 'function', 'cond must be a predicate')
   local result = {}

   for _,v in pairs(tab) do
      if type(v) == 'folder' then
         local fresult = fn.select(v.icons, cond)
         append(result, fresult)
      elseif type(v) == 'page' then
         local fresult = fn.select(v, cond)
         append(result, fresult)
      elseif type(v) == 'icon' then
         if cond(v) then
            insert(result, v)
         end
      end
   end

   return result
end



return fn


{'fraction_non_alphanumeric': 0.10717529518619437, 'fraction_numerical': 0.0, 'mean_word_length': 2.3597560975609757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4963022', 'n_tokens_mistral': 361, 'n_tokens_neox': 346, 'n_words': 121}