Sha256: 18dc2f50247c6251d237f05d2530d563c4e6806b71273cbd3653c964c7466e4c

Contents?: true

Size: 1.32 KB

Versions: 66

Compression:

Stored size: 1.32 KB

Contents

module Transpose exposing (transpose)

import List
import String


transpose : List String -> List String
transpose lines =
    let
        longestRow =
            Maybe.withDefault 0 <|
                List.maximum <|
                    List.map String.length lines

        padNothingRight maxLength line =
            line ++ List.repeat (maxLength - List.length line) Nothing

        stringify line =
            String.concat <|
                List.map
                    (\x ->
                        case x of
                            Nothing ->
                                " "

                            Just c ->
                                String.fromChar c
                    )
                    (dropNothingRight line)

        dropNothingRight line =
            Tuple.second <|
                List.foldr
                    (\x ( ignore, list ) ->
                        if ignore && x == Nothing then
                            ( ignore, list )
                        else
                            ( False, x :: list )
                    )
                    ( True, [] )
                    line
    in
    List.map stringify <|
        List.foldr
            (List.map2 (::))
            (List.repeat longestRow [])
            (List.map (padNothingRight longestRow << List.map Just << String.toList) lines)

Version data entries

66 entries across 66 versions & 1 rubygems

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