rambda 7.4.0 → 8.0.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/src/dropWhile.js CHANGED
@@ -8,19 +8,21 @@ export function dropWhile(predicate, iterable){
8
8
  if (!isArray && typeof iterable !== 'string'){
9
9
  throw new Error('`iterable` is neither list nor a string')
10
10
  }
11
- let flag = false
12
- const holder = []
13
- let counter = -1
14
11
 
15
- while (counter++ < iterable.length - 1){
16
- if (flag){
17
- holder.push(iterable[ counter ])
18
- } else if (!predicate(iterable[ counter ])){
19
- if (!flag) flag = true
12
+ const toReturn = []
13
+ let counter = 0
20
14
 
21
- holder.push(iterable[ counter ])
15
+ while (counter < iterable.length){
16
+ const item = iterable[ counter++ ]
17
+ if (!predicate(item)){
18
+ toReturn.push(item)
19
+ break
22
20
  }
23
21
  }
24
22
 
25
- return isArray ? holder : holder.join('')
23
+ while (counter < iterable.length){
24
+ toReturn.push(iterable[ counter++ ])
25
+ }
26
+
27
+ return isArray ? toReturn : toReturn.join('')
26
28
  }
package/src/isPromise.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { type } from './type.js'
2
2
 
3
3
  export function isPromise(x){
4
- return 'Promise' === type(x)
4
+ return type(x) === 'Promise'
5
5
  }
package/src/mergeWith.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { curry } from './curry.js'
2
2
 
3
3
  function mergeWithFn(
4
- mergeFn, a, b
4
+ mergeFn, aInput, bInput
5
5
  ){
6
+ const a = aInput ?? {}
7
+ const b = bInput ?? {}
6
8
  const willReturn = {}
7
9
 
8
10
  Object.keys(a).forEach(key => {
package/src/path.js CHANGED
@@ -1,11 +1,6 @@
1
1
  import { createPath } from './_internals/createPath.js'
2
2
 
3
- export function path(pathInput, obj){
4
- if (arguments.length === 1) return _obj => path(pathInput, _obj)
5
-
6
- if (obj === null || obj === undefined){
7
- return undefined
8
- }
3
+ export function pathFn(pathInput, obj){
9
4
  let willReturn = obj
10
5
  let counter = 0
11
6
 
@@ -23,3 +18,13 @@ export function path(pathInput, obj){
23
18
 
24
19
  return willReturn
25
20
  }
21
+
22
+ export function path(pathInput, obj){
23
+ if (arguments.length === 1) return _obj => path(pathInput, _obj)
24
+
25
+ if (obj === null || obj === undefined){
26
+ return undefined
27
+ }
28
+
29
+ return pathFn(pathInput, obj)
30
+ }
package/src/propEq.js CHANGED
@@ -3,7 +3,7 @@ import { equals } from './equals.js'
3
3
  import { prop } from './prop.js'
4
4
 
5
5
  function propEqFn(
6
- propToFind, valueToMatch, obj
6
+ valueToMatch, propToFind, obj
7
7
  ){
8
8
  if (!obj) return false
9
9
 
package/src/reduce.js CHANGED
@@ -10,6 +10,9 @@ class ReduceStopper{
10
10
  export function reduceFn(
11
11
  reducer, acc, list
12
12
  ){
13
+ if (list == null){
14
+ return acc
15
+ }
13
16
  if (!isArray(list)){
14
17
  throw new TypeError('reduce: list must be array or iterable')
15
18
  }
package/src/reverse.js CHANGED
@@ -1,7 +1,6 @@
1
- export function reverse(listOrString){
2
- if (typeof listOrString === 'string'){
3
- return listOrString.split('').reverse()
4
- .join('')
1
+ export function reverse(listOrString) {
2
+ if (typeof listOrString === 'string') {
3
+ return listOrString.split('').reverse().join('')
5
4
  }
6
5
 
7
6
  const clone = listOrString.slice()
package/src/set.js CHANGED
@@ -1,13 +1,9 @@
1
- import { always } from './always.js'
2
- import { curry } from './curry.js'
3
- import { over } from './over.js'
1
+ import {always} from './always.js'
2
+ import {curry} from './curry.js'
3
+ import {over} from './over.js'
4
4
 
5
- function setFn(
6
- lens, replacer, x
7
- ){
8
- return over(
9
- lens, always(replacer), x
10
- )
5
+ function setFn(lens, replacer, x) {
6
+ return over(lens, always(replacer), x)
11
7
  }
12
8
 
13
9
  export const set = curry(setFn)
package/src/startsWith.js CHANGED
@@ -1,17 +1,17 @@
1
1
  import { isArray } from './_internals/isArray.js'
2
2
  import { equals } from './equals.js'
3
3
 
4
- export function startsWith(target, iterable){
4
+ export function startsWith(question, iterable){
5
5
  if (arguments.length === 1)
6
- return _iterable => startsWith(target, _iterable)
6
+ return _iterable => startsWith(question, _iterable)
7
7
 
8
8
  if (typeof iterable === 'string'){
9
- return iterable.startsWith(target)
9
+ return iterable.startsWith(question)
10
10
  }
11
- if (!isArray(target)) return false
11
+ if (!isArray(question)) return false
12
12
 
13
13
  let correct = true
14
- const filtered = target.filter((x, index) => {
14
+ const filtered = question.filter((x, index) => {
15
15
  if (!correct) return false
16
16
  const result = equals(x, iterable[ index ])
17
17
  if (!result) correct = false
@@ -19,5 +19,5 @@ export function startsWith(target, iterable){
19
19
  return result
20
20
  })
21
21
 
22
- return filtered.length === target.length
22
+ return filtered.length === question.length
23
23
  }
@@ -5,17 +5,16 @@ export function takeLastWhile(predicate, input){
5
5
  return _input => takeLastWhile(predicate, _input)
6
6
  }
7
7
  if (input.length === 0) return input
8
- let found = false
8
+
9
9
  const toReturn = []
10
10
  let counter = input.length
11
11
 
12
- while (!found || counter === 0){
13
- counter--
14
- if (predicate(input[ counter ]) === false){
15
- found = true
16
- } else if (!found){
17
- toReturn.push(input[ counter ])
12
+ while (counter){
13
+ const item = input[ --counter ]
14
+ if (!predicate(item)){
15
+ break
18
16
  }
17
+ toReturn.push(item)
19
18
  }
20
19
 
21
20
  return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
package/src/takeWhile.js CHANGED
@@ -8,18 +8,17 @@ export function takeWhile(predicate, iterable){
8
8
  if (!isArray && typeof iterable !== 'string'){
9
9
  throw new Error('`iterable` is neither list nor a string')
10
10
  }
11
- let flag = true
12
- const holder = []
13
- let counter = -1
14
11
 
15
- while (counter++ < iterable.length - 1){
16
- if (!predicate(iterable[ counter ])){
17
- if (flag) flag = false
18
- } else if (flag){
19
- holder.push(iterable[ counter ])
12
+ const toReturn = []
13
+ let counter = 0
14
+
15
+ while (counter < iterable.length){
16
+ const item = iterable[ counter++ ]
17
+ if (!predicate(item)){
18
+ break
20
19
  }
20
+ toReturn.push(item)
21
21
  }
22
- holder
23
22
 
24
- return isArray ? holder : holder.join('')
23
+ return isArray ? toReturn : toReturn.join('')
25
24
  }
package/src/uniqBy.js CHANGED
@@ -1,13 +1,10 @@
1
+ import { _Set } from '../src/_internals/set.js'
2
+
1
3
  export function uniqBy(fn, list){
2
4
  if (arguments.length === 1){
3
5
  return _list => uniqBy(fn, _list)
4
6
  }
5
- const set = new Set()
6
-
7
- return list.filter(item => {
8
- if (set.has(fn(item))) return false
9
- set.add(fn(item))
7
+ const set = new _Set()
10
8
 
11
- return true
12
- })
9
+ return list.filter(item => set.checkUniqueness(fn(item)))
13
10
  }
package/src/unnest.js ADDED
@@ -0,0 +1,9 @@
1
+ export function unnest(list){
2
+ return list.reduce((acc, item) => {
3
+ if (Array.isArray(item)){
4
+ return [ ...acc, ...item ]
5
+ }
6
+
7
+ return [ ...acc, item ]
8
+ }, [])
9
+ }