A functional library for Swift programmers.
It contains a collection of useful functional libraries.
Data.Char, Data.List, Data.Maybe, Data.Either, Data.Tuple, Data.Function
Data.Num
Prelude
macOS 10.13 Xcode 9+
let xs = "haskell"
map(toUpper, xs)
"HASKELL"
let xs = [1, 2, 3, 4, 5]
let greaterThanThree = { x in x > 3 }
filter(greaterThanThree, list)
[4, 5]
let xs = [1, 2, 3]
let adds = { (x: Int,y: Int) in x+y }
foldl1(adds, xs)
6
let process : ([Int]) -> Int = last .. reverse
let xs = [1,2,3,4,5]
process(xs)
1
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
let x : Int? = nil
maybeToList(x)
[]
let xs: [Int?] = [1, nil, 3]
catMaybes(xs)
[1,3]
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.