@@ -280,13 +280,31 @@ fromLeft :: forall a b. a -> Either a b -> a
280
280
fromLeft _ (Left a) = a
281
281
fromLeft default _ = default
282
282
283
+ -- | Similar to `fromLeft` but for use in cases where the default value may be
284
+ -- | expensive to compute. As PureScript is not lazy, the standard `fromLeft`
285
+ -- | has to evaluate the default value before returning the result,
286
+ -- | whereas here the value is only computed when the `Either` is known
287
+ -- | to be `Right`.
288
+ fromLeft' :: forall a b . (Unit -> a ) -> Either a b -> a
289
+ fromLeft' _ (Left a) = a
290
+ fromLeft' default _ = default unit
291
+
283
292
-- | A function that extracts the value from the `Right` data constructor.
284
293
-- | The first argument is a default value, which will be returned in the
285
294
-- | case where a `Left` is passed to `fromRight`.
286
295
fromRight :: forall a b . b -> Either a b -> b
287
296
fromRight _ (Right b) = b
288
297
fromRight default _ = default
289
298
299
+ -- | Similar to `fromRight` but for use in cases where the default value may be
300
+ -- | expensive to compute. As PureScript is not lazy, the standard `fromRight`
301
+ -- | has to evaluate the default value before returning the result,
302
+ -- | whereas here the value is only computed when the `Either` is known
303
+ -- | to be `Left`.
304
+ fromRight' :: forall a b . (Unit -> b ) -> Either a b -> b
305
+ fromRight' _ (Right b) = b
306
+ fromRight' default _ = default unit
307
+
290
308
-- | Takes a default and a `Maybe` value, if the value is a `Just`, turn it into
291
309
-- | a `Right`, if the value is a `Nothing` use the provided default as a `Left`
292
310
-- |
0 commit comments