リストを複数のリストに分割したいと思っています。 私はこれがtuple
に格納される必要があると仮定していますが、完全にはわかりません。Elm:リストを複数のリストに分割する
は私はグループの特定の量にそれらを分割したい8人
users =
["Steve", "Sally", "Barry", "Emma", "John", "Gustav", "Ankaran", "Gilly"]
のこのグループを持っていると言います。 たとえば、2人、3人または4人のグループ。
-- desired result
(["Steve", "Sally", "Barry"]
, ["Emma", "John", "Gustav"]
, ["Ankaran", "Gilly"]
)
この質問のパート2は、どのようにしてさまざまな長さのタプルから結果を反復してレンダリングしますか?
この例では、tuple-map を使って遊んでいましたが、2つの値を持つタプルしか期待していないようです。
import Html exposing (..)
import List
data = (
["Steve", "Sally", "Barry"]
, ["Emma", "John", "Gustav"]
, ["Ankaran", "Gilly"]
)
renderLI value =
li [] [ text value ]
renderUL list =
ul [] (List.map renderLI list)
main =
div [] (map renderUL data)
-- The following taken from zarvunk/tuple-map for examples sake
{-| Map over the tuple with two functions, one for each
element.
-}
mapEach : (a -> a') -> (b -> b') -> (a, b) -> (a', b')
mapEach f g (a, b) = (f a, g b)
{-| Apply the given function to both elements of the tuple.
-}
mapBoth : (a -> a') -> (a, a) -> (a', a')
mapBoth f = mapEach f f
{-| Synonym for `mapBoth`.
-}
map : (a -> a') -> (a, a) -> (a', a')
map = mapBoth
アメージング。ありがとうございました。 ええ、私はリストのリストが可能かどうか確信が持てませんでしたが、それは完全に意味があります。再度、感謝します –