Fmap
Fmap is an operation that applies a function to values within a functor while preserving the functor’s structure.
Learn Haskell by Example
fmap is the standard Haskell function that applies a function to the contents of a value in a Functor while preserving the surrounding structure.
- How it is used
- Transforms parsed, command-line, and generated values without discarding their `Either`, `IO`, `Parser`, or generator context.
- How deep it goes
- Defines the Functor type and kinds, then implements a `Parser` instance through nested `Either` and tuple mappings.
- Examples
- Demonstrates CSV construction, `String`-to-`Text` command arguments, magic-number parsers, and a proposed `RandomIO` Functor instance.
- What you can do after
- Apply it via `fmap`, `<$>`, and `<$` to transform successful or produced values while preserving their wrapper.
Functional Programming in JavaScript
A mapping operation for a functor that applies a function to the wrapped value and returns a new functor of the same type.
- How it is used
- Uses functor mapping to transform encapsulated values while preserving their wrapper context.
- How deep it goes
- Defines fmap, implements it in Wrapper, and demonstrates chained transformations, but does not develop formal functor laws.
- Examples
- Demonstrates Wrapper values, incrementing 2 to 5, chaining to 15, identity extraction, and logging with tap.
- What you can do after
- Build it from scratch by implementing Wrapper.fmap and chain transformations without directly accessing the wrapped value.
Read how Functional Programming in JavaScript explains fmap →
Functional Design and Architecture: Examples in Haskell
fmap is the standard functor-mapping operation that applies a function to a functor's contained values while preserving its structure.
- How it is used
- Uses one abstract operation to transform values across lists, Maybe values, and free-monad structures without changing their shapes.
- How deep it goes
- Defines Functor behavior, works through list and Maybe examples, and implements fmap for a custom free-monad constructor.
- Examples
- Uses name-length lists, nested Maybe values, integer transformations, and SandwichConstructor continuations.
- What you can do after
- Apply transformations with fmap while preserving list, Maybe, or custom Functor structure.
Read how Functional Design and Architecture: Examples in Haskell explains fmap →
Also covered in
- The Coder CafeIn early access (MEAP)
What to know first
- listA list is an ordered collection of elements arranged in a sequence.
- EitherEither is a parameterized sum type whose values hold one of two alternatives, often used to represent an error or a successful result.
- filteringFiltering is the selection or exclusion of data or items according to specified criteria.
Related concepts
- (:>)equivalent to · (:>) is a Servant type operator that combines route or request information into the description of one API operation.
- bindused by · Bind is an operation that chains a value in a computational context to a function returning another value in that context, flattening the resulting nested context.
- functorpart of · A functor is an abstraction that maps values or objects while preserving the structure and relationships of their surrounding context.
- mapequivalent to · Map is an operation that applies a function to values in a collection or computational context and returns the results while preserving the structure or context.
- functionuses · A function is a callable unit of program code that performs a computation or operation, can accept inputs, and may produce a result or side effect.
Questions about fmap
What is fmap?
Fmap is an operation that applies a function to values within a functor while preserving the functor’s structure.
Which Manning books explain fmap?
Learn Haskell by Example, Functional Programming in JavaScript and Functional Design and Architecture: Examples in Haskell.
What should I know before learning fmap?
Manning books that teach fmap usually introduce list, Either and filtering first.
What is fmap part of?
Fmap is part of functor. A functor is an abstraction that maps values or objects while preserving the structure and relationships of their surrounding context.
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.


