Functor
From Academic Kids

 For functors in computer science, see the function object article.
In category theory, a functor is a special type of mapping between categories. Functors can be thought of as morphisms in the category of all (small) categories.
Functors were first considered in algebraic topology, where algebraic objects (like the fundamental group) are associated to topological spaces, and algebraic homomorphisms are associated to continuous maps. Nowadays, functors are used throughout modern mathematics to relate various categories.
Contents 
Definition
Let C and D be categories. A functor F from C to D is a mapping that
 associates to each object X in C an object F(X) in D,
 associates to each morphism f : X → Y in C a morphism F(f) : F(X) → F(Y) in D
such that the following two properties hold:
 <math>F(id_{X}) = id_{F(X)}<math> for every object <math>X \in C<math>
 <math>F(g \circ f) = F(g) \circ F(f)<math> for all morphisms <math>f:X \rightarrow Y<math> and <math>g:Y\rightarrow Z<math>.
That is, functors must preserve identity morphisms and composition of morphism.
Covariance and contravariance
There are many constructions in mathematics which would be functors but for the fact that they "turn morphisms around" and "reverse composition". We then define a contravariant functor F from C to D as a mapping that
 associates to each object <math>X \in C<math> an object <math>F(X) \in D<math>,
 associates to each morphism <math>f:X\rightarrow Y \in C<math> a morphism <math>F(f):F(Y) \rightarrow F(X) \in D<math> such that
 <math>F(id_X)=id_{F(X)}<math> for every object <math>X \in C<math>,
 <math>F(g \circ f) = F(f) \circ F(g)<math> for all morphisms <math>f:X\rightarrow Y<math> and <math>g:Y\rightarrow Z<math>.
Note that contravariant functors reverse the direction of composition.
Ordinary functors are also called covariant functors in order to distinguish them from contravariant ones. Note that one can also define a contravariant functor as a covariant functor on the dual category <math>C^{op}<math>. Some authors prefer to write all expressions covariantly. That is, instead of saying <math>F: C\rightarrow D<math> is a contravariant functor, they simply write <math>F: C^{op} \rightarrow D<math> (or sometimes <math>F:C \rightarrow D^{op}<math>) and call it a functor.
Contravariant functors are also occasionally called cofunctors. This is an incorrect usage of the prefix "co", which in a categorical context usually means "reverse all arrows". Recall that a functor F maps a morphism f:X→Y to a morphism F(f):F(X)→F(Y). Reversing all the arrows would map morphisms f:X←Y to morphisms F(f):F(X)←F(Y), but by transposing X and Y we see that this gives the same object as before. Consequently a cofunctor, properly speaking, is the same type of object as a functor.
Examples
Constant functor: A very boring functor C → D is one which maps every object of C to a fixed object X in D and every morphism in C to the identity morphism on X. Such a functor is called a constant or selection functor.
Power sets: The power set functor P : Set → Set maps each set to its power set and each function <math> f : X \subseteq Y<math> to the map which sends <math>U \subseteq X<math> to its image <math>f(U) \subseteq Y<math>. One can also consider the contravariant power set functor which sends f to the map which sends U to its inverse image in Y.
Dual vector space: The map which assigns to every vector space its dual space and to every linear map its dual or transpose is a contravariant functor from the category of all vector spaces over a fixed field to itself.
Fundamental group: Consider the category of pointed topological spaces, i.e. topological spaces with distinguished points. The objects are pairs (X, x_{0}), where X is a topological space and x_{0} is a point in X. A morphism from (X, x_{0}) to (Y, y_{0}) is given by a continuous map f : X → Y with f(x_{0}) = y_{0}.
To every topological space X with distinguished point x_{0}, one can define the fundamental group based at x_{0}, denoted π_{1}(X, x_{0}). This is the group of homotopy classes of loops based at x_{0}. If f : X → Y morphism of pointed spaces, then every loop in X with base point x_{0} can be composed with f to yield a loop in Y with base point y_{0}. This operation is compatible with the homotopy equivalence relation and the composition of loops, and we get a group homomorphism from π(X, x_{0}) to π(Y, y_{0}). We thus obtain a functor from the category of pointed topological spaces to the category of groups.
Algebra of continuous functions: a contravariant functor from the category of topological spaces (with continuous maps as morphisms) to the category of real associative algebras is given by assigning to every topological space X the algebra C(X) of all realvalued continuous functions on that space. Every continuous map f : X → Y induces an algebra homomorphism C(f) : C(Y) → C(X) by the rule C(f)(φ) = φ o f for every φ in C(Y).
Tangent and cotangent bundles: The map which sends every differentiable manifold to its tangent bundle and every smooth map to its derivative is a covariant functor from the category of differentiable manifolds to the category of vector bundles. Likewise, the map which sends every differentiable manifold to its cotangent bundle and every smooth map to its pullback is a contravariant functor.
Doing these constructions pointwise gives covariant and contravariant functors from the category of pointed differentiable manifolds to the category of real vector spaces.
Group actions/representations: Every group G can be considered as a category (or groupoid) with a single object. A functor from G to Set is nothing but a group action of G on a particular set, i.e. a Gset. Likewise, a functor from G to the category of vector spaces, Vect_{K}, is a linear representation of G. In general, a functor G → C can be considered as an "action" of G on an object in the category C.
Lie algebras: Assigning to every real (complex) Lie group its real (complex) Lie algebra defines a functor.
Tensor products: If C denotes the category of vector spaces over a fixed field, with linear maps as morphisms, then the tensor product <math>V \otimes W<math> defines a functor C × C → C which is covariant in both arguments.
Forgetful functors: The functor U : Grp → Set which maps a group to its underlying set and a group homomorphism to its underlying function of sets is a functor. Functors like these, which "forget" some structure, are termed forgetful functors. Another example is the functor Rng → Ab which maps a ring to its underlying additive abelian group. Morphisms in Rng (ring homomorphisms) become morphisms in Ab (abelian group homomorphisms).
Free functors: Going in the opposite direction of forgetful functors are free functors. The free functor F : Set → Grp sends every set X to the free group generated by X. Functions get mapped to group homomorphisms between free groups. Free constructions exist for many categories based on structured sets. See free object.
Homomorphism groups: To every pair A, B of abelian groups one can assign the abelian group Hom(A,B) consisting of all group homomorphisms from A to B. This is a functor which is contravariant in the first and covariant in the second argument, i.e. it is a functor Ab^{op} × Ab → Ab (where Ab denotes the category of abelian groups with group homomorphisms). If f : A_{1} → A_{2} and g : B_{1} → B_{2} are morphisms in Ab, then the group homomorphism Hom(f,g) : Hom(A_{2},B_{1}) → Hom(A_{1},B_{2}) is given by φ > g o φ o f.
Representable functors: We can generalize the previous example to any category C. To every pair X, Y of objects in C one can assign the set Mor(X,Y) of morphisms from X to Y. This defines a functor to Set which is contravariant in the first argument and covariant in the second, i.e. it is a functor C^{op} × C → Set. If f : X_{1} → X_{2} and g : Y_{1} → Y_{2} are morphisms in C, then the group homomorphism Mor(f,g) : Mor(X_{2},Y_{1}) → Mor(X_{1},Y_{2}) is given by φ > g o φ o f.
Functors like these are called representable functors. A major goal in many settings is to determine whether a given functor is representable.
Presheaves: If X is a topological space, then the open sets in X form a partially ordered set Open(X) under inclusion. Like every partially ordered set, Open(X) forms a small category by adding a single arrow U → V if and only if <math>U \subseteq V<math>. Contravariant functors on Open(X) are called presheaves on X. For instance, by assigning to every open set U the associative algebra of realvalued continuous functions on U, one obtains a presheaf of algebras on X.
Properties
Two important consequences of the functor axioms are:
 F transforms each commutative diagram in C into a commutative diagram in D;
 if f is an isomorphism in C, then F(f) is an isomorphism in D.
On any category C one can define the identity functor 1_{C} which maps each object and morphism to itself. One can also compose functors, i.e. if F is a functor from A to B and G is a functor from B to C then one can form the composite functor GF from A to C. Composition of functors is associative where defined. This shows that functors can be considered as morphisms in categories of categories.
A category with a single object is equivalent to a monoid whose elements are morphisms and whose operation is composition. Functors between monoids, considered as categories, are nothing more than monoid homomorphisms. So in a sense, functors between arbitrary categories are a kind of generalization of monoid homomorphisms to categories with more than one object.
Relation to other categorical concepts
Functors themselves can be considered as objects in a category called a functor category. Morphisms in this category are natural transformations between functors.
Functors are often defined by universal properties; examples are the tensor product, the direct sum and direct product of groups or vector spaces, construction of free groups and modules, direct and inverse limits. The concepts of limit and colimit generalize several of the above.
Universal constructions often give rise to pairs of adjoint functors.