e
and f
.cartesian :: Pair :: defaultinit
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
cartesian :: Pair :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).
# 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