How to lazy evaluate functions in a sequence in Scala -


let's have 3 functions in class can return option[file]. looking nice way execute them in order , stop when first function evaluates (similar pick() lazy evaluation), i.e. don't want use nested if-else statements.

abstract class foo() {   def first(): option[file]   def second(): option[file]   def third(): option[file]   def pick(): option[file] = {     seq(first(), second(), third()).find(_.isdefined).map(_.get)   ) } 

the parameter option.orelse passed name, can use chain methods:

def pick(): option[file] = first orelse second orelse third 

Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -