- See also
- Companion
- object
Value members
Concrete methods
The Functor
composition law only holds for functions that preserve
equivalence, i.e. for functions f
such that
The Functor
composition law only holds for functions that preserve
equivalence, i.e. for functions f
such that
- ∀ a1, a2 ∈ A
Order[A].equal(a1, a2)
⇒Order[B].equal(f(a1), f(a2))
In the case when the equivalence implied by Order[A]
is in fact
equality, i.e. the finest equivalence, i.e. satisfying the
substitution property (which is the above property quantified over
all f
, see Wikipedia page on Equality),
the requirement holds for all f
by definition.
When Order
instances are viewed as "mere" equivalences (as opposed
to equalities), we can loosely say that ISet
is an (endo-)functor
in the category Equiv of sets with an equivalence relation (where
the morphishms are equivalence-preserving functions, i.e. exactly the
functions satisfying the above requirement). By contrast, Functor
instances are functors in the Scala category, whose morphisms are
arbitrary functions, including the ones that don't preserve equivalence.
'''Note:''' this is not able to implement Functor
due to the Order
constraint on the destination type,
however it still is a functor in the mathematical sense.
Documentation as copied from the Haskell source:
-- | /O(n*log n)/.
-- @'map' f s@ is the set obtained by applying @f@ to each element of @s@.
--
-- It's worth noting that the size of the result may be smaller if,
-- for some @(x,y)@, @x \/= y && f x == f y@