selfrefactor / rambdax Goto Github PK
View Code? Open in Web Editor NEWExtended version of Rambda
Home Page: https://selfrefactor.github.io/rambdax
License: MIT License
Extended version of Rambda
Home Page: https://selfrefactor.github.io/rambdax
License: MIT License
I'm getting UglifyJs Unexpected token
error when trying to create production build in my project
I think, it's due to fact that by default, webpack does not transpile code in node_modules
but can understand import/export
modules.
It makes sense to use babel with preset ["env", {"modules": false }]
so it only leaves modules that can be used for tree shaking.
For cases when pure ES6 version is desired, it can be sourced from modules
source folder
const source = {a: {b: {c: 0, extra: "hey"}}}
const result = R.assocPath(['a', 'b', 'c'], 42, source)
result
console.log("extra=" + R.path(['a', 'b', 'extra'], result))
result to contain all original props at a.b
level, including extra
only a.b.c
is left
works in original Ramda repl
mapasync over objects
I don't know is it intentional, but I honestly anticipated defaultValue, but got an obj instead
This link leads to 404 - https://selfrefactor.gitbooks.io/blog/content/argumenting-rambdas-curry.html
And btw can I somehow do the same as ramda's curryN in rambdax?
Examples for async functions
mapAsync
mapFastAsync
debounce
pipeAsync
async
that is missing.Also found from running examples for many other of the functions (not all):
isType
for 'Async' type.partialCurry
is missing R.
in the example. Same for piped
, replaceAll
, splitAt
, symmetricDifference
& remove
.path
seems to return null
instead of undefined
. Same for prop
.pathOr
example is broken with syntax errors.paths
, and same problem as with path
as well.
props
.pick
does not match expected.pickAll
.pluck
, split
, set
, reject
, subtract
& produce
.propIs
& slice
.removeIndex
function is broken?sortByProps
is using sortByPath
!On another note: sort
and sortBy
difference should be better clarified I think.
Since this commit 65acf77 many dependent packages broke because contains
has been replaced by includes
.
So I think that 2.13.1
should have been a major (or at least a minor) bump since it contains such a breaking change.
From the changelog:
"6.0.0
Breaking change - R.map/R.filter/R.reject/R.forEach/R.partition doesn't pass index as second argument to the predicate, when looping over arrays. The old behaviour of map, filter and forEach can be found in Rambdax methods R.mapIndexed, R.filterIndexed and R.forEachIndexed(introduced in version 6.1.0)."
But rejectIndexed
was not added together with the others (and not partitionIndexed
either?).
Also, the rejectIndexed
REPL is broken.
Interface for "then" is in index.d.ts, but there is no then.js or then.spec.js in src folder
Typescript definitions are not great.
export const typesOfCommitRaw: CommitType[] = [
DOCS,
FEATURE_END,
FEATURE_START,
FIX_START,
FIX_END,
REFACTOR,
SUPPORT,
TEST_END,
TEST_START,
]
export const typeOfCommit: string[] = typesOfCommitRaw.map(x => x.key)
Creating typeOfCommit
with Rambda in Typescript context is not possible.
E.g.:
R.toPairs
R.fromPairs
take(n: number, input: string): string
take(n: number, input: T[]): T[]
take(n: number): {
(input: string): string
(input: T[]): T[]
}
This issue will be kept open to keep track of various suggestion for new Rambdax methods
Hi! ๐
Firstly, thanks for your work on this project! ๐
Today I used patch-package to patch [email protected]
for the project I'm working on.
Here is the diff that solved my problem:
diff --git a/node_modules/rambdax/dist/rambdax.esm.js b/node_modules/rambdax/dist/rambdax.esm.js
index 40b97d1..d2828f9 100644
--- a/node_modules/rambdax/dist/rambdax.esm.js
+++ b/node_modules/rambdax/dist/rambdax.esm.js
@@ -554,6 +554,7 @@ function filterObject(predicate, obj) {
return willReturn;
}
function filterArray(predicate, list, indexed = false) {
+ if (arguments.length === 1) return _list => filterArray(predicate, _list);
let index = 0;
const len = list.length;
const willReturn = [];
@@ -644,6 +645,7 @@ function filterIndexed(predicate, iterable) {
const _keys = Object.keys;
function mapArray(fn, list, isIndexed = false) {
+ if (arguments.length === 1) return _list => map(fn, _list);
let index = 0;
const willReturn = Array(list.length);
@@ -655,6 +657,7 @@ function mapArray(fn, list, isIndexed = false) {
return willReturn;
}
function mapObject(fn, obj) {
+ if (arguments.length === 1) return _obj => mapObject(fn, _obj);
let index = 0;
const keys = _keys(obj);
diff --git a/node_modules/rambdax/dist/rambdax.js b/node_modules/rambdax/dist/rambdax.js
index 4fba505..3715a8c 100644
--- a/node_modules/rambdax/dist/rambdax.js
+++ b/node_modules/rambdax/dist/rambdax.js
@@ -558,6 +558,7 @@ function filterObject(predicate, obj) {
return willReturn;
}
function filterArray(predicate, list, indexed = false) {
+ if (arguments.length === 1) return _list => filterArray(predicate, _list);
let index = 0;
const len = list.length;
const willReturn = [];
This issue body was partially generated by patch-package.
SMALL_DELAY
I think this is missing. There is an async version of map and filter, but not find.
This issue is opened to make it easier to discuss suggestions and share a feedback
It would be great if the definition were more like this:
throttle<T>(fn: T, time: number): T;
Casting the first argument and return type as Function
helps very little.
rambdax/src/dropRepeatsWith.js
Lines 3 to 28 in ef482c5
/es
package entry point is conventional in modern libraries.
The suggestion is to provide rambdax/es
imports in ES5 and ES module format , similarly to how it was done with ramda/es
. Notice that Ramda modules are transpiled to ES5 to skip transpilation on bundling, and there is index reimporting file.
Unlike rambda/lib
, rambdax
doesn't contain separately built CJS modules.
Currently it's possible to import modules as rambdax/src/debounce
. The problem is that src
is ES2017 and isn't published to NPM, it's also not a good habit to rely on internal package structure.
Trying to build a create-react-app with Rambda dependency and have this error:
Failed to minify the code from this file:
./node_modules/rambdax/dist/rambdax.esm.js:8
Read more here: http://bit.ly/2tRViJ9
I believe this is related to selfrefactor/rambda#71
In version 7.4.0:
node_modules/rambdax/index.d.ts:1981:83 - error TS2304: Cannot find name 'rray'.
1981 export function lensSatisfies<T>(predicate: (x: T) => boolean, lens: Lens, input: rray<T>): boolean;
See https://github.com/selfrefactor/rambdax/search?q=rray%3CT
https://circleci.com/gh/selfrefactor/rambdax/464
TypeError: Assignment to constant variable.
534 | nested = object
535 |
> 536 | while (nested != null && ++index < length){
| ^
537 | let key = toKey(path[ index ]),
538 | newValue = value
539 |
The currently published version has this problem too. For us, Webpack finds it while creating the bundles.
Hi,
I'm trying to learn to use rambdax and I'm importing it in an Create React App starter kit with a TypeScript template. However I cannot proceed with rambdax usage because of this error:
Failed to compile.
.../training-app/node_modules/rambdax/_ts-toolbelt/src/List/Append.ts
TypeScript error in .../training-app/node_modules/rambdax/_ts-toolbelt/src/List/Append.ts(13,6):
A rest element must be last in a tuple type. TS1256
11 | */
12 | export type Append<L extends List, A extends any> =
> 13 | [...L, A]
| ^
14 |
My code looks like this:
import React from 'react';
...
import { filter, range } from 'rambdax'
...
The line with imports breaks the app. I cannot figure out why.
I'm brand new to rambdax so it might be and my miss-use.
Thanks!
Basically the same as selfrefactor/rambda#565
Are there any plans to port the solution mentioned in selfrefactor/rambda#565 (comment) to rambdax?
Currently rambdax is using ES6 syntax within its source like i.e. arrow functions, see example: https://github.com/selfrefactor/rambdax/blob/master/dist/rambdax.esm.js#L125
This leads to compatibility issues with legacy browsers that do not yet support ES6 features, i.e. IE11 or Edge 14. Example screenshots taken from IE11 developer tools console debugger, project setup using Babel 6 + Webpack 3:
I'm using rambdax v0.7.7 in a project that needs to be transpiled to ES5 to be compatible with IE >= 11 using Babel.
Unfortunately Babel does not support the transpilation of ES6 features within the source code of node_modules, mainly because of build speed reasons. You can read more about the discussion here: facebook/create-react-app#1125
Furthermore the build process will fail when using i.e. the UglifyJS plugin for Webpack. Running:
npm run build
in a given setup leads to
ERROR in bundle.js from UglifyJs Unexpected token: operator (>) [../node_modules/rambda/dist/rambda.esm.js:3,0][bundle.js:1,73120]
Related issue: webpack-contrib/uglifyjs-webpack-plugin#104
Usually you could handle such cases within your own source code too using Babel. But since Babel will not touch the node_modules, what comes in ES6 syntax will remain ES6 in the bundle.
Precompiling the source to ES5 or using an ES5 friendly syntax would enable rambdax to be used in projects suitable for legacy browsers and would also solve build problems.
it is hard to understand and provides little value
Hello.
As it's mentioned in changelog:
Breaking change - R.map/R.filter/R.reject/R.forEach/R.partition doesn't pass index as second argument to the predicate, when looping over arrays.
What's the way to use it otherwise? I'm having a Gatsby website, and I'm using R.forEach
and R.filter
. If I upgrade to 6.0.0, my website doesn't build. So, if index isn't passed anymore, is there some alternative or something that's introduced or do I have to stick with 5.1.0?
Hey! We use rambdax quite extensively in https://github.com/Nozbe/WatermelonDB and between 0.12.x and 0.13, it's been breaking one of the tests.
TL;DR. This:
is(Array)([{}])
evaluates to true
in rambdax 0.12.x (consistently with ramda), but false
in 0.13.
I think this is a regression, but perhaps this was never meant to work this way?
Which brings me to another point: I think is()
should be called something else. It's incompatible with the API in Rambda and Ramda, which is very, very confusing, and will cause code to break when trying to upgrade from ram(b)da
to rambdax
. (and if in untested code, that might be especially bad).
It's a useful function, but I don't think it's a good thing that it's called the same thing as a function that does different things in what seems like the subset of the same library. I realize changing this now will result in a little bit of chaos, but I think it would be better in the long term.
(I'm happy to offer a PR with changes and/or missing tests โ let me know what you think is the right thing to do here)
Check this zipObj
I made a screencast in place of a written issue with written examples: https://www.loom.com/share/3ffe89519d2c4d45b982fe9142993d6d
TLDW const example = R.piped(1, x => x)
Expected: example
has type number
Actual: example
has type unknown
Other libraries do not require manual typing in the data-first case because it is not needed. See fp-ts
's pipe
(which has the same API as piped
, dont let the name confuse you)
I might be missing something, but I ran into the issue that map
calls the provided function with both the element and the index. This prevents me from doing something like
const isWeb = R.piped(["http://", "https://"], R.map(R.startsWith), R.anyPass);
const result = isWeb("http://example.com");
As R.startsWith will receive "http://", 0. And try to call 0.startsWith
.
Of course I can work around:
const isWeb = R.piped(["http://", "https://"], R.map(R.pipe(R.always, R.startsWith)), R.anyPass);
const result = isWeb("http://example.com");
But I lose some of the satisfaction I normally get from this kind of functional programming.
Do you have suggestions or better workarounds?
removeIndex seems to take a switched (wrong) order of the 2 arguments. And the tests seem to be wrong as well.
It should be removeIndex(index, list)
but it is removeIndex(list, index)
making it bad for composition.
It seems this commit (5cbad23) breaks in ie11 any module/component that is importing Rambdax as it is using Proxy.
It has been fixed in v2.10.0 (709963e), but I wanted to leave this here for posterity's sake in case people run into the same issue.
Thanks a lot for this library in general though. I love it.
Link to test "then" function in docs is broken. Here's the link https://github.com/selfrefactor/rambdax/blob/master/src/then.spec.js
First of all, thanks for this awesome library. I like it so much.
Recently, I had a project with some clients using old browser.
Where can I find the browser compatible list? Thanks.
It would be great to implement isEmpty function, because ramda has it and there's no need for other dependencies. Now I just npm i lodash.isempty what is not so good as having all spells at hand
R.inject(marker, injection, content) similar to R.replace
import { intersection } from 'rambdax';
console.debug(intersection); // > undefined
Edit: duplicates #31
The type
function returns 'Object'
for ES6 method shorthand when running in an environment where that ES6 isn't transpiled. It's technically correct, but 'Function'
seems like it would be more appropriate. This also makes isType
and isFunction
return unexpected results.
const obj = {
f(){
return 4;
}
};
type(obj.f); // => 'Object'
typeof obj.f; // => 'function'
It may also be worth considering that it produces the same result for computed property shorthand:
const name = 'f';
const obj = {
[name](){
return 4;
}
};
type(obj.f); // => 'Object'
typeof obj.f; // => 'function'
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.