<commit_before>package castalia.matcher

import akka.actor.ActorRef
import akka.http.scaladsl.model.Uri.Path
import castalia.matcher.types._

package object types{
  type Segments = List[String]
  type Params = List[(String, String)]
}


/**
  * Holds an endpoint matching structure and an ActorRef that can process the request
  *
  * @param segments containing the path segment matches and path parameters
  * @param handler ActorRef containing the name of the actor that can process this request
  */
case class Matcher(segments: Segments, handler: ActorRef) {
  /**
    * Compare the segments, matching the literals and collecting the parameters on the fly
    * @param requestSegments containing the path segments from the request
    */
  def matchPath(requestSegments: Segments): Option[Params] = {
    def marp( requestSeg: Segments, matchSeg: Segments, params: Params): Option[Params] =
      (requestSeg, matchSeg) match {
        case (Nil, Nil)  => Some(params)
        case (Nil, _) => None
        case (_, Nil) => None
        case (rSeg, mSeg) if isParam(mSeg.head) => marp(rSeg.tail, mSeg.tail, (paramName(mSeg.head), rSeg.head)::params)
        case (rSeg, mSeg) if rSeg.head.equals(mSeg.head) => marp(rSeg.tail, mSeg.tail, params)
        case (_, _) => None
    }

    marp( requestSegments, segments, List[(String, String)]())
  }

  private def isParam(segment: String): Boolean = {<commit_msg>Match on segments as List[String] to get rid of head and tail.<commit_after>package castalia.matcher

import akka.actor.ActorRef
import akka.http.scaladsl.model.Uri.Path
import castalia.matcher.types._

package object types{
  type Segments = List[String]
  type Params = List[(String, String)]
}


/**
  * Holds an endpoint matching structure and an ActorRef that can process the request
  *
  * @param segments containing the path segment matches and path parameters
  * @param handler ActorRef containing the name of the actor that can process this request
  */
case class Matcher(segments: Segments, handler: ActorRef) {
  /**
    * Compare the segments, matching the literals and collecting the parameters on the fly
    * @param requestSegments containing the path segments from the request
    */
  def matchPath(requestSegments: Segments): Option[Params] = {
    def marp( requestSeg: Segments, matchSeg: Segments, params: Params): Option[Params] =
      (requestSeg, matchSeg) match {
        case (Nil, Nil)  => Some(params)
        case (Nil, _) => None
        case (_, Nil) => None
        case (rhead::rtail, mhead::mtail) if isParam(mhead) => marp(rtail, mtail, (paramName(mhead), rhead)::params)
        case (rhead::rtail, mhead::mtail) if rhead.equals(mhead) => marp(rtail, mtail, params)
        case (_, _) => None
    }

    marp( requestSegments, segments, List[(String, String)]())
  }

  private def isParam(segment: String): Boolean = {
{'fraction_non_alphanumeric': 0.10775112964893986, 'fraction_numerical': 0.0, 'mean_word_length': 3.7491749174917492, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '249214', 'n_tokens_mistral': 875, 'n_tokens_neox': 856, 'n_words': 287}