I don't see anything wrong with your solution either, but scalaz defines types called
Monoid which could help you here. It also includes
Semigroup definitions for many common types like List and Int.
SemiGroup defines an append operation.
Semigroup but additionally provides a
zero or an initial value. This would be useful if
orchestrators could be empty, in which case you would want to
foldLeft instead of
Note: I reversed your type parameters
import scalaz._ import Scalaz._ import scala.concurrent.Future import scala.concurrent.ExecutionContext.Implicits.global def pollAll[O, T : Semigroup](orchestrators :Seq[O], poll :(O)=>Future[T]) :Future[T] = (Future sequence orchestrators.map(poll(_))) .map(res => res.reduce(implicitly[Semigroup[T]].append(_, _)))
or sugared a bit
def pollAll2[O, T : Semigroup](orchestrators :Seq[O], poll :(O)=>Future[T]) :Future[T] = (Future traverse orchestrators)(poll(_)).map(_.reduce(_ |+| _))
scala> pollAll(List(1, 2, 3, 4), (i: Int) => Future.successful(i)).foreach(println) scala> 10 scala> pollAll2(List(1, 2, 3, 4), (i: Int) => Future.successful(i)).foreach(println) scala> 10
- Implicit values of generic types for implicit parameters in scala
- Implicit conversion classes for type-aliased Function types fail to compile in Scala
- Conditional methods of Scala generic classes with restrictions for type parameters
- How to bypass or satisfy scala generic types for Thrift classes
- Scala factory for generic types using the apply method?
- Scala multiple implicit parameters with defaults resulting in ambiguous values
- Implicit conversion of a generic container for an implicit parameter in Scala
- Generic parameters for a constructor in Scala
- Error passing generic values to method using implicit parameter in Scala
- Scala generic implicit values ambiguous when overloading?
- How to generate values for case class parameters in scala
- Accounting for type parameters in a Scala generic class 'equals' method... are manifests the only way?
- How scala determines implicit type parameters for TreeSet constructor
- Scala mock function with implicit generic types
- Groovy equivalent for Scala implicit parameters
- Test two scala shapeless HList types for equivalence via implicit
- Play! 2.4 - Implicit Reads for ScalaJson w/ Generic Types
- Scala type parameterization, Shapeless - could not find implicit value for parameter Generic
- Type-safety for Patternmatching on Parameters with Dependent Types in Scala
- Is it possible for Scala to infer types for Generic types passed into a dependent class?
- Creating a generic reusable function with implicit and types in Scala
- Are implicit conversions for Scala numeric types special?
- how to set default values for function parameters in scala
- Groovy equivalent for Scala implicit parameters - extended
- Scala - passing defined values for optional parameters within routes file
- implicit parameters and generic types
- Writing a generic Scala merge function, can't get types to line up for compiler
- How to define an implicit deserializer using Play Json for generic types
- Scala map with keys of same type but with irregular types for values and subtypes of values themselves being irregular
- scala implicit ordering on generic Option[Any] types
More Query from same tag
- How to attach SBT classes to Intellij Idea?
- How to find out, why a DOM binding is rendered twice
- removing spaces in DataFrame using SCALA. (I have loaded CSV file into RDD then trying to remove spaces from it
- Trimming Special Characters in Apache Spark in java
- Scala convert Seq to k, v of sbt.Project.Setting[_]
- Scala Map Save to File - Hadoop
- Seq - reverseMap vs reverse.map in Scala
- Using Future and Async to handle multiple file IO requests without blocking
- Import implicit values from a companion object but not used
- Can two variables reference the same object and both change values, when one is changed
- Why is there an Option.get method
- Structural Type Parameters in Scala Collections
- Scala Swing Caret Position
- How to limit actors per user
- Union two DataFrame using spark 2.x with different schema/dataTypes
- #Repr[A] in Akka Stream source type
- Apache Spark: Get number of records per partition
- Convert Map of mutable Set of strings to Map of immutable set of strings in Scala
- Not able to import Specs2 in eclipse (scala-ide) project
- Case Switch Statement with Class Object in Scala
- Play framework with Scala 3
- To insert scala code for two methods
- NullPointerException when using UDF in Spark
- Unwrapping the Functions without parameters in scala with Futures
- Flatten nested json with array into single line dataframe in Apache Spark Scala
- Scala: Get Items from Seq by given index (all the items above given index)
- Best way to post binary data to a Scala playframework web site
- spark scala: Performance degrade with simple UDF over large number of columns
- How to dump contents of a Java library to the console?
- Fetching all the csv filenames from HDFS directory using spark/scala