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

eu.joaocosta.interim.ItemId.scala Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package eu.joaocosta.interim

import scala.annotation.alpha

/** Identifier of an item. Should be unique for each item.
  *
  * Can be either a Int, a String, or a sequence of that (which is especially useful for composite components).
  */
type ItemId = (Int | String) | List[(Int | String)]

object ItemId:
  /** Helper method to convert an ItemId into a List
    */
  extension (itemId: ItemId)
    def toIdList: List[(Int | String)] =
      itemId match {
        case int: Int                   => List(int)
        case str: String                => List(str)
        case list: List[(Int | String)] => list
      }

  /** Operator to add a child to an item id. Useful for composite components.
    */
  extension (parentId: ItemId)
    @alpha("addChild")
    def |>(childId: ItemId): ItemId =
      parentId.toIdList ++ childId.toIdList




© 2015 - 2025 Weber Informatics LLC | Privacy Policy