hemanth / hemanth/functional-programming-jargon

Setoid example

Open
#82 4 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.