Dataset Viewer
Auto-converted to Parquet Duplicate
id
stringlengths
37
274
text
stringlengths
34
138
-- | Return the contents of a 'Left'-value or a default value otherwise. -- > fromLeft 1 (Left 3) == 3 fromLeft 1 (Right foo") == 1"
fromLeft :: a -> Either a b -> a fromLeft _ (Left a) = a fromLeft a _ = a
-- | Return the contents of a 'Right'-value or a default value otherwise. -- > fromRight 1 (Right 3) == 3 fromRight 1 (Left foo") == 1"
fromRight :: b -> Either a b -> b fromRight _ (Right b) = b fromRight b _ = b
-- | The 'fromLeft'' function extracts the element out of a 'Left' and throws an error if its argument is 'Right'. Much like 'fromJust', using this function in polished code is usually a bad idea. -- > \x -> fromLeft' (Left x) == x \x -> fromLeft' (Right x) == undefined
fromLeft' :: Partial => Either l r -> l fromLeft' (Left x) = x fromLeft' _ = error "fromLeft', given a Right"
-- | The 'fromRight'' function extracts the element out of a 'Right' and throws an error if its argument is 'Left'. Much like 'fromJust', using this function in polished code is usually a bad idea. -- > \x -> fromRight' (Right x) == x \x -> fromRight' (Left x) == undefined
fromRight' :: Partial => Either l r -> r fromRight' (Right x) = x fromRight' _ = error "fromRight', given a Left"
-- | Pull the value out of an 'Either' where both alternatives have the same type. -- > \x -> fromEither (Left x ) == x \x -> fromEither (Right x) == x
fromEither :: Either a a -> a fromEither = either id id
-- | Given a 'Maybe', convert it to an 'Either', providing a suitable value for the 'Left' should the value be 'Nothing'. -- > \a b -> maybeToEither a (Just b) == Right b \a -> maybeToEither a Nothing == Left a
maybeToEither :: a -> Maybe b -> Either a b maybeToEither a (Just b) = Right b maybeToEither a Nothing = Left a
-- | Given an 'Either', convert it to a 'Maybe', where 'Left' becomes 'Nothing'. -- > \x -> eitherToMaybe (Left x) == Nothing \x -> eitherToMaybe (Right x) == Just x
eitherToMaybe :: Either a b -> Maybe b eitherToMaybe = either (const Nothing) Just
-- | The 'mapLeft' function takes a function and applies it to an Either value iff the value takes the form @'Left' _@. -- > mapLeft show (Left 1) == Left 1" mapLeft show (Right True) == Right True"
mapLeft :: (a -> c) -> Either a b -> Either c b mapLeft f = either (Left . f) Right
-- | The 'mapRight' function takes a function and applies it to an Either value iff the value takes the form @'Right' _@. -- > mapRight show (Left 1) == Left 1 mapRight show (Right True) == Right True""
mapRight :: (b -> c) -> Either a b -> Either a c mapRight = fmap
-- | Composition of 'not' and 'null'
notNull :: Foldable f => f a -> Bool notNull = not . null
-- | A generalization of 'Data.List.Extra.sum'' to 'Foldable' instances.
sum' :: (Foldable f, Num a) => f a -> a sum' = foldl' (+) 0
-- | A generalization of 'Data.List.Extra.product'' to 'Foldable' instances.
product' :: (Foldable f, Num a) => f a -> a product' = foldl' (*) 1
-- | A generalization of 'Data.List.Extra.sumOn'' to 'Foldable' instances.
sumOn' :: (Foldable f, Num b) => (a -> b) -> f a -> b sumOn' f = foldl' (\acc x -> acc + f x) 0
-- | A generalization of 'Data.List.Extra.productOn'' to 'Foldable' instances.
productOn' :: (Foldable f, Num b) => (a -> b) -> f a -> b productOn' f = foldl' (\acc x -> acc * f x) 1
-- | A generalization of 'Control.Monad.Extra.anyM' to 'Foldable' instances. Retains the short-circuiting behaviour.
anyM :: (Foldable f, Monad m) => (a -> m Bool) -> f a -> m Bool anyM p = foldr ((MX.||^) . p) (pure False)
-- | A generalization of 'Control.Monad.Extra.allM' to 'Foldable' instances. Retains the short-circuiting behaviour.
allM :: (Foldable f, Monad m) => (a -> m Bool) -> f a -> m Bool allM p = foldr ((MX.&&^) . p) (pure True)
-- | A generalization of 'Control.Monad.Extra.orM' to 'Foldable' instances. Retains the short-circuiting behaviour.
orM :: (Foldable f, Monad m) => f (m Bool) -> m Bool orM = anyM id
-- | A generalization of 'Control.Monad.Extra.andM' to 'Foldable' instances. Retains the short-circuiting behaviour.
andM :: (Foldable f, Monad m) => f (m Bool) -> m Bool andM = allM id
-- | A generalization of 'Control.Monad.Extra.findM' to 'Foldable' instances.
findM :: (Foldable f, Monad m) => (a -> m Bool) -> f a -> m (Maybe a) findM p = foldr (\x -> MX.ifM (p x) (pure $ Just x)) (pure Nothing)
-- | A generalization of 'Control.Monad.Extra.firstJustM' to 'Foldable' instances.
firstJustM :: (Foldable f, Monad m) => (a -> m (Maybe b)) -> f a -> m (Maybe b) firstJustM p = MX.firstJustM p . toList
-- | Evaluates the value before calling 'writeIORef'.
writeIORef' :: IORef a -> a -> IO () writeIORef' ref x = do evaluate x writeIORef ref x
-- | Evaluates the value before calling 'atomicWriteIORef'.
atomicWriteIORef' :: IORef a -> a -> IO () atomicWriteIORef' ref x = do evaluate x atomicWriteIORef ref x
-- | Variant of 'atomicModifyIORef' which ignores the return value
atomicModifyIORef_ :: IORef a -> (a -> a) -> IO () atomicModifyIORef_ r f = atomicModifyIORef r $ \v -> (f v, ())
-- | Variant of 'atomicModifyIORef'' which ignores the return value
atomicModifyIORef'_ :: IORef a -> (a -> a) -> IO () atomicModifyIORef'_ r f = atomicModifyIORef' r $ \v -> (f v, ())
-- | Like 'Control.Monad.when', but operating on a 'Monoid'. If the first argument is 'True' returns the second, otherwise returns 'mempty'. -- > mwhen True "test" == "test" mwhen False "test" == ""
mwhen :: Monoid a => Bool -> a -> a mwhen b x = if b then x else mempty
-- | Update the first component of a pair. -- > first succ (1,"test") == (2,"test")
first :: (a -> a') -> (a, b) -> (a', b) first = Arrow.first
-- | Update the second component of a pair. -- > second reverse (1,"test") == (1,"tset")
second :: (b -> b') -> (a, b) -> (a, b') second = Arrow.second
-- | Update the first component of a pair. -- > firstM (\x -> [x-1, x+1]) (1,"test") == [(0,"test"),(2,"test")]
firstM :: Functor m => (a -> m a') -> (a, b) -> m (a', b) firstM f ~(a,b) = (,b) <$> f a
-- | Update the second component of a pair. -- > secondM (\x -> [reverse x, x]) (1,"test") == [(1,"tset"),(1,"test")]
secondM :: Functor m => (b -> m b') -> (a, b) -> m (a, b') secondM f ~(a,b) = (a,) <$> f b
-- | Given two functions, apply one to the first component and one to the second. A specialised version of 'Control.Arrow.***'. -- > (succ *** reverse) (1,"test") == (2,"tset")
(***) :: (a -> a') -> (b -> b') -> (a, b) -> (a', b') (***) = (Arrow.***)
-- | Given two functions, apply both to a single argument to form a pair. A specialised version of 'Control.Arrow.&&&'. -- > (succ &&& pred) 1 == (2,0)
(&&&) :: (a -> b) -> (a -> c) -> a -> (b, c) (&&&) = (Arrow.&&&)
-- | Duplicate a single value into a pair. -- > dupe 12 == (12, 12)
dupe :: a -> (a,a) dupe x = (x,x)
-- | Apply a single function to both components of a pair. -- > both succ (1,2) == (2,3)
both :: (a -> b) -> (a, a) -> (b, b) both f ~(x,y) = (f x, f y)
-- | Extract the 'fst' of a triple. -- > fst3 (1,2,3) == 1
fst3 :: (a,b,c) -> a fst3 (a,b,c) = a
-- | Extract the 'snd' of a triple. -- > snd3 (1,2,3) == 2
snd3 :: (a,b,c) -> b snd3 (a,b,c) = b
-- | Extract the final element of a triple. -- > thd3 (1,2,3) == 3
thd3 :: (a,b,c) -> c thd3 (a,b,c) = c
-- | Converts an uncurried function to a curried function. -- > curry3 fst3 1 2 3 == 1
curry3 :: ((a, b, c) -> d) -> a -> b -> c -> d curry3 f a b c = f (a,b,c)
-- | Converts a curried function to a function on a triple. -- > uncurry3 add3 (1,2,3) == 6
uncurry3 :: (a -> b -> c -> d) -> ((a, b, c) -> d) uncurry3 f ~(a,b,c) = f a b c
-- | Update the first component of a triple. -- > first3 succ (1,1,1) == (2,1,1)
first3 :: (a -> a') -> (a, b, c) -> (a', b, c) first3 f ~(a,b,c) = (f a,b,c)
-- | Update the second component of a triple. -- > second3 succ (1,1,1) == (1,2,1)
second3 :: (b -> b') -> (a, b, c) -> (a, b', c) second3 f ~(a,b,c) = (a,f b,c)
-- | Update the third component of a triple. -- > third3 succ (1,1,1) == (1,1,2)
third3 :: (c -> c') -> (a, b, c) -> (a, b, c') third3 f ~(a,b,c) = (a,b,f c)
README.md exists but content is empty.
Downloads last month
7