Filtering calculated value with where function seems not working

Hey,

I build fairly complex data structure (from yaml files) in my template that I want to filter with the where function, but I simply couldn’t make it work. It took me quite some time to narrow down the (possible) reason enough to construct a minimal demonstrative example.

The following example works as expected, the GetSortedMapValues returns an array and the where function filters it based on the key ‘c’. The result is [map[a:2 b:7 c:7 d:[1 2 3] e:0xc000ecdee0]].

$q := newScratch
$q.SetInMap "foo" "A" (dict "a" 1 "b" 7 "c" 4)
$q.SetInMap "foo" "B" (dict "a" 2 "b" 7 "c" 7 "d" (slice 1 2 3) "e" newScratch)
where ($q.GetSortedMapValues "foo") "c" 7

But int the next example, where key ‘c’ holds an expression (that results 7), not a constant (and it is the case in my real code: I store a calculated value), the where function returns an empty array ([]).

$q2 := newScratch
$q2.SetInMap "foo" "A" (dict "a" 1 "b" 7 "c" 4)
$q2.SetInMap "foo" "B" (dict "a" 2 "b" 7 "c" (add 3 4) "d" (slice 1 2 3) "e" newScratch)
where ($q2.GetSortedMapValues "foo") "c" 7 

I would expect that the expression is evaluated and the where uses the value of that expression when it comes to filter. Using the expression in where gives the right result: [map[a:2 b:7 c:7 d:[1 2 3] e:0xc001e1a780]].

$q3 := newScratch
$q3.SetInMap "foo" "A" (dict "a" 1 "b" 7 "c" 4)
$q3.SetInMap "foo" "B" (dict "a" 2 "b" 7 "c" (add 3 4) "d" (slice 1 2 3) "e" newScratch)
where ($q3.GetSortedMapValues "foo") "c" (add 3 4)

Is it possible to apply the where function on the value of the expression instead of the expression itself?

Thank you in advance,
Gergő

environment: Hugo v0.55.6, linux64, go 1.12.4
ps: I thought it’s worth to mention that I can sort this data structure based on these calculated values, so sort function works as I expect.

I’ve used a workaround and made everything and expression like:

$q2 := newScratch
$q2.SetInMap "foo" "A" (dict "a" 1 "b" 7 "c" 4)
$q2.SetInMap "foo" "B" (dict "a" 2 "b" 7 "c" 6)
$q2.SetInMap "foo" "C" (dict "c" (add 3 4))
where ($q2.GetSortedMapValues "foo") "c" (add 0 7)

Actually, the real filter value comes from a variable and always adding zero to it makes my where expression work, but I fairly believe that something is wrong here.