Skip to content

Instantly share code, notes, and snippets.

@miguelemosreverte
Last active July 26, 2022 12:27
Show Gist options
  • Save miguelemosreverte/565c3959f31e75494bcb9e0d5e2af272 to your computer and use it in GitHub Desktop.
Save miguelemosreverte/565c3959f31e75494bcb9e0d5e2af272 to your computer and use it in GitHub Desktop.
Left to Right composition --
import Control.Arrow
(|>) = flip ($)
zipWithIndex = zip [0..]
fn' n = map (\(a,b) -> a) (zipWithIndex (replicate n 0))
fn n =
n
|> (flip replicate) 0 -- PRO TIP: same as (`replicate` 0)
|> zipWithIndex
|> map (\(a,b) -> a)
fn'' n =
(flip replicate 0) -- PRO TIP: same as (`replicate` 0)
>>> zipWithIndex
>>> map (\(a,b) -> a)
$ n
import Control.Arrow
(|>) :: a -> (a -> b) -> b
(|>) = flip ($)
(|>>) :: (a -> b) -> (b -> c) -> a -> c
(|>>) = flip (.)
-- left to right composition mediante flip, es valido, me bancan?
zipWithIndex = zip [0..]
filterOddIndex :: [Int] -> [Int]
filterOddIndex lst =
lst
|> zipWithIndex
|> filter (\(index, x) -> (index + 1) `mod` 2 == 0)
|> map (\(index, x) -> x)
filterOddIndex' :: [Int] -> [Int]
filterOddIndex' =
zipWithIndex
|>> filter (\(index, x) -> (index + 1) `mod` 2 == 0)
|>> map (\(index, x) -> x)
filterOddIndex'' :: [Int] -> [Int]
filterOddIndex'' =
zipWithIndex
>>> filter (\(index, x) -> (index + 1) `mod` 2 == 0)
>>> map (\(index, x) -> x)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment