mirror of
https://code.naskya.net/repos/ndqEd
synced 2025-03-20 15:14:54 +09:00
Unfinished updated outbox handler
This commit is contained in:
parent
7dda068ba3
commit
9a306e762c
16 changed files with 871 additions and 18 deletions
|
@ -1,6 +1,6 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016, 2018 by fr33domlover <fr33domlover@riseup.net>.
|
||||
- Written in 2016, 2018, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
|
@ -21,6 +21,7 @@ module Data.List.Local
|
|||
, groupMap
|
||||
, groupMapBy
|
||||
, groupMapBy1
|
||||
, lookupSorted
|
||||
)
|
||||
where
|
||||
|
||||
|
@ -97,3 +98,11 @@ groupMapBy1 eq f g = go
|
|||
[] -> []
|
||||
z:l -> toList $ go $ z :| l
|
||||
in (f x, g x :| map g ys) :| rest
|
||||
|
||||
lookupSorted :: Ord a => a -> [(a, b)] -> Maybe b
|
||||
lookupSorted _ [] = Nothing
|
||||
lookupSorted x ((y, z) : l) =
|
||||
case compare x y of
|
||||
LT -> lookupSorted x l
|
||||
EQ -> Just z
|
||||
GT -> Nothing
|
||||
|
|
60
src/Data/List/NonEmpty/Local.hs
Normal file
60
src/Data/List/NonEmpty/Local.hs
Normal file
|
@ -0,0 +1,60 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2019 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 Data.List.NonEmpty.Local
|
||||
( groupWithExtract
|
||||
, groupWithExtractBy
|
||||
, groupWithExtractBy1
|
||||
, groupAllExtract
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
import Data.Function
|
||||
import Data.List.NonEmpty (NonEmpty (..))
|
||||
|
||||
import qualified Data.List.NonEmpty as NE
|
||||
|
||||
extract :: (a -> b) -> (a -> c) -> NonEmpty a -> (b, NonEmpty c)
|
||||
extract f g (head :| tail) = (f head, g head :| map g tail)
|
||||
|
||||
groupWithExtract
|
||||
:: (Foldable f, Eq b)
|
||||
=> (a -> b)
|
||||
-> (a -> c)
|
||||
-> f a
|
||||
-> [(b, NonEmpty c)]
|
||||
groupWithExtract f g = map (extract f g) . NE.groupWith f
|
||||
|
||||
groupWithExtractBy
|
||||
:: Foldable f
|
||||
=> (b -> b -> Bool)
|
||||
-> (a -> b)
|
||||
-> (a -> c)
|
||||
-> f a
|
||||
-> [(b, NonEmpty c)]
|
||||
groupWithExtractBy eq f g = map (extract f g) . NE.groupBy (eq `on` f)
|
||||
|
||||
groupWithExtractBy1
|
||||
:: (b -> b -> Bool)
|
||||
-> (a -> b)
|
||||
-> (a -> c)
|
||||
-> NonEmpty a
|
||||
-> NonEmpty (b, NonEmpty c)
|
||||
groupWithExtractBy1 eq f g = NE.map (extract f g) . NE.groupBy1 (eq `on` f)
|
||||
|
||||
groupAllExtract :: Ord b => (a -> b) -> (a -> c) -> [a] -> [(b, NonEmpty c)]
|
||||
groupAllExtract f g = map (extract f g) . NE.groupAllWith f
|
|
@ -1,6 +1,6 @@
|
|||
{- This file is part of Vervis.
|
||||
-
|
||||
- Written in 2016 by fr33domlover <fr33domlover@riseup.net>.
|
||||
- Written in 2016, 2019 by fr33domlover <fr33domlover@riseup.net>.
|
||||
-
|
||||
- ♡ Copying is an act of love. Please copy, reuse and share.
|
||||
-
|
||||
|
@ -14,12 +14,19 @@
|
|||
-}
|
||||
|
||||
module Data.Maybe.Local
|
||||
( partitionMaybePairs
|
||||
( partitionMaybes
|
||||
, partitionMaybePairs
|
||||
)
|
||||
where
|
||||
|
||||
import Prelude
|
||||
|
||||
partitionMaybes :: [(Maybe a, b)] -> ([(a, b)], [b])
|
||||
partitionMaybes = foldr f ([], [])
|
||||
where
|
||||
f (Nothing, y) (ps, ys) = (ps , y : ys)
|
||||
f (Just x , y) (ps, ys) = ((x, y) : ps, ys)
|
||||
|
||||
partitionMaybePairs :: [(Maybe a, Maybe b)] -> ([a], [b], [(a, b)])
|
||||
partitionMaybePairs = foldr f ([], [], [])
|
||||
where
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue