rambda 9.4.2 → 10.0.0-beta.1

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.
Files changed (271) hide show
  1. package/CHANGELOG.md +177 -1
  2. package/README.md +6799 -11799
  3. package/dist/rambda.cjs +1795 -0
  4. package/dist/rambda.js +1162 -2234
  5. package/dist/rambda.umd.js +1801 -1
  6. package/immutable.d.ts +1154 -1403
  7. package/index.d.ts +1154 -1403
  8. package/package.json +102 -94
  9. package/rambda.js +24 -137
  10. package/src/_internals/baseSlice.js +5 -7
  11. package/src/_internals/createPath.js +4 -6
  12. package/src/_internals/includes.js +8 -4
  13. package/src/_internals/set.js +11 -11
  14. package/src/addProp.js +3 -0
  15. package/src/all.js +8 -6
  16. package/src/allPass.js +4 -4
  17. package/src/any.js +10 -10
  18. package/src/anyPass.js +4 -4
  19. package/src/append.js +6 -8
  20. package/src/ascend.js +8 -15
  21. package/src/checkObjectWithSpec.js +16 -0
  22. package/src/compact.js +12 -0
  23. package/src/complement.js +1 -1
  24. package/src/concat.js +2 -4
  25. package/src/count.js +7 -6
  26. package/src/countBy.js +13 -14
  27. package/src/createObjectFromKeys.js +10 -0
  28. package/src/defaultTo.js +4 -6
  29. package/src/descend.js +6 -13
  30. package/src/drop.js +4 -2
  31. package/src/dropLast.js +2 -8
  32. package/src/dropLastWhile.js +17 -26
  33. package/src/dropWhile.js +14 -22
  34. package/src/eqBy.js +3 -8
  35. package/src/eqProps.js +3 -9
  36. package/src/equals.js +99 -58
  37. package/src/evolve.js +3 -57
  38. package/src/excludes.js +5 -0
  39. package/src/filter.js +13 -43
  40. package/src/filterObject.js +13 -0
  41. package/src/find.js +10 -10
  42. package/src/findIndex.js +10 -10
  43. package/src/findLast.js +9 -9
  44. package/src/findLastIndex.js +9 -9
  45. package/src/findNth.js +16 -0
  46. package/src/flatMap.js +3 -0
  47. package/src/flatten.js +5 -5
  48. package/src/groupBy.js +14 -11
  49. package/src/head.js +5 -3
  50. package/src/includes.js +13 -11
  51. package/src/indexOf.js +2 -6
  52. package/src/init.js +6 -8
  53. package/src/innerJoin.js +11 -19
  54. package/src/interpolate.js +29 -0
  55. package/src/intersection.js +2 -4
  56. package/src/intersperse.js +13 -13
  57. package/src/join.js +2 -4
  58. package/src/last.js +4 -4
  59. package/src/lastIndexOf.js +2 -6
  60. package/src/map.js +9 -49
  61. package/src/mapAsync.js +11 -0
  62. package/src/mapKeys.js +11 -0
  63. package/src/mapObject.js +18 -0
  64. package/src/mapObjectAsync.js +10 -0
  65. package/src/mapParallelAsync.js +3 -0
  66. package/src/match.js +5 -5
  67. package/src/maxBy.js +2 -8
  68. package/src/merge.js +4 -1
  69. package/src/mergeTypes.js +3 -0
  70. package/src/minBy.js +2 -8
  71. package/src/modifyProp.js +20 -0
  72. package/src/none.js +8 -6
  73. package/src/objOf.js +2 -6
  74. package/src/objectIncludes.js +12 -0
  75. package/src/omit.js +26 -11
  76. package/src/partition.js +15 -42
  77. package/src/partitionObject.js +15 -0
  78. package/src/path.js +14 -15
  79. package/src/permutations.js +40 -0
  80. package/src/pick.js +15 -15
  81. package/src/pipe.js +70 -13
  82. package/src/pipeAsync.js +11 -0
  83. package/src/pluck.js +12 -14
  84. package/src/prepend.js +2 -6
  85. package/src/prop.js +2 -10
  86. package/src/propEq.js +8 -10
  87. package/src/propOr.js +7 -8
  88. package/src/propSatisfies.js +2 -9
  89. package/src/range.js +34 -11
  90. package/src/reduce.js +15 -30
  91. package/src/reject.js +2 -4
  92. package/src/rejectObject.js +13 -0
  93. package/src/replace.js +2 -8
  94. package/src/replaceItemAtIndex.js +15 -0
  95. package/src/shuffle.js +13 -0
  96. package/src/sort.js +2 -4
  97. package/src/sortBy.js +12 -10
  98. package/src/sortObject.js +15 -0
  99. package/src/sortWith.js +12 -16
  100. package/src/split.js +2 -4
  101. package/src/splitEvery.js +11 -13
  102. package/src/symmetricDifference.js +5 -8
  103. package/src/tail.js +2 -2
  104. package/src/take.js +11 -9
  105. package/src/takeLast.js +14 -14
  106. package/src/takeLastWhile.js +15 -16
  107. package/src/takeWhile.js +12 -21
  108. package/src/tap.js +5 -5
  109. package/src/test.js +2 -8
  110. package/src/tryCatch.js +5 -14
  111. package/src/type.js +6 -5
  112. package/src/union.js +10 -8
  113. package/src/uniq.js +2 -2
  114. package/src/uniqBy.js +5 -6
  115. package/src/uniqWith.js +15 -19
  116. package/src/unless.js +7 -9
  117. package/src/unwind.js +6 -14
  118. package/src/update.js +8 -11
  119. package/src/when.js +7 -9
  120. package/src/zip.js +8 -8
  121. package/src/zipWith.js +5 -7
  122. package/src/F.js +0 -3
  123. package/src/T.js +0 -3
  124. package/src/_internals/_arity.js +0 -64
  125. package/src/_internals/compare.js +0 -3
  126. package/src/_internals/constants.js +0 -1
  127. package/src/_internals/createPathInput.js +0 -7
  128. package/src/_internals/isFalsy.js +0 -13
  129. package/src/_internals/isInteger.js +0 -10
  130. package/src/_internals/isIterable.js +0 -5
  131. package/src/_internals/isObject.js +0 -5
  132. package/src/_internals/isTruthy.js +0 -13
  133. package/src/_internals/objectIs.js +0 -9
  134. package/src/_internals/utils.js +0 -21
  135. package/src/add.js +0 -5
  136. package/src/addIndex.js +0 -23
  137. package/src/addIndexRight.js +0 -9
  138. package/src/adjust.js +0 -16
  139. package/src/always.js +0 -3
  140. package/src/and.js +0 -5
  141. package/src/ap.js +0 -7
  142. package/src/aperture.js +0 -15
  143. package/src/apply.js +0 -7
  144. package/src/applySpec.js +0 -132
  145. package/src/applyTo.js +0 -7
  146. package/src/assoc.js +0 -11
  147. package/src/assocPath.js +0 -46
  148. package/src/binary.js +0 -5
  149. package/src/bind.js +0 -9
  150. package/src/both.js +0 -5
  151. package/src/call.js +0 -1
  152. package/src/chain.js +0 -7
  153. package/src/clamp.js +0 -15
  154. package/src/clone.js +0 -18
  155. package/src/collectBy.js +0 -27
  156. package/src/comparator.js +0 -5
  157. package/src/compose.js +0 -9
  158. package/src/composeWith.js +0 -33
  159. package/src/cond.js +0 -14
  160. package/src/converge.js +0 -18
  161. package/src/curry.js +0 -7
  162. package/src/curryN.js +0 -40
  163. package/src/dec.js +0 -1
  164. package/src/difference.js +0 -8
  165. package/src/differenceWith.js +0 -20
  166. package/src/dissoc.js +0 -13
  167. package/src/dissocPath.js +0 -47
  168. package/src/divide.js +0 -5
  169. package/src/dropRepeats.js +0 -20
  170. package/src/dropRepeatsBy.js +0 -21
  171. package/src/dropRepeatsWith.js +0 -28
  172. package/src/either.js +0 -8
  173. package/src/empty.js +0 -15
  174. package/src/endsWith.js +0 -23
  175. package/src/flip.js +0 -23
  176. package/src/forEach.js +0 -19
  177. package/src/forEachObjIndexed.js +0 -24
  178. package/src/fromPairs.js +0 -6
  179. package/src/groupWith.js +0 -46
  180. package/src/gt.js +0 -6
  181. package/src/gte.js +0 -6
  182. package/src/has.js +0 -7
  183. package/src/hasIn.js +0 -9
  184. package/src/hasPath.js +0 -9
  185. package/src/identical.js +0 -7
  186. package/src/identity.js +0 -3
  187. package/src/ifElse.js +0 -17
  188. package/src/inc.js +0 -1
  189. package/src/indexBy.js +0 -29
  190. package/src/insert.js +0 -11
  191. package/src/insertAll.js +0 -7
  192. package/src/is.js +0 -8
  193. package/src/isEmpty.js +0 -18
  194. package/src/isNil.js +0 -3
  195. package/src/isNotEmpty.js +0 -5
  196. package/src/isNotNil.js +0 -3
  197. package/src/isPromise.js +0 -5
  198. package/src/juxt.js +0 -3
  199. package/src/keys.js +0 -3
  200. package/src/length.js +0 -8
  201. package/src/lens.js +0 -7
  202. package/src/lensIndex.js +0 -7
  203. package/src/lensPath.js +0 -7
  204. package/src/lensProp.js +0 -7
  205. package/src/lt.js +0 -6
  206. package/src/lte.js +0 -6
  207. package/src/mathMod.js +0 -8
  208. package/src/max.js +0 -5
  209. package/src/maybe.js +0 -13
  210. package/src/mean.js +0 -5
  211. package/src/median.js +0 -17
  212. package/src/mergeAll.js +0 -11
  213. package/src/mergeDeepLeft.js +0 -5
  214. package/src/mergeDeepRight.js +0 -24
  215. package/src/mergeLeft.js +0 -7
  216. package/src/mergeRight.js +0 -8
  217. package/src/mergeWith.js +0 -25
  218. package/src/min.js +0 -5
  219. package/src/modify.js +0 -23
  220. package/src/modifyPath.js +0 -33
  221. package/src/modulo.js +0 -5
  222. package/src/move.js +0 -19
  223. package/src/multiply.js +0 -5
  224. package/src/negate.js +0 -3
  225. package/src/not.js +0 -3
  226. package/src/nth.js +0 -9
  227. package/src/of.js +0 -3
  228. package/src/on.js +0 -16
  229. package/src/once.js +0 -24
  230. package/src/or.js +0 -5
  231. package/src/over.js +0 -14
  232. package/src/partial.js +0 -17
  233. package/src/partialObject.js +0 -5
  234. package/src/pathEq.js +0 -11
  235. package/src/pathOr.js +0 -11
  236. package/src/pathSatisfies.js +0 -9
  237. package/src/paths.js +0 -9
  238. package/src/pickAll.js +0 -23
  239. package/src/pickBy.js +0 -11
  240. package/src/product.js +0 -4
  241. package/src/propIs.js +0 -10
  242. package/src/props.js +0 -13
  243. package/src/reduceBy.js +0 -29
  244. package/src/removeIndex.js +0 -7
  245. package/src/repeat.js +0 -7
  246. package/src/reverse.js +0 -9
  247. package/src/set.js +0 -9
  248. package/src/slice.js +0 -9
  249. package/src/splitAt.js +0 -21
  250. package/src/splitWhen.js +0 -25
  251. package/src/startsWith.js +0 -23
  252. package/src/subtract.js +0 -5
  253. package/src/sum.js +0 -3
  254. package/src/swap.js +0 -42
  255. package/src/times.js +0 -12
  256. package/src/toLower.js +0 -3
  257. package/src/toPairs.js +0 -3
  258. package/src/toString.js +0 -3
  259. package/src/toUpper.js +0 -3
  260. package/src/transpose.js +0 -10
  261. package/src/trim.js +0 -3
  262. package/src/unapply.js +0 -5
  263. package/src/unnest.js +0 -9
  264. package/src/values.js +0 -6
  265. package/src/view.js +0 -10
  266. package/src/where.js +0 -15
  267. package/src/whereAny.js +0 -12
  268. package/src/whereEq.js +0 -14
  269. package/src/without.js +0 -15
  270. package/src/xor.js +0 -5
  271. package/src/zipObj.js +0 -13
package/src/reduce.js CHANGED
@@ -1,36 +1,21 @@
1
1
  import { isArray } from './_internals/isArray.js'
2
- import { curry } from './curry.js'
3
2
 
4
- class ReduceStopper{
5
- constructor(value){
6
- this.value = value
7
- }
8
- }
9
-
10
- export function reduceFn(
11
- reducer, acc, list
12
- ){
13
- if (list == null){
14
- return acc
15
- }
16
- if (!isArray(list)){
17
- throw new TypeError('reduce: list must be array or iterable')
18
- }
19
- let index = 0
20
- const len = list.length
3
+ export function reduce(reducer, acc) {
4
+ return list => {
5
+ if (list == null) {
6
+ return acc
7
+ }
8
+ if (!isArray(list)) {
9
+ throw new TypeError('reduce: list must be array or iterable')
10
+ }
11
+ let index = 0
12
+ const len = list.length
21
13
 
22
- while (index < len){
23
- acc = reducer(
24
- acc, list[ index ], index, list
25
- )
26
- if (acc instanceof ReduceStopper){
27
- return acc.value
14
+ while (index < len) {
15
+ acc = reducer(acc, list[index], index, list)
16
+ index++
28
17
  }
29
- index++
30
- }
31
18
 
32
- return acc
19
+ return acc
20
+ }
33
21
  }
34
-
35
- export const reduce = curry(reduceFn)
36
- export const reduceStopper = value => new ReduceStopper(value)
package/src/reject.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { filter } from './filter.js'
2
2
 
3
- export function reject(predicate, list){
4
- if (arguments.length === 1) return _list => reject(predicate, _list)
5
-
6
- return filter(x => !predicate(x), list)
3
+ export function reject(predicate) {
4
+ return list => filter(x => !predicate(x))(list)
7
5
  }
@@ -0,0 +1,13 @@
1
+ export function rejectObject(predicate) {
2
+ return obj => {
3
+ const willReturn = {}
4
+
5
+ for (const prop in obj) {
6
+ if (!predicate(obj[prop], prop, obj)) {
7
+ willReturn[prop] = obj[prop]
8
+ }
9
+ }
10
+
11
+ return willReturn
12
+ }
13
+ }
package/src/replace.js CHANGED
@@ -1,9 +1,3 @@
1
- import { curry } from './curry.js'
2
-
3
- function replaceFn(
4
- pattern, replacer, str
5
- ){
6
- return str.replace(pattern, replacer)
1
+ export function replace(pattern, replacer) {
2
+ return str => str.replace(pattern, replacer)
7
3
  }
8
-
9
- export const replace = curry(replaceFn)
@@ -0,0 +1,15 @@
1
+ import { cloneList } from './_internals/cloneList.js'
2
+
3
+ export function replaceItemAtIndex(index, replaceFn) {
4
+ return list => {
5
+ const actualIndex = index < 0 ? list.length + index : index
6
+ if (index >= list.length || actualIndex < 0) {
7
+ return list
8
+ }
9
+
10
+ const clone = cloneList(list)
11
+ clone[actualIndex] = replaceFn(clone[actualIndex])
12
+
13
+ return clone
14
+ }
15
+ }
package/src/shuffle.js ADDED
@@ -0,0 +1,13 @@
1
+ export function shuffle(listInput) {
2
+ const list = cloneList(listInput)
3
+ let counter = list.length
4
+ while (counter > 0) {
5
+ const index = Math.floor(Math.random() * counter)
6
+ counter--
7
+ const temp = list[counter]
8
+ list[counter] = list[index]
9
+ list[index] = temp
10
+ }
11
+
12
+ return list
13
+ }
package/src/sort.js CHANGED
@@ -1,7 +1,5 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
 
3
- export function sort(sortFn, list){
4
- if (arguments.length === 1) return _list => sort(sortFn, _list)
5
-
6
- return cloneList(list).sort(sortFn)
3
+ export function sort(sortFn) {
4
+ return list => cloneList(list).sort(sortFn)
7
5
  }
package/src/sortBy.js CHANGED
@@ -1,16 +1,18 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
 
3
- export function sortBy(sortFn, list){
4
- if (arguments.length === 1) return _list => sortBy(sortFn, _list)
3
+ export function sortBy(sortFn) {
4
+ return list => {
5
+ const clone = cloneList(list)
5
6
 
6
- const clone = cloneList(list)
7
+ return clone.sort((a, b) => {
8
+ const aSortResult = sortFn(a)
9
+ const bSortResult = sortFn(b)
7
10
 
8
- return clone.sort((a, b) => {
9
- const aSortResult = sortFn(a)
10
- const bSortResult = sortFn(b)
11
+ if (aSortResult === bSortResult) {
12
+ return 0
13
+ }
11
14
 
12
- if (aSortResult === bSortResult) return 0
13
-
14
- return aSortResult < bSortResult ? -1 : 1
15
- })
15
+ return aSortResult < bSortResult ? -1 : 1
16
+ })
17
+ }
16
18
  }
@@ -0,0 +1,15 @@
1
+ import { sort } from './sort.js'
2
+
3
+ export function sortObject(predicate) {
4
+ return obj => {
5
+ const keys = Object.keys(obj)
6
+ const sortedKeys = sort((a, b) => predicate(a, b, obj[a], obj[b]))(keys)
7
+
8
+ const toReturn = {}
9
+ sortedKeys.forEach(singleKey => {
10
+ toReturn[singleKey] = obj[singleKey]
11
+ })
12
+
13
+ return toReturn
14
+ }
15
+ }
package/src/sortWith.js CHANGED
@@ -1,27 +1,23 @@
1
- function sortHelper(
2
- a, b, listOfSortingFns
3
- ){
1
+ function sortHelper(a, b, listOfSortingFns) {
4
2
  let result = 0
5
3
  let i = 0
6
- while (result === 0 && i < listOfSortingFns.length){
7
- result = listOfSortingFns[ i ](a, b)
4
+ while (result === 0 && i < listOfSortingFns.length) {
5
+ result = listOfSortingFns[i](a, b)
8
6
  i += 1
9
7
  }
10
8
 
11
9
  return result
12
10
  }
13
11
 
14
- export function sortWith(listOfSortingFns, list){
15
- if (arguments.length === 1)
16
- return _list => sortWith(listOfSortingFns, _list)
12
+ export function sortWith(listOfSortingFns) {
13
+ return list => {
14
+ if (Array.isArray(list) === false) {
15
+ return []
16
+ }
17
17
 
18
- if (Array.isArray(list) === false)
19
- return []
18
+ const clone = list.slice()
19
+ clone.sort((a, b) => sortHelper(a, b, listOfSortingFns))
20
20
 
21
- const clone = list.slice()
22
- clone.sort((a, b) => sortHelper(
23
- a, b, listOfSortingFns
24
- ))
25
-
26
- return clone
21
+ return clone
22
+ }
27
23
  }
package/src/split.js CHANGED
@@ -1,5 +1,3 @@
1
- export function split(separator, str){
2
- if (arguments.length === 1) return _str => split(separator, _str)
3
-
4
- return str.split(separator)
1
+ export function split(separator) {
2
+ return str => str.split(separator)
5
3
  }
package/src/splitEvery.js CHANGED
@@ -1,18 +1,16 @@
1
- export function splitEvery(sliceLength, listOrString){
2
- if (arguments.length === 1){
3
- return _listOrString => splitEvery(sliceLength, _listOrString)
4
- }
1
+ export function splitEvery(sliceLength) {
2
+ return list => {
3
+ if (sliceLength < 1) {
4
+ throw new Error('First argument to splitEvery must be a positive integer')
5
+ }
5
6
 
6
- if (sliceLength < 1){
7
- throw new Error('First argument to splitEvery must be a positive integer')
8
- }
7
+ const willReturn = []
8
+ let counter = 0
9
9
 
10
- const willReturn = []
11
- let counter = 0
10
+ while (counter < list.length) {
11
+ willReturn.push(list.slice(counter, (counter += sliceLength)))
12
+ }
12
13
 
13
- while (counter < listOrString.length){
14
- willReturn.push(listOrString.slice(counter, counter += sliceLength))
14
+ return willReturn
15
15
  }
16
-
17
- return willReturn
18
16
  }
@@ -1,12 +1,9 @@
1
- import { concat } from './concat.js'
2
1
  import { filter } from './filter.js'
3
2
  import { includes } from './includes.js'
4
3
 
5
- export function symmetricDifference(x, y){
6
- if (arguments.length === 1){
7
- return _y => symmetricDifference(x, _y)
8
- }
9
-
10
- return concat(filter(value => !includes(value, y), x),
11
- filter(value => !includes(value, x), y))
4
+ export function symmetricDifference(x) {
5
+ return y => [
6
+ ...filter(value => !includes(value)(y))(x),
7
+ ...filter(value => !includes(value)(x))(y),
8
+ ]
12
9
  }
package/src/tail.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { drop } from './drop.js'
2
2
 
3
- export function tail(listOrString){
4
- return drop(1, listOrString)
3
+ export function tail(listOrString) {
4
+ return drop(1)(listOrString)
5
5
  }
package/src/take.js CHANGED
@@ -1,12 +1,14 @@
1
- import baseSlice from './_internals/baseSlice.js'
1
+ import { baseSlice } from './_internals/baseSlice.js'
2
2
 
3
- export function take(howMany, listOrString){
4
- if (arguments.length === 1)
5
- return _listOrString => take(howMany, _listOrString)
6
- if (howMany < 0) return listOrString.slice()
7
- if (typeof listOrString === 'string') return listOrString.slice(0, howMany)
3
+ export function take(numberOfItems) {
4
+ return input => {
5
+ if (numberOfItems < 0) {
6
+ return input.slice()
7
+ }
8
+ if (typeof input === 'string') {
9
+ return input.slice(0, numberOfItems)
10
+ }
8
11
 
9
- return baseSlice(
10
- listOrString, 0, howMany
11
- )
12
+ return baseSlice(input, 0, numberOfItems)
13
+ }
12
14
  }
package/src/takeLast.js CHANGED
@@ -1,19 +1,19 @@
1
- import baseSlice from './_internals/baseSlice.js'
1
+ import { baseSlice } from './_internals/baseSlice.js'
2
2
 
3
- export function takeLast(howMany, listOrString){
4
- if (arguments.length === 1)
5
- return _listOrString => takeLast(howMany, _listOrString)
3
+ export function takeLast(numberOfItems) {
4
+ return input => {
5
+ const len = input.length
6
+ if (numberOfItems < 0) {
7
+ return input.slice()
8
+ }
9
+ let numValue = numberOfItems > len ? len : numberOfItems
6
10
 
7
- const len = listOrString.length
8
- if (howMany < 0) return listOrString.slice()
9
- let numValue = howMany > len ? len : howMany
11
+ if (typeof input === 'string') {
12
+ return input.slice(len - numValue)
13
+ }
10
14
 
11
- if (typeof listOrString === 'string')
12
- return listOrString.slice(len - numValue)
15
+ numValue = len - numValue
13
16
 
14
- numValue = len - numValue
15
-
16
- return baseSlice(
17
- listOrString, numValue, len
18
- )
17
+ return baseSlice(input, numValue, len)
18
+ }
19
19
  }
@@ -1,21 +1,20 @@
1
- import { isArray } from './_internals/isArray.js'
2
-
3
- export function takeLastWhile(predicate, input){
4
- if (arguments.length === 1){
5
- return _input => takeLastWhile(predicate, _input)
6
- }
7
- if (input.length === 0) return input
1
+ export function takeLastWhile(predicate) {
2
+ return input => {
3
+ if (input.length === 0) {
4
+ return input
5
+ }
8
6
 
9
- const toReturn = []
10
- let counter = input.length
7
+ const toReturn = []
8
+ let counter = input.length
11
9
 
12
- while (counter){
13
- const item = input[ --counter ]
14
- if (!predicate(item)){
15
- break
10
+ while (counter) {
11
+ const item = input[--counter]
12
+ if (!predicate(item)) {
13
+ break
14
+ }
15
+ toReturn.push(item)
16
16
  }
17
- toReturn.push(item)
18
- }
19
17
 
20
- return isArray(input) ? toReturn.reverse() : toReturn.reverse().join('')
18
+ return toReturn.reverse()
19
+ }
21
20
  }
package/src/takeWhile.js CHANGED
@@ -1,24 +1,15 @@
1
- import { isArray as isArrayModule } from './_internals/isArray.js'
2
-
3
- export function takeWhile(predicate, iterable){
4
- if (arguments.length === 1){
5
- return _iterable => takeWhile(predicate, _iterable)
6
- }
7
- const isArray = isArrayModule(iterable)
8
- if (!isArray && typeof iterable !== 'string'){
9
- throw new Error('`iterable` is neither list nor a string')
10
- }
11
-
12
- const toReturn = []
13
- let counter = 0
14
-
15
- while (counter < iterable.length){
16
- const item = iterable[ counter++ ]
17
- if (!predicate(item)){
18
- break
1
+ export function takeWhile(predicate) {
2
+ return iterable => {
3
+ const toReturn = []
4
+ let counter = 0
5
+
6
+ while (counter < iterable.length) {
7
+ const item = iterable[counter++]
8
+ if (!predicate(item)) {
9
+ break
10
+ }
11
+ toReturn.push(item)
19
12
  }
20
- toReturn.push(item)
13
+ return toReturn
21
14
  }
22
-
23
- return isArray ? toReturn : toReturn.join('')
24
15
  }
package/src/tap.js CHANGED
@@ -1,7 +1,7 @@
1
- export function tap(fn, x){
2
- if (arguments.length === 1) return _x => tap(fn, _x)
1
+ export function tap(fn) {
2
+ return x => {
3
+ fn(x)
3
4
 
4
- fn(x)
5
-
6
- return x
5
+ return x
6
+ }
7
7
  }
package/src/test.js CHANGED
@@ -1,9 +1,3 @@
1
- export function test(pattern, str){
2
- if (arguments.length === 1) return _str => test(pattern, _str)
3
-
4
- if (typeof pattern === 'string'){
5
- throw new TypeError(`R.test requires a value of type RegExp as its first argument; received "${ pattern }"`)
6
- }
7
-
8
- return str.search(pattern) !== -1
1
+ export function test(pattern) {
2
+ return str => str.search(pattern) !== -1
9
3
  }
package/src/tryCatch.js CHANGED
@@ -1,18 +1,9 @@
1
- import { type } from './type.js'
2
-
3
- const isFunction = x => [ 'Promise', 'Function' ].includes(type(x))
4
-
5
- export function tryCatch(fn, fallback){
6
- if (!isFunction(fn)){
7
- throw new Error(`R.tryCatch | fn '${ fn }'`)
8
- }
9
- const passFallback = isFunction(fallback)
10
-
11
- return (...inputs) => {
1
+ export function tryCatch(fn, fallback) {
2
+ return input => {
12
3
  try {
13
- return fn(...inputs)
14
- } catch (e){
15
- return passFallback ? fallback(e, ...inputs) : fallback
4
+ return fn(input)
5
+ } catch (e) {
6
+ return fallback
16
7
  }
17
8
  }
18
9
  }
package/src/type.js CHANGED
@@ -1,12 +1,13 @@
1
- export function type(input){
2
- if (input === null){
1
+ export function type(input) {
2
+ if (input === null) {
3
3
  return 'Null'
4
- } else if (input === undefined){
4
+ }
5
+ if (input === undefined) {
5
6
  return 'Undefined'
6
- } else if (Number.isNaN(input)){
7
+ }
8
+ if (Number.isNaN(input)) {
7
9
  return 'NaN'
8
10
  }
9
11
  const typeResult = Object.prototype.toString.call(input).slice(8, -1)
10
-
11
12
  return typeResult === 'AsyncFunction' ? 'Promise' : typeResult
12
13
  }
package/src/union.js CHANGED
@@ -1,14 +1,16 @@
1
1
  import { cloneList } from './_internals/cloneList.js'
2
2
  import { includes } from './includes.js'
3
3
 
4
- export function union(x, y){
5
- if (arguments.length === 1) return _y => union(x, _y)
4
+ export function union(x) {
5
+ return y => {
6
+ const toReturn = cloneList(x)
6
7
 
7
- const toReturn = cloneList(x)
8
+ y.forEach(yInstance => {
9
+ if (!includes(yInstance)(x)) {
10
+ toReturn.push(yInstance)
11
+ }
12
+ })
8
13
 
9
- y.forEach(yInstance => {
10
- if (!includes(yInstance, x)) toReturn.push(yInstance)
11
- })
12
-
13
- return toReturn
14
+ return toReturn
15
+ }
14
16
  }
package/src/uniq.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { _Set } from './_internals/set.js'
2
2
 
3
- export function uniq(list){
3
+ export function uniq(list) {
4
4
  const set = new _Set()
5
5
  const willReturn = []
6
6
  list.forEach(item => {
7
- if (set.checkUniqueness(item)){
7
+ if (set.checkUniqueness(item)) {
8
8
  willReturn.push(item)
9
9
  }
10
10
  })
package/src/uniqBy.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import { _Set } from '../src/_internals/set.js'
2
2
 
3
- export function uniqBy(fn, list){
4
- if (arguments.length === 1){
5
- return _list => uniqBy(fn, _list)
6
- }
7
- const set = new _Set()
3
+ export function uniqBy(fn) {
4
+ return list => {
5
+ const set = new _Set()
8
6
 
9
- return list.filter(item => set.checkUniqueness(fn(item)))
7
+ return list.filter(item => set.checkUniqueness(fn(item)))
8
+ }
10
9
  }
package/src/uniqWith.js CHANGED
@@ -1,13 +1,11 @@
1
- function includesWith(
2
- predicate, target, list
3
- ){
1
+ function includesWith(predicate, target, list) {
4
2
  let willReturn = false
5
3
  let index = -1
6
4
 
7
- while (++index < list.length && !willReturn){
8
- const value = list[ index ]
5
+ while (++index < list.length && !willReturn) {
6
+ const value = list[index]
9
7
 
10
- if (predicate(target, value)){
8
+ if (predicate(target, value)) {
11
9
  willReturn = true
12
10
  }
13
11
  }
@@ -15,21 +13,19 @@ function includesWith(
15
13
  return willReturn
16
14
  }
17
15
 
18
- export function uniqWith(predicate, list){
19
- if (arguments.length === 1) return _list => uniqWith(predicate, _list)
16
+ export function uniqWith(predicate) {
17
+ return list => {
18
+ let index = -1
19
+ const willReturn = []
20
20
 
21
- let index = -1
22
- const willReturn = []
23
-
24
- while (++index < list.length){
25
- const value = list[ index ]
21
+ while (++index < list.length) {
22
+ const value = list[index]
26
23
 
27
- if (!includesWith(
28
- predicate, value, willReturn
29
- )){
30
- willReturn.push(value)
24
+ if (!includesWith(predicate, value, willReturn)) {
25
+ willReturn.push(value)
26
+ }
31
27
  }
32
- }
33
28
 
34
- return willReturn
29
+ return willReturn
30
+ }
35
31
  }
package/src/unless.js CHANGED
@@ -1,11 +1,9 @@
1
- import { curry } from './curry.js'
1
+ export function unless(predicate, whenFalseFn) {
2
+ return input => {
3
+ if (predicate(input)) {
4
+ return input
5
+ }
2
6
 
3
- function unlessFn(
4
- predicate, whenFalseFn, input
5
- ){
6
- if (predicate(input)) return input
7
-
8
- return whenFalseFn(input)
7
+ return whenFalseFn(input)
8
+ }
9
9
  }
10
-
11
- export const unless = curry(unlessFn)
package/src/unwind.js CHANGED
@@ -1,16 +1,8 @@
1
- import { isArray } from './_internals/isArray.js'
2
- import { mapArray } from './map.js'
3
-
4
- export function unwind(property, obj){
5
- if (arguments.length === 1){
6
- return _obj => unwind(property, _obj)
1
+ export function unwind(property) {
2
+ return obj => {
3
+ return obj[property].map(x => ({
4
+ ...obj,
5
+ [property]: x,
6
+ }))
7
7
  }
8
-
9
- if (!isArray(obj[ property ])) return [ obj ]
10
-
11
- return mapArray(x => ({
12
- ...obj,
13
- [ property ] : x,
14
- }),
15
- obj[ property ])
16
8
  }