Questions tagged [either]

Either is a type used in functional languages such as Haskell and Scala to represent a value that is one of two parametrized types. In Scala, the Either type is often used as an alternative to scala.Option where Left represents failure (by convention) and Right is akin to Some.

341 questions
0
votes
0 answers

Using Either recursively

So I have defined a function like this one below: myFunction :: String -> Either String MyType I am reading String until the end. Left is used for handling errors. Right suppose to return me the tuple. In myFunction I am calling anotherFunction and…
dekanidze
  • 132
  • 2
  • 9
0
votes
1 answer

Haskell lexer input and returning list of tokens or error

Hi i am working on a problem where lexer takes in input string and return either list of tokens or the error. If anyone knows how to go about solving the problem please help. thank you :) lexer :: String -> Either Error [Token] I have gotten…
Zack
  • 21
  • 2
0
votes
2 answers

Compiler Error when using Either from dartz

I am currently experimenting with the flutter framework and dart and stumbled across a seemingly strange behaviour I fail to understand. Even though the context in which the actual problem occurs is way more complicated, I was even able to replicate…
Silverdust
  • 1,503
  • 14
  • 26
0
votes
2 answers

Scala: `ambigious implicit values` but the right value is not event found

I am writing a small Scala Program which should: Read a file (line by line) from a local FS Parse from each line three double values Make instances of a case class based on those three values Pass those instances to a Binary Heap To be able to…
vasigorc
  • 882
  • 11
  • 22
0
votes
2 answers

Patternmatching on 'Or' of 2 newtypes in haskell

I am using a decision diagram library within a haskell program. For this i want to declare 2 different (new)types that keeps track of which kind of decision diagram i am dealing with. The library i am using is cudd, and decision diagram base type…
0
votes
2 answers

Scala Yeild returning Try[Either[]] rather then Either

I am trying to do some handson with scala basic operations and got stuck here in the following sample code def insuranceRateQuote(a: Int, tickets:Int) : Either[Exception, Double] = { // ... something Right(Double) } def…
Ani
  • 463
  • 4
  • 20
0
votes
1 answer

Scala Future and Either Transformation

I have a variable of type val input: Future[Seq[Either[ErrorClass, Seq[WidgetCampaign]]]] = ??? I want to traverse this input and remove all duplicates WidgetCampaign and return the output as val result:…
Arjun Karnwal
  • 379
  • 3
  • 13
0
votes
2 answers

Combining two EitherT, return first if it succeeds else return second

Consider the following snippet: def foo(x:String): EitherT[F, Throwable, String] = ??? def bar(x:String): EitherT[F, Throwable, String] = ??? I want the following: On some input s, first call foo(s) and if it "fails" return the output of bar(s)…
Jus12
  • 17,824
  • 28
  • 99
  • 157
0
votes
1 answer

Convert Either> to Option> in c# LanguageExt

I'm using C# LanguageExt https://github.com/louthy/language-ext I have a class MyDto parsed from some Json. The parsing functions returns Either. If the dto matches a given rule, or it is an error, then I would like to get back the…
0
votes
1 answer

EitherT in Scala not working with For Comprehension

I have this code: (for { oldResult <- EitherT[Future, A, B](getById(id)) newResult <- EitherT.right(update(changeOldData(oldResult))) } yield newResult).value Where the functions returns getById -> Future[Either[A, B]] …
joao.sauer
  • 211
  • 2
  • 15
0
votes
1 answer

Figure out right types - Typescript interface method overload

I'm trying to figure out how to implement an auxiliary .flatMap method on Either monad. Unlike regular .flatMap it accepts a lambda that returns some regular value instead of Either instance. It's supposed to work like an adaptor to consume…
Ant
  • 181
  • 2
  • 14
0
votes
1 answer

Mapping an array of Eithers to an Either of an array of values

I have an Either type that is used to represent Failure and Success values, and I would like to write a function that takes an arbitrary number of Eithers and returns either the first Failure in the sequence, or a new Success with a value that is a…
0
votes
1 answer

Haskell I can not get exception ReadFile with try

I have a function "management" that checks parameters and return a Maybe (String): If there are not parameter -> return Nothing If my parameter is equal to "-h" -> Return a string help My problem arrived when I get a file and check if this file…
Guillaume
  • 191
  • 10
0
votes
1 answer

using the right side of the disjoint union properly

what's the best way to turn a Right[List] into a List I will parse a Json String like so val parsed_states = io.circe.parser.decode[List[List[String]]](source) And that will create an value equivalent to this val example_data =…
0
votes
2 answers

How to combine the left sides of Either objects in fp-ts?

I have two validation functions for different values that return Either. I'd like to throw an exception if one of them has a left value and do nothing if both are right. I've never used fp-ts before and can't figure out how to properly combine left…
chiborg
  • 26,978
  • 14
  • 97
  • 115