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 →
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 a monadic operation that sequences a context-bearing computation with a function producing the next computation while flattening the resulting nested context.
- mapequivalent to · An operation that applies a function to values in a collection or computational context, producing corresponding results while preserving the collection or context’s structure.
- functorpart of · A functor is an abstraction that maps values or objects while preserving the structure and relationships of their surrounding context.
- functionuses · A function is a callable program unit that performs an operation, may accept inputs, and can produce a result or side effect.
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.


