hemanth / hemanth/functional-programming-jargon
Setoid example
Open
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 18.7k
- Forks
- 1k
- PR merge metrics
- No merged PRs in 30d
Description
The example of setoid uses equality between the elements of the array but it assumes there's an equality operator (==) between the elements of the setoid.
I would do the following:
Number.prototype.equals = function(num) {
return num.valueOf() === this.valueOf();
}
(2).equals(2) // true
(2).equals(3) // false
Array.prototype.equals = function(arr) {
var len = this.length
if (len !== arr.length) {
return false
}
for (var i = 0; i < len; i++) {
if (! this[i].equals(arr[i])) {
return false
}
}
return true
}
[1,2].equals([1,2]) // true
[1,2].equals([1,2,3]) // false
[1,2].equals([2,3]) // false
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the setoid example in the repository and read its explanation alongside the issue's proposed equality behavior. Update the example so its equality assumption is explicit and verify that the displayed examples produce the stated results.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100