summaryrefslogtreecommitdiff
path: root/SmallRing.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-26 00:03:45 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-26 00:03:45 -0400
commit1595a9ea3ca1080ebf7d060ea28aecf19df8f968 (patch)
treee1dccea8d7dff7a5fb5166a7e8b0d74ce8f24d4a /SmallRing.hs
parent27aa69522ca3da4fe04f996eb87a13e295db0f9f (diff)
Avoid adding redundant points to ring buffer.
Diffstat (limited to 'SmallRing.hs')
-rw-r--r--SmallRing.hs6
1 files changed, 6 insertions, 0 deletions
diff --git a/SmallRing.hs b/SmallRing.hs
index d792899..f710393 100644
--- a/SmallRing.hs
+++ b/SmallRing.hs
@@ -30,6 +30,12 @@ pushFront a (Give1 f) = Give2 (\g -> f (g a))
30pushFront a (Give2 f) = Give3 (\g -> f (g a)) 30pushFront a (Give2 f) = Give3 (\g -> f (g a))
31pushFront a (Give3 f) = f $ \b c _ -> Give3 $ \g -> g a b c 31pushFront a (Give3 f) = f $ \b c _ -> Give3 $ \g -> g a b c
32 32
33front :: Giver a -> Maybe a
34front Give0 = Nothing
35front (Give1 f) = f Just
36front (Give2 g) = g (\x _ -> Just x)
37front (Give3 h) = h (\x _ _ -> Just x)
38
33take3 :: (a -> a -> a -> b) -> Giver a -> Maybe b 39take3 :: (a -> a -> a -> b) -> Giver a -> Maybe b
34take3 f (Give3 g) = Just (g f) 40take3 f (Give3 g) = Just (g f)
35take3 _ _ = Nothing 41take3 _ _ = Nothing