rescript-these

    1.0.0 • Public • Published

    rescript-these

    An "either-or-both" monadic type implementation in ReScript. This can be thought of as an "inclusive-or" type (as opposed to Result's "exclusive-or"), which can be used to represent the result of a computation that can fail, succeed, or do both at the same time.

    The data type is defined as:

    type These.t<'a, 'b> = This('a) | That('b) | These('a, 'b)

    This package provides various useful helper functions for transforming and querying the contained values.

    Installation

    npm install rescript-these

    Next, update the bs-dependencies key in your bsconfig.json to include rescript-these.

    Usage

    open These
    
    let result = This("Hello")
    
    // pattern matching
    switch result {
      | This(data) => Js.log(data)
      | That(error) => Js.log(error)
      | These(data, error) => Js.log2(data, error)
    }
    
    // transform the contained value
    let mapped = result->These.mapThis(data => data ++ " World!") // This("Hello World!")
    
    // chain the result of one computation with that of the next one
    let chain = result->These.flatMapThis(this => These(this, "Got error!")) // These("Hello World!", "Some Error!")

    Documentation

    API documentation is available at DOCUMENTATION.md.

    License

    MIT Licensed. See LICENSE file.

    External links

    1. fp-ts - These
    2. joneshf/elm-these
    3. purescript-contrib/purescript-these

    Install

    npm i rescript-these

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    8.82 kB

    Total Files

    8

    Last publish

    Collaborators

    • arafatamim