Giter VIP home page Giter VIP logo

auxify's Introduction

Hi there ๐Ÿ‘‹

Dmytro Mitin profile views

auxify's People

Contributors

dmytromitin avatar gitter-badger avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

auxify's Issues

@ instance: type not found

  import com.github.dmytromitin.auxify.macros.{aux, instance}

  /*@aux*/ @instance
  trait Compare[T1, T2] {
    type T
    type Out = (T, T)
    def apply(a: T1, b: T2): Out
  }

  object Compare {
    type Aux[T1, T2, T0] = Compare[T1, T2] { type T = T0 }
//    def instance[T1, T2, T0](f: (T1, T2) => (T0, T0)): Aux[T1, T2, T0] = new Compare[T1, T2] {
//      override type T = T0
//      override def apply(a: T1, b: T2): Out = f(a, b)
//    }

    implicit def reverseCompare[T1, T2](implicit ev: T2 => T1): Aux[T1, T2, T1] = instance((a, b) => (a, ev(b)))
    implicit def directCompare[T1, T2](implicit ev: T1 => T2): Aux[T1, T2, T2] = instance((a, b) => (ev(a), b))
  }

  def compare[T1, T2](a: T1, b: T2)(implicit cmp: Compare[T1, T2]) = (compareImpl[cmp.T] _).tupled(cmp(a, b))
  def compareImpl[T](a: T, b: T) = a == b

  case class Foo(s: String)
  case class Bar(s: String)

  implicit def foo2bar(f: Foo): Bar = Bar(f.s)

  compare(Foo("hello"), Bar("hello"))
Warning:scalac: {
  abstract trait Compare[T1, T2] extends scala.AnyRef {
    type T;
    type Out = scala.Tuple2[T, T];
    def apply(a: T1, b: T2): Out
  };
  object Compare extends scala.AnyRef {
    def <init>() = {
      super.<init>();
      ()
    };
    def instance[T1, T2, T0$macro$1](f$macro$2: _root_.scala.Function2[T1, T2, Out]): Compare[T1, T2] {
      type T = T0$macro$1
    } = {
      final class $anon extends Compare[T1, T2] {
        def <init>() = {
          super.<init>();
          ()
        };
        override type T = T0$macro$1;
        type Out = scala.Tuple2[T, T];
        override def apply(a: T1, b: T2): Out = f$macro$2(a, b)
      };
      new $anon()
    };
    type Aux[T1, T2, T0] = Compare[T1, T2] {
      type T = T0
    };
    implicit def reverseCompare[T1, T2](implicit ev: _root_.scala.Function1[T2, T1]): Aux[T1, T2, T1] = instance(((a, b) => scala.Tuple2(a, ev(b))));
    implicit def directCompare[T1, T2](implicit ev: _root_.scala.Function1[T1, T2]): Aux[T1, T2, T2] = instance(((a, b) => scala.Tuple2(ev(a), b)))
  };
  ()
}

Error:(11, 13) not found: type Out
  /*@aux*/ @instance

Is version 0.9 published?

According to commit history, last version is 0.9 but it seems last published version is 0.8.

My build is failing because of...

[error] (core / update) sbt.librarymanagement.ResolveException: Error downloading org.typelevel:macro-compat_2.13.5:1.1.1
[error]   Not found
[error]   not found: /Users/alex/.ivy2/local/org.typelevel/macro-compat_2.13.5/1.1.1/ivys/ivy.xml
[error]   not found: https://repo1.maven.org/maven2/org/typelevel/macro-compat_2.13.5/1.1.1/macro-compat_2.13.5-1.1.1.pom

... and it seems version 0.9 fixes this so it will be awesome to have it published ๐Ÿ˜ธ .

Thanks in advance!

Support extends DepFn1[C]

  /*@aux*/ @instance /*@delegated*/
  trait FlattenAndDeduplicate[C <: Coproduct] extends DepFn1[C]{
    type Out <: Coproduct
//    def apply(t: C): Out
  }
  object FlattenAndDeduplicate {
    type Aux[C <: Coproduct, Out0 <: Coproduct] = FlattenAndDeduplicate[C] { type Out = Out0 }
//    def instance[C <: Coproduct, Out0 <: Coproduct](f: C => Out0): Aux[C, Out0] = new FlattenAndDeduplicate[C] {
//      override type Out = Out0
//      override def apply(t: C): Out0 = f(t)
//    }

    object identityPoly extends Poly1 {
      implicit def identityCase[A]: Case.Aux[A, A] = at(identity)
    }

    implicit def mkFlattenAndDeduplicate[C <: Coproduct, C_flatten <: Coproduct](implicit
      flatMap: FlatMap.Aux[C, identityPoly.type, C_flatten],
      dedup: Deduplicate[C_flatten],
    ): Aux[C, dedup.Out] = instance(c => dedup(flatMap(c)))
  }
Error:(53, 39) no arguments allowed for nullary method instance: ()App165.FlattenAndDeduplicate[C]{type Out = Out0$macro$1}
    ): Aux[C, dedup.Out] = instance(c => dedup(flatMap(c)))

In 2.12.8 there is no warning if @ aux is used and paradise plugin is not switched on

scalaVersion := "2.12.8"
libraryDependencies += "com.github.dmytromitin" %% "auxify-macros" % "0.6"
//addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full)
  import com.github.dmytromitin.auxify.macros.{aux, instance}

  @aux @instance
  trait Compare[T1, T2] {
    type T
    type Out = (T, T)
    def apply(a: T1, b: T2): Out
  }

lens doesn't work with stringToSymbol

import com.github.dmytromitin.auxify.shapeless.stringToSymbol
import shapeless.lens
case class Test(id: String, calc: Long)
lens[Test] >> stringToSymbol("id")
Error: Expression {
  import shapeless.syntax.singleton._;
  com.github.dmytromitin.auxify.shapeless.`package`.stringToSymbolHlp[String("id"), Symbol @@ String("id")](SingletonOps.instance[String("id")](Witness.mkWitness[String("id")]("id".asInstanceOf[String("id")])).narrow)(shapeless.this.StringToSymbol.mkStringToSymbol[String("id")](Witness.mkWitness[String("id")]("id".asInstanceOf[String("id")])), Witness.mkWitness[Symbol with shapeless.tag.Tagged[String("id")]](scala.Symbol.apply("id").asInstanceOf[Symbol @@ String("id")].asInstanceOf[Symbol with shapeless.tag.Tagged[String("id")]]))
} does not evaluate to a constant or a stable reference value
  val len1 = lens[Test] >> stringToSymbol("id")

https://stackoverflow.com/questions/50418767/shapeless-lenses-usage-with-a-string-definition/

Implement implicitSupertypeOf etc. in AUXify-Shapeless

https://stackoverflow.com/questions/62747743/in-scala-2-13-how-to-use-implicitlypath-dependent-type

Implement implicitSupertypeOf, implicitSubtypeOf (implicitly), implicitExactTypeOf, implicitStrictSupertypeOf, implicitStrictSubtypeOf.

https://stackoverflow.com/questions/59348301/in-scala-2-or-3-is-it-possible-to-debug-implicit-resolution-process-in-runtime

? Implement existImplicit, localImplicit/nonLocalImplicit, allImplicits, secondImplicit.

Fix FieldType test

https://stackoverflow.com/questions/50526509/using-string-instead-of-symbol-in-labelledgeneric-etc

import shapeless.Witness
import shapeless.labelled.FieldType
import shapeless.syntax.singleton._

def syFldToStrFld[St <: String, Sy <: Symbol, T](syFld : FieldType[Sy,T])(implicit syWit : Witness.Aux[Sy]) : FieldType[St,T] =
  (syWit.value.name : String) ->> (syFld : T)
[error] /home/travis/build/DmytroMitin/AUXify/shapeless/src/test/scala/com/github/dmytromitin/auxify/shapeless/FieldTypeTest.scala:10:23: 
Expression (syWit.value.name: String) does not evaluate to a constant or a stable reference value
[error]     (syWit.value.name : String) ->> (syFld : T)
[error]                       ^
[error] /home/travis/build/DmytroMitin/AUXify/shapeless/src/test/scala/com/github/dmytromitin/auxify/shapeless/FieldTypeTest.scala:10:33: 
value ->> is not a member of String
[error]     (syWit.value.name : String) ->> (syFld : T)
[error]                

https://travis-ci.org/github/DmytroMitin/AUXify/jobs/703170252

annotation @ poly ?

Transforms

@poly
trait MyTypeclass[In] {
  type Out
  def foo(in: In): Out
}

into

trait MyTypeclass[In] {
  type Out
  def foo(in: In): Out
}
object MyTypeclass {
  object myTypeclassPoly extends Poly1 {
    implicit def cse(implicit mtc: MyTypeclass[In]): Case.Aux[In, mtc.Out] = at(in => mtc.foo(in))
  }
}

@ instance doesn't create by-name param

https://github.com/DmytroMitin/AUXify/blob/master/core/src/test/scala/com/github/dmytromitin/InstanceMonoidTest.scala

Warning:scalac: {
  abstract trait Monoid[A] extends scala.AnyRef {
    def empty: A;
    def combine(a: A, a1: A): A
  };
  object Monoid extends scala.AnyRef {
    def <init>() = {
      super.<init>();
      ()
    };
    def instance[A](f$macro$1: A, f$macro$2: _root_.scala.Function2[A, A, A]): Monoid[A] = {
      final class $anon extends Monoid[A] {
        def <init>() = {
          super.<init>();
          ()
        };
        override def empty: A = f$macro$1;
        override def combine(a: A, a1: A): A = f$macro$2(a, a1)
      };
      new $anon()
    };
    implicit val int: Monoid[Int] = instance(0, ((x$1, x$2) => x$1.$plus(x$2)));
    implicit val str: Monoid[String] = instance("", ((x$3, x$4) => x$3.$plus(x$4)))
  };
  ()
}
Block(List(ClassDef(Modifiers(ABSTRACT | INTERFACE | DEFAULTPARAM/TRAIT), TypeName("Monoid"), List(TypeDef(Modifiers(PARAM), TypeName("A"), List(), TypeBoundsTree(EmptyTree, EmptyTree))), Template(List(Select(Ident(scala), TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(DEFERRED), TermName("empty"), List(), List(), Ident(TypeName("A")), EmptyTree), DefDef(Modifiers(DEFERRED), TermName("combine"), List(), List(List(ValDef(Modifiers(PARAM), TermName("a"), Ident(TypeName("A")), EmptyTree), ValDef(Modifiers(PARAM), TermName("a1"), Ident(TypeName("A")), EmptyTree))), Ident(TypeName("A")), EmptyTree)))), ModuleDef(Modifiers(), TermName("Monoid"), Template(List(Select(Ident(scala), TypeName("AnyRef"))), noSelfType, List(DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))), DefDef(Modifiers(), TermName("instance"), List(TypeDef(Modifiers(PARAM), TypeName("A"), List(), TypeBoundsTree(EmptyTree, EmptyTree))), List(List(ValDef(Modifiers(PARAM), TermName("f$macro$1"), Ident(TypeName("A")), EmptyTree), ValDef(Modifiers(PARAM), TermName("f$macro$2"), AppliedTypeTree(Select(Select(Ident(termNames.ROOTPKG), scala), TypeName("Function2")), List(Ident(TypeName("A")), Ident(TypeName("A")), Ident(TypeName("A")))), EmptyTree))), CompoundTypeTree(Template(List(AppliedTypeTree(Ident(TypeName("Monoid")), List(Ident(TypeName("A"))))), noSelfType, List())), Block(List(ClassDef(Modifiers(FINAL), TypeName("$anon"), List(), Template(List(AppliedTypeTree(Ident(TypeName("Monoid")), List(Ident(TypeName("A"))))), noSelfType, List(DefDef(Modifiers(), termNames.CONSTRUCTOR, List(), List(List()), TypeTree(), Block(List(pendingSuperCall), Literal(Constant(())))), DefDef(Modifiers(OVERRIDE), TermName("empty"), List(), List(), Ident(TypeName("A")), Ident(TermName("f$macro$1"))), DefDef(Modifiers(OVERRIDE), TermName("combine"), List(), List(List(ValDef(Modifiers(PARAM), TermName("a"), Ident(TypeName("A")), EmptyTree), ValDef(Modifiers(PARAM), TermName("a1"), Ident(TypeName("A")), EmptyTree))), Ident(TypeName("A")), Apply(Ident(TermName("f$macro$2")), List(Ident(TermName("a")), Ident(TermName("a1"))))))))), Apply(Select(New(Ident(TypeName("$anon"))), termNames.CONSTRUCTOR), List()))), ValDef(Modifiers(IMPLICIT), TermName("int"), AppliedTypeTree(Ident(TypeName("Monoid")), List(Ident(TypeName("Int")))), Apply(Ident(TermName("instance")), List(Literal(Constant(0)), Function(List(ValDef(Modifiers(PARAM | SYNTHETIC), TermName("x$1"), TypeTree(), EmptyTree), ValDef(Modifiers(PARAM | SYNTHETIC), TermName("x$2"), TypeTree(), EmptyTree)), Apply(Select(Ident(TermName("x$1")), TermName("$plus")), List(Ident(TermName("x$2")))))))), ValDef(Modifiers(IMPLICIT), TermName("str"), AppliedTypeTree(Ident(TypeName("Monoid")), List(Ident(TypeName("String")))), Apply(Ident(TermName("instance")), List(Literal(Constant("")), Function(List(ValDef(Modifiers(PARAM | SYNTHETIC), TermName("x$3"), TypeTree(), EmptyTree), ValDef(Modifiers(PARAM | SYNTHETIC), TermName("x$4"), TypeTree(), EmptyTree)), Apply(Select(Ident(TermName("x$3")), TermName("$plus")), List(Ident(TermName("x$4")))))))))))), Literal(Constant(())))

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.