Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/webcpu/haskellswift
A functional library for Swift programmers
https://github.com/webcpu/haskellswift
functional-programming haskell swift
Last synced: about 2 months ago
JSON representation
A functional library for Swift programmers
- Host: GitHub
- URL: https://github.com/webcpu/haskellswift
- Owner: webcpu
- License: mit
- Created: 2017-07-15T20:34:57.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-11-13T15:57:56.000Z (about 5 years ago)
- Last Synced: 2024-10-30T17:20:29.406Z (2 months ago)
- Topics: functional-programming, haskell, swift
- Language: Swift
- Homepage:
- Size: 9.58 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HaskellSwift
A functional library for Swift programmers.It contains a collection of useful functional libraries.
### Data
Data.Char, Data.List, Data.Maybe, Data.Either, Data.Tuple, Data.Function### GHC
Data.Num### Language
Prelude# Prerequisites
macOS 10.13
Xcode 9+# Examples
## Data.List
### map
```
let xs = "haskell"
map(toUpper, xs)
```
`"HASKELL"`### filter
```
let xs = [1, 2, 3, 4, 5]
let greaterThanThree = { x in x > 3 }
filter(greaterThanThree, list)
```
`[4, 5]`### foldl
```
let xs = [1, 2, 3]
let adds = { (x: Int,y: Int) in x+y }
foldl1(adds, xs)
```
`6`## Data.Function
### .. (Function Composition)
#### 1
```
let process : ([Int]) -> Int = last .. reverse
let xs = [1,2,3,4,5]
process(xs)
```
`1`
#### 2
```
func _isPrime(n : Int) -> Bool {
let array2ToN : Int->[Int] = { x in Array(2...x) }
let divisors : Int->[Int] = array2ToN .. Int.init .. ceil .. sqrt .. Double.init
let isDivisible = or .. map({ x in n % x == 0})
let isNotPrime = isDivisible .. divisors
return !isNotPrime(n)
}
_isPrime(3)
```
`true`## Data.Maybe
### maybeToList
```
let x : Int? = nil
maybeToList(x)
```
`[]`### catMaybes
```
let xs: [Int?] = [1, nil, 3]
catMaybes(xs)
```
`[1,3]`### How does it help?
There are 3 solutions to the same problem. A, B, C
A doesn't use HaskellSwift, B and C use HaskellSwift.
A is imperative, B and C are declarative.If you want to know more about it, please check the test cases in the Xcode Project or use Hoogle.
https://www.haskell.org/hoogle/?hoogle=map
In addition, there is a public project which is written in HaskellSwift.
https://github.com/unchartedworks/autobuild