Hot answers tagged

5

One way to simplify As far as I can tell, each of your RegExps just looks at the start of your string for certain exact content - at that point you probably don't want match but startsWith, and you probably don't want to compile RegExps when you can just use the strings you're looking for directly It seems to me like you can get rid of look entirely and ...


2

There is one flaw in your code, that I can't pass. If I first put a positive number and then a negative, such as 3*-3, it won't do anything. It just ends and that's all.


2

First of all, the formatting could be a bit better. It's odd to have the first .replace at the same indentation level as else, and you can call map using curly braces if you want a function with multiple statements/expressions instead of making the function result a block. You don't actually need curly braces, but I'd say they're used for multi-line ...


1

Maybe regex to the rescue? val formatRegexp = "([A-Za-z0-9]+)(-.*)?[;,]?".r data.map(_.split(" ").map({ case formatRegexp(value, _*) => value case _ => "" }).sorted.distinct.mkString(" ") )


1

Parsing with Precedence I gather you want to add precedence to your operators, so you can write: 15 | !6 & 12 in place of: (15 | (!6) & 12) with the understanding that ! binds more tightly than & which binds more tightly than |. Fortunately, Parsec has built in support for this in the Text.Parsec.Expr module. The way you use it is to write a ...


Only top voted, non community-wiki answers of a minimum length are eligible