These are chat archives for typelevel/cats

25th
Jun 2018
Anthony Cerruti
@srnb_gitlab
Jun 25 03:49
@LukaJCB so how should I do this?
I'm running regex replacements to transform underscored_keys into camelCasedKeys and back
Jakub Kozłowski
@kubukoz
Jun 25 09:17
@srnb_gitlab just so you know, you can configure circe to use a particular naming strategy when decoding/encoding
like using camelcased keys or underscored keys
see https://circe.github.io/circe/codecs/custom-codecs.html#custom-key-mappings-via-annotations
e.g. implicit val config: Configuration = Configuration.default.withSnakeCaseMemberNames with semiauto decoding/encoding should work
and you could provide your own Configuration with a custom key renaming strategy. Probably better than manually traversing the jsons
Zara Turtle
@turt13
Jun 25 10:29
does cats have actors? My boss wants me to use reactive actors.
Manuel Cueto
@manuelcueto
Jun 25 10:32
I went to a meetup where a guy explained a way to construct actors with cats-effects . Unfortunately I’m on holidays and i have his github on a notebook somewhere at home
Martin Grigorov
@martin-g
Jun 25 10:34
aren't all actors reactive ? they react on messages/events/signals
Zara Turtle
@turt13
Jun 25 10:39
ok! I will watch this
:heartpulse:
Martin Grigorov
@martin-g
Jun 25 10:40
Zara Turtle
@turt13
Jun 25 10:41
ok! ty
Martin Grigorov
@martin-g
Jun 25 10:42
both videos show how to create really minimalistic actors
Zara Turtle
@turt13
Jun 25 10:43
I have seen this one. I do not understand it. That is why I am researching typelevel and scalaz.
I am very confused by Akka. I do not know any Erlang.
Martin Grigorov
@martin-g
Jun 25 10:46
spend some more time on it! it will be useful to compare the alternatives
Zara Turtle
@turt13
Jun 25 11:17
I watched these videos. I do not understand the first one. I like the sound of scalaz but this talk is very vague.
Martin Grigorov
@martin-g
Jun 25 11:19
I agree on both observations!
anyway, I think you should tell your boss what you have found. Explain what you have understood and what you haven't. And decide which one to dig deeper
Piotr Gawryś
@Avasil
Jun 25 14:28
FYI @turt13 you can easily cover those use cases using cats.effect.IO or monix.eval.Task too
Rob Norris
@tpolecat
Jun 25 14:33
Why does your boss want you to use actors? Maybe chase that down a bit.
Matthew de Detrich
@mdedetrich
Jun 25 14:34
If you need to seperate your business logic across multiple nodes, then there may be a case for using actors. Otherwise you probably don’t need them.
Rob Norris
@tpolecat
Jun 25 14:34
It’s like saying fix my car, be sure to use a band saw.
In that it would probably make sense to ask some follow up questions.
Anthony Cerruti
@srnb_gitlab
Jun 25 14:43
@kubukoz so like this?
  val keyCorrectionReg: Regex = """_([a-z])""".r
  val keyDeCorrectionReg: Regex = """([A-Z])""".r
  implicit val config: Configuration = Configuration.default.withSnakeCaseMemberNames.copy(transformMemberNames = s => {
    keyDeCorrectionReg.replaceAllIn(s, m => "_" + m.group(1).toLowerCase)
  })
Jakub Kozłowski
@kubukoz
Jun 25 14:50
I'm not sure what exactly you want to do
looks like keyCorrectionReg isn't used in this
it'd be best if you could provide an example of
  1. the JSON that comes in
  2. the case class you want to have after decoding
Anthony Cerruti
@srnb_gitlab
Jun 25 14:54
We're solving this in the circe/circe room now, but I need a solution that works for both encoding thisCase => this_case and decoding this_case => thisCase
Jakub Kozłowski
@kubukoz
Jun 25 14:56
I would guess that's just withSnakeCaseMemberNames but maybe not
I see Travis said the same thing :P
you should write tests for your usecase anyways, so you can see if that's enough
Conner Bryan
@cab
Jun 25 16:21

r.e. recursion schemes -- I'm creating the corresponding NodeF[A] for my Node type, but what's the right way to generalize something like

sealed trait Node
final case class Name(value: String) extends Node
sealed trait Expression extends Node
final case class Block(name: Name, exprs: List[Expression]) extends Node

where I want to keep the more narrow type for some values? because I currently have

sealed trait NodeF[A]
final case class NameF(value: String) extends NodeF[A]
sealed trait ExpressionF[A] extends NodeF[A]
final case class BlockF[A](name: A, exprs: List[A]) extends NodeF[A]
Conner Bryan
@cab
Jun 25 16:27
or do I have to give up that subtyping?
Conner Bryan
@cab
Jun 25 17:13
hmm, or does that subtyping not even matter for the generalized type
elyphas
@elyphas
Jun 25 20:55
Q
Rakesh
@rakeshkr00
Jun 25 21:59
I am encountering
FieldsValidation.scala:45: value mapN is not a member of (FieldsValidation.this.ValidationResult[Boolean], FieldsValidation.this.ValidationResult[Boolean])
[error]         checkPoints(in.geom) map { y => (res,y).mapN(FieldValidationResult)}
[error]
and the code I have is
case class FieldValidationResult(inLandMass:Boolean, gt4Points: Boolean)

sealed trait FieldsValidation  {
  type ValidationResult[A] = ValidatedNel[FieldException, A]

  def validateGeom(in: Loc360FieldsAvro)(implicit system: ActorSystem, db: Database ): Future[ValidationResult[FieldValidationResult]] = {

    def checkPoints(wkt: String): Future[ValidationResult[Boolean]] = {
      val geom: Geometry = new WKTReader().read(in.geom)
      geom.setSRID(4326)
      Future {
        if (geom.getNumPoints > 4) true.validNel else LessThanFourVerticesError.invalidNel
      }
    }

    def checkIfWithinLandmass(wkt: String): Future[ValidationResult[Boolean]] = {
      db.run(checkIfGeometryWithinLandMass(wkt)) map { x => {
        if (!x) false.validNel else GeometryFallOutsideOfLandAreaError.invalidNel
      }
      }
    }

    checkIfWithinLandmass(in.geom) flatMap {
      res => {
        checkPoints(in.geom) map { y => (res,y).mapN(FieldValidationResult)}
      }
    }

  }
}

object FieldsValidation extends FieldsValidation
what has gone wrong here?
Rob Norris
@tpolecat
Jun 25 22:09
Are you compiling with -Ypartial-unification? If so then what are your imports?
Rakesh
@rakeshkr00
Jun 25 23:47
.
Apart from application specific imports, other relevant ones are :
import akka.actor.ActorSystem
import cats.data.Validated._
import cats.data._
import cats.implicits._
import cats.syntax.apply._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
Rob Norris
@tpolecat
Jun 25 23:59
Remove the import for cats.syntax.apply