---
title: "Discussion on \"Practical Guide to Fp-ts P4: Arrays, Semigroups, Monoids\" | Hashnode"
description: "Discussion on \"Practical Guide to Fp-ts P4: Arrays, Semigroups, Monoids\". Learn how to use Fp-ts practically. Introduces functional arrays, semigroups, and monoids."
url: "https://hashnode.com/posts/practical-guide-to-fp-ts-part-4/6071bcb61494367be6d29fbf"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Practical Guide to Fp-ts P4: Arrays, Semigroups, Monoids](https://rlee.dev/practical-guide-to-fp-ts-part-4?utm_source=hashnode&utm_medium=feed)

Learn how to use Fp-ts practically. Introduces functional arrays, semigroups, and monoids.

Sep 14, 2020 · 10 min read · rlee.dev  
Updated Apr 14, 2024  
Read the article

-   [#functional-programming](https://hashnode.com/tag/functional-programming)
-   [#typescript](https://hashnode.com/tag/typescript)

## Written by

[Ryan Lee](https://hashnode.com/@ryanleecode)

@ryanleecode · Toronto, CA

  
[View profile](https://hashnode.com/@ryanleecode)

Full Stack Developer writing about functional programming, AI, and blockchain.

## Responses 1

Markdown supported · ⌘↵ to post

[Carsten Leue](https://hashnode.com/@cleue)

[Oct 23, 2021](https://hashnode.com/posts/practical-guide-to-fp-ts-part-4/6071bcb61494367be6d29fbf/comment/61746c580f452c1cd94fa904)

Hi Ryan, I am really enjoying your series of articles about fp-ts. The pragmatic approach and real life usecases help a lot.

I'd like to give the following feedback and would be interested to see your views on that:

-   in your examples across the series you are importing from `fp-ts/lib/`, but that one is the commonjs version. Wouldn't it be more flexible to import from `fp-ts` instead and rely on the `main` and `module` entry point in the `package.json` for `fp-ts` to locate the best version, e.g.

```
import * as A from 'fp-ts/Array'
import { pipe } from 'fp-ts/function'

...
```

-   in the `pipe` examples you chose a version of the operators that accepts the array as a parameter. This looks a bit asymmetric to the subsequent operators that use the raw transformer function. I wonder why you chose this style instead of e.g.

```
import * as A from 'fp-ts/Array'
import { pipe } from 'fp-ts/function'

const foo = [1, 2, 3, 4, 5]

const sum = pipe(
  foo,
  A.map((x) => x - 1),
  A.filter((x) => x % 2 === 0),
  A.reduce(0, (prev, next) => prev + next),
)
console.log(sum) // 6
```

\-

[Ryan Lee](https://hashnode.com/@ryanleecode)

[Nov 7, 2022](https://hashnode.com/posts/practical-guide-to-fp-ts-part-4/6071bcb61494367be6d29fbf/comment/61746c580f452c1cd94fa904#reply-63688d9c7c7b23ca600888ca)

I believe if you use `/lib` it will treeshake where as if you use fp-ts directly it will not. Sorry for the extremely late reply. I never got a notif for this!

[Carsten Leue](https://hashnode.com/@carstenleue)

[Nov 7, 2022](https://hashnode.com/posts/practical-guide-to-fp-ts-part-4/6071bcb61494367be6d29fbf/comment/61746c580f452c1cd94fa904#reply-6368b18310f016d3006cc639)

Hi [Ryan Lee](https://hashnode.com/@ryanleecode)

thanks for answering. I have done some investigation since and also addressed the same in fp-ts issues 1606 because Giulio Canti's examples also imported from `/lib`. According to my own experiments and the comments on the issue above, the tree shakable import is without `/lib`, because `/lib` references the CJS version of the code.
