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.159 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.158 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.157 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.156 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.155 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.154 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.153 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.152 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.151 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.150 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.149 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.148 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.147 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.146 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.145 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.144 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.143 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.142 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.141 tracks/elm/exercises/transpose/Transpose.example.elm
trackler-2.2.1.140 tracks/elm/exercises/transpose/Transpose.example.elm