template <typename Collection, typename V8Collection, typename Fn>
static void SaveEach(V8Collection& v8collection, Collection& collection, Fn& callback){
auto len = v8collection.Length();
for(auto i=0; i<len; i++){
auto tmp = callback(v8collection[i]);
if(!isEmpty(tmp))
collection.push_back(tmp);
}
}
template <typename V8Collection, typename Fn>
static auto
Search(V8Collection& v8collection, Fn& callback) ->decltype(callback(v8collection[0])) {
auto len = v8collection.Length();
for(auto i=0; i<len; i++){
auto tmp = callback(v8collection[i]);
if(!isEmpty(tmp))
return tmp;
}
return nullptr;
}
template <typename Methods, typename Fn>
static auto CreateJSObject(Methods& methods, int hashcode, Fn& callback ) ->decltype(Nan::New<v8::Object>()) {
auto object = Nan::New<v8::Object>();
for(auto method: methods) {
auto fnCallback = Nan::New<v8::FunctionTemplate>(callback);
std::string name = method.GetName() + "@" + std::to_string(hashcode);
fnCallback->SetClassName(Nan::New( name ).ToLocalChecked());
object->Set(Nan::New( method.GetName() ).ToLocalChecked(),
fnCallback->GetFunction() );
}
return object;
};
};
}
#endif /* ella_utils_hpp */