-
-
Save v0d1ch/33e9410de560b01158becfaf62ed74e4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
traverseX :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a) | |
traverseX f (Vec3 x y z) = (\h -> Vec3 h) <$> f x | |
traverseY :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a) | |
traverseY f (Vec3 x y z) = (\h -> Vec3 h) <$> f x | |
traverseZ :: forall f. Functor f = (a -> f a) -> Vec3 a -> f (Vec3 a) | |
traverseZ f (Vec3 x y z) = (\h -> Vec3 h) <$> f x | |
type Lens s a = forall f. Funtor f => (a -> f a) -> s -> f s | |
_X :: Lens a (Vec3 a) | |
_X = traverseX | |
_Y :: Lens a (Vec3 a) | |
_Y = traverseY | |
_Z :: Lens a (Vec3 a) | |
_Z = traverseZ | |
-- > over _X (+1) (Vec3 1 0 7) | |
-- this is just for visual prettification, its just "flipped application" | |
(&) = flip ($) | |
(%~) = over | |
-- We can use it like this | |
-- > (Vec3 1 0 7) & _X %~ (+1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment