Add a new Transducer module built on the one for graphs

This commit is contained in:
Tissevert 2019-05-06 08:21:50 +02:00
parent a8f87be2c1
commit e562d0e605
2 changed files with 24 additions and 0 deletions

View file

@ -20,6 +20,7 @@ extra-source-files: CHANGELOG.md
library
exposed-modules: Graph
, Stream
, Transducer
, Tree
-- other-modules:
-- other-extensions:

23
src/Transducer.hs Normal file
View file

@ -0,0 +1,23 @@
module Transducer (
Transducer
, fromList
, run
) where
import Stream (Stream)
import Graph (Graph, editLabel, open, rewind, singleton, weave)
type Transducer input output = Graph input [output]
empty :: Transducer input output
empty = open $ singleton []
add :: Ord input => Transducer input output -> ([input], output) -> Transducer input output
add transducer (path, output) =
rewind $ editLabel (weave transducer path) (output:)
fromList :: Ord input => [([input], output)] -> Transducer input output
fromList = foldl add empty
run :: Ord input => Transducer input output -> Stream input -> Stream output
run = undefined