Fp-ts: Array map is unsafe (Regression)

Created on 14 Dec 2018  路  2Comments  路  Source: gcanti/fp-ts

We've switched back to standard Js array map function.
I've seen some code breaking due to that change.

Here's a repro:

describe('array map is unsafe', () => {
  it('is as unsafe as native array map function', () => {
    interface Foo {
      bar: () => number
    }
    const f = (a: number, x?: Foo) => (x ? `${a}${x.bar()}` : `${a}`)
    const res = array.array.map([1, 2], f) // ERROR: TypeError: x.bar is not a function
    assert.deepEqual(res, ['1', '2'])
  })
})

I think fp-ts should be safe by default.
In the current state I cannot upgrade and have no means to detect the regressions.

@gcanti do you agree?

Most helpful comment

Could we change map to

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

?

All 2 comments

Could we change map to

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

?

thanks a lot @gcanti !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jollytoad picture jollytoad  路  4Comments

bioball picture bioball  路  4Comments

bobaaaaa picture bobaaaaa  路  4Comments

mohsensaremi picture mohsensaremi  路  3Comments

steida picture steida  路  4Comments