Sha256: 0337bf6f19f0741da1e87b29ed79388fa224a721ee1b050b0f2c6d0dcc9b5d5a

Contents?: true

Size: 1.08 KB

Versions: 66

Compression:

Stored size: 1.08 KB

Contents

module ListOps
    exposing
        ( append
        , concat
        , filter
        , foldl
        , foldr
        , length
        , map
        , reverse
        )


length : List a -> Int
length list =
    foldl (\_ acc -> 1 + acc) 0 list


reverse : List a -> List a
reverse list =
    foldl (::) [] list


foldl : (a -> b -> b) -> b -> List a -> b
foldl f acc list =
    case list of
        [] ->
            acc

        head :: tail ->
            foldl f (f head acc) tail


foldr : (a -> b -> b) -> b -> List a -> b
foldr f acc list =
    case list of
        [] ->
            acc

        head :: tail ->
            f head (foldr f acc tail)


map : (a -> b) -> List a -> List b
map f list =
    foldr (\x acc -> f x :: acc) [] list


filter : (a -> Bool) -> List a -> List a
filter f list =
    foldr
        (\x acc ->
            if f x then
                x :: acc
            else
                acc
        )
        []
        list


append : List a -> List a -> List a
append xs ys =
    foldr (::) ys xs


concat : List (List a) -> List a
concat list =
    foldr append [] list

Version data entries

66 entries across 66 versions & 1 rubygems

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