<commit_before>package org.specs.util

object ExtendedFunctions extends ExtendedFunctions 
trait ExtendedFunctions {
  implicit def extend[A, B](f: Function[A, B]) = new ExtendedFunction(f)
}
/**
 * this class allows to use a function as if it was a partial function.
 *
 * It is especially useful when one want to overload a function with both functions and partial function
 * literals. This usually is an issue because of the way the compiler interprets function and 
 * partial function literals (see the Scala Language Specification, section 8.5). 
 *
 * The following specification shows the how to use it: 
 * <code>
 * 	class Test[T](val t: T) {
 *     def call[S](x: Function[T, S]): Option[S] = x.applySafely(t)
 *  }
 *  val test = new Test("hello")
 *  test call identity must beSome("hello")
 *  // this behaves like a partial function but is a function really
 *  test call { case s if s.size < 2 => "partial " + s } must beNone
 * </code>
 * 
 */
class ExtendedFunction[A, B](f: Function[A, B]) {
  def applySafely(a: A): Option[B] = {
	try {
	  Some(f(a))
	} catch {
	  case e: MatchError => {
	 	if (e.getCause() == null) 
	 	  None
	 	else
	 	  throw e
	  }
	}
  }
}<commit_msg>simplified the extended function code. checking what's the cause of the match error has no effect<commit_after>package org.specs.util

object ExtendedFunctions extends ExtendedFunctions 
trait ExtendedFunctions {
  implicit def extend[A, B](f: Function[A, B]) = new ExtendedFunction(f)
}
/**
 * this class allows to use a function as if it was a partial function.
 *
 * It is especially useful when one want to overload a function with both functions and partial function
 * literals. This usually is an issue because of the way the compiler interprets function and 
 * partial function literals (see the Scala Language Specification, section 8.5). 
 *
 * The following specification shows the how to use it: 
 * <code>
 * 	class Test[T](val t: T) {
 *     def call[S](x: Function[T, S]): Option[S] = x.applySafely(t)
 *  }
 *  val test = new Test("hello")
 *  test call identity must beSome("hello")
 *  // this behaves like a partial function but is a function really
 *  test call { case s if s.size < 2 => "partial " + s } must beNone
 * </code>
 * 
 */
class ExtendedFunction[A, B](f: Function[A, B]) {
  def applySafely(a: A): Option[B] = {
	try {
	  Some(f(a))
	} catch {
	  case e: MatchError => None
	}
  }
}
{'fraction_non_alphanumeric': 0.10982179859096561, 'fraction_numerical': 0.0024865312888520514, 'mean_word_length': 3.5121495327102803, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '6099179', 'n_tokens_mistral': 784, 'n_tokens_neox': 739, 'n_words': 301}