-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement geo API in test executor #446
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass done. Once you address the comments I'll re-review. It's getting there!
val key = input.head.asString | ||
val unit = input.last.asString match { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are unsafe calls.
orWrongType(isSortedSet(key))( | ||
for { | ||
scoreMap <- sortedSets.getOrElse(key, Map.empty) | ||
hashes = members collect scoreMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use functions as operators.
hashOption.map { hash => | ||
val geoHash = Hash.asGeoHash(hash.toLong) | ||
RespValue.bulkString(geoHash) | ||
}.getOrElse(RespValue.NullBulkString) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer fold
to map
+ getOrElse
. Less important, avoid long expressions in yield
. You can calculate the array contents before.
hashes.map { hashOption => | ||
hashOption.map { hash => | ||
val longLat = Hash.decodeHash(hash.toLong) | ||
RespValue.array( | ||
RespValue.bulkString(longLat.longitude.toString), | ||
RespValue.bulkString(longLat.latitude.toString) | ||
) | ||
}.getOrElse(RespValue.NullArray) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remarks as above.
) | ||
|
||
case api.Geo.GeoPos => | ||
val key = input.head.asString |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe call.
case api.Geo.GeoRadius => | ||
val stringInput = input.map(_.asString) | ||
|
||
val key = stringInput.head |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe call.
val withCoord = stringInput.find(_ == "WITHCOORD") | ||
val withDist = stringInput.find(_ == "WITHDIST") | ||
val withHash = stringInput.find(_ == "WITHHASH") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WithCoord
, WithDist
and WithHash
have stringify methods. Use it instead of raw values. Technically speaking it's less efficient but it reduces the amount of magic values roaming around the code.
val count = stringInput.toList.sliding(2) collectFirst { case "COUNT" :: count :: _ => | ||
count.toInt | ||
} | ||
val order = stringInput collectFirst { | ||
case "ASC" => Order.Ascending | ||
case "DESC" => Order.Descending | ||
} | ||
val store = stringInput.toList.sliding(2) collectFirst { case "STORE" :: key :: _ => | ||
key | ||
} | ||
val storeDist = stringInput.toList.sliding(2) collectFirst { case "STOREDIST" :: key :: _ => | ||
key | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't use functions as operators. Also, take care of the "magic" values.
case api.Geo.GeoRadiusByMember => | ||
val stringInput = input.map(_.asString) | ||
|
||
val key = stringInput.head |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unsafe call.
val withCoord = stringInput.find(_ == "WITHCOORD") | ||
val withDist = stringInput.find(_ == "WITHDIST") | ||
val withHash = stringInput.find(_ == "WITHHASH") | ||
val count = stringInput.toList.sliding(2) collectFirst { case "COUNT" :: count :: _ => | ||
count.toInt | ||
} | ||
val order = stringInput collectFirst { | ||
case "ASC" => Order.Ascending | ||
case "DESC" => Order.Descending | ||
} | ||
val store = stringInput.toList.sliding(2) collectFirst { case "STORE" :: key :: _ => | ||
key | ||
} | ||
val storeDist = stringInput.toList.sliding(2) collectFirst { case "STOREDIST" :: key :: _ => | ||
key | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checkout the remarks given above.
private[this] def orMissingParameter2[A, B](paramA: Option[A], paramB: Option[B])( | ||
program: (A, B) => USTM[RespValue] | ||
): USTM[RespValue] = | ||
apply(apply(Some(program.curried))(paramA))(paramB).getOrElse(STM.succeedNow(Replies.Error)) | ||
|
||
private[this] def orMissingParameter3[A, B, C](paramA: Option[A], paramB: Option[B], paramC: Option[C])( | ||
program: (A, B, C) => USTM[RespValue] | ||
): USTM[RespValue] = | ||
apply(apply(apply(Some(program.curried))(paramA))(paramB))(paramC).getOrElse(STM.succeedNow(Replies.Error)) | ||
|
||
private[this] def orMissingParameter4[A, B, C, D]( | ||
paramA: Option[A], | ||
paramB: Option[B], | ||
paramC: Option[C], | ||
paramD: Option[D] | ||
)( | ||
program: (A, B, C, D) => USTM[RespValue] | ||
): USTM[RespValue] = | ||
apply(apply(apply(apply(Some(program.curried))(paramA))(paramB))(paramC))(paramD) | ||
.getOrElse(STM.succeedNow(Replies.Error)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, we can later replace this apply reimplementation with the existing stuff present in zio-prelude.
Resolves #191