mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-03-20 15:14:54 +09:00
Minimal pagination for git and darcs change log
This commit is contained in:
parent
17c4ff3d23
commit
b2f5b20184
12 changed files with 223 additions and 77 deletions
src/Control/Applicative
52
src/Control/Applicative/Local.hs
Normal file
52
src/Control/Applicative/Local.hs
Normal file
|
@ -0,0 +1,52 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
- The author(s) have dedicated all copyright and related and neighboring
|
||||
- rights to this software to the public domain worldwide. This software is
|
||||
- distributed without any warranty.
|
||||
-
|
||||
- You should have received a copy of the CC0 Public Domain Dedication along
|
||||
- with this software. If not, see
|
||||
- <http://creativecommons.org/publicdomain/zero/1.0/>.
|
||||
-}
|
||||
|
||||
module Control.Applicative.Local
|
||||
( atMost
|
||||
, atMost_
|
||||
, upTo
|
||||
, upTo_
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Control.Applicative
|
||||
|
||||
-- | Apply action between zero and @n@ times, inclusive, and list the results.
|
||||
atMost :: Alternative f => Int -> f a -> f [a]
|
||||
atMost n action = go n
|
||||
where
|
||||
go n =
|
||||
if n <= 0
|
||||
then pure []
|
||||
else liftA2 (:) action (go $ n - 1) <|> pure []
|
||||
|
||||
-- | Apply action between zero and @n@ times, inclusive, and discard results.
|
||||
atMost_ :: Alternative f => Int -> f a -> f ()
|
||||
atMost_ n action = go n
|
||||
where
|
||||
go n =
|
||||
if n <= 0
|
||||
then pure ()
|
||||
else action *> (go $ n - 1) <|> pure ()
|
||||
|
||||
-- | Apply action between one and @n@ times, inclusive, and list the results.
|
||||
upTo :: Alternative f => Int -> f a -> f [a]
|
||||
upTo n action = liftA2 (:) action $ atMost n action
|
||||
|
||||
-- | Apply action between one and @n@ times, inclusive, and discard results.
|
||||
upTo_ :: Alternative f => Int -> f a -> f ()
|
||||
upTo_ n action = action *> atMost_ n action
|
Loading…
Add table
Add a link
Reference in a new issue