<commit_before>package org.talkingpuffin.filter

import ui.LinkExtractor

object Retweets {
  private val user = LinkExtractor.usernameRegex
  private val rtUser = ("""(rt|RT|♺)\:? ?""" + user + ".*").r
  private val viaUser = (""".*\((via|VIA|Via) +""" + user + """\)""").r

  def fromFriend_?(text: String, friendUsernames: List[String]): Boolean = {
    List(rtUser, viaUser).foreach(regex =>
      try {
        val regex(rtSymbol, username) = text
        if (friendUsernames.contains(username)) return true
      } catch {
        case e: MatchError => 
      })
    false
  }
}
<commit_msg>Using pattern matching with regular expressions, and better functional programming<commit_after>package org.talkingpuffin.filter

import ui.LinkExtractor

object Retweets {
  private val user = LinkExtractor.usernameRegex
  private val rtUser = ("""(rt|RT|♺)\:? ?""" + user + ".*").r
  private val viaUser = (""".*\((via|VIA|Via) +""" + user + """\)""").r
  private val regexes = List(rtUser, viaUser)

  def fromFriend_?(text: String, friendUsernames: List[String]) = regexes.exists(regex => text match {
    case regex(rtSymbol, username) => friendUsernames.contains(username)
    case _ => false
  })
}

{'fraction_non_alphanumeric': 0.16209476309226933, 'fraction_numerical': 0.0, 'mean_word_length': 3.8548387096774195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '3018596', 'n_tokens_mistral': 394, 'n_tokens_neox': 391, 'n_words': 94}