Map on empty array


#1

Does anyone know what happens when you attempt to use the map filter on an array that’s empty? Say, for example, that you attempt:

site.pages | map: “path”

But site,pages doesn’t contain any pages. Will map return an empty array? Will it return false, or nil?


#2

Why not try it and see? If you add the inspect filter it should tell you.

{{ site.pages | map: “path” | inspect }}

#3

That’s awesome. I had no idea that existed. Thanks.


#4

Also, for things like this, Ruby’s irb (interactive shell, aka ‘REPL’) is great. You can start it by typing irb at the command line, then just run any Ruby command:

➜  ~   irb
2.5.3 :001 > [].map { |x| x.to_s }
 => []

#5

Thanks, I’ll give that a shot as well. Does IRB recognize all of Liquid’s filters?