public IEnumerable IndexingFunction(IEnumerable <dynamic> items) { try { EnsureGroupItemCreated(); foreach (DynamicBlittableJson item in items) { if (_groupedItems.TryGetValue(item.BlittableJson, out var list) == false) { list = new List <BlittableJsonReaderObject>(); _groupedItems[item.BlittableJson] = list; } list.Add(item.BlittableJson); } foreach (var item in _groupedItems.Values) { Engine.ResetCallStack(); Engine.ResetStatementsCount(); Engine.ResetTimeoutTicks(); _oneItemArray[0] = ConstructValues(item); JsValue jsItem = null; try { jsItem = Reduce.Call(JsValue.Null, _oneItemArray).AsObject(); } catch (JavaScriptException jse) { var(message, success) = JavaScriptIndexFuncException.PrepareErrorMessageForJavaScriptIndexFuncException(ReduceString, jse); if (success == false) { throw new JavaScriptIndexFuncException($"Failed to execute {ReduceString}", jse); } throw new JavaScriptIndexFuncException($"Failed to execute reduce script, {message}", jse); } catch (Exception e) { throw new JavaScriptIndexFuncException($"Failed to execute {ReduceString}", e); } yield return(jsItem); _resolver.ExplodeArgsOn(null, null); } } finally { _oneItemArray[0] = null; _groupedItems.Clear(); } }