Thursday, 15 January 2015

scala - How to write a lazy, variable argument version of "orElse" -


Is it possible to write the normalized orElse method to option arguments Takes a variable number of? Instead:

  lazy wall o1 = {println ("foo"); None) Lazy val o2 = {println ("bar"); Some ("bar")} lazy wall o3 = {println ("falcon"); Some ("falcon")} // ... o1 or ales o2 or else o3 // or else ...  

You can use:

< Pre> orElse (O1, o2, o3) //, ...

< According to p> (4.6 function declaration and definitions) you can not define parameters by the name of aliases:

  ParamType :: = Type | '= & Gt;' Type | Type '*' scala & gt; Def or Else (x: (=> string) *) & lt; Console & gt ;: 1: Error: Any name parameter type is not allowed def or else (x: (=> string) *)  
  Diff or Else [T] (X: ((=) => option [T]) *): option [t] = if (x.isEmpty) none x.first.apply.orElse (or Else ((x drop 1): _ *)) contained anyToFun0 [T] (T: = & gt; t): ((=) = & gt; t) = () = & gt; T or Else (O1, O2, O3)  

No comments:

Post a Comment