@@ -26,6 +26,9 @@ module Data.Syntax.Combinator
2626 sepBy,
2727 sepBy1,
2828
29+ -- * Arrowized combinators.
30+ takeArr,
31+
2932 -- * Vectors.
3033 vecNSepBy,
3134 ivecNSepBy,
@@ -48,10 +51,11 @@ import Control.Category.Structures
4851import Control.Lens
4952import Control.Lens.SemiIso
5053import Control.SIArrow
54+import qualified Data.MonoTraversable as Seq
5155import Data.Syntax
5256import qualified Data.Vector as V
5357import qualified Data.Vector.Unboxed as VU
54−import Prelude hiding (id, (.))
58+import Prelude hiding (id, (.), take)
5559
5660-- | One or zero occurences of @f@.
5761optional :: SIArrow cat => cat () a -> cat () (Maybe a)
@@ -89,6 +93,11 @@ sepBy v s = sepBy1 v s /+/ sipure _Empty
8993sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
9094sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
9195
96+-- | A string of given length.
97+takeArr :: Syntax syn => syn Int (Seq syn)
98+takeArr = sibind $ iso (\n -> constant n #>> take n)
99+ (\s -> constant (Seq.olength s) #>> take (Seq.olength s))
100+
92101-- | Constant size vector with separators.
93102--
94103-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.