Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 2 additions & 21 deletions calico/src/main/scala/calico/syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,5 @@ extension [F[_], A](signal: Signal[F, A])
def get = signal.get

extension [F[_], A](sigRef: SignallingRef[F, A])
def zoom[B <: AnyRef](lens: Lens[A, B])(using Sync[F]): SignallingRef[F, B] =
val ref = Ref.lens[F, A, B](sigRef)(lens.get(_), a => b => lens.replace(b)(a))
new:
def access = ref.access
def modify[C](f: B => (B, C)) = ref.modify(f)
def modifyState[C](state: State[B, C]) = ref.modifyState(state)
def tryModify[C](f: B => (B, C)) = ref.tryModify(f)
def tryModifyState[C](state: State[B, C]) = ref.tryModifyState(state)
def tryUpdate(f: B => B) = ref.tryUpdate(f)
def update(f: B => B) = ref.update(f)
def set(b: B) = ref.set(b)
def get = ref.get
def continuous = sigRef.map(lens.get).continuous
def discrete = sigRef.map(lens.get).discrete

extension [F[_], A, B](pipe: Pipe[F, A, B])
def channel(using F: Concurrent[F]): Resource[F, Channel[F, A]] =
Comment on lines -100 to -101
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't remember what I thought this would be useful for. Anyway, I think most likely you want to convert a Stream to a Signal with hold*. Not a Channel :)

for
ch <- Channel.unbounded[F, A].toResource
_ <- ch.stream.through(pipe).compile.drain.background
yield ch
def zoom[B](lens: Lens[A, B])(using Functor[F]): SignallingRef[F, B] =
SignallingRef.lens[F, A, B](sigRef)(lens.get(_), a => b => lens.replace(b)(a))
Comment on lines +85 to +86
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems useful, right? 😅