Using `apply` on slice of slices

Hi all,

So in a template I wanted to obtain a slice of lengths from a slice of slices.
Crafted examples:

{{- $lengths := apply (slice (slice 1 2) (slice 3 4)) "len"  -}}

throws

... executing "*.html" at <apply (slice (slice 1 2) (slice 3 4)) "len">: error calling apply: runtime error: index out of range [0] with length 0

With context:

{{- $lengths := apply (slice (slice 1 2) (slice 3 4)) "len" "." -}}

throws

... executing "*.html" at <apply (slice (slice 1 2) (slice 3 4)) "len" ".">: error calling apply: called apply using []int as type reflect.Value

I expected it to work and I had to resort to slice-range-append method, any thoughts on this? Thank you.

Given:

{{ $s1 := slice
  (slice "a" "c" "b")
  (slice "f" "d" "e")
}}

These functions that operate on a slice all work as expected:

{{ apply $s1 "after" 1 "." }}
{{ apply $s1 "delimit" "." ", " ", and " }}
{{ apply $s1 "in" "." "a" }}
{{ apply $s1 "index" "." 0 }}
{{ apply $s1 "shuffle" "."  }}
{{ apply $s1 "sort" "." "value" "asc" }}

It seems to me that len should work too.

Please log a bug.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.