Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
deprecate(fmap): use map instead
Browse files Browse the repository at this point in the history
  • Loading branch information
David Zukowski committed May 29, 2017
1 parent 0fc3700 commit 634ebfa
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 87 deletions.
1 change: 0 additions & 1 deletion src/bundles/index.js
Expand Up @@ -29,7 +29,6 @@ export { default as findIndex } from '../findIndex'
export { default as findLast } from '../findLast'
export { default as flatten } from '../flatten'
export { default as flattenDeep } from '../flattenDeep'
export { default as fmap } from '../fmap'
export { default as forEach } from '../forEach'
export { default as fromPairs } from '../fromPairs'
export { default as groupBy } from '../groupBy'
Expand Down
37 changes: 0 additions & 37 deletions src/fmap.js

This file was deleted.

13 changes: 8 additions & 5 deletions src/map.js
@@ -1,7 +1,6 @@
import _defn from './internal/_defn'
import _mapList from './internal/_mapList'
import _mapObject from './internal/_mapObject'
import isType from './isType'

/**
* @name map
Expand All @@ -19,8 +18,12 @@ import isType from './isType'
* map(x => x * 2, [1, 2, 3, 4, 5]) // => [2, 4, 6, 8, 10]
* map(x => x * 2, { a: 1, b: 2, c: 3 }) // => { a: 2, b: 4, c: 6 }
*/
export default _defn('map', function (fn, xs) {
return isType('Object', xs)
? _mapObject(fn, xs)
: _mapList(fn, xs)
export default _defn('map', function (fn, functor) {
if (Array.isArray(functor)) {
return _mapList(fn, functor)
}
if (typeof functor.map === 'function') {
return functor.map(fn)
}
return _mapObject(fn, functor)
})
43 changes: 0 additions & 43 deletions tests/fmap.spec.js

This file was deleted.

1 change: 0 additions & 1 deletion tests/general/general.spec.js
Expand Up @@ -34,7 +34,6 @@ const EXPECTED_FNS = [
, 'findLast'
, 'flatten'
, 'flattenDeep'
, 'fmap'
, 'forEach'
, 'fromPairs'
, 'get'
Expand Down
22 changes: 22 additions & 0 deletions tests/map.spec.js
Expand Up @@ -10,6 +10,28 @@ test('is curried', (t) => {
t.is(typeof map(() => {}), 'function')
})

// Dispatching
// ------------------------------------
test('dispatches to `map` if present', (t) => {
const spy = sinon.spy()
, fn = () => {}

map(fn, { map: spy })
t.is(spy.callCount, 1)
t.true(spy.calledWithExactly(fn))
})

test('does not dispatch to native Array.prototype.map', (t) => {
const fn = sinon.spy(() => {})
, arr = [1, 2, 3, 4]

arr.map = sinon.spy(Array.prototype.map)

map(fn, [1, 2, 3, 4])
t.is(arr.map.callCount, 0)
t.is(fn.callCount, 4)
})

// Lists
// ------------------------------------
test('List => returns a new list where each element has been transformed in place', (t) => {
Expand Down

0 comments on commit 634ebfa

Please sign in to comment.