Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.84 KB  |  views: 19  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import TheFamily.{Name, parents, children, male, female}
  2. import TraversalsAndFilters.{Extractor, Flattener}
  3.  
  4. object CreatingALanguage {
  5.  
  6.   def pattern[B](pf: PartialFunction[Name,B]) =
  7.     new Extractor(pf.lift)
  8.  
  9.   val Parents = new Extractor(parents.get)
  10.   val Children = new Extractor(children.get)
  11.   val Female = pattern { case n if female contains n => n }
  12.   val GrandChildren =
  13.     pattern { case Children(Children(c)) => c }
  14.   val GrandDaughters =
  15.     pattern { case GrandChildren(Female(c)) => c }
  16.  
  17.   val Mother = pattern { case Parents(Female(p)) => p }
  18.   val Siblings = pattern {
  19.     case self @ Parents(Children(siblings)) if(siblings.size != 1)  =>
  20.       siblings - self
  21.   }
  22.   val Sisters = pattern { case Siblings(Female(s)) => s }
  23.   val Male = pattern { case n if male contains n => n }
  24.   val Brothers = pattern { case Siblings(Male(b)) => b }
  25.  
  26. }
clone this paste RAW Paste Data