liveBook · Manning

Functor

A functor is an abstraction that maps values or objects while preserving the structure and relationships of their surrounding context.

How 9 Manning books explain it

The Joy of JavaScript

A functor is a structure or abstraction that provides a mapping operation over contained values while preserving the surrounding structure.

How it is used
Uses map to compose transformations over contained values, including validation flows that skip work after failure.
How deep it goes
Defines map through identity and composition rules, then implements a reusable mixin; defers extensive algebraic theory.
Examples
Demonstrates array mapping, an Id transformation pipeline, and Success/Failure branches that run or skip mapped functions.
What you can do after
Build it from scratch with an Id-style container and map mixin, then apply the contract to conditional validation.

Read how The Joy of JavaScript explains functor →

Learn Haskell by Example

Functor is the Haskell type class for types whose parameterized values support structure-preserving mapping over their contents.

How it is used
Uses fmap to transform values inside CSV results, IO actions, parsers, and random generators without discarding their contexts.
How deep it goes
Defines Functor through fmap and kinds, then implements a Parser instance; functor laws are not detailed.
Examples
Demonstrates CSV Either mapping, command-line IO [String] conversion, Parser MagicNumber construction, and a RandomIO Functor exercise.
What you can do after
Apply it via fmap, <$> and <$ to change contained results while preserving list, Maybe, Either, IO, or Parser structure.

Read how Learn Haskell by Example explains functor →

Functional Programming in Scala, Second Edition

A functor is an abstraction that provides a map operation for transforming values inside a computational structure while preserving that structure.

How it is used
Generalizes map across type constructors to factor duplicated transformations into reusable combinators.
How deep it goes
Defines the Scala interface, derives distribute and codistribute, and justifies identity and composition laws through structural preservation.
Examples
Uses List, Option, Gen, Parser, Par, generic unzip, and codistribute to demonstrate map’s shared shape.
What you can do after
Apply it to derive structure-preserving transformations and generic combinators from map alone.

Read how Functional Programming in Scala, Second Edition explains functor →

Functional Programming in C#, Second Edition

A type equipped with a mapping operation that applies a function to its contained values without changing the type’s structure or producing side effects.

How it is used
Uses functors to generalize mapping across containers and lazy computations.
How deep it goes
Defines Map by signature and behavior, implements it for lazy functions, and relates it to monadic operations.
Examples
Illustrates mapping over Either’s successful value and composing a lazy function with a transformation.
What you can do after
Builds a Map operation for a lazy C# function and understands how to apply the pattern to other structures.

Read how Functional Programming in C#, Second Edition explains functor →

Functional Design and Architecture: Examples in Haskell

A functor is an abstraction that supports mapping a function over a value while preserving the structure of its context.

How it is used
Generalizes structure-preserving mapping into reusable functional operations for lists, optional values, and domain models.
How deep it goes
Defines fmap, demonstrates lists and nested Maybe values, and constructs a custom instance for a domain-specific algebraic type.
Examples
Uses name-length lists, nested Maybe values, integer-to-string mapping, and a SandwichConstructor continuation instance.
What you can do after
Build a Functor instance for a parameterized type and apply fmap across ordinary, nested, and domain-specific structures.

Read how Functional Design and Architecture: Examples in Haskell explains functor →

Functional Programming in JavaScript

An abstract container or computational context that supports mapping a function over its contents while preserving its structure.

How it is used
Uses containers to transform values while reducing scattered null checks and caller-managed error-handling complexity.
How deep it goes
Explains fmap operationally and demonstrates immutable chaining, while deliberately stopping short of category theory.
Examples
Demonstrates Wrapper, arithmetic with plus3, identity extraction, logging, chained fmap calls, and Array map and filter signatures.
What you can do after
Build it from scratch with a Wrapper class, wrap values, map transformations, and chain immutable computations.

Read how Functional Programming in JavaScript explains functor →

The Coder Cafe

A functor is a functional abstraction that supports applying a function to a value within a computational context while preserving that context.

How it is used
Applies ordinary functions to wrapped values without manual unwrapping, supporting composition across missing values and lists.
How deep it goes
Defines context-preserving mapping and works through populated, empty, and list cases; leaves wrapped functions and dependent steps to other abstractions.
Examples
Shows fmap (+1) turning Just 42 into Just 43, preserving Nothing, and transforming [1, 2, 3] into [2, 3, 4].
What you can do after
Apply it via Haskell fmap to transform values in Maybe or a list while retaining the context.

Read how The Coder Cafe explains functor →

100 C++ Mistakes and How to Avoid Them

A functor is an object or class that can be invoked like a function by implementing the call operator.

How it is used
Uses a callable object to encapsulate an operation, while contrasting it with behavior written directly at the call site.
How deep it goes
Defines `operator()` and works through a maximum-finding implementation, without detailing deeper language mechanics.
Examples
Shows a `Maximum` functor and a lambda that finds the maximum value in a vector.
What you can do after
Build a callable `Maximum` class and compare it with a lambda-based alternative.

Read how 100 C++ Mistakes and How to Avoid Them explains functor →

Fabulous Adventures in Data Structures and Algorithms

A functor is a mapping between categories that preserves their objects, morphisms, and composition.

How it is used
Uses composable abstractions to connect category theory with programming-language design and generic interfaces.
How deep it goes
Defines categories, morphisms, variance, and endofunctors, then stops short of deeper category-theoretic development.
Examples
Uses a three-object category, a C# integer-to-string function, and a diagram of dashed mapping arrows.
What you can do after
Evaluate type relationships and generic interfaces using covariance, contravariance, and preserved morphisms.

Read how Fabulous Adventures in Data Structures and Algorithms explains functor →

Also covered in

What to know first

Related concepts

Questions about functor

What is functor?

A functor is an abstraction that maps values or objects while preserving the structure and relationships of their surrounding context.

Which Manning books explain functor?

The Joy of JavaScript, Learn Haskell by Example, Functional Programming in Scala, Second Edition, Functional Programming in C#, Second Edition, Functional Design and Architecture: Examples in Haskell, Functional Programming in JavaScript, The Coder Cafe, 100 C++ Mistakes and How to Avoid Them and 1 more.

What should I know before learning functor?

Manning books that teach functor usually introduce list, Either, option and data transformation first.

What kinds of functor are there?

Kinds of functor include monad, option and IEnumerable.

What are the parts of functor?

Functor includes map.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.