46 Matching Annotations
  1. Mar 2021
    1. endpoint Diagram::Operation::Create do |ctx, **| redirect_to diagram_path(ctx[:diagram].id) end.Or do |ctx, **| render :form end
  2. Feb 2021
    1. Or you can use Maybe container! It consists of Some and Nothing types, representing existing state and empty (instead of None) state respectively.
    1. Let’s start with the same number dividing example, which returns 0 when the error happens. Maybe instead we can indicate that the result was not successful without any explicit numerical value?
    2. Now you can easily spot them! The rule is: if you see a Result it means that this function can throw an exception. And you even know its type in advance.
    3. You can use container values, that wraps actual success or error value into a thin wrapper with utility methods to work with this value. That’s exactly why we have created @dry-python/returns project. So you can make your functions return something meaningful, typed, and safe.
    1. Though rarer in computer science, one can use category theory directly, which defines a monad as a functor with two additional natural transformations. So to begin, a structure requires a higher-order function (or "functional") named map to qualify as a functor:

      rare in computer science using category theory directly in computer science What other areas of math can be used / are rare to use directly in computer science?

    2. can transform monadic values m a applying f to the unwrapped value a
    3. In fact, the Product comonad is just the dual of the Writer monad and effectively the same as the Reader monad (both discussed below)
    4. procedure to wrap values of any basic type within the monad (yielding a monadic value)
    5. A combinator, typically called bind (as in binding a variable) and represented with an infix operator >>=, that unwraps a monadic variable, then inserts it into a monadic function/expression, resulting in a new monadic value:(mx >>= f) : (M T, T → M U) → M U
    6. A type constructor M that builds up a monadic type M T
    7. A type converter, often called unit or return, that embeds an object x in the monad:.mw-parser-output .block-indent{padding-left:3em;padding-right:0;overflow:hidden}unit(x) : T → M T
    8. allows monads to simplify a wide range of problems
    9. another to compose functions that output monadic values (called monadic functions)
    10. Monads achieve this by providing their own data type (a particular type for each type of monad), which represents a specific form of computation
    11. In functional programming, a monad is an abstraction that allows structuring programs generically
    12. Supporting languages may use monads to abstract away boilerplate code needed by the program logic.
    13. Whatever language or default programming paradigm a developer uses, following the monad pattern brings many of the benefits of purely functional programming.
    14. By reifying a specific kind of computation, a monad not only encapsulates the tedious details of that computational pattern, but it does so in a declarative way, improving the code's clarity.
    15. Maybe T can be understood as a "wrapping" type, wrapping the type T into a new type with built-in exception handling
    16. Since monads make semantics explicit for a kind of computation, they can also be used to implement convenient language features.
    17. Research beginning in the late 1980s and early 1990s established that monads could bring seemingly disparate computer-science problems under a unified, functional model.
    18. handling potential undefined values (with the Maybe monad)
    1. The IO monad wraps computations in the following context: "This computation can read information from or write information to the terminal, file system, operating system, and/or network". If you want to get user input, print a message to the user, read information from a file, or make a network call, you'll need to do so within the IO Monad. These are "side effects". We cannot perform them from "pure" Haskell code.
    2. A Monad wraps a value or a computation with a particular context. A monad must define both a means of wrapping normal values in the context, and a way of combining computations within the context.
  3. Jan 2020