This project aims to be the Scala Incubator project for Automatic-Resource-Management in the scala library
and
without flatMap
def sequenceManagedResources[R, T[X] <: TraversableOnce[X]](managedResources: T[ManagedResource[R]])(implicit canBuildFrom: CanBuildFrom[T[ManagedResource[R]], R, T[R]]): ManagedResource[T[R]] = {
val initialBuilderResource = unitManaged(canBuildFrom(managedResources))
val finalManagedBuilder = managedResources.foldLeft(initialBuilderResource) { case (builderResource, managedR) ⇒
builderResource.flatMap { builder ⇒
managedR.map(r ⇒ builder += r)
}
}
finalManagedBuilder.map(_.result())
}
def unitManaged[T](value: => T): ManagedResource[T] = {
managed(()).map(_ ⇒ value)
}
@Arty
to @Atry
in https://github.com/jsuereth/scala-arm/releases/tag/v2.0, please
try
s for closing resources. Could you tell me what you think? I understand that it's nicer to hide the closing of a resource from other resources, but I can't see any other way to do this other than using continuations. https://gist.github.com/anonymous/32e847129948b84e622e715cecd4ff6b