giogonzo / fp-ts-ramda

Ramda functions reimplemented in fp-ts
https://giogonzo.github.io/fp-ts-ramda/
MIT License
138 stars 9 forks source link

add clamp #4

Closed giogonzo closed 5 years ago

giogonzo commented 5 years ago

@gcanti I think this is ready to go, care to take a look?

gcanti commented 5 years ago
return (low: A, hi?: A, x?: A) => {
  if (hi === undefined) {
  }
}

@giogonzo there's a possible corner case when A = undefined

giogonzo commented 5 years ago

This test is somehow passing already:

const ordUndefined: Ord<undefined> = {
  equals: (a, b) => a === b,
  compare: () => 0
};
expect(
  JSONEqual(
    R.clamp(undefined, undefined, undefined),
    FR.clamp(ordUndefined)(undefined, undefined, undefined)
  )
).toBe(true);
giogonzo commented 5 years ago

yes, it fails without the JSON.stringify:

expected: undefined
received: [Function]
giogonzo commented 5 years ago

@gcanti added support for it in the last commit, but it has a perf cost. Probably it can be improved by switching back to function instead of () => and accessing arguments.length

giogonzo commented 5 years ago

Tracking further perf improvements in #13