多重コンテナ
多重のmap
code:haskell
fmap . fmap :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
リストのリストを結合
code:haskell
concat :: a -> a
mconcat :: Monoid a => a -> a
join :: Monad m => m (m a) -> m a
fold :: (Foldable f, Monoid a) => f a -> a
fold = foldMap id
MaybeのリストからJustな値を取り出す(Nothingが一つでも入っていれば諦める)
code:haskell
sequence :: (Applicative f, Traversable t) => t (f a) -> f (t a)
sequence :: Maybe a -> Maybe a
MaybeのリストからJustな値を取り出す(Nothingを無視する)
code:haskell
catMaybes :: Maybe a -> a
catMaybes :: Filterable f => f (Maybe a) -> f a -- witherable: Data.Witherable
foldMap toList :: Foldable f => f a -> a
Eitherのリストの分離
code:haskell
partitionEithers :: Either a b -> (a, b)
リストの転置
code:haskell
transpose :: a -> a -- Data.List
getZipList . traverse ZipList :: Traversable t => t b -> t b
リストを固定長のリストに分割
code:haskell
chunksOf :: Int -> e -> e -- split: Data.List.Split
chunksOf 3 0..9
0,1,2],3,4,5,6,7,8,[9
Mapの転置
code:haskell
unionsWith (<>) . mapWithKey (fmap . singleton) :: Map i (Map j a) -> Map j (Map i a)
foldMapWithKey (fmap . singleton) :: MonoidalMap i (MonoidalMap j a) -> MonoidalMap j (MonoidalMap i a) -- monoidal-containers
行ベクトルと行列の積
code:haskell
(!*) :: (Foldable t, Num a, Applicative f, Applicative t) => row a -> row (col a) -> col a
v !* m = foldl' (liftA2 (+)) (pure 0) $ liftA2 (fmap . (*)) v m
行列と列ベクトルの積
code:haskell
(*!) :: (Functor row, Applicative col, Foldable col, Num a) => row (col a) -> col a -> row a
m *! v = fmap (sum . liftA2 (*) v) m
冪集合(リスト)
code:haskell
subsequences :: a -> a
filterM (const False,True) :: a -> a
filterM 0,1,2
],2,1,1,2,0,0,2,0,1,[0,1,2
Distributive
code:haskell
distribute :: (Functor f, Distributive g) => f (g a) -> g (f a)
対角成分の抽出
ビンパッキング
リカーシブスローダウン
素集合データ構造
https://hackage.haskell.org/package/disjoint-set-0.2/docs/Data-IntDisjointSet.html
#変換 #データ構造