Skip to content

Commit

Permalink
Bug Fix: array.map should be safe when executed with a binary function,
Browse files Browse the repository at this point in the history
fix #675
  • Loading branch information
gcanti committed Dec 14, 2018
1 parent e689f5f commit 6caecec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 1.12.1

- **Bug Fix**
- `array.map` should be safe when executed with a binary function, fix #675 (@gcanti)

# 1.12.0

- **Deprecation**
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fp-ts",
"version": "1.12.0",
"version": "1.12.1",
"description": "Functional programming in TypeScript",
"files": [
"lib"
Expand Down
2 changes: 1 addition & 1 deletion src/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export const getOrd = <A>(O: Ord<A>): Ord<Array<A>> => {
}

const map = <A, B>(fa: Array<A>, f: (a: A) => B): Array<B> => {
return fa.map(f)
return fa.map(a => f(a))
}

const mapWithIndex = <A, B>(fa: Array<A>, f: (index: number, a: A) => B): Array<B> => {
Expand Down
9 changes: 9 additions & 0 deletions test/Array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,13 @@ describe('Array', () => {
assert.deepEqual(difference(setoidNumber)([1, 2], [2, 3]), [1])
assert.deepEqual(difference(setoidNumber)([1, 2], [1, 2]), [])
})

it('should be safe when calling map with a binary function', () => {
interface Foo {
bar: () => number
}
const f = (a: number, x?: Foo) => (x !== undefined ? `${a}${x.bar()}` : `${a}`)
const res = array.map([1, 2], f)
assert.deepEqual(res, ['1', '2'])
})
})

0 comments on commit 6caecec

Please sign in to comment.