Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by handler on Monday October 28, 2013 @03:27PM
(#6629205)
in general your repository functions will be wrapped in some monad, whether it's Reader/Maybe/List doesn't really matter as far as the for comprehension is concerned.
[ Parent
| on HN ]
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by kilovoltaire on Monday October 28, 2013 @03:39PM
(#6629276)
Yeah, I guess that helps a little since Scala's for comprehensions let you mix monads. (Which, for the record, Haskell's otherwise similar do notation doesn't seem to allow.)
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by jarhart on Monday October 28, 2013 @04:20PM
(#6629496)
Technically, Scala's for comprehensions don't let you mix monads either, but implicit conversions make it work in some cases. For example, there's an implicit conversion from Option to Iterable so the Option (Maybe) and List monads can be mixed. It's really more a matter of Scala's type system allowing it. The Scala compiler just re-writes comprehensions into equivalent higher-order function application.
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by kilovoltaire on Monday October 28, 2013 @04:33PM
(#6629581)
Cool thanks, didn't realize it was due to implicits.
Here are my tests, for the record.
Works in Scala:
for {a <- Seq(Some(1), None, Some(3)); b <- a} yield b
Doesn't work in Haskell: do a <- [Just 1, Nothing, Just 3]; b <- a; return b