Code Monkey home page Code Monkey logo

purescript-either's Introduction

purescript-either

Latest release Build status Pursuit

The Either type provides is used to represent values that can be one of two possibilities. For example, Either Int Number can be used in a place where either integers or floating point numbers are acceptable.

A common use for this type is error handling, where by convention the Left constructor carries error messages and the Right constructor carries expected values (“Right is right”). This convention is used as the Functor, Applicative, Monad, etc. instances all operate on the Right part of the Either.

Installation

spago install either

Documentation

Module documentation is published on Pursuit.

purescript-either's People

Contributors

anttih avatar garyb avatar hdgarrood avatar i-am-the-slime avatar jdegoes avatar jordanmartinez avatar kika avatar kl0tl avatar kritzcreek avatar liamgoodacre avatar marcosh avatar matthewleon avatar milesfrain avatar monoidmusician avatar natefaubion avatar paf31 avatar passy avatar pseudonom avatar rhendric avatar safareli avatar srghma avatar thomashoneyman avatar tmcgilchrist avatar zudov 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

purescript-either's Issues

Add Left and Right projections into some Alternative

I think it might be useful to have functions like this:

asRight :: forall e a f. Alternative f => Either e a -> f a
asRight (Right x) = pure x
asRight _ = empty

asLeft :: forall e a f. Alternative f => Either e a -> f e
asLeft (Left x) = pure x
asLeft _ = empty

let me know if this is desired addition and will open PR. (are names fine?)

lazy note

Would love to see a lazy note, in the spirit purescript-maybe's lazy functions (maybe' and fromMaybe')

note' :: forall a b. (Unit -> a) -> Maybe b -> Either a b

Semiring Either instance is dodgy

A Semiring is supposed to form a commutative monoid under addition, but:

> Left "hello" + Left " world" :: Either String Int
(Left "hello")

> Left " world" + Left "hello" :: Either String Int
(Left " world")

Should `injectReflexive` be the first `Inject` instance?

See discussion in purescript/documentation#211

With the current instance, we have:

> import Data.Either
> import Data.Either.Inject
> x = Left 0 :: Either Int String
> inj x :: Either Int String
Error found:
in module $PSCI
at <internal> line 0, column 0 - line 0, column 0

  No type class instance was found for
                                                 
    Data.Either.Inject.Inject (Either Int String)
                              String             
                                                 

while applying a function inj
  of type Inject t0 t1 => t0 -> t1
  to argument x
while checking that expression inj x
  has type Either Int String
in value declaration it

where t0 is an unknown type
      t1 is an unknown type

See https://github.com/purescript/documentation/blob/master/errors/NoInstanceFound.md for more information,
or to contribute content related to this error.

If being able to have inj specialise to the identity function is important, should injectReflexive go first? Alternatively, should we consider just dropping the instance?

Travis publish to Pursuit fails with dirty working tree

$ test $TRAVIS_TAG && echo $GITHUB_TOKEN | pulp login && echo y | pulp publish --no-push
Please obtain a GitHub personal access token at:
  https://github.com/settings/tokens/new
No scopes are required, so don't check any of the boxes.

After you've done that, paste it in here: Successfully authenticated as garyb.
* ERROR: Your git working tree is dirty. Please commit or stash your changes first.

https://s3.amazonaws.com/archive.travis-ci.org/jobs/246280467/log.txt?X-Amz-Expires=30&X-Amz-Date=20170623T212624Z&X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAJRYRXRSVGNKPKO5A/20170623/us-east-1/s3/aws4_request&X-Amz-SignedHeaders=host&X-Amz-Signature=e07ad853543fdea2e8fd453428ce9473079819c918c2cbbbfe216855bdcc87cc

`from` and `to` are used in incorrect order?

toEither3 :: Either3 Number Number Number -> Color should be named fromEither3 as it takes Either3 (it's not returning Either3).

fromEither3 :: Color -> Either3 Number Number Number returns Either and it should be named toEither3.

Am I messing something?

data Color = Red Number | Green Number | Blue Number
-- 
toEither3 :: Either3 Number Number Number -> Color
toEither3 = either3 Red Green Blue

fromEither3 :: Color -> Either3 Number Number Number
fromEither3 (Red   v) = in1 v
fromEither3 (Green v) = in2 v
fromEither3 (Blue  v) = in3 v

see

Conversion to and from `V`?

Oftentimes, I find myself wanting to convert an Either to perform error accumulation. Currently I have a custom function that uses the either function, but it's kind of cumbersome. Maybe we should add a function here or in purescript-validation?

`fromLeft` / `fromRight` shouldn't be partial

I'd like to have

fromLeft :: forall a b. a -> Either a b -> a
fromRight ::  forall a b. b -> Either a b -> b

over the current partial

fromLeft :: Partial => forall a b. Either a b -> a
fromLeft :: Partial => forall a b. Either a b -> b

as typing either (const a) identity becomes old rather quickly and I need these functions much more frequently than their partial counterparts. I'm not sure how confusing it would be to define these functions differently in two modules in this package, but even if don't rename the old ones I think this would be a win.

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.