Coder Social home page Coder Social logo

Lua: vim.func functional utils about neovim HOT 3 OPEN

justinmk avatar justinmk commented on May 27, 2024
Lua: vim.func functional utils

from neovim.

Comments (3)

lewis6991 avatar lewis6991 commented on May 27, 2024 1

nil is the very annoy params in lua because it not only none value but also absent argument. we can not tell the difference, so if we curry the method, the nil args is rejected to send or the method will return a curried function as a invalid result.

I don't think this is true. select('#', ...) should tell you the number of passed arguments, including any tailing nil's.

I would implement currying as this:

local function curry(fn, ...)
  local n, args = select('#', ...), { ... }
  return function(...)
    local fargs = {}
    for i = 1, n do
      fargs[i] = args[i]
    end
    for i = 1, select('#', ...) do
      fargs[n+i] = select(i, ...)
    end
    return fn(unpack(fargs, 1, n + n2)
  end
end

local curried = curry(f, 1, 2, 3, 4, nil, nil)

curried(5, 6, 7, nil)
-- equiv to:
-- f(1, 2, 3, 4, nil, nil, 5, 6, 7, nil)

from neovim.

justinmk avatar justinmk commented on May 27, 2024
curried(5, 6, 7, nil)

Is that currying or partial application? https://stackoverflow.com/a/218055/152142

from neovim.

lewis6991 avatar lewis6991 commented on May 27, 2024

Ah yeah, it's creating a partial, which is what you usually want.

I'm sure the same concept can be used to create a currying function.

from neovim.

Related Issues (20)

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.