[Hoisted] what is going on on this line?

19 views
Skip to first unread message

Diego Medina

unread,
Jun 9, 2012, 8:02:48 PM6/9/12
to Lift
Hi, (a bit off topic, sorry about that)

I was looking over the Hoisted code and I found this:
https://github.com/fmpwizard/hoisted/commit/b9562ea6bb4ff1164b0d570507ae317c919567f4#L5R145

/**
* Compute the title of the file
*/
def computeTitle: (ParsedFile) => String = pf => {
pf match {
case md: ParsedFile with HasMetaData =>
md.findData(TitleKey).flatMap(_.asString) or
pf.findData(LinkKey).flatMap(_.asString) openOr
computeTitleFromFileName(pf)
case _ => computeTitleFromFileName(pf)
}
}



This is the first time I see a pattern math like:

case md: ParsedFile with HasMetaData =>

I thought that what is checking there is that is pf is of type
ParsedFile but it also has to extend HasMetaData, is that the case? I
tried replicating it on the REPL but I get code cannot be reached for
anything that I put as a second match. (But maybe it is just a REPL
limitation)

Thanks

Diego


--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

David Pollak

unread,
Jun 10, 2012, 1:29:27 AM6/10/12
to lif...@googlegroups.com
On Sat, Jun 9, 2012 at 5:02 PM, Diego Medina <di...@fmpwizard.com> wrote:
Hi,  (a bit off topic, sorry about that)

I was looking over the Hoisted code and I found this:
https://github.com/fmpwizard/hoisted/commit/b9562ea6bb4ff1164b0d570507ae317c919567f4#L5R145

 /**
 * Compute the title of the file
 */
 def computeTitle: (ParsedFile) => String = pf => {
   pf match {
     case md: ParsedFile with HasMetaData =>
md.findData(TitleKey).flatMap(_.asString) or
       pf.findData(LinkKey).flatMap(_.asString) openOr
computeTitleFromFileName(pf)
     case _ => computeTitleFromFileName(pf)
   }
 }



This is the first time I see a pattern math like:

 case md: ParsedFile with HasMetaData =>

I thought that what is checking there is that is pf is of type
ParsedFile but it also has to extend HasMetaData, is that the case?

Yes... it's testing to see if it's an instance of ParsedFile and HasMetaData
 
I
tried replicating it on the REPL but I get code cannot be reached for
anything that I put as a second match. (But maybe it is just a REPL
limitation)

Sounds like a REPL issue.
 

Thanks

 Diego


--
Diego Medina
Lift/Scala Developer
di...@fmpwizard.com
http://www.fmpwizard.com

--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code



--
Telegram, Simply Beautiful CMS https://telegr.am
Lift, the simply functional web framework http://liftweb.net


Diego Medina

unread,
Jun 10, 2012, 1:44:55 AM6/10/12
to lif...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages