Last active
August 29, 2015 14:01
-
-
Save blouerat/526b6ee8f03573702811 to your computer and use it in GitHub Desktop.
1HaskellADay: appendSwapped
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
import Control.Applicative | |
import Data.Tuple (swap) | |
{- Given a list of tuples, return a list containing the initial elements and the swapped elements | |
It's an easy one to start the week. | |
Example | |
> appendSwapped [(1,2),(2,3)] | |
[(1,2),(2,3),(2,1),(3,2)] | |
-} | |
appendSwapped :: [(a, a)] -> [(a, a)] | |
appendSwapped = ([id, swap] <*>) | |
-- Find a similar process for an entry type: [(a,b)] | |
appendSwapped' :: [(a,b)] -> [Either (a,b) (b,a)] | |
appendSwapped' = ([Left, Right . swap] <*>) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment