coco icon indicating copy to clipboard operation
coco copied to clipboard

Feature: `[a, b] is [c, d]`

Open thejh opened this issue 14 years ago • 4 comments

Hello, what would you think about a feature that converts a comparison like [a, b] is [c, d] that must be false (same for objects) to element comparisons? E.g.:

b() if ["foo", "bar"] is a()

would compile to

var _ref;
if (_ref=a(), _ref.length === 2 && _ref[0] === "foo" && _ref[1] === "bar") {
  b();
}

thejh avatar Oct 17 '11 11:10 thejh

Hmm, wondering about whether there should be a Object.keys(_ref).length === n check for object literals... maybe that could be the default for is, and {a: "foo", b: "bar"} <= obj wouldn't have that check? edited

thejh avatar Oct 17 '11 12:10 thejh

Same for arrays: [x, y] <= arr wouldn't have the length check

thejh avatar Oct 17 '11 12:10 thejh

[x, y] <= arr wouldn't have the length check

  • What exactly would that compile to?
  • Are you proposing all binary operators should support arraywise overload?

satyr avatar Oct 17 '11 13:10 satyr

I thought that [x, y] <= arr should compile to arr[0] === x && arr[1] === y... but that part seems like a bad idea now.

thejh avatar Oct 17 '11 15:10 thejh