mostjs / prelude Goto Github PK
View Code? Open in Web Editor NEWMoved to https://github.com/mostjs/core
Moved to https://github.com/mostjs/core
This would add some kb for sure, but the work there seems pretty solid and follows Fantasy Land. WDYT?
The recent addition of the module
field in #14 is not being used correctly.
The module
field is suppose to point to code that "has ES2015 module syntax but otherwise only syntax features that browser/node supports." However the current module field points to the src folder - which still contains es6 features (e.g. let
).
Maybe it would be better to also transpile the source to a lib
folder where the code is all es5 expect for the es6 import/export syntax. Then that lib
code could be exposed via the module
field.
There's a jsnext:main
field in package.json, but there should be a module
field too.
While attempting to use @most/prelude
's compose function to make my own switchMap
, like
import { map, switchLatest } from 'most'
import { compose } from '@most/prelude'
const switchMap = compose(switchLatest, map)
I ran into an error and realized it was because map needs to take in multiple arguments. I got around the problem by writing my own compose function in the library, like this:
const compose2 = (f, g) => (...args) => f(g(...args))
const switchMap = compose2(switchLatest, map)
And we could do the same with apply:
const apply = (f, ...args) => f(...args)
or maybe
const applyArray = (f, argsArr) => f(...argsArr)
I realize I could still accomplish the same things by using prelude's compose/apply + the curry functions, but it would require additional steps and would be less convenient.
We could also add partial application:
const partial = (f, ...args) => (...rest) => f(...args, ...rest)
And it might be more than what's wanted or is necessary for prelude, but we could go further by defining a fold1
to help create a variadic compose
:
// like foldl1 in Haskell
const fold1 = (f, arr) => {
if (!arr.length) {
throw Error('fold1 must only be applied to non-empty lists')
}
let acc
for (let i = 0; i < arr.length; i++) {
acc = !acc ? arr[i] : f(acc, arr[i])
}
return acc
}
const compose2 = (f, g) => (...args) => f(g(...args))
// compose function for when the function arity is unknown
const compose = (...fs) => fold1(compose2, fs)
Thoughts on changing and/or adding any of these?
Could we modify the structure of the build to enable modular imports (like what Ramda offers under ramda/src/...
) so that all of @most/prelude
isn't included when we only need a few utility functions from it?
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.