% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/progressive.R
\name{\%::\%}
\alias{\%::\%}
\alias{contract_syntax}
\title{Evaluate an S7 call under an interface or trait contract}
\usage{
expr \%::\% contract
}
\arguments{
\item{expr}{An expression evaluated in a contract mask. Calls to generics
named in the contract are checked.}

\item{contract}{An interface created by \code{\link[=new_interface]{new_interface()}} or a trait created
by \code{\link[=new_trait]{new_trait()}}.}
}
\value{
The value of \code{expr}, after any optional return check.
}
\description{
\code{with(contract, expr)} and \code{expr \%::\% contract} evaluate \code{expr} in a
contract mask. Required generics are shadowed by checking wrappers, so calls
to those generics use normal S7 dispatch while checking the optional argument
and return specifications stored in an interface requirement or trait method.
}
\examples{
local({
  draw <- S7::new_generic("draw", "x", function(x, color) {
    S7::S7_dispatch()
  })
  Circle <- S7::new_class("TypedCircle", properties = list(r = S7::class_double))
  S7::method(draw, Circle) <- function(x, color) paste(color, x@r)
  Drawable <- new_interface(
    "TypedDrawable",
    generics = list(draw = interface_requirement(
      draw,
      args = list(color = S7::class_character),
      returns = S7::class_character
    ))
  )
  with(Drawable, draw(Circle(r = 2), color = "red"))
  checked_draw <- with(Drawable, function(x) draw(x, color = "red"))
  checked_draw(Circle(r = 2))
  draw(Circle(r = 2), color = "red") \%::\% Drawable
})
}
