1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Conduit遊び sorter

Posted at

とりあえずお手軽に、前回定義した (|||)を利用。
キーと値のペアを入力に取って、キーに応じて分配してくれる。

Helper.hs
{-| sorter
>>> C.sourceList [(1, 1),(1,2),(2,3),(4,4),(3,5),(2,6)] 
      C.=$= ( 
        1 =$-> C.map ((+) 1) 
        $ 2 =$-> C.map negate 
        $ 3 =$-> C.map ((-) 1) 
        $ C.map (\(k,v) -> (k, v * 2)) 
      ) C.$$ C.consume
[(1,2),(1,3),(2,-3),(4,8),(3,-4),(2,-6)] 
-}
(=$->) :: forall k i o m r. (Eq k, Monad m) => 
          k 
          -> C.Pipe i o m () 
          -> C.Pipe (k, i) (k, o) m () 
          -> C.Pipe (k, i) (k, o) m ()
(=$->) k pa pb =
   (C.map (\input@(x, v) -> if x == k then Right v else Left input)) 
     C.=$= (pb ||| (pa C.=$= C.map (\v -> (k, v))) )
1
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?