All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cgta.oscala.extensions.IterableExtensions.scala Maven / Gradle / Ivy

The newest version!
package cgta.oscala
package extensions


//////////////////////////////////////////////////////////////
// Copyright (c) 2015 Ben Jackman, Jeff Gomberg
// All Rights Reserved
// please contact [email protected] or [email protected]
// for licensing inquiries
// Created by bjackman @ 1/14/15 6:35 PM
//////////////////////////////////////////////////////////////

class IterableExtensions[A](val xs : Iterable[A]) extends AnyVal {

  def minOpt[B >: A](implicit cmp: Ordering[B]): Option[A] = if (xs.isEmpty) None else Some(xs.min[B])
  def maxOpt[B >: A](implicit cmp: Ordering[B]): Option[A] = if (xs.isEmpty) None else Some(xs.max[B])

  def minByOpt[B](f: A => B)(implicit cmp: Ordering[B]): Option[A] = if (xs.isEmpty) None else Some(xs.minBy[B](f))
  def maxByOpt[B](f: A => B)(implicit cmp: Ordering[B]): Option[A] = if (xs.isEmpty) None else Some(xs.maxBy[B](f))


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy