mirror of
https://github.com/ilyakooo0/syntax.git
synced 2024-10-05 21:08:55 +03:00
Implement takeArr.
This commit is contained in:
parent
f20997102c
commit
5b979f5ddd
@ -26,6 +26,9 @@ module Data.Syntax.Combinator
|
||||
sepBy,
|
||||
sepBy1,
|
||||
|
||||
-- * Arrowized combinators.
|
||||
takeArr,
|
||||
|
||||
-- * Vectors.
|
||||
vecNSepBy,
|
||||
ivecNSepBy,
|
||||
@ -48,10 +51,11 @@ import Control.Category.Structures
|
||||
import Control.Lens
|
||||
import Control.Lens.SemiIso
|
||||
import Control.SIArrow
|
||||
import qualified Data.MonoTraversable as Seq
|
||||
import Data.Syntax
|
||||
import qualified Data.Vector as V
|
||||
import qualified Data.Vector.Unboxed as VU
|
||||
import Prelude hiding (id, (.))
|
||||
import Prelude hiding (id, (.), take)
|
||||
|
||||
-- | One or zero occurences of @f@.
|
||||
optional :: SIArrow cat => cat () a -> cat () (Maybe a)
|
||||
@ -89,6 +93,11 @@ sepBy v s = sepBy1 v s /+/ sipure _Empty
|
||||
sepBy1 :: SIArrow cat => cat () a -> cat () () -> cat () [a]
|
||||
sepBy1 v s = _Cons /$/ v /*/ (s */ sepBy1 v s /+/ sipure _Empty)
|
||||
|
||||
-- | A string of given length.
|
||||
takeArr :: Syntax syn => syn Int (Seq syn)
|
||||
takeArr = sibind $ iso (\n -> constant n #>> take n)
|
||||
(\s -> constant (Seq.olength s) #>> take (Seq.olength s))
|
||||
|
||||
-- | Constant size vector with separators.
|
||||
--
|
||||
-- @vecNSepBy n e sep@ describes a size @n@ vector with elements @e@ separated by @sep@.
|
||||
|
Loading…
Reference in New Issue
Block a user