Giter Club home page Giter Club logo

circuit-breaker-monad's Introduction

Hey there! ๐Ÿ‘‹

I'm Yuriy Bogomolov, a seasoned software architect with a passion for functional programming, type systems, and category theory. You might recognize me from my work on #MonadicMondays, my lectures and workshops on YouTube, or my contributions to the fp-ts ecosystem. And if you're looking for some additional resources, I also write articles on my personal blog that cover everything from the basics of functional programming to advanced techniques and best practices.

Are you an individual developer or part of a small team looking to level up your functional programming skills in TypeScript? Look no further, because I'm here to help. As a mentor, I offer personalized guidance and support as you navigate the complex world of functional programming. Whether you're just starting out or looking to take your skills to the next level, I'll work with you to develop a customized learning plan that fits your unique needs and goals.

So why wait? Let's start your journey towards mastering functional programming in TypeScript today. You can reach me via email at [email protected], or shoot me a message on Telegram - I'm always happy to chat!

circuit-breaker-monad's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar fenbka avatar ybogomolov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

circuit-breaker-monad's Issues

circuit-breaker-monad v2.0.0

I would like to refactor this module a bit with the following points in mind:

  1. Currently, circuit breaker was just a Reader which returned a so-called "enhanced fetch" โ€“ which was, according to signature, very similar to the State monad. If we use type isomorphism from product (pair) to a curried function, we get exactly a Reader of State monad:

    // This type:
    export type EnhancedFetch<T> =
      (request: Lazy<Promise<T>>, ref: IORef<BreakerState>) => 
        [IORef<BreakerState>, TaskEither<Error, T>];
    
    // ...is isomorphic to:
    export type EnhancedFetch<T> =
      (request: Lazy<Promise<T>>) => (ref: IORef<BreakerState>) => 
        [TaskEither<Error, T>, IORef<BreakerState>];
    
    // ...which gives us a State monad:
    export type EnhancedFetch<T> =
      (request: Lazy<Promise<T>>) => State<IORef<BreakerState>, TaskEither<Error, T>>;
    
    // ...and being further reduced to a Reader:
    export type EnhancedFetch<T> =
      Reader<Lazy<Promise<T>>, State<IORef<BreakerState>, TaskEither<Error, T>>>;

    I've decided to move the request and breaker state parts to a new BreakerEnvironment type, so the final type of circuit breaker would be:

    export interface BreakerEnvironment<T> {
      request: Lazy<Promise<T>>;
      breakerState: IORef<BreakerState>;
    }
    
    export type CircuitBreaker<T> = 
      Reader<BreakerOptions, State<BreakerEnvironment<T>, TaskEither<Error, T>>>;

    Of course, I can just put BreakerOptions part inside the BreakerEnvironment<> type (or compose them), but I don't like this idea. I want to segregate the concerns: Reader provides a read-only environment, while State deals with mutable parts. I want to keep request as a Lazy<Promise<T>> due to Promises in JS being eager. If this project migrates to fluture one day, I will change it to just a single Future.

  2. As fp-ts is actively moving towards 2.0.0 release (see gcanti/fp-ts#823), this project as a part of its ecosystem needs to keep up. So I think it would be better to sync this project's major version to fp-ts's (at least, for now). I will not abandon v1 and will provide fixes for issues (if any are found).

  3. According to usage in my projects, it's better to expose an explicit singleton with clojure-bound IORef<BreakerState> variable, than to build such instance ad-hoc in each project. I would like to keep balance between purity and convenience of practical usage.

  4. As such refactoring effectively changes the types and behaviour of circuit breaker, I will remove note about this project being a port of Glue.CircuitBreaker from Haskell. This bothered me a bit, and now I can put my heart at ease.

Please vote or leave a comment about these changes!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.