|
Scala example source code file (Dup.scala)
The Dup.scala Scala example source codepackage scalaz package effect /**Duplicate a handle in the parent region. */ trait Dup[H[_[_]]] { def dup[PP[_]: MonadIO, CS, PS]: H[RegionT[CS, RegionT[PS, PP, ?], ?]] => RegionT[CS, RegionT[PS, PP, ?], H[RegionT[PS, PP, ?]]] } sealed abstract class DupInstances { import Dup._ implicit val FinalizerHandleDup: Dup[FinalizerHandle] = new Dup[FinalizerHandle] { def dup[PP[_] : MonadIO, CS, PS]: FinalizerHandle[RegionT[CS, RegionT[PS, PP, ?], ?]] => RegionT[CS, RegionT[PS, PP, ?], FinalizerHandle[RegionT[PS, PP, ?]]] = h => RegionT[CS, RegionT[PS, PP, ?], FinalizerHandle[RegionT[PS, PP, ?]]]( Kleisli[RegionT[PS, PP, ?], IORef[List[RefCountedFinalizer]], FinalizerHandle[RegionT[PS, PP, ?]]](hsIORef => copy[PS, PP, RegionT[CS, RegionT[PS, PP, ?], ?]](h))) } } object Dup extends DupInstances { /**Duplicates a handle to its parent region. */ def dup[H[_[_]] : Dup, PP[_] : MonadIO, CS, PS](h: H[RegionT[CS, RegionT[PS, PP, ?], ?]]): RegionT[CS, RegionT[PS, PP, ?], H[RegionT[PS, PP, ?]]] = implicitly[Dup[H]].dup.apply(h) def copy[S, P[_] : MonadIO, R[_]](h: FinalizerHandle[R]): RegionT[S, P, FinalizerHandle[RegionT[S, P, ?]]] = h match { case h => RegionT(Kleisli(hsIORef => (for { _ <- h.finalizer.refcount.mod(_ + 1) _ <- hsIORef.mod(h.finalizer :: _) } yield FinalizerHandle[RegionT[S, P, ?]](h.finalizer)).liftIO[P])) } } Other Scala examples (source code examples)Here is a short list of links related to this Scala Dup.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.