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.139 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.138 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.137 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.136 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.135 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.134 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.133 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.132 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.131 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.130 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.129 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.128 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.127 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.126 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.125 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.124 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.123 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.122 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.121 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.120 tracks/elm/exercises/transpose/Transpose.example.elm