File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
package sttp .monad
2
2
3
+ import sttp .shared .Identity
4
+
3
5
import scala .concurrent .{ExecutionContext , Future , Promise }
4
6
import scala .util .{Failure , Success , Try }
5
7
@@ -169,3 +171,17 @@ class FutureMonad(implicit ec: ExecutionContext) extends MonadAsyncError[Future]
169
171
170
172
override def blocking [T ](t : => T ): Future [T ] = Future (scala.concurrent.blocking(t))
171
173
}
174
+
175
+ object IdentityMonad extends MonadError [Identity ] {
176
+ override def unit [T ](t : T ): Identity [T ] = t
177
+ override def map [T , T2 ](fa : Identity [T ])(f : T => T2 ): Identity [T2 ] = f(fa)
178
+ override def flatMap [T , T2 ](fa : Identity [T ])(f : T => Identity [T2 ]): Identity [T2 ] = f(fa)
179
+ override def error [T ](t : Throwable ): Identity [T ] = throw t
180
+ override protected def handleWrappedError [T ](rt : Identity [T ])(
181
+ h : PartialFunction [Throwable , Identity [T ]]
182
+ ): Identity [T ] = rt
183
+ override def eval [T ](t : => T ): Identity [T ] = t
184
+ override def ensure [T ](f : Identity [T ], e : => Identity [Unit ]): Identity [T ] =
185
+ try f
186
+ finally e
187
+ }
Original file line number Diff line number Diff line change
1
+ package sttp
2
+
3
+ package object shared {
4
+
5
+ /** The `Identity` type constructor can be used where an "effect" or wrapper (usually called `F[_]`) is expected. It
6
+ * represents direct-style / synchronous programming, and allows passing in code written in this style.
7
+ */
8
+ type Identity [X ] = X
9
+ }
You can’t perform that action at this time.
0 commit comments