Is Option wrapping a value a good pattern?

后端 未结 3 1815
攒了一身酷
攒了一身酷 2021-02-05 22:52

I recently wrote the following bit of Scala:

val f: File = ... // pretend this file came from somewhere
val foo = toFoo(io.Source.fromFile(f).mkString)
         


        
3条回答
  •  悲&欢浪女
    2021-02-05 23:34

    You add toFoo to String through the pimp my library pattern. Then it becomes:

    val foo = Source fromFile f mkString () toFoo
    

提交回复
热议问题