Code Monkey home page Code Monkey logo

Comments (2)

regiskuckaertz avatar regiskuckaertz commented on September 22, 2024

@tolomaus sorry about that, the two algebras were designed at different times I think. It should be easy but actually is not, first off the type of Array.reduce forces the result type to be a super-type of the element type, which is why it works for updates. Second, AndCondition takes two type parameters. So

filter(0) and filter(1):
  AndCondition[Contains, Contains]

but

filter(0) and filter(1) and filter(2):
  AndCondition[AndCondition[Contains, Contains], Contains]

so, to write a reduce that works for this, you will need to go beyond simple arrays and functions, something like (not tested):

trait ConditionReduce[Xs <: HList] {
  type Z
  def reduceAnd(xs: Xs): Z
}
object ConditionReduce {
  implicit val hNilReduce: ConditionReduce[HNil] = new ConditionReduce[HNil] {
    type Z = True.type
    def reduceAnd(xs: HNil): Z = True // we don't have `True` but it could be written
  }
  implicit def hConsReduce[X, Xs](implicit X: ConditionExpression[X], Xs: ConditionReduce[Xs]): ConditionReduce[X ::: Xs] =
    new ConditionReduce[X ::: Xs] {
      type Z = AndCondition[X, Xs.Z]
      def reduceAnd(xs: X ::: Xs): Z = xs.head and Xs.reduceAnd(xs.tail)
    }
}

This is ugly as hell but given how all the conditions are defined, it is the only way currently. Ha, you will also need a proof that Z has a ConditionExpression so the above is probably not enough. So as you can see, the library needs a bit of a makeover there 😄

from scanamo.

tolomaus avatar tolomaus commented on September 22, 2024

Thanks for your take on this @regiskuckaertz ! I'm not too familiar with the advanced scala features like cats, shapeless etc so I'm afraid I have reached my limits here ;-)

Ideally scanamo would support all possible dynamodb features (like the reduce), but in reality this will not always be possible. In these cases my current workaround is to manipulate the underlying QueryRequest directly.

from scanamo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.