Skip to content

Instantly share code, notes, and snippets.

@akanehara
Last active December 14, 2015 04:28
Show Gist options
  • Save akanehara/5027996 to your computer and use it in GitHub Desktop.
Save akanehara/5027996 to your computer and use it in GitHub Desktop.
Ginqのデフォルトの同値比較の動作はこれでいいだろうか? distinct や groupBy で使われる予定。
<?php
class DefaultEqualityComparer implements EqualityComparer
{
public function equals($v0, $v1, $k0, $k1)
{
// オブジェクト
// (==) に委譲
// 同一でなく同値。全フィールドが一致?
if (is_object($v0) && is_object($v1)) {
return $v0 == $v1;
}
// 配列
// (===) に委譲
// キー/値のペアが等しく、その並び順が等しく、 かつデータ型も等しい
if (is_array($v0) && is_array($v1)) {
return $v0 === $v1;
}
// それ以外の組み合わせでは (===) に委譲
return $v0 === $v1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment