<commit_before>package com.wbillingsley.handy

trait HasId[K] {
  
  def id:K

}

trait GetsId[-T, K] {
  
  def getId(obj: T): Option[K]
  
  def canonical(key:Any): Option[K]
  
}

/**
 * In places where we want to use an implicit GetsId, but still allow the call
 * if there isn't one (such as EqualsById's equals method), this is used as a
 * default for the implicit argument.  Essentially telling the compiler
 * "If there is no implicit GetsId, it has no id". 
 */
object GetsNoId extends GetsId[Any, Nothing] {
  def getId(obj:Any) = None
  
  def canonical(key:Any) = None
}<commit_msg>Added HasStringId<commit_after>package com.wbillingsley.handy

trait HasId[K] {
  
  def id:K

}

trait GetsId[-T, K] {
  
  def getId(obj: T): Option[K]
  
  def canonical(key:Any): Option[K]
  
}

/**
 * In places where we want to use an implicit GetsId, but still allow the call
 * if there isn't one (such as EqualsById's equals method), this is used as a
 * default for the implicit argument.  Essentially telling the compiler
 * "If there is no implicit GetsId, it has no id". 
 */
object GetsNoId extends GetsId[Any, Nothing] {
  def getId(obj:Any) = None
  
  def canonical(key:Any) = None
}


import scala.util.Try

trait HasStringId extends HasId[String] {
  
}

object HasStringId {
  
  implicit object GetsStringId extends GetsId[HasStringId, String] {
    
    var pf:PartialFunction[Any, Option[String]] = { 
      case s:String => Some(s)
      case _ => None 
    }
    
	def getId(obj:HasStringId) = Some(obj.id)
  
	def canonical(key:Any) = pf(key) 
  }   
}
{'fraction_non_alphanumeric': 0.10432569974554708, 'fraction_numerical': 0.0, 'mean_word_length': 3.3214285714285716, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7243004', 'n_tokens_mistral': 552, 'n_tokens_neox': 546, 'n_words': 179}