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

com.twilio.guardrail.generators.Module.scala Maven / Gradle / Ivy

package com.twilio.guardrail
package generators

import com.twilio.guardrail.languages.LA
import cats.data.StateT
import cats.syntax.all._

abstract class AbstractModule[L <: LA] {
  def popModule[A](section: String, first: (String, A), rest: (String, A)*): StateT[Target, Set[String], A] =
    StateT[Target, Set[String], A]({ modules =>
      modules.toList.flatTraverse { module =>
        (first :: rest.toList).flatTraverse({
          case (`module`, value) => (Set.empty[String], List(value))
          case _                 => (Set(module), Nil)
        })
      } match {
        case (_, Nil)             => Target.raiseError(MissingModule(section, (first :: rest.toList).map(_._1)))
        case (rest, value :: Nil) => Target.pure((rest, value))
        case (rest, a :: b :: _) =>
          Target.raiseError(ModuleConflict(section))
      }
    })
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy