Skip to content

Commit 312f296

Browse files
radrowsharkdp
authored andcommitted
Add toInt
1 parent ef12043 commit 312f296

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Data/BigInt.purs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@ module Data.BigInt
2424
, shr
2525
, quot
2626
, rem
27+
, toInt
2728
, toNumber
2829
) where
2930

3031
import Prelude
3132

3233
import Data.Array.NonEmpty (NonEmptyArray)
3334
import Data.Int (floor)
35+
import Data.Int as Int
3436
import Data.Maybe (Maybe(..), fromJust)
3537
import Data.String.NonEmpty (NonEmptyString)
3638
import Data.String.NonEmpty as NES
@@ -56,6 +58,9 @@ foreign import fromBaseImpl
5658
-- | Convert an integer to a BigInt.
5759
foreign import fromInt :: Int -> BigInt
5860

61+
toInt :: BigInt -> Maybe Int
62+
toInt = toNumber >>> Int.fromNumber
63+
5964
-- | FFI wrapper to parse a Number into a BigInt.
6065
foreign import fromNumberImpl
6166
:: forall a

0 commit comments

Comments
 (0)