Property definitions

cartesian $ Pair :: defaultinit
# A simple read-only pair of two elements `e` and `f`.
class Pair[E, F]
	# The first element of the pair
	var e: E

	# The second element of the pair
	var f: F

	# The parenthesized notation.
	#
	# ~~~
	# var p = new Pair[Int, String](1, "hello")
	# assert p.to_s == "(1,hello)"
	# ~~~
	redef fun to_s
	do
		var es = e or else ""
		var fs = f or else ""
		return "({es},{fs})"
	end

	# Untyped pair equality.
	#
	# ~~~
	# var p1 = new Pair[Object, Object](1, 2)
	# var p2 = new Pair[Int, Int](1, 2)
	# var p3 = new Pair[Int, Int](1, 3)
	#
	# assert p1 == p2
	# assert p2 != p3
	# ~~~
	#
	# Untyped because we want that `p1 == p2` above.
	# So the method just ignores the real types of `E` and `F`.
	redef fun ==(o) do return o isa Pair[nullable Object, nullable Object] and e == o.e and f == o.f

	redef fun hash do return e.hash * 13 + f.hash * 27 # Magic numbers are magic!
end
lib/cartesian/cartesian.nit:24,1--61,3