Skip to content
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

Rename/alias :=? operator to :?= #93

Closed
seigert-xx opened this issue Apr 17, 2014 · 6 comments
Closed

Rename/alias :=? operator to :?= #93

seigert-xx opened this issue Apr 17, 2014 · 6 comments

Comments

@seigert-xx
Copy link

Consider following example:

Json(
  "required" := Option(1) filter (_ > 0),
  "optional" :=? (Option(1)) filter (_ < 0))
)

StringWrap.:= ends with = symbol and thus, according to SLS 6.12.4, has lowest precedence of all infix operators. StringWrap.:=? for Options ends with ? which implies that it is 'normal' infix operator with precedence defined by first : symbol.

: has higher precedence than letters, according to SLS 6.12.3 and that what requires us to put Option(1)) filter (_ < 0) in additional, otherwise unnecessary, brackets.

@markhibberd
Copy link
Contributor

Happy to add the new operator as an alias now, but will leave the other one for now and consider removing it later.

@seigert-xx
Copy link
Author

I was wondering also: is it possible to provide some operator (or reuse :=?), which would produce Option[(Json.JsonField, Json)] instance based on 'is right-hand Json is empty or not'?
Example:

("none" ~= jEmptyObject) == None
("some" ~= jSingleObject("test", "value")) == Some(Json("some" := jSingleObject("test", "value")))

@seigert-xx
Copy link
Author

->?: is not of any help here, because we unable to produce Option[JsonAssoc] from jEmptyObject:

scala> import argonaut._, Argonaut._
import argonaut._
import Argonaut._

scala> ("none" :=? jEmptyObject) ->?: jEmptyObject
<console>:14: error: type mismatch;
 found   : argonaut.Json
 required: Option[?]
              ("none" :=? jEmptyObject) ->?: jEmptyObject
                          ^

scala> ("none" := jEmptyObject) ->?: jEmptyObject
<console>:14: error: type mismatch;
 found   : (String, argonaut.Json)
 required: Option[(argonaut.Json.JsonField, argonaut.Json)]
              ("none" := jEmptyObject) ->?: jEmptyObject
                                       ^

markhibberd added a commit that referenced this issue Apr 21, 2014
@markhibberd
Copy link
Contributor

@seigert This is what you were after in the first instance?

("optional" :?= Some(1) filter (x => x > 0)) must_== Some("optional" := 1)

As for the follow up, the best I can suggest for now is:

def x: Json = ???
("none" :=? x.obj.exists(_.isNotEmpty).option(x)) ->?: jEmptyObject

I will have a think about adding something to do that, but if you really want it can you just throw it in another issue so I can close this one when I release the operator change.

@seigert-xx
Copy link
Author

@markhibberd Yep, that's what I meant.

Will move second part to a separate issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants