GithubHelp home page GithubHelp logo

selfrefactor / rambdax Goto Github PK

View Code? Open in Web Editor NEW
221.0 221.0 24.0 4.38 MB

Extended version of Rambda

Home Page: https://selfrefactor.github.io/rambdax

License: MIT License

JavaScript 100.00%
functional-programming lodash rambda ramda utils

rambdax's Introduction

rambdax's People

Contributors

agriffis avatar andarist avatar darosh avatar dependabot[bot] avatar greenkeeper[bot] avatar justjish avatar makarkotlov avatar marcoworms avatar matthewcallis avatar michalwerner avatar mobily avatar onurozkan avatar pinceladasdaweb avatar radex avatar selfrefactor avatar vetin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

rambdax's Issues

transpile ES6 code in `esm` version, only leaving ES6 modules

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

assocPath clears all other props at the last level

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))

expecting

result to contain all original props at a.b level, including extra

actual results

only a.b.c is left

works in original Ramda repl

Broken examples

Examples for async functions

  • mapAsync
  • mapFastAsync
  • debounce
  • pipeAsync
    do not run as expected. Oftentimes it's just an async that is missing.

Also found from running examples for many other of the functions (not all):

  • Something deeper is wrong with 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.
  • Logical error in example for paths, and same problem as with path as well.
    • Same for props.
  • pick does not match expected.
  • Neither does pickAll.
  • Syntax error for pluck , split, set, reject, subtract & produce.
  • Logic error for propIs & slice.
  • removeIndex function is broken?
  • sortByProps is using sortByPath!

On another note: sort and sortBy difference should be better clarified I think.

v2.13.1 should have been a major/minor bump

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.

rejectIndexed is missing

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.

incorrect typings

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.

order matters in typings

take(n: number, input: string): string
take(n: number, input: T[]): T[]
take(n: number): {
(input: string): string
(input: T[]): T[]
}

mapArray filterArray curried error

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.

`dropRepeatsWith` takes an equality predicate but documents suggests it takes projector

documentation

export function dropRepeatsWith(predicate, list){
if (arguments.length === 1){
return _iterable => dropRepeatsWith(predicate, _iterable)
}
if (!_isArray(list)){
throw new Error(`${ list } is not a list`)
}
const toReturn = []
list.reduce((prev, current) => {
if (prev === undefined){
toReturn.push(current)
return current
}
if (!predicate(prev, current)){
toReturn.push(current)
}
return current
}, undefined)
return toReturn
}

Provide public ES modules

/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.

"isArray" is missing

I have the following error

image

It exists in index.d.ts

image

But there is no isArray.js in src

image

BTW: isobject is not working either

Importing rambdax into React with typescript breaks the app.

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!

Provide ES5 precompiled source

Issue Description

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:

Console error:
error_console_rambdax

... leads to:
bundlejs-rambdax-error

Context

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.

Suggestion

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.

R.forEach 6.0.0

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?

`is()` changed its behavior between 0.12.x and 0.13 (and is confusing)

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)

flatMap is not a function

Hello.

I'm using this in a Gatsby website (repo, file). Today, I updated to 4.0.1 and my build fails with the error flatMap is not a function (line 77). This worked fine till the 3.7.0. Has something changed? I read the changelog, but, didn't find anything useful.

Thanks.

piped isn't properly typed

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)

Index on map breaks currying

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 has backward arguments

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.

v2.0 - v2.9.1 break ie11 due to use of Proxy in src/_.js

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.

Maybe add isEmpty function

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

R.inject(marker, injection, content) similar to R.replace

type returns 'Object' for ES6 shorthand method declarations

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'

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.