- 12
- 43 500
MrFunctor
Registrace 1. 01. 2023
I make videos about functional programming, so if you're interested in that, you might want to subscribe :)
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
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...
😭😭😭 Mr.Functor,I wish you could back to continue.Without your video,I felt I couldn't live.😭😭😭😭😭😭😭😭😭😭
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!!!!
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.
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.
The series is finished?
Please continue, just please
Great content! Thanks for making these videos. Looking forward to more.
The documentation for fp-ts is quite poor, watching these tutorials has really clarified how to use this library.
This series is brilliant! Looking forward to more of it! 💯
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!
man, it got really REALLY interesting and you stopped :( nothing to do other than to thank you for what you achieved so far.
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.
Thanks man, this is awesome
Your tutorial is freaking brilliant, I need more of it
Why use ts-adt when you can use an exhaustively-checked switch statement?
A switch statement would be much more verbose and less ergonomic.
give this guy a nobel prize!
perfect tutorial! Thanks a lot
非常牛逼的fp-ts教程
Thank you very much! Simple and clear example.
Finally a good example of functional programming for TypeScript. Thank you!
Oh my god, you are crushing it, and production quality is top notch
Thank you!
I am still waiting @@MrFunctor
Keep up the good work man. I am really enjoying this series and get a better feel for FP 🎉
I am glad to hear that! Thanks!
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?
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. 🙂
Perfect !
Awesome! Love the new animations!
Thank you Gio!
Please keep this coming. Awesome work
Thanks, will do!
Another banger, keep up the good work!
Thank you!
thank you
Thank you so much! Have also been waiting patiently for this! 😄🙏🏻
Thank you Dawid! Yes, I know it's been a while! 😅 I will try to release the next videos more frequently! 😉
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.
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. 😅
Also find State very puzzling, hope you get to it eventually!
a wonderful playlist, really well teached.
great
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!
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. 😅
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!
Thanks! Yes, I will for sure cover io-ts in the future! 🙂
@@MrFunctor I second this. Please continue this series. It has been very helpful
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
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.
@@MrFunctor Thank you very much!
Cool, thanks!
I like the thinking here but this code is very difficult to read.
Yeah, it takes time to get used to it. But once you understand it, it's very readable. 🙂
Good to know! 💯
Is this monadic?
Yes, Option is a monad.
life saver !
thank u, now i can feel rust on my typescript
Do you have any views of the Effect library?
The fp-ts creator is now part of the Effect team. You should use Effect from now on tbh
I love these videos, thank you!
Please explain why E.tryCatchK and not E.tryCatch?
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. 🙂
@@MrFunctor In your opinion, is the decrease in code readability warranted, since many people won’t know we slap a Kleisli K on there? 🙏🏻
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.
@@MrFunctor Awesome! Looking forward to it! 🙏🏻😃
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
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. 🙂
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.
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.
Thanks for your video. What do you plan to show us next ?
I plan on starting with Chapter 4, which will introduce the IO monad.
Thanks for good lecture. Do you have a plan to give a lecture on reducing the use of many if-else statements?
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.
Great
Supercool! Thanks from norway! Valuble content!🎉