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

com.gregorpurdy.ident.IdentZioSchema.scala Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2023 Gregor Purdy
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.gregorpurdy.ident

import zio.schema.Schema

object IdentZioSchema {

  implicit val cikZioSchemaLong: Schema[Cik] =
    Schema.primitive[Long].transformOrFail(value => Cik.fromLong(value), ident => Right(ident.value))

  // FIXME: How to combine cikZioSchemaLong and cikZioSchemaString into fallback so we can flexibly accept Long or String input for decode?
  // implicit val cikZioSchemaString: Schema[Cik] =
  //   Schema.primitive[String].transformOrFail(value => Cik.fromString(value), ident => Right(ident.value.toString))

  implicit val cusipZioSchema: Schema[Cusip] =
    Schema.primitive[String].transformOrFail(value => Cusip.fromString(value), ident => Right(ident.value))

  implicit val figiZioSchema: Schema[Figi] =
    Schema.primitive[String].transformOrFail(value => Figi.fromString(value), ident => Right(ident.value))

  implicit val isinZioSchema: Schema[Isin] =
    Schema.primitive[String].transformOrFail(value => Isin.fromString(value), ident => Right(ident.value))

  implicit val leiZioSchema: Schema[Lei] =
    Schema.primitive[String].transformOrFail(value => Lei.fromString(value), ident => Right(ident.value))

  implicit val micZioSchema: Schema[Mic] =
    Schema.primitive[String].transformOrFail(value => Mic.fromString(value), ident => Right(ident.value))

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy