git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add a couple Either/Maybe tests.
commit7e599d6da45201637f30e8265bef761af869413e authorjoneshf <jones3.hardy@gmail.com> dateWed 12 Mar 2014, 18:11 (13 years ago) parentd94ecd6
1 file changed+17−5
prelude/prelude.purs+17−5
prelude/prelude.purs+17−5
@@ -12,7 +12,7 @@ module Prelude where
1212 class Category a where
1313 id :: forall t. a t t
1414 (<<<) :: forall b c d. a c d -> a b c -> a b d
15−
15+
1616 (>>>) :: forall a b c d. (Category a) => a b c -> a c d -> a b d
1717 (>>>) f g = g <<< f
1818
@@ -179,7 +179,7 @@ module Prelude where
179179 show LT = "LT"
180180 show GT = "GT"
181181 show EQ = "EQ"
182−
182+
183183 class Ord a where
184184 compare :: a -> a -> Ordering
185185
@@ -191,19 +191,19 @@ module Prelude where
191191 _ -> false
192192
193193 infixl 4 >
194−
194+
195195 (>) :: forall a. (Ord a) => a -> a -> Boolean
196196 (>) a1 a2 = case a1 `compare` a2 of
197197 GT -> true
198198 _ -> false
199−
199+
200200 infixl 4 <=
201201
202202 (<=) :: forall a. (Ord a) => a -> a -> Boolean
203203 (<=) a1 a2 = case a1 `compare` a2 of
204204 GT -> false
205205 _ -> true
206−
206+
207207 infixl 4 >=
208208
209209 (>=) :: forall a. (Ord a) => a -> a -> Boolean
@@ -418,6 +418,12 @@ module Data.Maybe where
418418 fromMaybe :: forall a. a -> Maybe a -> a
419419 fromMaybe a = maybe a (id :: forall a. a -> a)
420420
421+ isJust :: forall a. Maybe a -> Boolean
422+ isJust = maybe false (const true)
423+
424+ isNothing :: forall a. Maybe a -> Boolean
425+ isNothing = maybe true (const false)
426+
421427 instance monadMaybe :: Monad Maybe where
422428 return = Just
423429 (>>=) m f = maybe Nothing f m
@@ -451,6 +457,12 @@ module Data.Either where
451457 either f _ (Left a) = f a
452458 either _ g (Right b) = g b
453459
460+ isLeft :: forall a b. Either a b -> Boolean
461+ isLeft = either (const true) (const false)
462+
463+ isRight :: forall a b. Either a b -> Boolean
464+ isRight = either (const false) (const true)
465+
454466 instance monadEither :: Monad (Either e) where
455467 return = Right
456468 (>>=) = either (\e _ -> Left e) (\a f -> f a)