Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate from turtles to droste #2

Merged
merged 13 commits into from Aug 2, 2018
Merged

Migrate from turtles to droste #2

merged 13 commits into from Aug 2, 2018

Conversation

pepegar
Copy link
Member

@pepegar pepegar commented Aug 1, 2018

Use droste for recursion schemes

@pepegar pepegar requested review from andyscott and a team August 1, 2018 09:20
Copy link

@diesalbla diesalbla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few, small, stylish, comments. LGTM.

val printSymbols = symbols.map({ case (s, i) => s"$s = $i;" }).mkString("\n")
val printAliases = aliases.map({ case (s, i) => s"$s = $i;" }).mkString("\n")

s"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, you could use stripMargin?

      s"""
        |enum $name {
        |  $printOptions
        |  $printSymbols
        |  $printAliases
        |}
      """.stripMargin

case TMessage(name, fields, reserved) =>
val printReserved = reserved.map(l => s"reserved " + l.mkString(", ")).mkString("\n ")
def printOptions(options: List[Option]) =
if (options.isEmpty) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for braces in this if-then-else.

.map(f => s"""${f.tpe} ${f.name} = ${f.position}${printOptions(f.options)};""")
.mkString("\n ")
s"""
message $name {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use stripMargin here, too.


val printFields =
fields
.map(f => s"""${f.tpe} ${f.name} = ${f.position}${printOptions(f.options)};""")
Copy link

@diesalbla diesalbla Aug 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that, for this line, a single-quoted string will suffice.

proto.name,
proto.types.map(toFreestyle),
proto.messages.map(
msg =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would extract this as a def toOperation function.

```scala
def nestedNamedTypesTrans[T](implicit T: Basis[Schema, T]): Trans[Schema, Schema, T] = Trans {
case TProduct(name, fields) =>
TProduct[T](

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, I would extract the function of the map as a def, so as to get:

def ttt(f: Field[T]) = f.copy(tpe = namedTypes(T)(f.tpe))
TProduct[T](name, fields.map(tt) )

case TProduct(name, fields) =>
TProduct[T](
name,
fields.map { f: Field[T] =>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the comment for the optimize.md file.

invariants.toList.mkString("Cop[", " :: ", ":: TNil]")
case TSum(name, fields) =>
val printFields = fields.map(f => s"case object $f extends $name").mkString("\n ")
s"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another use for stripMargin.

"""
case TProduct(name, fields) =>
val printFields = fields.map(f => s"${f.name}: ${f.tpe}").mkString(", ")
s"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would the next three lines be the same as the following line?

"@message case class $name($printFields)" 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, good catch! ;)

if (options.isEmpty) {
""
} else {
options.map(printOption).mkString(" [", ", ", "]")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the mkString, I had some problem reading apart each quote and comma. It may be worth using named parameters:

mkString( start = " [" , sep = ", " , end = "]" ) 

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

```

```tut
ast[Mu[Schema]].transCataT(namedTypes)
val optimization = Optimize.namedTypes[Fix[Schema]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to use Mu still, if you want.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, IDK why I didn't see it in droste :) Thanks!

Copy link
Member

@andyscott andyscott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@pepegar pepegar merged commit 368e786 into master Aug 2, 2018
@pepegar pepegar deleted the droste branch August 2, 2018 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants