Effect for Beginners

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024

Комментарии • 68

  • @ethanniser
    @ethanniser  Год назад +20

    CORRECTIONS:
    Recent versions of Effect have flipped around the order of the type parameters, so Effect is now Effect
    None of the concepts here have changed, but it might be a bit confusing if you go straight to the current docs
    8:10 - "x > 5" should be "x >= 5"
    12:12 - “Error” should be “Error | ParseError”

    • @hafermuech
      @hafermuech 4 месяца назад

      also, the generator now does not require the wrapper function anymore

  • @mattpocockuk
    @mattpocockuk Год назад +70

    Great video.
    A few thoughts:
    - I'd love to know why Requirements are implemented in this way. It seems like an extraordinary amount of code for doing dependency injection on a single string.
    - Watching the errors automatically propagate through the pipeline was the most exciting/enticing bit of the video. Seems like leaning into this would get folks excited about it.
    - I have no idea why you would use generators, and the video didn't go into why. A concrete use case for where generators are better would be useful.
    - I would love to see direct comparisons between non-Effect and Effect code. My main concern about using Effect is that it seems like an enormous ring-around-the-roses to get strongly-typed errors. I'm not convinced that it's a good thing yet.

    • @ethanniser
      @ethanniser  Год назад +32

      Hey Matt,
      Truly thank you for taking the time to watch my video, and I really appreciate your thoughts. Here are my thoughts on those thoughts :)
      Requirements:
      The examples in this video might have been too simple to show the full power here. Dependency Injection is a really powerful concept (see @CodeAesthetic 's newest video) but the problem is its kind of annoying to do right, so most of the time we just don’t. In Effect its as simple as making a Tag for some type and using the tag. Once you realize how easy this is you can dependency inject things you never would have before. I’ve personally seen projects using Effect that have a union of ~30 types in the Requirements field of Effects before they start providing them. Doing that level of dependency injection without both the type safety and runtime abstraction provided by something like Effect would be very very difficult. Another case study here is “Typed” (TylorS/typed-fp - an experimental Effect web framework) which uses Requirements to create a react context like API that’s fully typesafe. It also makes things like the entire DOM a typed requirement, meaning you can easily just swap it out with a fake one for testing.
      Error Handling:
      Yes, and it is the most exciting part for me too. Having experience in rust, this is the “Result + ? Operator” I love but right back home in typescript. What it enables is also very exciting. Just like tracking dependencies, imagine using the “typed” web framework and having errors bubble up your entire component tree fully typed, it would be really really powerful.
      Generators:
      The case for generators is the exact same as async/await. Without either you have to write all your code in nested callbacks and through functional pipelines which isn’t everyone’s cup of tea. Just how you can just ‘await’ a promise and use the result as if it wasn’t a promise, you can just ‘yield*’ an Effect and use it like it isn’t an Effect. It also allows for the use of imperative concepts like for loops and if statements, who’s functional alternatives are harder to read and grasp.
      Comparisons:
      If your willing to spend another ~30 minutes of your time (half on 2x speed :) ) on Effect, the creator of Effect, Michael, has a great conference talk where he spends the first half writing without Effect, then uses Effect to clean things up. I think this is exactly what your looking for, the link is: ruclips.net/video/zrNr3JVUc8I/видео.html.

    • @nicholainissen
      @nicholainissen 4 месяца назад +1

      Hey Matt! Love your stuff. With regards to Requirements, I recommend watching Mark Seemans talk about "Dependency Rejection" to understand why we employ patterns like this. It's really useful for composition and function purity.

  • @samuelgunter
    @samuelgunter Год назад +38

    your channel has had a profund Effect on my life, thank you

    • @dawid_dahl
      @dawid_dahl Год назад +1

      Caught any errors so far?

  • @Phlickey
    @Phlickey Год назад +13

    Best tutorial on fp with monads I've ever seen, and didn't use the word monad once. Thank you.

  • @Daniel-hz6pt
    @Daniel-hz6pt Год назад +7

    This seems like the perfect mix of Rust and Typescript, really exciting stuff, I’d love to see some Fireship style videos of implementing real world applications and the changed concepts you’d need to know to use Effect… effectively :)

  • @lorenzogabriele9533
    @lorenzogabriele9533 Год назад +2

    Scala continues to drive innovation which gets adopted on all programming languages.
    ZIO for typescript, cool!

  • @Daniel-hz6pt
    @Daniel-hz6pt Год назад +3

    I think a great video would be taking some kind of full stack TS app, such as a Reddit clone, notes app, etc, something that has a lot of interacting layers and showing how to port that code/rewrite it in Effect, I’m trying to learn Effect atm and sometimes things make total sense, but sometimes they just make no sense in the context of real world applications, after working with it for a little bit I really like it.. but this feels like something that should be handled at the compiler layer ala rust, instead of bolting it on to JavaScript/TypeScript, I’m really excited for the ecosystem to migrate to Effect and get some rust-analyzer tier quality error handling/robust code encouragement in typescript

  • @seannewell397
    @seannewell397 Год назад +3

    +1 for the pnpm shout. #best

  • @helleye311
    @helleye311 Год назад +3

    I've heard of Effect before but never saw a full video like this. I can see why people are starting to talk about it.
    Really feels like the best parts of rust moved to typescript.
    The syntax seems a little clunky, writing Effect.[*] for everything and all the functions and brackets and such (it's better with generators, but still yield* _([*]) isn't exactly the prettiest). Might give it a shot at some point though. It hits an uncanny valley of "typescript but not quite" in an interesting way.

  • @MrZiyak99
    @MrZiyak99 Год назад +2

    love being able to extend errors with _tag. overall i love the concept of Effect and hope some of these will trickle down to typescript/javascript. great video!

  • @ShawnShaddock
    @ShawnShaddock Год назад

    What a great video, it was extremely well made! Thank you and the effect team for making it possible. Looking forward to watching the Schema video too!

  • @dawid_dahl
    @dawid_dahl Год назад +1

    Wonderful tutorial, thank you!
    My dream would be to be able to use this FP library at work.

  • @Thundechile
    @Thundechile 5 месяцев назад +2

    Note: Effect v2.3 changed the order of the Effect signature from Effect to Effect.

    • @ethanniser
      @ethanniser  5 месяцев назад +1

      I updated the corrections comment
      Thanks for the reminder

    • @Thundechile
      @Thundechile 5 месяцев назад

      @@ethanniserno problem, thanks for the great video, it's really well done!

  • @mathiasmaerker613
    @mathiasmaerker613 Год назад +3

    Great video! Thanks a lot. Can you explain Layers in your next video😅 still struggling with those

  • @12px
    @12px Год назад +1

    Consider using a language that supports strong typing and exhaustive pattern matching, such as Rust. Rust offers Result, Option (with Some(x) or None), and Future, which are all you need to write safe, type-checked, asynchronous code using your preferred async runtime like Tokio.

    • @ethanniser
      @ethanniser  Год назад +3

      Rust is amazing, trust me I’m a big fan.
      But that doesn’t change the fact that most of the web is built with JavaScript. What’s cool about effect is we get some of those features you mentioned that rust has (result type + pattern matching) from a library that interops with mountains of existing code.

  • @christofferbergj
    @christofferbergj Год назад +4

    Thank you for making this video. Very concise, understandable and really interesting.
    I have been using `supermacro/neverthrow" for quite some time, which carries a few similarities to the error handling mentioned in this video.
    I am unsure if using Effect is going too deep into "robustness/correctness" for day-to-day use, building "normal" content and CRUD React applications.
    I'm entirely on board with treating errors as first-class citizens, but will I find myself writing more code (more code is not always worse) with Effect, possibly confusing myself and the next developer? Or is `neverthrow` the perfect concise way of surfacing errors. I'm not sure.

    • @chris94kennedy
      @chris94kennedy 5 месяцев назад

      just write golang and be done with it

  • @itsandyagain
    @itsandyagain 4 месяца назад +1

    I like the concept. It would be nice to remove the hidden control flow from TypeScript, but this solution seems extremely noisy/cluttered. If this gets simplified then I would use it in every project

    • @invinciblemode
      @invinciblemode 22 дня назад

      Give it a try! I felt the same way, but after actually writing some effect code, it’s more ergonomic and readable than I expected.

  • @trentcox9239
    @trentcox9239 6 месяцев назад +1

    im a big fan of fp-ts and im trying to come to grips with accepting the fact that effect-ts is the way forward, but gooooood damn if generators aren't the ugliest things ive ever seen in a code base. enough to scare off most junior devs being onboarded into a pre existing project...
    EDIT: sigh...should of reserved my opinion until after watching the video. The generators used in the way described actually looked decent and read fairly well.....

    • @ethanniser
      @ethanniser  6 месяцев назад

      What’s great is generators are completely optional. Everything you can do in them you can do with sweet sweet functions only.
      It’s really just a bridge for people newer to FP to get all the benefits but not have to change that much about how they code.
      If you know async await you know generators, which I think is huge for onboarding.

    • @ethanniser
      @ethanniser  6 месяцев назад

      What’s great is generators are completely optional. Everything you can do in them you can do with sweet sweet functions only.
      It’s really just a bridge for people newer to FP to get all the benefits but not have to change that much about how they code.
      If you know async await you know generators, which I think is huge for onboarding.

  • @romankoshchei
    @romankoshchei Год назад

    Brilliant video. I am a bit confused about runSync, because you can't understand weather Effect is sync or async without looking at it. But imagine quite complex Effect. So probably you end up using runPromise most of the time to ensure working code.

    • @michaelarnaldi6680
      @michaelarnaldi6680 Год назад +1

      The general rule is "run to a Promise when you can, run sync when you have no other choice"

  • @dawid_dahl
    @dawid_dahl Год назад +3

    I bet it will feel weird when one is encountering the Effect type in a function signature, and you won't know whether to use .sync, .syncTry, .promise or .promiseTry to run it. In fp-ts I see TaskEither and I immediately know that it is async and that it could fail.
    You see what I mean?

    • @michaelarnaldi6680
      @michaelarnaldi6680 Год назад +1

      You end up running an effect only at the edges of your program, the usual case is running with either runPromise or runFork that handle all types of effects. The case for runSync is mostly when you have to run sync things like if you have to create a runtime within a component render or similar cases, there you'd use runSync and having async code is an exception, we experimented making the async marker apparent but we realized after a while that it was mostly restricting and polluting the types for no tangible benefit

    • @dawid_dahl
      @dawid_dahl Год назад

      @@michaelarnaldi6680 So cool of you to reply, thank you! So I can run sync stuff with .tryPromise too? Like it won’t throw an exception or something?
      That’s good to know at least, then as a function caller unaware of an Effect-function’s internals I could maybe have as a rule to run most of them like that, even though it would feel slightly awkward.

    • @michaelarnaldi6680
      @michaelarnaldi6680 Год назад +1

      Yes `runPromise` like `runFork` can run any effects, and should be used as the default case, it's to some extent like an async function being able to include sync code too, in JS sync execution is kind of risky in the sense that you only got one thread and you never want to block it so execution using runSync should really only be a special case for when there is nothing else you can do

    • @dawid_dahl
      @dawid_dahl Год назад

      @@michaelarnaldi6680 Thanks, Michael. I’m currently using fp-ts at work and I’m therefore super interested in Effect.

    • @invinciblemode
      @invinciblemode 22 дня назад

      @@michaelarnaldi6680why isn’t there just an Effect.run that just works?

  • @PatrickJBauer89
    @PatrickJBauer89 Год назад +2

    Hey Ethan, thanks for your videos.
    Could you explain why the program code at 12:12 only has Error as a possible error? Shouldn't it also be a ParseError like the Error options that the getPokemon effect has?

    • @ethanniser
      @ethanniser  Год назад +3

      Your correct, thanks for pointing this out, I’ve updated the pinned corrections comment

  • @js9170
    @js9170 Год назад +1

    Thanks for that video! In the example at 8:10, there is a small and infamous bug: it should be „x >= 5“ instead of „x > 5“ (line 6). Also, why is the input parameter returned in case of success? Wouldn’t it make more sense to return true or false for a function „checkIfAtLeastFive“?

    • @ethanniser
      @ethanniser  Год назад +1

      Added to the corrections comment thank you.
      For your second point, you could do that although my idea for the example was just to add something to the pipeline that left use with Effect so in that case passing the number on made sense but its just an example

  • @HNXakido
    @HNXakido Год назад

    Thank you for this video.
    A question for 12:10
    Is flattening an array of 10 random number effects equivalent to wrapping an array of 10 random numbers with sync?

  • @eillioniscreating
    @eillioniscreating Год назад

    Can you make the tutorial for BETH stack pls?

  • @meyou118
    @meyou118 Год назад +6

    ZIO for typescript

  • @austincodes
    @austincodes 4 месяца назад

    2:53 couldn't you just use an implicit return type here? Do you need to always write an explicit return type when using Effect?

    • @ethanniser
      @ethanniser  4 месяца назад

      It’s just so it’s visible for the video
      Effect can fully infer everything

  • @venil82
    @venil82 Месяц назад +1

    Is it right to think that effect is just glorified ReaderTaskEither from fp-ts with advanced dependency providing mechanism ?

    • @ethanniser
      @ethanniser  Месяц назад

      effect.website/docs/other/fp-ts

  • @dolevgo8535
    @dolevgo8535 Год назад +1

    a quick thing that bothers me- why is the actual return type the last parameter of the Effect generic? It's not common for a function to not have a return type, and with the current ordering the type has nevers as the first argument for no real reason(actually using the type would be a bit of a pain as you need to pass void twice before the actual type)

    • @ethanniser
      @ethanniser  Год назад +2

      Anywhere I used explicit typing, typescript is able to infer, you do not need to ever type function return types when using effect if your don't want to.
      As for "why is the actual return type the last parameter of the Effect generic?"
      Because an Effect can describe the computation of a value of any type, the generic describes the type of that value for that effect.

    • @dolevgo8535
      @dolevgo8535 Год назад

      @@ethanniser huh, I can see that what you mean
      i'll give it a try- seems pretty cool

  • @jofla
    @jofla Год назад +19

    honestly, I think Effect is not productive. I was also interested in functional programming but tbh most people don't give a fuck, and, it ends up being counter-productive to introduce technologies like this to an organization. It's kind of sad because I love Scala but I have made peace with the situation

    • @michaelarnaldi6680
      @michaelarnaldi6680 Год назад +11

      Fwiw I've seen the opposite being true for zio & effect. For general FP I'd have to agree. Most of what effect is suffering from is burnout from other technologies that people wanted to believe in.

    • @gandalfthegrey2777
      @gandalfthegrey2777 4 месяца назад +3

      This is not for hobby projects, start ups or small SAAS projects.
      This is for typescript at scale, for extremely large projects with 10s to 100s of millions of users and millions of lines of code
      Usually in such big projects people don't mind writting extra steps and not sacrificing some dx to get better performance and safety

  • @stefanvanjaarsveld7589
    @stefanvanjaarsveld7589 Год назад

    See some simularities between Effect and Rxjs. What would make Effect a better option?

    • @ethanniser
      @ethanniser  Год назад +1

      Rxjs is kind of similar in some ways, but Effect has much superior error handling as well as a much larger and more robust ecosystem of supporting tools.

    • @Joshua-dc4un
      @Joshua-dc4un Год назад +1

      Dependency injection

    • @stefanvanjaarsveld7589
      @stefanvanjaarsveld7589 Год назад

      @@ethanniser Ahh I see, will give it a try :)

  • @seannewell397
    @seannewell397 Год назад

    Has someone already got a structured JSON Logger for Effect?

  • @zzzyyyxxx
    @zzzyyyxxx Год назад

    How does this compare to fp-ts?

    • @magne6049
      @magne6049 Год назад

      it is a superset of fp-ts, and that is why the creator of fp-ts decided to merge fp-ts into effect-ts going forward. But effect-ts will be much better documented and less complex to grasp for beginners.

    • @zzzyyyxxx
      @zzzyyyxxx Год назад

      @@magne6049 Thanks I just took a look more into Effect and its relationship to fp-ts, looks like you're right. That's pretty cool, it's the successor to fp-ts.

  • @oscarljimenez5717
    @oscarljimenez5717 Год назад

    The only sad of this is that change your code to be fully functional, i don't support any extreme (yeah, i'm looking at you OOP fans like Java or C#). I would like that the code look more a procedural way with some aspect of functional. Procedural is always the best way. Because this fully functional take is make Effect very hard to introduce in codebases, yeah, you can use it anyway, but people will tend to not.

  • @derekv210
    @derekv210 Год назад

    'promo sm'

  • @mattmmilli8287
    @mattmmilli8287 6 месяцев назад

    no