generic vector instructions done
This commit is contained in:
parent
74d95c26aa
commit
34a0afb242
@ -313,3 +313,16 @@ instructionVectorReplace state primAccessor vectorAccessor =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, p2 : ps)) -> state & vectorAccessor .~ (replace v1 [p1] [p2] Nothing : vs) & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
instructionVectorReplaceFirst :: Eq a => State -> Lens' State [a] -> Lens' State [[a]] -> State
|
||||
instructionVectorReplaceFirst state primAccessor vectorAccessor =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, p2 : ps)) -> state & vectorAccessor .~ (replace v1 [p1] [p2] (Just 1) : vs) & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
instructionVectorRemove :: Eq a => State -> Lens' State [a] -> Lens' State [[a]] -> State
|
||||
instructionVectorRemove state primAccessor vectorAccessor =
|
||||
case (uncons (view vectorAccessor state), uncons (view primAccessor state)) of
|
||||
(Just (v1, vs), Just (p1, ps)) -> state & vectorAccessor .~ (replace v1 [p1] [] Nothing : vs) & primAccessor .~ ps
|
||||
_ -> state
|
||||
|
||||
|
@ -106,8 +106,7 @@ instructionStringSplitOnChar state@(State {_string = s1 : ss, _char = c1 : cs})
|
||||
instructionStringSplitOnChar state = state
|
||||
|
||||
instructionStringReplaceFirstChar :: State -> State
|
||||
instructionStringReplaceFirstChar state@(State {_string = s1 : ss, _char = c1 : c2 : cs}) = state {_string = replace s1 [c1] [c2] (Just 1) : ss, _char = cs}
|
||||
instructionStringReplaceFirstChar state = state
|
||||
instructionStringReplaceFirstChar state = instructionVectorReplaceFirst state char string
|
||||
|
||||
instructionStringReplaceNChar :: State -> State
|
||||
instructionStringReplaceNChar state@(State {_string = s1 : ss, _char = c1 : c2 : cs, _int = i1 : is}) = state{_string = replace s1 [c1] [c2] (Just i1) : ss, _char = cs, _int = is}
|
||||
@ -125,8 +124,7 @@ instructionStringRemoveNChar state@(State {_string = s1 : ss, _char = c1 : cs, _
|
||||
instructionStringRemoveNChar state = state
|
||||
|
||||
instructionStringRemoveAllChar :: State -> State
|
||||
instructionStringRemoveAllChar state@(State {_string = s1 : ss, _char = c1 : cs}) = state{_string = replace s1 [c1] "" Nothing : ss, _char = cs}
|
||||
instructionStringRemoveAllChar state = state
|
||||
instructionStringRemoveAllChar state = instructionVectorRemove state char string
|
||||
|
||||
instructionStringOccurrencesOfChar :: State -> State
|
||||
instructionStringOccurrencesOfChar state = instructionVectorOccurrencesOf state char string
|
||||
|
@ -53,3 +53,12 @@ instructionVectorIntOccurrencesOf state = instructionVectorOccurrencesOf state i
|
||||
|
||||
instructionVectorIntSetNth :: State -> State
|
||||
instructionVectorIntSetNth state = instructionVectorSetNth state int vectorInt
|
||||
|
||||
instructionVectorIntReplace :: State -> State
|
||||
instructionVectorIntReplace state = instructionVectorReplace state int vectorInt
|
||||
|
||||
instructionVectorIntReplaceFirst :: State -> State
|
||||
instructionVectorIntReplaceFirst state = instructionVectorReplaceFirst state int vectorInt
|
||||
|
||||
instructionVectorIntRemove :: State -> State
|
||||
instructionVectorIntRemove state = instructionVectorRemove state int vectorInt
|
||||
|
@ -283,4 +283,8 @@ main = do
|
||||
intTestFunc "instructionVectorIntOccurrencesOf0" [0] [GeneVectorInt [1,2,3,4,2,6,7], GeneInt 0, StateFunc instructionVectorIntOccurrencesOf] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntSetNth3" [[0,1,2,99,4,5]] [GeneVectorInt [0,1,2,3,4,5], GeneInt 99, GeneInt 3, StateFunc instructionVectorIntSetNth] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntSetNth9" [[0,1,2,99,4,5]] [GeneVectorInt [0,1,2,3,4,5], GeneInt 99, GeneInt 9, StateFunc instructionVectorIntSetNth] emptyState
|
||||
-- vectorIntTestFunc "instructionVectorInt"
|
||||
vectorIntTestFunc "instructionVectorIntReplace3" [[0,1,2,99,4,5,99,5,99]] [GeneInt 99, GeneInt 3, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplace] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntReplace-1" [[0,1,2,3,4,5,3,5,3]] [GeneInt 99, GeneInt (-1), GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplace] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntReplaceFirst3" [[0,1,2,99,4,5,3,5,3]] [GeneInt 99, GeneInt 3, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplaceFirst] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntReplaceFirst-2" [[0,1,2,3,4,5,3,5,3]] [GeneInt 99, GeneInt (-2), GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntReplaceFirst] emptyState
|
||||
vectorIntTestFunc "instructionVectorIntRemove" [[0,1,2,4,5,5]] [GeneInt 3, GeneVectorInt [0,1,2,3,4,5,3,5,3], StateFunc instructionVectorIntRemove] emptyState
|
||||
|
Loading…
x
Reference in New Issue
Block a user