Sha256: 898372c64d4a56dbb32860276e59dbe7ac7f2c45c9406200444a1c870a2bc321

Contents?: true

Size: 621 Bytes

Versions: 185

Compression:

Stored size: 621 Bytes

Contents

module ListOps

let rec foldl folder state list =
    match list with
    | [] -> state
    | x::xs -> foldl folder (folder state x) xs

let rec foldr folder state list =
    list
    |> List.rev
    |> foldl (fun acc item -> folder item acc) state

let length list = foldl (fun acc _ -> acc + 1) 0 list

let reverse list = foldl (fun acc item -> item :: acc) [] list

let map f list = foldr (fun item acc -> f item :: acc) [] list

let filter f list = foldr (fun item acc -> if f item then item :: acc else acc) [] list

let append xs ys = foldr (fun item acc -> item :: acc) ys xs

let concat xs = foldr append [] xs

Version data entries

185 entries across 185 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/list-ops/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/list-ops/Example.fs