score:7
Accepted answer
There is in fact an Applicative
instance for Reader
, which you can use like this (you should of course replace String
with whatever type you want your environment to be):
3.point[({type L[X] = Reader[String, X]})#L]
If you'd prefer to avoid the ugly type lambda and don't mind defining an extra type alias, you can write the following instead:
type MyReader[X] = Reader[String, X]
3.point[MyReader]
Scalaz 7 also provides a nice bit of shorthand that makes this even cleaner:
3.liftReader[String]
These are all more or less equivalent to each other (and to your solution), though.
Source: stackoverflow.com
Related Query
- point reader monad scala
- reader writer state monad - how to run this scala code
- Program architecture using the monad reader in Scala
- Scala cannot infer parameter type in Reader monad implementation
- Composing Kleisli and Reader monad in Scala
- Reader Monad for Dependency Injection: multiple dependencies, nested calls
- Scala Functor and Monad differences
- Configuration data in Scala -- should I use the Reader monad?
- Why does Scala not have a return/unit function defined for each monad (in contrast to Haskell)?
- monoid vs monad in Scala
- Monad trait in Scala
- Using Reader Monad for Dependency Injection
- The case for point free style in Scala
- Stacking monadic effects in a Free Monad in Scala
- Understanding Random monad in Scala
- Make an arbitrary class in Scala as a monad instance
- Scala State monad - combining different state types
- Scala and State Monad
- Why does Scala 2.11.2 give me compilation error for floating point number in scientific notation?
- Reader Monad with Scalaz
- Scala Monad - Full worked example
- Scala playframework implicit reader writer for Timestamp
- Creating a scala Reader from a file
- How to understand monad in scala
- Scala Cats State Monad
- How to implement a short-circuit with IO monad in Scala
- how to implement this future/state concept as a monad in scala
- Stacking Monad Transformers in scala
- What is the IO Haskell Monad equivalent in Scala standard API?
- Understanding monad transformers in Scala
More Query from same tag
- how to get current application instance in companion object
- Play! framework 2.0: Validate field in forms using other fields
- Canonical way to define and execute a method that outputs Unit?
- Javafx's @FXML fields not being populated in certain cases
- How to initialize covariant variable?
- Scala + How to do placeholder replacement in Spark Dataframe Column from file?
- How to mock spray-client response
- Scala SortedSet - sorted by one Ordering and unique by something else?
- Configure logging with Lift
- JS script works only when embedded in scala/html code
- JavaScript file not loading in .jsp file
- load csv file in sql table using scala
- error mismatching in scala
- Self in trait invisible from outside the trait?
- Slick: retrieve id of inserted value
- Low performance reduceByKey() in Spark
- Copy all the fields of a case class when only the mixed in trait is known
- Drop column(s) in spark csv data frame
- How to handle java.util.NoSuchElementException: reduce over empty stream akka stream?
- Scala: Using the App trait
- Implicit parameter precedence
- Scala- JSON HTTP Post request throwing errors
- How do I run the play-scala demo?
- How to convert nested array to a flat array?
- Scala REPL. First it says "illegal start of definition", then "error: not found: type" when I try it a different way
- balanced parantheses recursive method in scala
- Remove keys that don't contain any of the values in a set
- What scala version Intellij Idea scala plugin uses?
- Is there an equivalent of Haskell's CHP for Scala?
- Using Play Framework Anorm, how do I get the auto-generated id back for an insert?