Тёмный

Using Either to structure your validations 

RyanDavisDev
Подписаться 1,1 тыс.
Просмотров 6 тыс.
50% 1

The fp-ts library in Typescript provides the Either abstraction which works well for organizing validations. This video walks through how to establish some simple patterns to get you started. There is a lot more to be said about this type class, expect more soon.

Опубликовано:

 

29 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 33   
@billc7
@billc7 Год назад
very nice, could you do a video about Task or whatever your approach is to side effect management?
@dawid_dahl
@dawid_dahl Год назад
Yes please I would love that as well. Especially I am confused about how the in-built promise functionality relates to fp-ts Task/TaskEither. Do they play nice together or not? Thanks so much for another super useful video!
@hotharvey2
@hotharvey2 Год назад
So fp-ts Either is right biased... sad:(
@GreatBritton
@GreatBritton Год назад
I'm just starting down this path of learning fp-ts and you have been a great resource on this journey. One question I have is when to use the function declaration of "function validateUser(user)" vs "const validateUser = (user) => " These seem to do the same thing and are just a syntactical difference, but I haven't seen anything really explain why you would use one over the other. Also kind of on the same thread, I've seen you use interface, but is there a reason to use "interface" vs "type" declaration? Just trying to learn best practices as I go.
@ryandavisdev
@ryandavisdev Год назад
Yeah, these are good questions, and I don't have strong opinions. I will say that arrow functions make a better syntax for currying, which is used a lot in fp-ts and functional programming in general.
@JohnMcSmith
@JohnMcSmith 2 месяца назад
More FP tutorials please
@jakeycakester
@jakeycakester Год назад
It would be cool if you could upload your code to github so people can look at it after the video. Thanks
@Fullflexno
@Fullflexno 11 месяцев назад
Thank you for this!
@SuperQuwertz
@SuperQuwertz Год назад
Can you do a video explaining the Either functions more? Like what is the difference of E.map and E.chain ? Also as @ms23605 mentioned, chaining, branching, working with promises would be awesome.
@struggopuggo
@struggopuggo Год назад
Map calls the provided function on the value held as a right. It will ignore values held as a left. Chain does the same but it also unnests a type of either. So if you have an either which has a value which is also an either you'll return only one. You can think of it as working similar to Array.map and Array.flatMap.
@SuperQuwertz
@SuperQuwertz Год назад
@@struggopuggo Thank you, this was a nice and simple explanation
@SuperQuwertz
@SuperQuwertz Год назад
@@struggopuggo This knowledge just saved me, thank you again
@struggopuggo
@struggopuggo Год назад
@@SuperQuwertz no problem. I'm glad I was helpful.
@SuperQuwertz
@SuperQuwertz Год назад
FInally someone who does videos on this which are more understandable :D
@ryandavisdev
@ryandavisdev Год назад
haha thanks, I understand the frustration
@m23605
@m23605 Год назад
Would be good to know how you then work with the validated either (it could have one of two error messages or it could be right so how do you set up your logic branching). Also looking forward to TE and the K and W chainEithers
@ryandavisdev
@ryandavisdev Год назад
Thanks for the feedback, I agree with your suggestions
@dawid_dahl
@dawid_dahl Год назад
You’re a really good teacher by the way, showing progress and justification by working up from a non-optimal solution to a fp-better solution. (I know better here is in quotes as it is all subjective. But you know what I mean… 😄)
@erezbenkimon3899
@erezbenkimon3899 Год назад
I really like how you construct your tutorials, keep up the good work!
@bburgess_keys
@bburgess_keys Год назад
Hey, @RyanDavisDev great content. I would love to see a video that is like an overview of `fp-ts`. I'm getting into FP with TS, and `fp-ts` is clearly the way to go. But as has been notable in several places, the barrier to entry is kinda high with the docs being so... terse.
@ryandavisdev
@ryandavisdev Год назад
Hey Bradley, thanks for the feedback, I agree an overview could be helpful. For now, my video on the array module is the most introductory ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Zbu7flpYnGc.html
@bburgess_keys
@bburgess_keys Год назад
@@ryandavisdev Thanks! If you're looking to do another module video, I think I would be most interested in Task / TaskEither, and integrating that in a flow.
@rafaelhernand3z
@rafaelhernand3z Год назад
Ryan we need more of your videos! Some TE advanced patterns would be cool
@js9170
@js9170 Год назад
Very interesting video again, many thanks, hoping for more of it. 🎉
@mikeyim9985
@mikeyim9985 Год назад
Thank you for these!
@danielkeefer1901
@danielkeefer1901 Год назад
loving this content. keep it coming !
@ryandavisdev
@ryandavisdev Год назад
Thanks Daniel, glad to hear it
@SophearyChiv
@SophearyChiv Год назад
Thanks for the videos. Could you do a video on sequenceS and sequenceT?
@Lambdaphile
@Lambdaphile Год назад
Please, keep doing these videos! Thanks!
@ShawnShaddock
@ShawnShaddock Год назад
This was great, I love how you nitpicked and got into the details. I would love to see a series on io-ts as well!
@ApprendreSansNecessite
@ApprendreSansNecessite Год назад
There are a lot of weird patterns in this video. Why wrap `user` with `of` then chain when the first function you call takes a `User`? It is completely unnecessary. I have seen people make this "error" when composing functions with `pipe` because they think of it as the functional method chaining. It is more flexible than that. I am also sceptical about returning `Option` for the sake of adding your own error message. If you want to change the error message, you can simply use `mapLeft` without making `parseTime` fail with no useful error message for any of its callers. Parsing errors are not easily recoverable, but it's always nice to know when debugging that it encountered an unexpected token at a specific location for example. And if the error is recoverable, then you can use the error information to retry with `orElse` or you can figure out a fallback and use `getOrElse`.
@LeeXiangWei
@LeeXiangWei 4 месяца назад
const either = pipe( user, E.fromPredicate(userIsVerified, () => "User must be verified"), E.filterOrElse(userHas2FA, () => "User must setup 2FA") );
@volodymyryovchenko4240
@volodymyryovchenko4240 Год назад
JS objects wrapped in some crap, the author proudly calls Pipeable API. The name of this hype
Далее
If I were starting with fp-ts in TypeScript
14:55
Просмотров 10 тыс.
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32
Qalpoq - Amakivachcha (hajviy ko'rsatuv)
41:44
Просмотров 399 тыс.
ТАРАКАН
00:38
Просмотров 1,2 млн
When to use Do-Notation with fp-ts
10:01
Просмотров 4,6 тыс.
Enums considered harmful
9:23
Просмотров 207 тыс.
17 Pieces of C# Syntax That Make Your Code Short
12:41
An Option type in TypeScript (inspired by Rust)
12:53
Are you making the most of fp-ts Option?
27:21
Просмотров 8 тыс.
The purest coding style, where bugs are near impossible
10:25
Leveraging fp-ts Smart Constructors
7:49
Просмотров 2,7 тыс.
Ditch your Favorite Programming Paradigm
6:08
Просмотров 183 тыс.
Next Generation TypeScript | Prime Reacts
24:45
Просмотров 101 тыс.
КАК БОМЖУ ЗАРАБОТАТЬ НА ТАЧКУ
1:36:32