Skip to Content
Learning Functional Programming in Go
book

Learning Functional Programming in Go

by Lex Sheehan
November 2017
Intermediate to advanced
670 pages
17h 35m
English
Packt Publishing
Content preview from Learning Functional Programming in Go

Definition of a functor in Haskell

We've seen a functor in the previous chapter in the type class hierarchy diagram. A functor has only one type class method, fmap, which has a type of fmap :: (a -> b) -> f a -> f b. It says--give me a function that takes an a and returns a b, a structure with an a inside it, and I'll give you a structure with a b inside it. The function is applied to each element inside the structure. The fmap function transforms values inside the structure.

We could use the following terms interchangeably:

  • Structure
  • Container
  • Box

The important thing to remember is that a functor operates on the element inside the thing (structure/container/box) and returns the structure with the transformed value (not the raw value). ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Functional Programming

Learning Functional Programming

Jack Widman

Publisher Resources

ISBN: 9781787281394Supplemental Content