Skip to content

Commit 1d9347e

Browse files
committed
Merge pull request #12 from purescript/fix-partial-warnings
Fix warnings about partial functions
2 parents 777607f + 6095ecc commit 1d9347e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/Data/Either/Unsafe.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* global exports */
2+
"use strict";
3+
4+
// module Data.Either.Unsafe
5+
6+
exports.unsafeThrow = function (msg) {
7+
throw new Error(msg);
8+
};

src/Data/Either/Unsafe.purs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
module Data.Either.Unsafe where
1+
module Data.Either.Unsafe
2+
( fromLeft
3+
, fromRight
4+
) where
25

36
import Prelude
47

@@ -8,9 +11,12 @@ import Data.Either
811
-- | Passing a `Right` to `fromLeft` will throw an error at runtime.
912
fromLeft :: forall a b. Either a b -> a
1013
fromLeft (Left a) = a
14+
fromLeft _ = unsafeThrow "Data.Either.Unsafe.fromLeft called on Right value"
1115

1216
-- | A partial function that extracts the value from the `Right` data constructor.
1317
-- | Passing a `Left` to `fromRight` will throw an error at runtime.
1418
fromRight :: forall a b. Either a b -> b
1519
fromRight (Right a) = a
20+
fromRight _ = unsafeThrow "Data.Either.Unsafe.fromLeft called on Left value"
1621

22+
foreign import unsafeThrow :: forall a. String -> a

0 commit comments

Comments
 (0)