2 | import Control.Function
9 | isNothing : Maybe a -> Bool
10 | isNothing Nothing = True
11 | isNothing (Just _) = False
14 | isJust : Maybe a -> Bool
15 | isJust Nothing = False
16 | isJust (Just _) = True
20 | data IsJust : Maybe a -> Type where
21 | ItIsJust : IsJust (Just x)
24 | Uninhabited (IsJust Nothing) where
25 | uninhabited ItIsJust
impossible
29 | isItJust : (v : Maybe a) -> Dec (IsJust v)
30 | isItJust (Just _) = Yes ItIsJust
31 | isItJust Nothing = No absurd
36 | fromMaybe : (Lazy a) -> Maybe a -> a
37 | fromMaybe def Nothing = def
38 | fromMaybe _ (Just j) = j
42 | fromJust : (v : Maybe a) -> (0 _ : IsJust v) => a
43 | fromJust (Just x) = x
44 | fromJust Nothing impossible
49 | toMaybe : Bool -> Lazy a -> Maybe a
50 | toMaybe True j = Just j
51 | toMaybe False _ = Nothing
54 | Injective Just where
55 | injective Refl = Refl
60 | lowerMaybe : Monoid a => Maybe a -> a
61 | lowerMaybe Nothing = neutral
62 | lowerMaybe (Just x) = x
66 | raiseToMaybe : Monoid a => Eq a => a -> Maybe a
67 | raiseToMaybe x = if x == neutral then Nothing else Just x
70 | filter : (a -> Bool) -> Maybe a -> Maybe a
71 | filter _ Nothing = Nothing
72 | filter f (Just x) = toMaybe (f x) x
77 | [Deep] Semigroup a => Semigroup (Maybe a) where
78 | Nothing <+> Nothing = Nothing
79 | Just l <+> Nothing = Just l
80 | Nothing <+> Just r = Just r
81 | Just l <+> Just r = Just $
l <+> r
86 | [Deep] Semigroup a => Monoid (Maybe a) using Semigroup.Deep where
90 | Zippable Maybe where
91 | zipWith f x y = [| f x y |]
92 | zipWith3 f x y z = [| f x y z |]
94 | unzipWith f Nothing = (Nothing, Nothing)
95 | unzipWith f (Just x) = let (a, b) = f x in (Just a, Just b)
97 | unzipWith3 f Nothing = (Nothing, Nothing, Nothing)
98 | unzipWith3 f (Just x) = let (a, b, c) = f x in (Just a, Just b, Just c)