Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    jpcooper
    @jpcooper
    @jsuereth Would you be interested in a sequence method, which takes T[ManagedResource[R]] to ManagedResource[T[R]]?
    Or have I been missing something, and does it implicitly exist somewhere else?
    I.e. it's tied to Seq
    a more generic Seq would be welcome, but perhaps we just try to support non/cats sequence method
    ALthough, We can't be a vanilla applicative functor, which I think it requires....
    jpcooper
    @jpcooper
    @jsuereth I did this:
    def sequenceManagedResources[R, T[X] <: TraversableOnce[X]](managedResources: T[ManagedResource[R]])(implicit canBuildFrom: CanBuildFrom[T[ManagedResource[R]], R, T[R]]): ManagedResource[T[R]] = {
        val builder = canBuildFrom(managedResources)
        val initialBuilderResource = unitManaged(builder)
    
        val finalManagedBuilder = managedResources.foldLeft(initialBuilderResource) { case (builderResource, managedR) ⇒
          builderResource.flatMap { builder ⇒
            managedR.map(r ⇒ builder += r)
          }
        }
    
        finalManagedBuilder.map(_.result())
      }
    is this bad?
    jpcooper
    @jpcooper
    join seems to start from the right and mine from the left
    Josh Suereth
    @jsuereth
    yeah.... kind of necessary
    at least depending on what properties you want to preserve
    SO, your function: Have you tested opening/closing?
    e.g. what happens if an exception is thrown
    I'm just thinking through implications. It looks a hell of lot cleaner :)
    Yeah, actually yours is fine
    just had to think through the mutability and such
    If you'd like to deprecate the existing join in favor of that method
    I'd just call it ManagedResource.sequence though
    jpcooper
    @jpcooper
    I haven't made any tests, but I just imagined that it would be safe because I'm using flatMap
    Josh Suereth
    @jsuereth
    You're mutating a value inside the resource, so it's a matter of figuring out if anything will bypass normal resource cleanup
    and I think the answer here is no :)
    jpcooper
    @jpcooper
    I'm slightly confused. Is the answer no because it's inside a ManagedResource.map? Could you give an example where it might not be okay?
    Josh Suereth
    @jsuereth
    also, you can probably do:
    val finalManagedBuilder = managedResources.foldLeft(initialBuilderResource) { case (builderResource, managedR) ⇒
          for { 
            builder <- builderResource
            r <- managedR
          } yield builder +=r
        }
    The answer is no because it's flatMap+map, yeah
    jpcooper
    @jpcooper
    okay cool
    that looks nicer
    Josh Suereth
    @jsuereth
    Which should be true of the library generally :)
    jpcooper
    @jpcooper
    one would hope :)
    Josh Suereth
    @jsuereth
    I was also checking the failure property
    e.g. how many resources are opened if one throws an error when it's opened
    the answer is "N" where "N is the number of resources before you get to the exception
    i.e. it won't keep trying to open things
    BUT using map/flatMap means it's not an issue, I jsut remember I had other "clever" ways of doign that function, had to refresh my memory on what they were
    jpcooper
    @jpcooper
    because of stacking of acquireFors implied by flatMap, I suppose
    Josh Suereth
    @jsuereth
    yep
    jpcooper
    @jpcooper
    okay
    Josh Suereth
    @jsuereth
    SO yeah, the function looks better. Feel free to add it/deprecate the old one
    jpcooper
    @jpcooper
    will do
    Josh Suereth
    @jsuereth
    I need to push out 2.0 final soon, have you tried RC1?
    jpcooper
    @jpcooper
    I haven't yet
    Josh Suereth
    @jsuereth
    I can push a 2.0.1 with that change though, it won't be binary incompatible
    or a 2.1, I mean
    jpcooper
    @jpcooper
    which version should I fork?
    Josh Suereth
    @jsuereth
    2.0
    err master
    If you want we can release it on 1.x too
    Yang, Bo
    @Atry
    Hello @jsuereth , could you review my Pull Request jsuereth/scala-arm#46, please?
    jpcooper
    @jpcooper
    @jsuereth I'll make a PR to master either this evening or on Saturday
    @Atry nice
    Josh Suereth
    @jsuereth
    @Atry nice! Comments in line, I can merge when I'm not mobile