wqferr / functional Goto Github PK
View Code? Open in Web Editor NEWFunctional programming utilities implemented in pure Lua.
Home Page: https://wqferr.github.io/functional/
License: MIT License
Functional programming utilities implemented in pure Lua.
Home Page: https://wqferr.github.io/functional/
License: MIT License
Similar to Python's chain
Add missing functions under lax typing, e.g. function(any...): any...
f.iterate {'a', 'b', 'c', 'd'}
:enumerate()
:foreach(print)
Should produce
1 a
2 b
3 c
4 d
Hi, evilbadmad from reddit.
On string lambda, may consider a specific form that match more lambda calculus? eg.
(parameter-list)=>lua-or-lambda-expression instead of lua-expression
This allow not predefined variable name and making some functional handy, eg The currying function for 2 parameters function
local function add2(a,b)return a+b end local curry2 = _lambda'(f)=>(x)=>(y)=>f(x,y)' print(curry2(add2)(1)(3)) -- 4
Some memorization may help save some overhead too.
This my expandLambda function to transform before eval by loadstring/load
local function expandlambda(expr)
local params, body = expr:match'^(%b())=>(.*)'
if not params then return expr end
return string.format('function %s return %s end', params, expandlambda(body))
end
bye~
Just make sure to add it to exports, nothing fancy here
From lua-stdlib's functional module:
add = curry (function (x, y) return x + y end, 2)
incr, decr = add (1), add (-1)
Akin to python's zip.
Something like
function zip(...)
local iter = base_iter(blabla)
iter.sources = {...}
return iter
end
It probably won't be able to be used in Teal until variadic type arguments is stable.
Return the first or last value which passes a given predicate
There was an issue with the 'table.unpack' api. It wasn't available under LuaJIT or Lua 5.1. The unpack function was available instead. I already fixed it myself with a simple polyfill.
-- LuaJIT polyfill
if not table.unpack then
table.unpack = unpack
end
lambda("(x, y) => x*y"):bind(3) should be possible
This should create two buffered iterators which split the original according to a predicate
Most likely it should be placed in exports as
function identity(x)
return x
end
Should this be added here or in a separate package?
This lua-users page has some initial ideas. Obviously patching the Lua parser is not an option.
Currently I'm leaning towards the "Stringified Anonymous Functions" pattern.
Line 278 in b9f8179
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.