I'd like to define the following function:
compactAndConvertToList : Array (Maybe String) -> List String
This function should remove all Nothing
appearances in the given array, and convert it to List
.
I came up with the solution below, but it feels dirty a bit.
Is there a better way to achieve this?
import Graphics.Element exposing (..)
import Array
model : Array.Array (Maybe String)
model = Array.fromList [ Just "Hello", Just "Stack", Nothing, Just "Overflow" ]
compactAndConvertToList : Array.Array (Maybe String) -> List String
compactAndConvertToList maybeStrings =
maybeStrings
|> Array.filter (\x -> x /= Nothing)
|> Array.map (Maybe.withDefault "")
|> Array.toList
main =
model
|> compactAndConvertToList
|> show
Maybe String
, it would be interpreted as two separate arguments forArray
.