Last active
July 26, 2022 12:27
-
-
Save miguelemosreverte/565c3959f31e75494bcb9e0d5e2af272 to your computer and use it in GitHub Desktop.
Left to Right composition --
This file contains 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
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 |
This file contains 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
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