Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kdungs/cpp-prelude
Implement functionality from Haskell's Prelude in C++11. Just for fun. Errors guaranteed.
https://github.com/kdungs/cpp-prelude
exercise
Last synced: 8 days ago
JSON representation
Implement functionality from Haskell's Prelude in C++11. Just for fun. Errors guaranteed.
- Host: GitHub
- URL: https://github.com/kdungs/cpp-prelude
- Owner: kdungs
- License: mit
- Created: 2015-02-18T14:56:45.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-19T10:13:41.000Z (almost 10 years ago)
- Last Synced: 2023-03-24T18:56:12.486Z (over 1 year ago)
- Topics: exercise
- Language: C++
- Homepage:
- Size: 164 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# cpp-prelude
[![Build Status](https://travis-ci.org/kdungs/cpp-prelude.svg?branch=master)](https://travis-ci.org/kdungs/cpp-prelude) ← _This doesn't mean that everything is all right!_Implement functionality from Haskell's Prelude in C++11. Just for fun. Errors guaranteed.
After playing around with [functional immutable lists in C++11](https://github.com/kdungs/cpp-list), I though it would be nice to have the functionality from Haskell's Prelude (or at least the interesting functions) in C++. This is an attempt to implement some of the functionality on STL containers. Whenever possible, functionality from the STL is used.
## Functionality
### List operations
* [x] `map :: (a -> b) -> [a] -> [b]`
* [x] `(++) :: [a] -> [a] -> [a]` as `join`
* [x] `filter :: (a -> Bool) -> [a] -> [a]`
* [x] `head :: [a] -> a`
* [x] `last :: [a] -> a`
* [x] `tail :: [a] -> [a]`
* [x] `init :: [a] -> [a]`
* [x] `null :: [a] -> Bool`
* [x] `length :: [a] -> Int`
* [x] `(!!) :: [a] -> Int -> a` as `at`
* [x] `reverse :: [a] -> [a]`### Reducing lists (folds)
* [x] `foldl :: (b -> a -> b) -> b -> [a] -> b`
* [x] `foldl1 :: (a -> a -> a) -> [a] -> a`
* [x] `foldr :: (a -> b -> b) -> b -> [a] -> b`
* [x] `foldr1 :: (a -> a -> a) -> [a] -> a`### Special folds
* [x] `and :: [Bool] -> Bool`
* [x] `or :: [Bool] -> Bool`
* [x] `any :: (a -> Bool) -> [a] -> Bool`
* [x] `all :: (a -> Bool) -> [a] -> Bool`
* [x] `sum :: Num a => [a] -> a`
* [x] `product :: Num a => [a] -> a`
* [x] `concat :: [[a]] -> [a]`
* [x] `concatMap :: (a -> [b]) -> [a] -> [b]`
* [x] `maximum :: Ord a => [a] -> a`
* [x] `minimum :: Ord a => [a] -> a`### Building lists
* [ ] `scanl :: (b -> a -> b) -> b -> [a] -> [b]`
* [ ] `scanl1 :: (a -> a -> a) -> [a] -> [a]`
* [ ] `scanr :: (a -> b -> b) -> b -> [a] -> [b]`
* [ ] `scanr1 :: (a -> a -> a) -> [a] -> [a]`### Infinite lists
Without lazy evaluation, there is not really any way to produce infinite
lists. Maybe I'll implement these functions with an additional size
parameter.### Sublists
* [x] `take :: Int -> [a] -> [a]`
* [x] `drop :: Int -> [a] -> [a]`
* [x] `splitAt :: Int -> [a] -> ([a], [a])`
* [x] `takeWhile :: (a -> Bool) -> [a] -> [a]`
* [x] `dropWhile :: (a -> Bool) -> [a] -> [a]`
* [x] `span :: (a -> Bool) -> [a] -> ([a], [a])`
* [x] `break :: (a -> Bool) -> [a] -> ([a], [a])`### Searching lists
* [ ] `elem :: Eq a => a -> [a] -> Bool`
* [ ] `notElem :: Eq a => a -> [a] -> Bool`
* [ ] `lookup :: Eq a => a -> [(a, b)] -> Maybe b`### Zipping and unzipping lists
* [x] `zip :: [a] -> [b] -> [(a, b)]`
* [x] `zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]`
* [x] `zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]`
* [x] `zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]`
* [x] `unzip :: [(a, b)] -> ([a], [b])`
* [x] `unzip3 :: [(a, b, c)] -> ([a], [b], [c])`