Skip to content

Commit

Permalink
Merge pull request #31 from armanbilge/fix/map-to-target-side-effect
Browse files Browse the repository at this point in the history
Reading target value is a side-effect
  • Loading branch information
armanbilge authored Apr 18, 2022
2 parents 7d6c7a2 + ff5e208 commit 822a8d1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions calico/src/main/scala/calico/syntax.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ extension [F[_], A, B](pipe: Pipe[F, A, B])
yield ch

extension [F[_]](events: Stream[F, dom.Event])
def mapToTargetValue: Stream[F, String] =
events.map(_.target).collect {
case button: dom.HTMLButtonElement => button.value
case input: dom.HTMLInputElement => input.value
case option: dom.HTMLOptionElement => option.value
case select: dom.HTMLSelectElement => select.value
case textArea: dom.HTMLTextAreaElement => textArea.value
}
def mapToTargetValue(using F: Sync[F]): Stream[F, String] =
events
.map(_.target)
.evalMap {
case button: dom.HTMLButtonElement => F.delay(button.value.some)
case input: dom.HTMLInputElement => F.delay(input.value.some)
case option: dom.HTMLOptionElement => F.delay(option.value.some)
case select: dom.HTMLSelectElement => F.delay(select.value.some)
case textArea: dom.HTMLTextAreaElement => F.delay(textArea.value.some)
case _ => F.pure(None)
}
.unNone

0 comments on commit 822a8d1

Please sign in to comment.