working with lists and function application

27 views
Skip to first unread message

owreese

unread,
Jul 11, 2012, 10:04:34 PM7/11/12
to treehugg...@googlegroups.com
How do you work with a list where you want to have something akin to the following:

a |•| b |•| c |•| d

Be produced without explicitly writing it out. All my approaches have wound up with DOT and/or APPLY. Produces things like the

A.(B.(c))

eugene yokota

unread,
Jul 11, 2012, 10:19:25 PM7/11/12
to treehugg...@googlegroups.com
I thought I'd put that in treehugger, but turned out I only
implemented in scalaxb:

def INFIX_CHAIN(op: String, seq: Iterable[Tree]): Tree =
seq.toList match {
case Nil => EmptyTree
case List(x) => x
case xs => xs reduceLeft { (x, y) => x INFIX(op) APPLY y }
}


scala> val list = List(REF("a"), REF("b"), REF("c"), REF("d"))
list: List[treehugger.package.forest.Ident] = List(Ident(a), Ident(b),
Ident(c), Ident(d))

scala> INFIX_CHAIN("|•|", list)
res7: treehugger.package.forest.Tree =
Infix(Infix(Infix(Ident(a),|•|,List(Ident(b))),|•|,List(Ident(c))),|•|,List(Ident(d)))

scala> treeToString(res7)
res8: String = a |•| b |•| c |•| d

-eugene
> --
> You received this message because you are subscribed to the Google Groups "treehugger-scala" group.
> To view this discussion on the web visit https://groups.google.com/d/msg/treehugger-scala/-/zXwfzZSKfvAJ.
> To post to this group, send email to treehugg...@googlegroups.com.
> To unsubscribe from this group, send email to treehugger-sca...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/treehugger-scala?hl=en.
>
Reply all
Reply to author
Forward
0 new messages