File tree 1 file changed +11
-1
lines changed 1 file changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import Data.Bitraversable (class Bitraversable)
10
10
import Data.Eq (class Eq1 )
11
11
import Data.Foldable (class Foldable )
12
12
import Data.Functor.Invariant (class Invariant , imapF )
13
- import Data.Maybe (Maybe (..), maybe )
13
+ import Data.Maybe (Maybe (..), maybe , maybe' )
14
14
import Data.Monoid (mempty )
15
15
import Data.Ord (class Ord1 )
16
16
import Data.Traversable (class Traversable )
@@ -262,6 +262,16 @@ fromRight (Right a) = a
262
262
note :: forall a b . a -> Maybe b -> Either a b
263
263
note a = maybe (Left a) Right
264
264
265
+ -- | Similar to `note`, but for use in cases where the default value may be
266
+ -- | expensive to compute.
267
+ -- |
268
+ -- | ```purescript
269
+ -- | note' (\_ -> "default") Nothing = Left "default"
270
+ -- | note' (\_ -> "default") (Just 1) = Right 1
271
+ -- | ```
272
+ note' :: forall a b . (Unit -> a ) -> Maybe b -> Either a b
273
+ note' f = maybe' (Left <<< f) Right
274
+
265
275
-- | Turns an `Either` into a `Maybe`, by throwing eventual `Left` values away and converting
266
276
-- | them into `Nothing`. `Right` values get turned into `Just`s.
267
277
-- |
You can’t perform that action at this time.
0 commit comments