All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lucuma.itc.binding.PrimitiveBinding.scala Maven / Gradle / Ivy

There is a newer version: 0.22.3
Show newest version
// Copyright (c) 2016-2023 Association of Universities for Research in Astronomy, Inc. (AURA)
// For license information see LICENSE or https://opensource.org/licenses/BSD-3-Clause

package lucuma.odb.graphql.binding

import grackle.Value
import grackle.Value.AbsentValue
import grackle.Value.NullValue

/** A primitive non-nullable binding. */
def primitiveBinding[A](name: String)(pf: PartialFunction[Value, A]): Matcher[A] =
  case NullValue   => Left(s"$name cannot be null")
  case AbsentValue => Left(s"$name is not optional")
  case other       =>
    pf.lift(other) match {
      case Some(value) => Right(value)
      case None        => Left(s"expected $name, found $other")
    }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy