Coder Social home page Coder Social logo

macrame's Issues

Unable to delegate dependent types

  object Foo {
    def setType(t: scala.reflect.api.Types#Type): Unit = ???
  }
  object Bar {
    @delegate def foo: Foo.type = Foo
  }
[error] Bar.scala:20: not found: type Type
[error]     @delegate def foo: Foo.type = Foo
[error]      ^

Add autoFold function.

autoFold function that matches the correct functions to the correct cases. Given:

sealed trait Foo
case class Bar(i : Int) extends Foo
case class Baz(s : String) extends Foo
val foo : Foo = Bar(5)

def barF(b : Bar) : String = b.i
def bazF(b : Baz) : String = b.s

both

foo.autoFold(barF _, bazF _)

and

foo.autoFold(bazF _, barF _)

compile to

foo match {
  case b @ Bar(_) => barF(b)
  case b @ Baz(_) => bazF(b)
}

`@delegate` does not properly create stable identifier for `val`

package myPackage

import macrame.delegate

object Foo {

  val s = ""

}

object Bar {

  @delegate
  val underlying: Foo.type = Foo

}

object Main {

  def main(args: Array[String]): Unit = {
    val s1: Foo.s.type = Foo.s
    val s2: Bar.s.type = Bar.s
    assert(s1 eq s2)
  }
}
/private/tmp/TypeDelegate/TypeDelegate.scala:22: stable identifier required, but Bar.s found.
    val s2: Bar.s.type = Bar.s
                ^
one error found

Provide higher-level self-typed traits for enumerations.

Use at Gawker has made it clear that people prefer to use traits rather than use EnumApi directly, e.g.

trait EnumAsString[Enum] { self: EnumApi[Enum] =>
  def asString(e : Enum) : String = asStringImpl(e)
}

Especially when combined with implicit wrapper classes, this really reduces boilerplate. Instead of redefining these all the time it would be better to add them into Macramé. I should also finally get around to publishing macrame-play and macrame-slick.

`@delegate` does not properly forward type aliases

package myPackage

import macrame.delegate

object Foo {

  type AnySeq = Seq[_]

  def emptySeq: AnySeq = Nil

}

object Bar {

  @delegate
  val underlying: Foo.type = Foo

}

object Main {

  def main(args: Array[String]): Unit = {
    val x: AnySeq = Bar.emptySeq
  }
}
/private/tmp/TypeDelegate/TypeDelegate.scala:23: type AnySeq is not a member of object myPackage.Bar
    val x: Bar.AnySeq = Bar.emptySeq
               ^
one error found

`@delegate` does not properly forward objects

package myPackage

import macrame.delegate

object Foo {

  object O

}

object Bar {

  @delegate
  val underlying: Foo.type = Foo

}

object Main {

  def main(args: Array[String]): Unit = {
    val o1 = Foo.O
    val o2 = Bar.O
    assert(o1 eq o2)
  }
}

/private/tmp/TypeDelegate/TypeDelegate.scala:22: value O is not a member of object myPackage.Bar
    val o2 = Bar.O
                 ^
one error found

Delegates for generic types.

99% of the time when I want to delegate methods to a wrapped class it is for generic classes, e.g. case class WithDbMeta[A](id : Id[A], updateTime : DateTime, underlying : A). I think I've worked out a way to make @delegate work with these based on this gist and implicit macros.

The basic idea would look something like this:

// In User.scala
@delegatable
case class User(name : String, password : String)
// in WithDbMeta.scala
case class WithDbMeta[A](id : Id[A], updateTime : DateTime, @delegate underlying : A)

expanding to:

// In User.scala
case class User(name : String, password : String)
object User {
  object delegates {
    <UserLike typeclass, ops class, extension implementation, etc>
  }
}
// in WithDbMeta.scala
case class WithDbMeta[A](id : Id[A], updateTime : DateTime, @delegate underlying : A)
object WithDbMeta {
  // We would check that `T` extends some dummy trait here to perform a fast exit if this isn't delegate related. Otherwise, we try to generate the appropriate instance, using whitebox macros to fail gracefully if we have the wrong type.
  implicit def delegateInstance[T[_], A]: T[WithDbMeta[A] = macro impl
}

Unable to forward implicit classes

Welcome to Scala version 2.10.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_102).
Type in expressions to have them evaluated.
Type :help for more information.

scala> object Foo {
     |   implicit final class RichAnyRef[A](val underlying: A) {
     |     def get: A = underlying
     |   }
     | }
defined module Foo

scala> object Bar {
     |   @macrame.delegate
     |   def foo: Foo.type = Foo
     | }
defined module Bar

scala> Bar.RichAnyRef("xxx")
res2: Foo.RichAnyRef[String] = Foo$RichAnyRef@4f05610e

scala> import Bar.RichAnyRef
import Bar.RichAnyRef

scala> RichAnyRef("xxx").get
res3: String = xxx

scala> "xxx".get
<console>:11: error: value get is not a member of String
              "xxx".get
                    ^

scala> new RichAnyRef("xxx").get
<console>:11: error: not found: type RichAnyRef
              new RichAnyRef("xxx").get
                  ^

"xxx".get would compile if the implicit converter is correctly forwarded.

new RichAnyRef("xxx").get would compile if there is a type RichAnyRef[A] = Foo.RichAnyRef[A] alias.

@delegate fails with "recursive value byline needs type"

The following code causes /home/chris/Programming/macrame/macrame/src/test/scala/macrame/PostDelegateFailure.scala:9: recursive value byline needs type

object Post {
   final case class Byline()
}

final case class CleanPost(byline : Option[Post.Byline] = None)

final case class Post(@delegate clean : CleanPost)

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.