MyNixOS website logo
Description

Swizzle lens functions.

swizzle-lens

{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}

module Lib where

import Control.Lens
import Data.SwizzleLens qualified as SwzL
import Data.SwizzleLens.TH

foo :: (Int, Int, Int)
foo = (0, 1, 2, 3, 4, 5, 6, 7, 8) ^. SwzL.ywv	-- (1, 3, 4)

bar :: (Int, Int, Char, Int, String, Int, Int, Int, Int)
bar = (0, 1, 2, 3, 4, 5, 6, 7, 8) & SwzL.zv .~ ('c', "hello")
	-- (0, 1, 'c', 3, "hello", 5, 6, 7, 8)

swizzleLens "" "ywtr"

baz :: (Int, Int, Int, Int)
baz = (0, 1, 2, 3, 4, 5, 6, 7, 8) ^. ywtr	-- (1, 3, 6, 8)

qux :: (Int, Bool, Int, String, Int, Int, Char, Int, ())
qux = (0, 1, 2, 3, 4, 5, 6, 7, 8) & ywtr .~ (False, "hello", 'c', ())
	-- (0, False, 2, "hello", 4, 5, 'c', 7, ())
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Try.Color where

import GHC.Generics
import Control.Lens

import Data.SwizzleLens as SwzL
import Data.Swizzle.Class qualified as Swz
import Data.SwizzleSet.Class qualified as SwzS

newtype Alpha = Alpha Double deriving Show
newtype Red = Red Double deriving Show
newtype Green = Green Double deriving Show
newtype Blue = Blue Double deriving Show

data Argb = Argb Alpha Red Green Blue deriving (Show, Generic)

instance Swz.Swizzle1 Argb where type X Argb = Alpha
instance Swz.Swizzle2 Argb where type Y Argb = Red
instance Swz.Swizzle3 Argb where type Z Argb = Green
instance Swz.Swizzle4 Argb where type W Argb = Blue

instance SwzS.SwizzleSet1 Argb Alpha where type X Argb Alpha = Argb
instance SwzS.SwizzleSet2 Argb Red where type Y Argb Red = Argb
instance SwzS.SwizzleSet3 Argb Green where type Z Argb Green = Argb
instance SwzS.SwizzleSet4 Argb Blue where type W Argb Blue = Argb

sample :: Argb
sample = Argb (Alpha 0.8) (Red 0.3) (Green 0.8) (Blue 0.1)

foo :: (Red, Blue)
foo = sample ^. SwzL.yw

bar :: Argb
bar = sample & SwzL.xz .~ (Alpha 0.5, Green 0.9)
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE FlexibleContexts #-}
{-# OPTIONS_GHC -Wall -fno-warn-tabs #-}

module Try.Prefix where

import Control.Lens
import Data.SwizzleLens.TH

swizzleLens "lens" "wtsq"

foo :: (Int, Int, Int, Int)
foo = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) ^. lensWtsq	-- (3, 6, 7, 9)

bar :: (Int, Int, Int, Char, Int, Int, Bool, String, Int, ())
bar = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) & lensWtsq .~ ('c', True, "hello", ())
	-- (0, 1, 2, 'c', 4, 5, True, "hello", 8, ())
Metadata

Version

0.1.0.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows