Skip to content

Commit 30e3754

Browse files
author
Colin Wahl
authored
Remove purescript-naturals dependency (#9)
1 parent 88c73c1 commit 30e3754

File tree

3 files changed

+9
-12
lines changed

3 files changed

+9
-12
lines changed

bower.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
"package.json"
1616
],
1717
"dependencies": {
18-
"purescript-naturals": "master",
1918
"purescript-web-dom": "master"
2019
},
2120
"devDependencies": {

src/Web/DOM/XPath.purs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import Data.Array (catMaybes, range)
66
import Data.Int (round, toNumber)
77
import Data.Maybe (Maybe(..))
88
import Data.Nullable (Nullable, toMaybe, toNullable)
9-
import Data.Natural (Natural, intToNat, natToInt)
109
import Data.Traversable (sequence)
1110
import Effect (Effect)
1211
import Web.DOM.Document (Document, documentElement)
@@ -97,18 +96,18 @@ singleNodeValue = map toMaybe <<< singleNodeValueInternal
9796
foreign import invalidIteratorState :: XPathResult -> Boolean
9897

9998
foreign import snapshotLengthInternal :: XPathResult -> Effect Number
100-
snapshotLength :: XPathResult -> Effect Natural
101-
snapshotLength = map (intToNat <<< round) <<< snapshotLengthInternal
99+
snapshotLength :: XPathResult -> Effect Int
100+
snapshotLength = map round <<< snapshotLengthInternal
102101

103102
foreign import iterateNextInternal :: XPathResult -> Effect (Nullable Node)
104103
iterateNext :: XPathResult -> Effect (Maybe Node)
105104
iterateNext = map toMaybe <<< iterateNextInternal
106105

107106
foreign import snapshotItemInternal ::
108107
XPathResult -> Number -> Effect (Nullable Node)
109-
snapshotItem :: XPathResult -> Natural -> Effect (Maybe Node)
108+
snapshotItem :: XPathResult -> Int -> Effect (Maybe Node)
110109
snapshotItem xpres ix = map toMaybe $
111-
snapshotItemInternal xpres (toNumber $ natToInt $ ix)
110+
snapshotItemInternal xpres (toNumber ix)
112111

113112
-- | High level wrapper around [snapshotItem](#v:snapshotItem)
114113
-- | and [snapshotLength](#v:snapshotLength)
@@ -120,14 +119,14 @@ snapshot xpres = case snapMay of
120119
where
121120
snapTypMay = RT.res2SnapType $ resultType xpres
122121
snapMay = map snapshotInternal snapTypMay
123-
nodeAtIdx :: Natural -> Effect (Maybe Node)
122+
nodeAtIdx :: Int -> Effect (Maybe Node)
124123
nodeAtIdx = snapshotItem xpres
125124
snapshotInternal :: RT.SnapshotType -> Effect (Array Node)
126125
snapshotInternal snapType = do
127126
nNodes <- snapshotLength xpres
128-
nNodesInt <- pure $ natToInt nNodes
127+
nNodesInt <- pure nNodes
129128
-- nodeArray <- pure $ replicate nNodesInt _emptyNode
130-
indices <- pure $ map intToNat $ range 0 (nNodesInt - 1)
129+
indices <- pure $ range 0 (nNodesInt - 1)
131130
nodeArray <- sequence $ map nodeAtIdx indices
132131
-- TODO: currently this is likely slow due to not using state
133132
pure $ catMaybes nodeArray

test/Main.purs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import Data.Array ((!!), length)
88
import Data.Either (Either, fromRight')
99
import Data.Int (toNumber)
1010
import Data.Maybe (Maybe(..), fromJust, fromMaybe)
11-
import Data.Natural (intToNat)
1211
import Effect (Effect)
1312
import Effect.Aff (launchAff_)
1413
import Effect.Class (class MonadEffect, liftEffect)
@@ -155,7 +154,7 @@ main { browser } = launchAff_ $ flip runReaderT "" do
155154
catalogDoc
156155
cdsSnapLen <- liftEffect $ XP.snapshotLength cdsSnapRes
157156
tlog $ "got " <> (show cdsSnapLen) <> " CDs"
158-
shouldEqual (intToNat 26) cdsSnapLen
157+
shouldEqual 26 cdsSnapLen
159158
cdsSnap <- liftEffect $ XP.snapshot cdsSnapRes
160159
cdYearEval <- pure $ mkCdYear catalogDoc
161160
shouldEqual 26 (length cdsSnap)
@@ -208,7 +207,7 @@ main { browser } = launchAff_ $ flip runReaderT "" do
208207
atomFeedDoc
209208
atomEntriesLen <- liftEffect $ XP.snapshotLength atomEntriesRes
210209
tlog $ "got " <> (show atomEntriesLen) <> " atom entries"
211-
shouldEqual (intToNat 3) atomEntriesLen
210+
shouldEqual 3 atomEntriesLen
212211

213212
test "metajelo.xml" do
214213
domParser <- liftEffect $ makeDOMParser

0 commit comments

Comments
 (0)