rambda 9.2.0 → 9.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,16 @@
1
- 9.1.2
1
+ 9.3.0
2
+
3
+ - Breaking change in relation to TS typings of `R.assoc`, `R.dissoc` and `R.modify` - https://github.com/ramda/types/pull/37
4
+
5
+ - Add `R.isNotEmpty` as it is new method in `Ramda`
6
+
7
+ - Fix `R.head`/`R.last` TS definition - It returns `undefined` if array has length of 0. Before
8
+
9
+ 9.2.1
10
+
11
+ - Broken `Deno` build - [Issue #731](https://github.com/selfrefactor/rambda/issues/731)
12
+
13
+ 9.2.0
2
14
 
3
15
  - `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)
4
16
 
package/README.md CHANGED
@@ -106,59 +106,57 @@ One of the main issues with `Ramda` is the slow process of releasing new version
106
106
 
107
107
  <details>
108
108
  <summary>
109
- Click to see the full list of 43 Ramda methods not implemented in Rambda and their status.
109
+ Click to see the full list of 46 Ramda methods not implemented in Rambda and their status.
110
110
  </summary>
111
111
 
112
- - into
113
- - invert
112
+ - construct - Using classes is not very functional programming oriented.
113
+ - constructN - same as above
114
+ - into - no support for transducer as it is overly complex to implement, understand and read.
115
+ - invert - overly complicated and limited use case
114
116
  - invertObj
115
117
  - invoker
116
- - keysIn
118
+ - keysIn - we shouldn't encourage extending object with `.prototype`
117
119
  - lift
118
120
  - liftN
119
- - mapAccum
121
+ - mapAccum - `Ramda` example doesn't looks convincing
120
122
  - mapAccumRight
121
- - memoizeWith
122
- - mergeDeepWith
123
+ - memoizeWith - hard to imagine its usage in context of `R.pipe`/`R.compose`
124
+ - mergeDeepWith - limited use case
123
125
  - mergeDeepWithKey
124
126
  - mergeWithKey
125
- - nAry
126
- - nthArg
127
- - o
128
- - otherwise
129
- - pair
130
- - partialRight
131
- - pathSatisfies
127
+ - nAry - hard to argument about and hard to create meaningful TypeScript definitions
128
+ - nthArg - limited use case
129
+ - o - enough TypeScript issues with `R.pipe`/`R.compose` to add more composition methods
130
+ - otherwise - naming is confusing
131
+ - pair - `left-pad` types of debacles happens partially because of such methods that should not be hidden, bur rather part of your code base even if they need to exist.
132
+ - partialRight - I dislike `R.partial`, so I don't want to add more methods that are based on it
132
133
  - pipeWith
133
- - project
134
+ - project - naming is confusing, but also limited use case
134
135
  - promap
135
- - reduceRight
136
- - reduceWhile
136
+ - reduceRight - I find `right/left` methods confusing so I added them only where it makes sense.
137
+ - reduceWhile - functions with 4 inputs - I think that even 3 is too much
137
138
  - reduced
138
- - remove
139
- - scan
139
+ - remove - nice name but it is too generic. Also, `Rambdax` has such method and there it works very differently
140
+ - scan - hard to explain
140
141
  - sequence
141
142
  - splitWhenever
142
143
  - symmetricDifferenceWith
143
144
  - andThen
144
145
  - toPairsIn
146
+ - transduce - currently is out of focus
147
+ - traverse - same as above
145
148
  - unary
146
149
  - uncurryN
147
- - unfold
148
- - unionWith
150
+ - unfold - similar to `R.scan` and I find that it doesn't help with readability
151
+ - unionWith - why it has its usage, I want to limit number of methods that accept more than 2 arguments
149
152
  - until
150
- - useWith
153
+ - useWith - hard to explain
151
154
  - valuesIn
152
- - xprod
155
+ - xprod - limited use case
153
156
  - thunkify
154
- - default
155
-
156
- Most of above methods are in progress to be added to **Rambda**. The following methods are not going to be added:
157
157
  - __ - placeholder method allows user to further customize the method call. While, it seems useful initially, the price is too high in terms of complexity for TypeScript definitions. If it is not easy exressable in TypeScript, it is not worth it as **Rambda** is a TypeScript first library.
158
- - construct - Using classes is not very functional programming oriented.
159
- - constructN - same as above
160
- - transduce - currently is out of focus
161
- - traverse - same as above
158
+
159
+ The following methods are not going to be added(reason for exclusion is provided as a comment):
162
160
  </details>
163
161
 
164
162
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#-missing-ramda-methods)
@@ -216,7 +214,7 @@ There are methods which are benchmarked only with `Ramda` and `Rambda`(i.e. no `
216
214
 
217
215
  Note that some of these methods, are called with and without curring. This is done in order to give more detailed performance feedback.
218
216
 
219
- The benchmarks results are produced from latest versions of *Rambda*, *Lodash*(4.17.21) and *Ramda*(0.29.1).
217
+ The benchmarks results are produced from latest versions of *Rambda*, *Lodash*(4.17.21) and *Ramda*(0.30.1).
220
218
 
221
219
  </summary>
222
220
 
@@ -5853,7 +5851,7 @@ describe('R.hasPath', () => {
5853
5851
  head(str: string): string
5854
5852
  ```
5855
5853
 
5856
- It returns the first element of list or string `input`.
5854
+ It returns the first element of list or string `input`. It returns `undefined` if array has length of 0.
5857
5855
 
5858
5856
  <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.head(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.head('foo')%20%0A%5D%0A%2F%2F%20%3D%3E%20%5B1%2C%20'f'%5D">Try this <strong>R.head</strong> example in Rambda REPL</a>
5859
5857
 
@@ -5864,6 +5862,7 @@ It returns the first element of list or string `input`.
5864
5862
  ```typescript
5865
5863
  head(str: string): string;
5866
5864
  head(str: ''): undefined;
5865
+ head(list: readonly[]): undefined;
5867
5866
  head<T>(list: never[]): undefined;
5868
5867
  head<T extends unknown[]>(array: T): FirstArrayElement<T>
5869
5868
  head<T extends readonly unknown[]>(array: T): FirstArrayElement<T>
@@ -5937,9 +5936,9 @@ describe('R.head', () => {
5937
5936
  it('empty array', () => {
5938
5937
  const list = [] as const
5939
5938
  head(emptyList) // $ExpectType undefined
5940
- head(list) // $ExpectType never
5939
+ head(list) // $ExpectType undefined
5941
5940
  last(emptyList) // $ExpectType undefined
5942
- last(list) // $ExpectType never
5941
+ last(list) // $ExpectType undefined
5943
5942
  })
5944
5943
 
5945
5944
  it('mixed', () => {
@@ -6595,12 +6594,6 @@ export function isEmpty(input){
6595
6594
  return false
6596
6595
  if (!input) return true
6597
6596
 
6598
- if (type(input.isEmpty) === 'Function') {
6599
- return input.isEmpty();
6600
- } else if (input.isEmpty) {
6601
- return !!input.isEmpty;
6602
- }
6603
-
6604
6597
  if (inputType === 'Object'){
6605
6598
  return Object.keys(input).length === 0
6606
6599
  }
@@ -6635,10 +6628,6 @@ test('happy', () => {
6635
6628
  expect(isEmpty(0)).toBeFalse()
6636
6629
  expect(isEmpty(NaN)).toBeFalse()
6637
6630
  expect(isEmpty([ '' ])).toBeFalse()
6638
- expect(isEmpty({ isEmpty: false})).toBeFalse()
6639
- expect(isEmpty({ isEmpty: () => false})).toBeFalse()
6640
- expect(isEmpty({ isEmpty: true})).toBeTrue()
6641
- expect(isEmpty({ isEmpty: () => true})).toBeTrue()
6642
6631
  })
6643
6632
  ```
6644
6633
 
@@ -6716,6 +6705,27 @@ test('happy', () => {
6716
6705
 
6717
6706
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#isNil)
6718
6707
 
6708
+ ### isNotEmpty
6709
+
6710
+ ```typescript
6711
+
6712
+ isNotEmpty<T>(value: T[]): value is NonEmptyArray<T>
6713
+ ```
6714
+
6715
+ <details>
6716
+
6717
+ <summary>All TypeScript definitions</summary>
6718
+
6719
+ ```typescript
6720
+ isNotEmpty<T>(value: T[]): value is NonEmptyArray<T>;
6721
+ isNotEmpty<T>(value: readonly T[]): value is ReadonlyNonEmptyArray<T>;
6722
+ isNotEmpty(value: any): boolean;
6723
+ ```
6724
+
6725
+ </details>
6726
+
6727
+ [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#isNotEmpty)
6728
+
6719
6729
  ### isNotNil
6720
6730
 
6721
6731
  <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.isNotNil(null)%2C%0A%20%20R.isNotNil(undefined)%2C%0A%20%20R.isNotNil(%5B%5D)%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5Bfalse%2C%20false%2C%20true%5D">Try this <strong>R.isNotNil</strong> example in Rambda REPL</a>
@@ -6930,7 +6940,7 @@ test('happy', () => {
6930
6940
  last(str: ''): undefined
6931
6941
  ```
6932
6942
 
6933
- It returns the last element of `input`, as the `input` can be either a string or an array.
6943
+ It returns the last element of `input`, as the `input` can be either a string or an array. It returns `undefined` if array has length of 0.
6934
6944
 
6935
6945
  <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5B%0A%20%20R.last(%5B1%2C%202%2C%203%5D)%2C%0A%20%20R.last('foo')%2C%0A%5D%0A%2F%2F%20%3D%3E%20%5B3%2C%20'o'%5D">Try this <strong>R.last</strong> example in Rambda REPL</a>
6936
6946
 
@@ -6941,9 +6951,11 @@ It returns the last element of `input`, as the `input` can be either a string or
6941
6951
  ```typescript
6942
6952
  last(str: ''): undefined;
6943
6953
  last(str: string): string;
6954
+ last(list: readonly[]): undefined;
6944
6955
  last(list: never[]): undefined;
6945
- last<T extends unknown[]>(array: T): LastArrayElement<T>
6946
- last<T extends readonly unknown[]>(array: T): LastArrayElement<T>
6956
+ last<T extends unknown[]>(array: T): LastArrayElement<T>;
6957
+ last<T extends readonly unknown[]>(array: T): LastArrayElement<T>;
6958
+ last(str: string): string | undefined;
6947
6959
  ```
6948
6960
 
6949
6961
  </details>
@@ -7251,7 +7263,7 @@ export function lens(getter, setter){
7251
7263
  <summary><strong>TypeScript</strong> test</summary>
7252
7264
 
7253
7265
  ```typescript
7254
- import {lens, assoc, lensProp, view, lensIndex, lensPath} from 'rambda'
7266
+ import {lens, assoc, lensProp, view, lensIndex, over, lensPath} from 'rambda'
7255
7267
 
7256
7268
  interface Input {
7257
7269
  foo: string,
@@ -7275,6 +7287,10 @@ describe('R.lensProp', () => {
7275
7287
  const result = view<Input, string>(lensProp('foo'), testObject)
7276
7288
  result // $ExpectType string
7277
7289
  })
7290
+ it('issue 740', () => {
7291
+ // @ts-expect-error
7292
+ over(lensProp('x'), (n) => String(n), {x: 1})
7293
+ })
7278
7294
  })
7279
7295
 
7280
7296
  describe('R.lensIndex', () => {
@@ -7570,6 +7586,12 @@ test('get (set(set s v1) v2) === v2', () => {
7570
7586
 
7571
7587
  [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#lt)
7572
7588
 
7589
+ ### lte
7590
+
7591
+ <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20%5BR.lte(2%2C%201)%2C%20R.lte(2%2C%202)%2C%20R.lte(2%2C%203)%5D%0A%2F%2F%20%3D%3E%20%5Bfalse%2C%20true%2C%20true%5D">Try this <strong>R.lte</strong> example in Rambda REPL</a>
7592
+
7593
+ [![---------------](https://raw.githubusercontent.com/selfrefactor/rambda/master/files/separator.png)](#lte)
7594
+
7573
7595
  ### map
7574
7596
 
7575
7597
  ```typescript
@@ -8822,11 +8844,7 @@ It returns the lesser value between `x` and `y` according to `compareFn` functio
8822
8844
 
8823
8845
  ```typescript
8824
8846
 
8825
- modify<T extends object, K extends keyof T, P>(
8826
- prop: K,
8827
- fn: (a: T[K]) => P,
8828
- obj: T,
8829
- ): Omit<T, K> & Record<K, P>
8847
+ modify<K extends PropertyKey, T>(prop: K, fn: (value: T) => T): <U extends Record<K, T>>(object: U) => U
8830
8848
  ```
8831
8849
 
8832
8850
  <a title="redirect to Rambda Repl site" href="https://rambda.now.sh?const%20result%20%3D%20R.modify()%0A%2F%2F%20%3D%3E">Try this <strong>R.modify</strong> example in Rambda REPL</a>
@@ -8836,15 +8854,12 @@ modify<T extends object, K extends keyof T, P>(
8836
8854
  <summary>All TypeScript definitions</summary>
8837
8855
 
8838
8856
  ```typescript
8839
- modify<T extends object, K extends keyof T, P>(
8840
- prop: K,
8841
- fn: (a: T[K]) => P,
8842
- obj: T,
8843
- ): Omit<T, K> & Record<K, P>;
8844
- modify<K extends string, A, P>(
8845
- prop: K,
8846
- fn: (a: A) => P,
8847
- ): <T extends Record<K, A>>(target: T) => Omit<T, K> & Record<K, P>;
8857
+ modify<K extends PropertyKey, T>(prop: K, fn: (value: T) => T): <U extends Record<K, T>>(object: U) => U;
8858
+ modify<U, K extends keyof U>(prop: K, fn: (value: U[K]) => U[K], object: U): U;
8859
+ modify<K extends PropertyKey>(prop: K): {
8860
+ <T>(fn: (value: T) => T): <U extends Record<K, T>>(object: U) => U;
8861
+ <T, U extends Record<K, T>>(fn: (value: T) => T, object: U): U;
8862
+ };
8848
8863
  ```
8849
8864
 
8850
8865
  </details>
@@ -8985,23 +9000,52 @@ describe('brute force', () => {
8985
9000
  <summary><strong>TypeScript</strong> test</summary>
8986
9001
 
8987
9002
  ```typescript
8988
- import {modify, add} from 'rambda'
8989
- const person = {name: 'James', age: 20}
9003
+ import { add, identity, map, modify, pipe, toUpper } from 'rambda';
9004
+
9005
+ type Obj = {
9006
+ foo: string;
9007
+ bar: number;
9008
+ };
8990
9009
 
8991
9010
  describe('R.modify', () => {
8992
- it('happy', () => {
8993
- const {age} = modify('age', add(1), person)
8994
- const {age: ageAsString} = modify('age', String, person)
9011
+ it('ramda tests', () => {
9012
+ const result1 = modify('foo', toUpper, {} as Obj);
9013
+ result1; // $ExpectType Obj
8995
9014
 
8996
- age // $ExpectType number
8997
- ageAsString // $ExpectType string
8998
- })
8999
- it('curried', () => {
9000
- const {age} = modify('age', add(1))(person)
9015
+ const result2 = modify('bar', add(1), {} as Obj);
9016
+ result2; // $ExpectType Obj
9001
9017
 
9002
- age // $ExpectType number
9003
- })
9004
- })
9018
+ const result3 = modify('foo', toUpper)({} as Obj);
9019
+ result3; // $ExpectType Obj
9020
+
9021
+ const result4 = modify('bar', add(1))({} as Obj);
9022
+ result4; // $ExpectType Obj
9023
+
9024
+ const result5 = modify('foo')(toUpper)({} as Obj);
9025
+ result5; // $ExpectType Obj
9026
+
9027
+ const result6 = modify('bar')(add(1))({} as Obj);
9028
+ result6; // $ExpectType Obj
9029
+
9030
+ const result7 = modify('foo')(toUpper, {} as Obj);
9031
+ result7; // $ExpectType Obj
9032
+
9033
+ const result8 = modify('bar')(add(1), {} as Obj);
9034
+ result8; // $ExpectType Obj
9035
+
9036
+ const result9 = modify('foo', identity, {} as Obj);
9037
+ result9; // $ExpectType Obj
9038
+
9039
+ // @ts-expect-error
9040
+ modify('foo', add(1), {} as Obj);
9041
+ // @ts-expect-error
9042
+ modify('bar', toUpper, {} as Obj);
9043
+
9044
+ const f = pipe(map<Obj, Obj>(modify('foo', toUpper)));
9045
+
9046
+ f([] as Obj[]); // $ExpectType Obj[]
9047
+ });
9048
+ });
9005
9049
  ```
9006
9050
 
9007
9051
  </details>
@@ -17220,7 +17264,19 @@ describe('R.zipWith', () => {
17220
17264
 
17221
17265
  ## ❯ CHANGELOG
17222
17266
 
17223
- 9.1.2
17267
+ 9.3.0
17268
+
17269
+ - Breaking change in relation to TS typings of `R.assoc`, `R.dissoc` and `R.modify` - https://github.com/ramda/types/pull/37
17270
+
17271
+ - Add `R.isNotEmpty` as it is new method in `Ramda`
17272
+
17273
+ - Fix `R.head`/`R.last` TS definition - It returns `undefined` if array has length of 0. Before
17274
+
17275
+ 9.2.1
17276
+
17277
+ - Broken `Deno` build - [Issue #731](https://github.com/selfrefactor/rambda/issues/731)
17278
+
17279
+ 9.2.0
17224
17280
 
17225
17281
  - `R.once` TS type definition miss to context argument and its type - [Issue #728](https://github.com/selfrefactor/rambda/issues/728)
17226
17282
 
@@ -17640,11 +17696,11 @@ Fix wrong versions in changelog
17640
17696
 
17641
17697
  > Links to Rambda
17642
17698
 
17643
- - [https://github.com/stoeffel/awesome-fp-js](awesome-fp-js)
17699
+ - [awesome-fp-js](https://github.com/stoeffel/awesome-fp-js)
17644
17700
 
17645
- - [ https://mailchi.mp/webtoolsweekly/web-tools-280 ]( Web Tools Weekly #280 )
17701
+ - [Web Tools Weekly #280](https://mailchi.mp/webtoolsweekly/web-tools-280)
17646
17702
 
17647
- - [https://github.com/docsifyjs/awesome-docsify](awesome-docsify)
17703
+ - [awesome-docsify](https://github.com/docsifyjs/awesome-docsify)
17648
17704
 
17649
17705
  > Deprecated from `Used by` section
17650
17706
 
package/dist/rambda.js CHANGED
@@ -834,6 +834,14 @@ function dissoc(prop, obj) {
834
834
  return willReturn;
835
835
  }
836
836
 
837
+ function _defineProperty(e, r, t) {
838
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
839
+ value: t,
840
+ enumerable: !0,
841
+ configurable: !0,
842
+ writable: !0
843
+ }) : e[r] = t, e;
844
+ }
837
845
  function ownKeys(e, r) {
838
846
  var t = Object.keys(e);
839
847
  if (Object.getOwnPropertySymbols) {
@@ -855,33 +863,19 @@ function _objectSpread2(e) {
855
863
  }
856
864
  return e;
857
865
  }
858
- function _defineProperty(obj, key, value) {
859
- key = _toPropertyKey(key);
860
- if (key in obj) {
861
- Object.defineProperty(obj, key, {
862
- value: value,
863
- enumerable: true,
864
- configurable: true,
865
- writable: true
866
- });
867
- } else {
868
- obj[key] = value;
869
- }
870
- return obj;
871
- }
872
- function _toPrimitive(input, hint) {
873
- if (typeof input !== "object" || input === null) return input;
874
- var prim = input[Symbol.toPrimitive];
875
- if (prim !== undefined) {
876
- var res = prim.call(input, hint || "default");
877
- if (typeof res !== "object") return res;
866
+ function _toPrimitive(t, r) {
867
+ if ("object" != typeof t || !t) return t;
868
+ var e = t[Symbol.toPrimitive];
869
+ if (void 0 !== e) {
870
+ var i = e.call(t, r || "default");
871
+ if ("object" != typeof i) return i;
878
872
  throw new TypeError("@@toPrimitive must return a primitive value.");
879
873
  }
880
- return (hint === "string" ? String : Number)(input);
874
+ return ("string" === r ? String : Number)(t);
881
875
  }
882
- function _toPropertyKey(arg) {
883
- var key = _toPrimitive(arg, "string");
884
- return typeof key === "symbol" ? key : String(key);
876
+ function _toPropertyKey(t) {
877
+ var i = _toPrimitive(t, "string");
878
+ return "symbol" == typeof i ? i : i + "";
885
879
  }
886
880
 
887
881
  function compare(a, b) {
@@ -1536,11 +1530,6 @@ function isEmpty(input) {
1536
1530
  const inputType = type(input);
1537
1531
  if (['Undefined', 'NaN', 'Number', 'Null'].includes(inputType)) return false;
1538
1532
  if (!input) return true;
1539
- if (type(input.isEmpty) === 'Function') {
1540
- return input.isEmpty();
1541
- } else if (input.isEmpty) {
1542
- return !!input.isEmpty;
1543
- }
1544
1533
  if (inputType === 'Object') {
1545
1534
  return Object.keys(input).length === 0;
1546
1535
  }
@@ -1554,6 +1543,10 @@ function isNil(x) {
1554
1543
  return x === undefined || x === null;
1555
1544
  }
1556
1545
 
1546
+ function isNotEmpty(input) {
1547
+ return !isEmpty(input);
1548
+ }
1549
+
1557
1550
  function isNotNil(input) {
1558
1551
  return input != null;
1559
1552
  }
@@ -1622,6 +1615,11 @@ function lt(a, b) {
1622
1615
  return a < b;
1623
1616
  }
1624
1617
 
1618
+ function lte(a, b) {
1619
+ if (arguments.length === 1) return _b => lte(a, _b);
1620
+ return a <= b;
1621
+ }
1622
+
1625
1623
  function match(pattern, input) {
1626
1624
  if (arguments.length === 1) return _input => match(pattern, _input);
1627
1625
  const willReturn = input.match(pattern);
@@ -2608,6 +2606,7 @@ exports.intersperse = intersperse;
2608
2606
  exports.is = is;
2609
2607
  exports.isEmpty = isEmpty;
2610
2608
  exports.isNil = isNil;
2609
+ exports.isNotEmpty = isNotEmpty;
2611
2610
  exports.isNotNil = isNotNil;
2612
2611
  exports.join = join;
2613
2612
  exports.juxt = juxt;
@@ -2620,6 +2619,7 @@ exports.lensIndex = lensIndex;
2620
2619
  exports.lensPath = lensPath;
2621
2620
  exports.lensProp = lensProp;
2622
2621
  exports.lt = lt;
2622
+ exports.lte = lte;
2623
2623
  exports.map = map;
2624
2624
  exports.mapArray = mapArray;
2625
2625
  exports.mapObjIndexed = mapObjIndexed;