Skip to content

Commit

Permalink
fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jan 31, 2020
1 parent 5b23a10 commit 63846a3
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait JsonObjectCatss {
FF.map2(acc, f(v)){(elems, newV) =>
(k, newV) :: elems
}
}.map(elems => JsonObject.fromTraversableOnce(elems.reverse))
}.map(elems => JsonObject.fromIterable(elems.reverse))
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait JsonObjectMonocles {
from.toList.traverse[F, (JsonField, Json)]{ case (field, json) =>
Applicative[F].map(if(predicate(field)) f(json) else json.point[F])(field -> _)
}
)(JsonObject.fromTraversableOnce(_))
)(JsonObject.fromIterable(_))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ trait JsonObjectScalazs {
FF.apply2(acc, f(v)){(elems, newV) =>
(k, newV) :: elems
}
}.map(elems => JsonObject.fromTraversableOnce(elems.reverse))
}.map(elems => JsonObject.fromIterable(elems.reverse))
}
}
6 changes: 3 additions & 3 deletions argonaut/shared/src/main/scala/argonaut/ACursor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ case class ACursor(either: Either[HCursor, HCursor]) {

/** Get the current hcursor if we are in an succeeded state. Alias for `success`. */
def hcursor: Option[HCursor] =
either.right.toOption
either.toOption

/** Get the current hcursor if we are in an succeeded state. Alias for `hcursor`. */
def success: Option[HCursor] =
Expand Down Expand Up @@ -73,7 +73,7 @@ case class ACursor(either: Either[HCursor, HCursor]) {

/** Update the focus with the given function (alias for `>->`). */
def withFocus(k: Json => Json): ACursor =
ACursor(either.right.map(_.withFocus(k)))
ACursor(either.map(_.withFocus(k)))

/** Set the focus to the given value (alias for `:=`). */
def set(j: Json): ACursor =
Expand All @@ -95,7 +95,7 @@ case class ACursor(either: Either[HCursor, HCursor]) {
def rights: Option[JsonArray] = hcursor.flatMap(_.rights)

def withHCursor(f: HCursor => ACursor): ACursor =
ACursor(either.right.flatMap(c => f(c).either))
ACursor(either.flatMap(c => f(c).either))

/** Move the cursor left in a JSON array. */
def left: ACursor =
Expand Down
8 changes: 4 additions & 4 deletions argonaut/shared/src/main/scala/argonaut/DecodeResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ case class DecodeResult[A](result: Either[(String, CursorHistory), A]) {
result.isLeft

def map[B](f: A => B): DecodeResult[B] =
DecodeResult(result.right.map(f))
DecodeResult(result.map(f))

def flatMap[B](f: A => DecodeResult[B]): DecodeResult[B] =
DecodeResult(result.right.flatMap(f(_).result))
DecodeResult(result.flatMap(f(_).result))

def message: Option[String] =
failure.map(_._1)
Expand All @@ -25,7 +25,7 @@ case class DecodeResult[A](result: Either[(String, CursorHistory), A]) {
failure.map(_._2)

def toOption: Option[A] =
result.right.toOption
result.toOption

def toEither: Either[(String, CursorHistory), A] =
result
Expand All @@ -35,7 +35,7 @@ case class DecodeResult[A](result: Either[(String, CursorHistory), A]) {

/** alias for `toOption` */
def value: Option[A] =
result.right.toOption
result.toOption

def failure: Option[(String, CursorHistory)] =
result.left.toOption
Expand Down
4 changes: 2 additions & 2 deletions argonaut/shared/src/main/scala/argonaut/Json.scala
Original file line number Diff line number Diff line change
Expand Up @@ -673,11 +673,11 @@ trait Jsons {
* Construct a JSON value that is an object from an association list.
*/
def jObjectAssocList(x: JsonAssocList): Json =
JObject(JsonObject.fromTraversableOnce(x))
JObject(JsonObject.fromIterable(x))

/**
* Construct a JSON value that is an object from an association list (var args).
*/
def jObjectFields(x: (JsonField, Json)*): Json =
JObject(JsonObject.fromTraversableOnce(x))
JObject(JsonObject.fromIterable(x))
}
6 changes: 3 additions & 3 deletions argonaut/shared/src/main/scala/argonaut/JsonObject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ object JsonObject extends JsonObjects {
JsonObject.empty + (f, j)
}
/**
* Construct an object from a TraversableOnce instance.
* Construct an object from a Iterable instance.
*/
def fromTraversableOnce(t: TraversableOnce[(JsonField, Json)]): JsonObject = {
def fromIterable(t: Iterable[(JsonField, Json)]): JsonObject = {
t.foldLeft(empty)(_ :+ _)
}
}

trait JsonObjects {
}
}
22 changes: 11 additions & 11 deletions argonaut/shared/src/main/scala/argonaut/JsonParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ object JsonParser {
}
}

expectValue(json, 0).right.flatMap(parseResult)
expectValue(json, 0).flatMap(parseResult)
}

@tailrec
Expand Down Expand Up @@ -89,10 +89,10 @@ object JsonParser {
case ' ' | '\r' | '\n' | '\t' => expectObject(stream, position + 1, first, fields)
case _ => {
val next = for {
afterEntrySeparator <- (if (first) Right(position) else expectEntrySeparator(stream, position)).right
streamAndKey <- expectString(stream, afterEntrySeparator).right
afterFieldSeparator <- expectFieldSeparator(stream, streamAndKey._1).right
streamAndValue <- expectValue(stream, afterFieldSeparator).right
afterEntrySeparator <- (if (first) Right(position) else expectEntrySeparator(stream, position))
streamAndKey <- expectString(stream, afterEntrySeparator)
afterFieldSeparator <- expectFieldSeparator(stream, streamAndKey._1)
streamAndValue <- expectValue(stream, afterFieldSeparator)
} yield (streamAndValue._1, fields.add(streamAndKey._2, streamAndValue._2))
next match {
case Right((newPosition, newFields)) => expectObject(stream, newPosition, false, newFields)
Expand All @@ -111,8 +111,8 @@ object JsonParser {
case ' ' | '\r' | '\n' | '\t' => expectArray(stream, position + 1, first, fields)
case _ => {
val next = for {
afterEntrySeparator <- (if (first) Right(position) else expectEntrySeparator(stream, position)).right
streamAndValue <- expectValue(stream, afterEntrySeparator).right
afterEntrySeparator <- (if (first) Right(position) else expectEntrySeparator(stream, position))
streamAndValue <- expectValue(stream, afterEntrySeparator)
} yield (streamAndValue._1, fields += streamAndValue._2)
next match {
case Right((newPosition, newFields)) => expectArray(stream, newPosition, false, newFields)
Expand All @@ -139,7 +139,7 @@ object JsonParser {
else stream(position) match {
case '[' => expectArray(stream, position + 1)
case '{' => expectObject(stream, position + 1)
case '"' => expectStringNoStartBounds(stream, position + 1).right.map(pair => (pair._1, jString(pair._2)))
case '"' => expectStringNoStartBounds(stream, position + 1).map(pair => (pair._1, jString(pair._2)))
case 't' if stream.startsWith("true", position) => Right((position + 4, jTrue))
case 'f' if stream.startsWith("false", position) => Right((position + 5, jFalse))
case 'n' if stream.startsWith("null", position) => Right((position + 4, jNull))
Expand All @@ -161,8 +161,8 @@ object JsonParser {
@inline
private[this] final def expectString(stream: TokenSource, position: Int): Either[String, (Int, String)] = {
for {
afterOpen <- expectStringBounds(stream, position).right
afterString <- expectStringNoStartBounds(stream, afterOpen).right
afterOpen <- expectStringBounds(stream, position)
afterString <- expectStringNoStartBounds(stream, afterOpen)
} yield afterString
}

Expand Down Expand Up @@ -230,7 +230,7 @@ object JsonParser {
@inline
private[this] final def expectStringNoStartBounds(stream: TokenSource, position: Int): Either[String, (Int, String)] = {
for {
elements <- collectStringParts(stream, position).right
elements <- collectStringParts(stream, position)
} yield (elements._1, elements._2.toString())
}
}
8 changes: 4 additions & 4 deletions argonaut/shared/src/main/scala/argonaut/Parse.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ trait Parse[A] {
* Parses the value to a possible JSON value.
*/
def parseOption(value: A): Option[Json] = {
parse(value).right.toOption
parse(value).toOption
}

/**
* Parses the value and decodes it returning a list of all the failures stemming from
* either the JSON parsing or the decoding.
*/
def decode[X: DecodeJson](value: A): Either[Either[String, (String, CursorHistory)], X] = for {
json <- parse(value).left.map(Left.apply).right
decoded <- json.jdecode[X].fold((msg, history) => Left(Right((msg, history))), Right.apply).right
json <- parse(value).left.map(Left.apply)
decoded <- json.jdecode[X].fold((msg, history) => Left(Right((msg, history))), Right.apply)
} yield decoded

/**
Expand Down Expand Up @@ -94,7 +94,7 @@ trait Parse[A] {
* Parses and decodes the value to a possible JSON value.
*/
def decodeOption[X: DecodeJson](value: A): Option[X] = {
decode(value).right.toOption
decode(value).toOption
}

/**
Expand Down
6 changes: 3 additions & 3 deletions argonaut/shared/src/test/scala/argonaut/Data.scala
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ object Data {
Arbitrary(Gen.listOf(arbTuple2[T, U].arbitrary).map(_.toMap))

def jsonObjectGenerator(depth: Int = maxJsonStructureDepth): Gen[JObject] = arbImmutableMap(Arbitrary(arbitrary[String]), Arbitrary(jsonValueGenerator(depth - 1))).arbitrary.map{map =>
JObject(JsonObject.fromTraversableOnce(map.toList))
JObject(JsonObject.fromIterable(map.toList))
}

val nonJsonObjectGenerator = oneOf(jsonNumberGenerator, jsonStringGenerator, jsonBoolGenerator, jsonNothingGenerator, jsonArrayGenerator())
Expand All @@ -189,7 +189,7 @@ object Data {

def objectsOfObjectsGenerator(depth: Int = maxJsonStructureDepth): Gen[Json] = {
if (depth > 1) {
listOfN(2, arbTuple2(Arbitrary(arbitrary[String]), Arbitrary(objectsOfObjectsGenerator(depth - 1))).arbitrary).map(fields => JObject(JsonObject.fromTraversableOnce(fields)))
listOfN(2, arbTuple2(Arbitrary(arbitrary[String]), Arbitrary(objectsOfObjectsGenerator(depth - 1))).arbitrary).map(fields => JObject(JsonObject.fromIterable(fields)))
} else {
oneOf(jsonNumberGenerator, jsonStringGenerator, jsonBoolGenerator, jsonNothingGenerator)
}
Expand Down Expand Up @@ -234,7 +234,7 @@ object Data {
implicit def ArbitraryJson: Arbitrary[Json] = Arbitrary(jsonValueGenerator())

implicit def ArbitraryJsonObject: Arbitrary[JsonObject] =
Arbitrary(arbitrary[List[(JsonField, Json)]] map { JsonObject.fromTraversableOnce(_) })
Arbitrary(arbitrary[List[(JsonField, Json)]] map { JsonObject.fromIterable(_) })

implicit def ArbitraryCursor: Arbitrary[Cursor] = {
Arbitrary(arbitrary[Json] flatMap (j => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object StringWrapSpecification extends ArgonautSpec {
returns a failure for undecodable JSON ${
forAllNoShrink(alphaStr, arbitrary[Int]) { (name: String, age: Int) =>
val json = invalidJSONTemplate.format(name, age)
json.decode[Person].left.map(_.right.map(_._1)) must_== Left(Right("Person"))
json.decode[Person].left.map(_.map(_._1)) must_== Left(Right("Person"))
}
}

Expand Down

0 comments on commit 63846a3

Please sign in to comment.