---
title: "Discussion on \"Practical Guide to Fp-ts P2: Option, Map, Flatten, Chain\" | Hashnode"
description: "Discussion on \"Practical Guide to Fp-ts P2: Option, Map, Flatten, Chain\". Learn how to use the Option type in fp-ts to safely handle nullable values. Discover the powerful map operator and how to flatten nested Options."
url: "https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52"
---

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

Discussion

# [Practical Guide to Fp-ts P2: Option, Map, Flatten, Chain](https://rlee.dev/practical-guide-to-fp-ts-part-2?utm_source=hashnode&utm_medium=feed)

Learn how to use the Option type in fp-ts to safely handle nullable values. Discover the powerful map operator and how to flatten nested Options.

Jun 18, 2020 · 6 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 4

Markdown supported · ⌘↵ to post

[oluwatomisin babatunde](https://hashnode.com/@Tomisinteazer)

[Apr 2, 2022](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/6247cdb74b4dde0dc0be5ff8)

I'm trying to go along with this and I think I'm stuck I really don't know much about functional programming but this

```
pipe(
  undefined,
  O.fromNullable,
  O.map(({ bar }) => bar)
);
```

returns a **ts error** of **cannot find name O** I would like to know what I'm doing wrong? is there something I'm missing or didn't import to use the options?

[Todd Marek](https://hashnode.com/@mahabhusuku)

[Apr 14, 2022](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/6247cdb74b4dde0dc0be5ff8#reply-625858ed52fb7bd53380b50c)

You need to:

```
import * as O from "fp-ts/Option"
```

[Grzegorz Rozdzialik](https://hashnode.com/@Gelio)

[Jan 19, 2022](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/61e8165e6f4d6f431978da6c)

Nice guide!

Just wanted to say that the final example can be simplified a bit. `O.map` and `O.fromNullable` can be replaced with a single function: `O.fromNullable`.

```
pipe(
  foo,
  O.fromNullable,
  O.chain(O.fromNullableK(({bar}) => bar)),
  O.chain(O.fromNullableK(({buzz}) => buzz))
)
```

[TS playground](https://www.typescriptlang.org/play?ssl=24&ssc=1&pln=29&pc=2#code/JYWwDg9gTgLgBAbzmYYCmAaOAzANhAdzgF8coIQ4BybMAWhgGcB6XYAI2ewFcA7AYxjAIvKgFgAUKEiw4AKjgBDRnADyZCtVoMWbTqrBCRVANyTJ-EY3jYIEOAF5EkuHHaKoALmcTXr9twAXoHeAIwYLiSSxOYSKOgAFJG2EBG+agB02OQgAHLcuLiK7LiYkaoZIIpgCQlI7lAkAJSOAHxuHk1prhX8ABaKwLxJ6a54hCN+fhXZFPmFxaXdU5lVNXVuQYHNbZvBXZGuB+nHTbHMzHBoAI7cwABuiqW88DAQsfFokzh2yzM58yKJTK6V6AyGCX+cwKQNKAGlaggGsQWg52g0mscehl+oNhlC8jDFmgEXUAsEUbtyYFMZImkA)

[Andreas Herd](https://hashnode.com/@Mendrik)

[Mar 20, 2023](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/61e8165e6f4d6f431978da6c#reply-6418ae476fd77cec7793b485)

What's the K in fromNullableK? I also saw optionT.

[Grzegorz Rozdzialik](https://hashnode.com/@Gelio)

[Mar 26, 2023](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/61e8165e6f4d6f431978da6c#reply-64204831df7f026515a61dfc)

[Andreas Herd](https://hashnode.com/@Mendrik) Both suffixes are explained in [the FAQ in the fp-ts documentation](https://gcanti.github.io/fp-ts/guides/code-conventions.html#faq). `K` is for Kleisli arrow, `T` is for transformer.

[Nghiệp](https://hashnode.com/@nghiepit)

[Jul 3, 2021](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/60e0b65b03707d644a5014e0)

Awesome

[Роман Киселёв](https://hashnode.com/@rke)

[May 24, 2021](https://hashnode.com/posts/practical-guide-to-fp-ts-part-2/6071ba4b8b2b857c0bdb5e52/comment/60ab6c72f06aaf7b7c3de995)

Very useful, awesome.
