GithubHelp home page GithubHelp logo

Comments (6)

joeytepp avatar joeytepp commented on May 29, 2024 3

The following code should work

payload = {
   a_key = array({ 1, 2, 3 })
}

from goluago.

joeytepp avatar joeytepp commented on May 29, 2024 1

Closing this as a solution was found.

from goluago.

fbogsany avatar fbogsany commented on May 29, 2024

This happens because we rely on an "array" marker to efficiently identify the table as an array:

if isArray(l, idx) {
return pullArrayRec(l, idx)
}

from goluago.

amomchilov avatar amomchilov commented on May 29, 2024

Thanks Joey, that works.

@fbogsany It looks like this Lua function can detect arrays in O(1), without needing to remember to tag them with a marker:

function is_array(tbl)
  return type(tbl) == 'table' and (#tbl > 0 or next(tbl) == nil)
end

This could be converted to go and be used by the JSON utilities. I'm curious how the performance compares.

The array function call works, but it's not very discoverable.

from goluago.

fbogsany avatar fbogsany commented on May 29, 2024

@amomchilov unfortunately, that isn't O(1). The length operator (#tbl in your example) is O(log n) where n is the largest natural key in the table: https://www.lua.org/manual/5.4/manual.html#3.4.7

from goluago.

amomchilov avatar amomchilov commented on May 29, 2024

Interesting!

Do you think that might be prohibitively expensive, though I'm not sure.

I wonder if there are anyways to increase the discoverability of the array function.

from goluago.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.