Scala Programming Language
  1. Scala Programming Language
  2. SI-5267

Specialize Function1 and Function2 for AnyRef

    Details

      Description

      Scala 2.9 introduced partial specialization (add AnyRef to the list of @specialized targets). However this wasn't employed in any of the handful of specialized classes in the standard library.

      I think this would be a valuable addition to Function1. Without this, I recently resorted to:

      abstract class Function1ADouble[A] extends Function1[A, Double] {
        def apply(a: A): Double
      }
      
      def mapSum[A](as: Iterable[A])(f: Function1ADouble[A]): Double = {
          var sum = 0d
          val iterator = as.iterator
          while (iterator.hasNext) {
            sum += f.apply(iterator.next())
          }
          sum
      }
      

      }

      Function2 might also be a candidate, although it will add more weight.

        Issue Links

          Activity

          Hide
          Paul Phillips added a comment -

          bb23d766bc

          Show
          Paul Phillips added a comment - bb23d766bc
          Hide
          Ismael Juma added a comment -

          Yay!

          Show
          Ismael Juma added a comment - Yay!

            People

            • Assignee:
              Paul Phillips
              Reporter:
              Jason Zaugg
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development