question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Evaluation of array.filter with function pointer not working

See original GitHub issue

Using the exampe template from the documentation of array.filter:

var result = Template.Parse("{{['', '200', '','400'] | array.filter @string.empty}}").Replace(new TemplateContext());

The above gives the desired result:

["", ""]

Using Evaluate instead of Replace:

var result = Template.Parse("{{['', '200', '','400'] | array.filter @string.empty}}").Evaluate(new TemplateContext());

returns an object of type ScribanRange. When trying to iterate the items in result, i get the following exception:

Value cannot be null. (Parameter 'callerContext')
  at Scriban.Syntax.ScriptFunctionCall.Call(TemplateContext context, ScriptNode callerContext, IScriptCustomFunction function, ScriptArray arguments)
  at Scriban.Functions.ArrayFunctions.FilterInternal(TemplateContext context, SourceSpan span, IEnumerable list, IScriptCustomFunction function, Type destType)+MoveNext()
  at Scriban.Runtime.ScriptRange.GetEnumerator()+MoveNext()

Expectation would be to either be able to iterate over the result or directly getting an array or list as a result. Am I doing anything wrong here?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
xoofxcommented, Feb 1, 2021

Fixed by commit d77a23736ecc3a90fe204799ee53e73a929e5870

0reactions
NeilMacMullencommented, Feb 1, 2021

nice - thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How is filter function working for different types of pointers?
A unique problem with your filter function is that creating a new array that potentially shares data with the previous array opens up...
Read more >
Function Pointers in C are Underrated : r/programming
I like function pointers as a mechanism for callbacks, but I'm not that sure if the author's example of a function pointer being...
Read more >
Arrays - Rhai - Embedded Scripting for Rust
Function Parameter(s) Description push , += operator array; element to append (not another array) appends an element to the... + operator first array; second array...
Read more >
Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >
array_filter - Manual
Iterates over each value in the array passing them to the callback function. If the callback function returns true , the current value...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found