-
Notifications
You must be signed in to change notification settings - Fork 7
/
ReadyState.purs
46 lines (37 loc) · 993 Bytes
/
ReadyState.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Web.XHR.ReadyState where
import Prelude
import Data.Enum (class BoundedEnum, class Enum, Cardinality(..), defaultPred, defaultSucc)
import Data.Maybe (Maybe(..))
data ReadyState
= Unsent
| Opened
| HeadersReceived
| Loading
| Done
derive instance eqReadyState :: Eq ReadyState
derive instance ordReadyState :: Ord ReadyState
instance boundedReadyState :: Bounded ReadyState where
bottom = Unsent
top = Done
instance enumReadyState :: Enum ReadyState where
succ = defaultSucc toEnum fromEnum
pred = defaultPred toEnum fromEnum
instance boundedEnumReadyState :: BoundedEnum ReadyState where
cardinality = Cardinality 5
toEnum = toEnum
fromEnum = fromEnum
toEnum :: Int -> Maybe ReadyState
toEnum = case _ of
0 -> Just Unsent
1 -> Just Opened
2 -> Just HeadersReceived
3 -> Just Loading
4 -> Just Done
_ -> Nothing
fromEnum :: ReadyState -> Int
fromEnum = case _ of
Unsent -> 0
Opened -> 1
HeadersReceived -> 2
Loading -> 3
Done -> 4