Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Ryan Zeigler
    @rzeigler
    that said, I'm not even sure this would resolve at a use site, but it seemed conceivable it might
    Georgi Krastev
    @joroKr21
    Why do you import auto.show?
    You should use either semi or auto but not both
    Georgi Krastev
    @joroKr21
    But it doesn't work either way
    Ryan Zeigler
    @rzeigler
    I think i'm a dummy. I have just been copying this snippet for years now from the README. But I realize its scoped to avoid bringing auto into scope.
    Georgi Krastev
    @joroKr21
    The README needs some love
    Georgi Krastev
    @joroKr21
    I forgot about Typeable
    @rzeigler this works:
      import cats.Show
      import cats.instances.all._
      import shapeless.Typeable
    
      case class Foo[I[_]](a: String, i: I[String])
      object Foo {
        implicit def show[I[_]](implicit show: Show[I[String]], typ: Typeable[I[String]]): Show[Foo[I]] =
          semiauto.show[Foo[I]]
      }
    Ryan Zeigler
    @rzeigler
    nifty
    thanks
    Lena Brüder
    @lenalebt
    Hey together, while looking for replacements for a lib that does "equals ignoring some fields" I was looking into cats Eq, which pointed to kittens. Is it easily doable to derive an Eq instance that takes care of all but one field? In my specific use-case, it's a very large case class with about 25 fields, and I'd like to avoid the error-prone boilerplate... I need to compare all but the database ID :D
    Miles Sabin
    @milessabin
    It's doable, but if you can I'd recommend wrapping your db id in a newtype with the desired (universal) equality semantics.
    Lena Brüder
    @lenalebt
    Oh, thank you - I think I can work something out that applies for the case at hand. Thank you!
    Paul Snively
    @paul-snively
    So this seems like something Kittens can likely help with.
    Let's say I have an HList of values of some typeclass that forms a Monad, so it has some means of combining or sequencing. In my concrete case, it's Atto Parsers.
    Atto Parsers can be sequenced with ~, for example, to yield a Parser that yields a pair of the types of the combined Parsers.
    Is it possible to type-safely, say, "reduce" an HList of Parser[T] to get a single Parser with (an unfortunately horribly nested) Tuple?
    Georgi Krastev
    @joroKr21
    You can traverse with a Poly or sequence
    That's in the cats.sequence package
    But you will not get a tuple
    You will get Parser[HList]
    You can convert it to a tuple easily though
      test("sequencing Either")(check {
        forAll { (x: Either[String, Int], y: Either[String, String], z: Either[String, Float]) =>
          val expected = (x, y, z) mapN (_ :: _ :: _ :: HNil)
          (x :: y :: z :: HNil).sequence == expected
        }
      })
    Paul Snively
    @paul-snively
    Right. I need to combine elements with ~, and the result should be a Parser[T], where T is some nested Tuple because ~ gives you a Parser of a Pair.
    So, reduce.
    Georgi Krastev
    @joroKr21
    x ~ y should be just (x, y).tupled or am I missing something?
    Paul Snively
    @paul-snively
    @joroKr21: I think it's an alias for flatMap. It sequences two Atto Parsers.
    @joroKr21: Parser[A] ~ Parser[B] => Parser[(A, B)].
    Georgi Krastev
    @joroKr21
    That doesn't look like flatMap
    Anyway you can use hlistOfParsers.sequence.map(_.tupled)
    Provided there is Applicative[Parser]
    Paul Snively
    @paul-snively
      implicit class Command[P <: HList : IsHCons : *->*[Parser]#λ](parsers: P) {
        def command[InF, InL <: HList, R, O <: Product, OL <: HList](f: InF)
          (implicit
            fntop: FnToProduct.Aux[InF, InL => R],
            pgood: Comapped.Aux[P, Parser, InL]
          ): String => Either[Throwable, R] = { s =>
            val tough  = parsers.sequence
            val parser = tough.map(flatten).map(_.productElements)
            val args   = parser.parseOnly(s).either.leftMap(s => new RuntimeException(s))
            args.map(a => fntop(f)(a))
          }
      }
    This complains that it can't construct a Sequencer.
    "!I seq (cannot construct sequencer, make sure that every item of your hlist P is an Apply): Sequencer[P]"
    Georgi Krastev
    @joroKr21
    So do you have an Apply[Parser] in scope?
    Paul Snively
    @paul-snively
    Well, every element is a Parser; every Parser is an Applicative, and every Applicative is an Apply.
    Georgi Krastev
    @joroKr21
    But perhaps the issue is in the generics here
    Paul Snively
    @paul-snively
    Hmm. Maybe I need another import?
    Georgi Krastev
    @joroKr21
    I've never tried to use sequence in a generic context
    Paul Snively
    @paul-snively
    Right. I'm trying to 1) ensure my HList is a stable value, 2) give whatever evidence I need.
    Georgi Krastev
    @joroKr21
    I guess you just need an implicit Sequencer[P] { type F[x] = Parser[x] }
    Ah wait
    Sequencer.Aux[P, Parser, InL]
    Paul Snively
    @paul-snively
    That goes right back to not finding a Sequencer...
    Georgi Krastev
    @joroKr21
    Can you put it in scastie?
    Paul Snively
    @paul-snively
    Oh wait... I added it to the implicit stanza and I think it worked!
    Georgi Krastev
    @joroKr21
    Yes, that's what I meant you need it as implicit
    Paul Snively
    @paul-snively
    Right, of course. Thanks!
    Georgi Krastev
    @joroKr21
    :thumbsup: