Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Jul 19 20:37
    @SethTisue banned @tonyobanon
  • Jan 02 23:58
    @SethTisue banned @fakubishes:nerdsin.space
  • Dec 15 2021 05:01
    som-snytt commented #12516
  • Dec 15 2021 04:38
    SethTisue edited #1312
  • Dec 15 2021 04:38
    SethTisue opened #2273
  • Dec 15 2021 04:31
    jackkoenig opened #12516
  • Dec 15 2021 04:29
    SethTisue edited #1312
  • Dec 15 2021 04:28
    SethTisue edited #1312
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    scala-jenkins milestoned #9831
  • Dec 15 2021 04:27
    SethTisue labeled #9831
  • Dec 15 2021 04:27
    SethTisue opened #9831
  • Dec 15 2021 03:35
    som-snytt commented #11339
  • Dec 15 2021 03:27
    som-snytt labeled #12494
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:07
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 03:05
    SethTisue edited #1312
  • Dec 15 2021 02:58
    SethTisue edited #1312
Georgi Krastev
@joroKr21
Nothing is stopping you to define a type class Exists:
trait Exists[A] { def apply(): Boolean }
object Exists extends Nope {
  implicit def sure[A](implicit a: A): Exists[A] = new Exists[A] {
    def apply() = true
  }
}
trait Nope {
  implicit def nope[A]: Exists[A] = new Exists[A] {
    def apply() = false
  }
}
then you can do def isEffect[T](implicit isIt: Exists[Effect[T]]) = isIt()
Fabio Labella
@SystemFw
that's still at compile time though I think
they want it at runtime
it's the same rho issue
when rho only had Task
Andi Miller
@andimiller
rho should be able to do that at compile time
Fabio Labella
@SystemFw
you would take a type and tests at runtime if it was Task (with a TypeTag)
Andi Miller
@andimiller
I dunno why it'd need that
Fabio Labella
@SystemFw
now they need the same, but for a typeclass, and I'm not sure it's possible
it's been asked by several people several times, and still no solution :(
this is for the implementation of swagger support in rho iirc (might be wrong here)
Georgi Krastev
@joroKr21
Well you could do it for a sealed trait with shapeless, but in general that's just a really weird thing to want
And that's actually the other way around: I have a value and I want to see if the typeclass resolves for its runtime type, which is of course impossible in general.
Fabio Labella
@SystemFw
lol, I hadn't even noticed this wasn't the http4s channel
It's definitely a very very niche case
I agree it's not possible, you'd need something like TypeTag, which would need to also capture typeclass instances
OlegYch
@OlegYch
rho would do well to use a typeclass for docs
tom-Kc
@tom-Kc
  trait TagHandler {
    def success(x: Any): Unit
    def failure(reason: Throwable): Unit
  }

  abstract class StandardTagHandler(val pfAllowedStates : PartialFunction[State, Unit]) extends TagHandler {
    def sth_success(x : Any) : Unit

    def success(x : Any) : Unit =
      if (pfAllowedStates.isDefinedAt(state)) sth_success(x)
      else resetToInit(s"$this called in unallowed state $state")

    def failure(reason : Throwable) : Unit = {
      resetToInit(s"$this failed with reason : $reason")
    }
  }
this is inside a FSM class that has a state : State . i want to make this intermediate StandardTagHandlerclass so I don't keep rewriting the state check boiler plate
is this is right way to use the partialFunction? or should it be State => Boolean check or something like that
Saurabh Rawat
@eklavya
I have no idea about whether or not it was possible, so I thought I would ask the experts :P
I think the consensus is that it's not possible
Martijn Hoekstra
@martijnhoekstra
@tom-Kc State => Boolean is much better IMO. Even better would be to do your state transitions strongly typed
tom-Kc
@tom-Kc
@martijnhoekstra you are right i actually had to go with State => Boolean in the end ... the pf actually wouldnt compile because of using pf literal in the constructor ... How could I make them strongly typed?
Martijn Hoekstra
@martijnhoekstra
it depends on what your state transitions look like. If you have State1 <: State etc, you could have a class StateTransition[A, B], have the method that does a state transition from From to To take an implicit StateTransition[From, To], and have a bunch of implicit object transitionFromTo extends StateTransition[From, To] for the allowed transitions
those could be phantom types too
Anthony Garo
@agaro1121
does anyone here have suggestions for git hook scripts for scala projects?
I don’t really want to write my own :smile:
Seth Tisue
@SethTisue
you mean like to enforce code formatting and that kind of thing?
Stefano Tondo
@tondostefano_twitter
is it possible to write a generic function that updated a single field of a case class?
Let's say I have athe following case class:
case class Person(name: String, age: Int)
trepidacious
@trepidacious
@tondostefano_twitter shapeless might be what you need?
@tondostefano_twitter Or lenses. I should prbably wait for you to finish :)
Stefano Tondo
@tondostefano_twitter
I think I'm done already :D
I mean, I oversimplified my example, but that's the core
Danilo Salvio
@0x6C38
what do you mean by generic
Stefano Tondo
@tondostefano_twitter
I want to copy the case clas, updating 1 field, but I don't know which field and I want to avoid writing 57 or more methods
let me show my code, perhpas it's gonna be more clear
trepidacious
@trepidacious
@tondostefano_twitter Monocle will give you Person.name and Person.age as lenses that can update those fields
@tondostefano_twitter Shapeless will give you a lot more stuff to work with Person as "a string and an int", etc.
Stefano Tondo
@tondostefano_twitter
  def updatePhoneCallWithCodiceStatistica(guid: String, codiceStatistica: String, fieldName: String): Future[Option[Future[Int]]] =
    phoneCallsDAO.findByGuid(guid).map { ph =>
      ph.map { call =>
        val callUpdated = call.copy(codiceStatistica = Some(codiceStatistica))
        phoneCallsDAO.update(call.id.get, callUpdated)
    }
}
I know it's ugly
but what I'm trying to achieve is to make the copy parameter dynamic
trepidacious
@trepidacious
@tondostefano_twitter You want to pick a field to update based on some parameter?
Are all the fields the same type?
Stefano Tondo
@tondostefano_twitter
nope
fields type are arbitrary
trepidacious
@trepidacious
Have you used lenses before? That would probably be a good place to start looking if not...
Stefano Tondo
@tondostefano_twitter
I'll take a look at Lens documentation right now