MrFunctor
MrFunctor
  • 12
  • 43 500
fp-ts Tutorial | Chapter 4: IO
In Chapter 4 of this fp-ts tutorial (functional programming in TypeScript), we will introduce the IO type, which is used to represent a non-deterministic synchronous computation that can cause side effects and that never fails.
IO allows us to have pure functions even when dealing with side effects since a function can just return an IO representing a side-effect rather than actually performing that side effect.
00:00 Side effects in fp-ts
00:23 IO definition
01:32 Why IO
01:56 IO type definition
02:23 IO examples
02:41 Pure print function
04:31 How to work with IOs
zhlédnutí: 1 548

Video

How to auto-import fp-ts modules
zhlédnutí 782Před 9 měsíci
In this quick video, we'll see how to automatically import fp-ts modules as namespaces using a TypeScript language service plugin called @unsplash/ts-namespace-import-plugin. Plugin on GitHub: github.com/unsplash/ts-namespace-import-plugin GitHub gist: gist.github.com/MrFunctor/7f60d5ad211b9f9e56ab02d4695a0f1b 00:00 Manual fp-ts imports 00:15 Automatic fp-ts imports 00:30 Set up the namespace i...
fp-ts Tutorial | Chapter 3.4: Either orElse error recovery
zhlédnutí 1,5KPřed 10 měsíci
In Chapter 3.4 of this fp-ts tutorial (functional programming in TypeScript), we will see how to do error recovery with Either. More specifically, we will introduce the Either orElse and orElseW utils, which allow us to perform fallback operations when previous operations fail. 00:00 Error recovery 00:19 Login example 00:36 validateLoginName implementation 03:16 Either orElse definition 03:32 I...
fp-ts Tutorial | Chapter 3.3: Either flatMap (chain)
zhlédnutí 1,7KPřed 10 měsíci
In Chapter 3.3 of this fp-ts tutorial (functional programming in TypeScript), we will introduce Either flatMap (also known as chain in prior versions of fp-ts), which allows us to perform a sequence of operations that can fail. 00:00 Sequential operations that can fail 00:30 decodeUser example 00:53 decodeUser implementation 04:13 Step by step walk-through 06:23 Either flatMap vs chain
fp-ts Tutorial | Chapter 3.2: Either map, mapLeft, bimap
zhlédnutí 2,7KPřed rokem
In Chapter 3.2 of this fp-ts tutorial (functional programming in TypeScript), we will introduce Either map, mapLeft, and bimap, which allow us to do transformations on an Either's value. 00:00 Mapping Either's value 00:24 createResponse example 01:31 J.stringify 02:02 Either map 02:30 Either mapLeft 03:06 Either bimap 03:34 Better J.stringify
fp-ts Tutorial | Chapter 3.1: Either tryCatch
zhlédnutí 3,2KPřed rokem
In Chapter 3.1 of this fp-ts tutorial (functional programming in TypeScript), we will introduce Either tryCatch and tryCatchK, which are utils that allow us to have interoperability with Either for synchronous functions that might throw errors. To explain how tryCatch and tryCatchK work, we will look at JSON.parse as example, which is a function that might throw an error, and create our own fun...
fp-ts Tutorial | Chapter 3: Either
zhlédnutí 4,8KPřed rokem
In Chapter 3 of this fp-ts tutorial (functional programming in TypeScript), we will introduce the Either type, which is used to represent the result of a computation that can fail. Traditionally, you don't have any indication in the type system that a function might throw, and when you catch errors in a try/catch block, you just get an error with type 'unknown', which is not helpful at all! Wit...
fp-ts Tutorial | Chapter 2.3: Option error handling
zhlédnutí 3,5KPřed rokem
In Chapter 2.3 of this fp-ts tutorial (functional programming in TypeScript), we will see a concrete example of how to do error handling with Option. More specifically, we will introduce the Option alt util, which allows us to perform an alternative computation in case the previous computations failed. 00:00 Introduction 01:01 getMovieHighlight implementation 02:28 Option alt definition 02:39 I...
fp-ts Tutorial | Chapter 2.2: Option fromPredicate
zhlédnutí 3,1KPřed rokem
In Chapter 2.2 of this fp-ts tutorial (functional programming in TypeScript), we will introduce Option fromPredicate, which is a util that allows creating smart Option constructors from predicate functions. 00:00 Definition 00:31 getEven example 00:59 getDiscountText example 01:59 Working with refinements
fp-ts Tutorial | Chapter 2.1: Option map, flatten, chain
zhlédnutí 4,7KPřed rokem
In Chapter 2.1 of this fp-ts tutorial (functional programming in TypeScript), we will introduce Option map, flatten, and chain, which are essential operations when working with Options in fp-ts. First, we will look at the Option map operation, which allows us to perform transformations on an Option's value. Then, we will see that sometimes we might end up with a nested Option, which is not easy...
fp-ts Tutorial | Chapter 2: Option
zhlédnutí 5KPřed rokem
In Chapter 2 of this fp-ts tutorial (functional programming in TypeScript), we will introduce the Option data type, which is used to represent optional values, like the result of a computation that might fail. Option is one of the most used data types in fp-ts programs, which is why it's important for you to understand it well and to learn how to work with it. After defining what an Option is a...
fp-ts Tutorial | Chapter 1: pipe and flow
zhlédnutí 11KPřed rokem
In Chapter 1 of this fp-ts tutorial, we will introduce the pipe and flow utility functions, which are essential when writing programs with fp-ts as they allow you to compose operations. The pipe function pipes the value of an expression into a pipeline of functions. We will go through several examples to understand how pipe works, and then we will look at how pipe can be implemented. The flow f...

Komentáře

  • @user-ue9td5dr3e
    @user-ue9td5dr3e Před 4 dny

    😭😭😭 Mr.Functor,I wish you could back to continue.Without your video,I felt I couldn't live.😭😭😭😭😭😭😭😭😭😭

  • @cocolavayen9250
    @cocolavayen9250 Před 11 dny

    Excelentes videos!!! Muy bien explicado y me ayudaron muchisimo!!! Saludos desde Argentina Excellent videos!!! Very well explained and they helped me a lot!!! Greetings from Argentina!!!!

  • @76Freeman
    @76Freeman Před 11 dny

    Man I would pay for a course on ft-ts. If you ever think on releasing a course you can count me in. Your material is first class, super clear and I love how you go step by step. I'd love to see more content, specially with IO.

  • @76Freeman
    @76Freeman Před 12 dny

    I can't thank you enough for this series. I've been searching for a nice resource to learn fp-ts and your videos are really well done. They are clear and concise and so easy to watch.

  • @rgao7262
    @rgao7262 Před měsícem

    The series is finished?

  • @dbmusicz
    @dbmusicz Před měsícem

    Please continue, just please

  • @johnbeckius5814
    @johnbeckius5814 Před měsícem

    Great content! Thanks for making these videos. Looking forward to more.

  • @smittycb10
    @smittycb10 Před 2 měsíci

    The documentation for fp-ts is quite poor, watching these tutorials has really clarified how to use this library.

  • @jagk4459
    @jagk4459 Před 3 měsíci

    This series is brilliant! Looking forward to more of it! 💯

  • @ealder
    @ealder Před 3 měsíci

    The most helpful series of videos on functional programming in typescript. Have spent the last few days trying to understand Option, Either, Some, None and a host of other things and this series explains it so well. Look forward to any future videos!

  • @gnorts_mr_alien
    @gnorts_mr_alien Před 3 měsíci

    man, it got really REALLY interesting and you stopped :( nothing to do other than to thank you for what you achieved so far.

  • @isaacyuen5409
    @isaacyuen5409 Před 3 měsíci

    Really enjoy the whole series. Never thought of using FP in typescript. Hope the series to be updated more often. I need more of it.

  • @g3org3ir
    @g3org3ir Před 3 měsíci

    Thanks man, this is awesome

  • @TheUndead404
    @TheUndead404 Před 4 měsíci

    Your tutorial is freaking brilliant, I need more of it

  • @Christian-on9jg
    @Christian-on9jg Před 4 měsíci

    Why use ts-adt when you can use an exhaustively-checked switch statement?

    • @MrFunctor
      @MrFunctor Před 3 měsíci

      A switch statement would be much more verbose and less ergonomic.

  • @simple-stack-by-ed
    @simple-stack-by-ed Před 5 měsíci

    give this guy a nobel prize!

  • @fighterl1551
    @fighterl1551 Před 6 měsíci

    perfect tutorial! Thanks a lot

  • @xiaoboshi5813
    @xiaoboshi5813 Před 6 měsíci

    非常牛逼的fp-ts教程

  • @asdf9640
    @asdf9640 Před 7 měsíci

    Thank you very much! Simple and clear example.

  • @zomars
    @zomars Před 7 měsíci

    Finally a good example of functional programming for TypeScript. Thank you!

  • @ravikumarmistry
    @ravikumarmistry Před 7 měsíci

    Oh my god, you are crushing it, and production quality is top notch

  • @tomsour1s-oc6rb
    @tomsour1s-oc6rb Před 7 měsíci

    Keep up the good work man. I am really enjoying this series and get a better feel for FP 🎉

    • @MrFunctor
      @MrFunctor Před 7 měsíci

      I am glad to hear that! Thanks!

  • @xvna2036
    @xvna2036 Před 7 měsíci

    Awesome series so far, thanks a lot for your hard work: I wish it existed when I started using fp-ts! Do you have thoughts on what looks like the successor lib effects? Would it make sense to mention it in titles to ease discovery?

    • @MrFunctor
      @MrFunctor Před 7 měsíci

      Thanks! I am glad you're finding it helpful! You mean effect-ts? If so, I think it's an interesting library. I will definitely explore it in the future and probably make videos about it. However, my current focus right now is fp-ts. 🙂

  • @beyaz1404
    @beyaz1404 Před 7 měsíci

    Perfect !

  • @gionatha
    @gionatha Před 7 měsíci

    Awesome! Love the new animations!

  • @Danielo515
    @Danielo515 Před 7 měsíci

    Please keep this coming. Awesome work

  • @ShawnShaddock
    @ShawnShaddock Před 7 měsíci

    Another banger, keep up the good work!

  • @decentralizedvietnam
    @decentralizedvietnam Před 7 měsíci

    thank you

  • @dawid_dahl
    @dawid_dahl Před 7 měsíci

    Thank you so much! Have also been waiting patiently for this! 😄🙏🏻

    • @MrFunctor
      @MrFunctor Před 7 měsíci

      Thank you Dawid! Yes, I know it's been a while! 😅 I will try to release the next videos more frequently! 😉

  • @izyumrockstar7815
    @izyumrockstar7815 Před 7 měsíci

    Thanks. I had been waiting for a new video for a long time. I am struggling with the State monad in fp-ts. Hope you explain it.

    • @MrFunctor
      @MrFunctor Před 7 měsíci

      Thank you! I will try to be more frequent with the next videos! 😉 As for the State monad, I will probably cover it later, however, there's currently a long list of other things that I need to cover. 😅

    • @xvna2036
      @xvna2036 Před 7 měsíci

      Also find State very puzzling, hope you get to it eventually!

  • @Talaria.School
    @Talaria.School Před 8 měsíci

    a wonderful playlist, really well teached.

  • @decentralizedvietnam
    @decentralizedvietnam Před 8 měsíci

    great

  • @hansschenker
    @hansschenker Před 9 měsíci

    I am a fan of Typescript, Functional Programming and RxJs. FP-TS has a fp-ts-rxjs. I have a hard time to understand it. Could you make short series on fp-ts-rxjs? Anyway thanks a lot for publishing FP-TS videos!

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      That's great! I am actually not very familiar with rxjs, so I don't think I can make a series about it any time soon... Currently, I am focused on the fp-ts series and there's still a lot to cover. 😅

  • @savkelita
    @savkelita Před 9 měsíci

    Can you make one video with io-ts and fp-ts together? :) Define one runtime type ( Codec ) as the expected result from API fetch with TaskEither? Might be interesting :) p.s Great work!

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      Thanks! Yes, I will for sure cover io-ts in the future! 🙂

    • @AmitErandole
      @AmitErandole Před 9 měsíci

      @@MrFunctor I second this. Please continue this series. It has been very helpful

  • @Danielo515
    @Danielo515 Před 9 měsíci

    It is awesome in theory. But in practice I never make it work, and I don’t get any response in the issue I’ve opened

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      I commented on your issue. 😉 For people who read this comment and are dealing with the same problem, it could be due to VSCode using its own version of TypeScript rather than the workspace version, so you should just switch to the workspace version of TypeScript.

    • @Danielo515
      @Danielo515 Před 9 měsíci

      @@MrFunctor Thank you very much!

  • @dawid_dahl
    @dawid_dahl Před 9 měsíci

    Cool, thanks!

  • @whatthefunction9140
    @whatthefunction9140 Před 9 měsíci

    I like the thinking here but this code is very difficult to read.

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      Yeah, it takes time to get used to it. But once you understand it, it's very readable. 🙂

  • @luizgabriel98
    @luizgabriel98 Před 9 měsíci

    Good to know! 💯

  • @whatthefunction9140
    @whatthefunction9140 Před 9 měsíci

    Is this monadic?

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      Yes, Option is a monad.

  • @jena_thornwyrd
    @jena_thornwyrd Před 9 měsíci

    life saver !

  • @PeterSahanaya
    @PeterSahanaya Před 9 měsíci

    thank u, now i can feel rust on my typescript

  • @dawid_dahl
    @dawid_dahl Před 9 měsíci

    Do you have any views of the Effect library?

    • @JohnMcclaned
      @JohnMcclaned Před 5 měsíci

      The fp-ts creator is now part of the Effect team. You should use Effect from now on tbh

  • @dawid_dahl
    @dawid_dahl Před 9 měsíci

    I love these videos, thank you!

  • @dawid_dahl
    @dawid_dahl Před 9 měsíci

    Please explain why E.tryCatchK and not E.tryCatch?

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      With E.tryCatch we would have to create a wrapper function just to pass through the arguments to base64.decode. With E.tryCatchK, we don't need to create any wrapper function - we can just pass the function that might throw (base64.decode in this case) and get back a function that takes the same arguments and returns an Either. I recommend watching the video about Either tryCatch, which covers the difference in more detail. 🙂

    • @dawid_dahl
      @dawid_dahl Před 9 měsíci

      @@MrFunctor In your opinion, is the decrease in code readability warranted, since many people won’t know we slap a Kleisli K on there? 🙏🏻

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      That's a good question! The K at the end of function names is very common in fp-ts. So, I guess people just need to get used to it. I think that once they learn about the concept of Kleisli arrows, it would be clear why there's a K in there. I plan to cover this concept at some point in the future.

    • @dawid_dahl
      @dawid_dahl Před 9 měsíci

      @@MrFunctor Awesome! Looking forward to it! 🙏🏻😃

  • @yogeshmurarka4653
    @yogeshmurarka4653 Před 9 měsíci

    Content is great!! But it is a bit difficult to understand. I guess maybe because i loose the link between the code that you are explaining since at a given point only a small snippet of code is visible. I am unable to refer the previous code snippets

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      Since these videos are fast paced, it's totally possible to get confused. In that case, I would recommend pausing the video and reading the code carefully, when necessary rewinding to see the previously shown code, and even watching the video multiple times until you understand. 🙂

  • @ludwignagelhus524
    @ludwignagelhus524 Před 10 měsíci

    Isn't flatMap in this case a misnomer? In haskell fmap is just map for functors I think. The reason why it is prefixed with "f" is that map is already the name of a function which works exclusively on lists, so it was named fmap (functor-map). The fact that we are doing things which look like flattening doesn't actually have anything to do with the "f" in fmap. If I am correct, I really wish fp-ts had chosen a diffetent name.

    • @MrFunctor
      @MrFunctor Před 9 měsíci

      The equivalent of Haskell's fmap in fp-ts is just map. On the other hand, flatMap is the combination of two functions: map and flatten. So, in short, flatMap is not fmap, but fmap + flatten.

  • @izyumrockstar7815
    @izyumrockstar7815 Před 10 měsíci

    Thanks for your video. What do you plan to show us next ?

    • @MrFunctor
      @MrFunctor Před 10 měsíci

      I plan on starting with Chapter 4, which will introduce the IO monad.

  • @user-ud8rf7pp9q
    @user-ud8rf7pp9q Před 10 měsíci

    Thanks for good lecture. Do you have a plan to give a lecture on reducing the use of many if-else statements?

    • @MrFunctor
      @MrFunctor Před 10 měsíci

      Using Option and Either should already reduce the amount of if-else statements that you would normally write. Then, as we go forward with the series, more concepts will be introduced that will allow you to reduce the use of if-else statements even further.

  • @Danielo515
    @Danielo515 Před 10 měsíci

    Great

  • @Fullflexno
    @Fullflexno Před 10 měsíci

    Supercool! Thanks from norway! Valuble content!🎉