Skip to content

Instantly share code, notes, and snippets.

@dminuoso
Created February 22, 2019 11:34
Show Gist options
  • Save dminuoso/d761720b160861ad81b9566d2e51421a to your computer and use it in GitHub Desktop.
Save dminuoso/d761720b160861ad81b9566d2e51421a to your computer and use it in GitHub Desktop.
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