lue-bird/elm-linear-direction/2.2.0

NOTE: the latest version is 11.2.0

List.LinearDirection

transform

-> (element -> result -> result)
-> result
-> List element
-> result

Reduce a List in a direction.

List.fold FirstToLast (++) ""
    [ "l", "i", "v", "e" ]
--> "live"


List.fold LastToFirst (++) ""
    [ "l", "i", "v", "e" ]
--> "evil"
order : LinearDirection -> List a -> List a

Keep the order if FirstToLast, reverse if LastToFirst.

[ 1, 2, 3 ] |> List.order LastToFirst
--> [ 3, 2, 1 ]


[ 1, 2, 3 ] |> List.order FirstToLast
--> [ 1, 2, 3 ]

part

Int
-> List a
-> { groups : List (List a)
, less : List a
}

Split the Array into equal-sized chunks. The elements left over on one side are in less.

[ 1, 2, 3, 4, 5, 6, 7 ]
    |> List.group 3 FirstToLast
--> { groups = [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
--> , less = Array.fromList [ 7 ]
--> }


[ 1, 2, 3, 4, 5, 6, 7 ]
    |> List.group 3 LastToFirst
--> { less = [ 1 ]
--> , groups = [ [ 2, 3, 4 ], [ 5, 6, 7 ] ]
--> }
takeFrom : LinearDirection -> Int -> List a -> List a

Only use a number of elements from one side.

[ 1, 2, 3, 4 ]
    |> List.takeFrom FirstToLast 2
--> [ 1, 2 ]


[ 1, 2, 3, 4 ]
    |> List.takeFrom LastToFirst 2
--> [ 3, 4 ]

Named this way to avoid name clashes with List.take.

dropFrom : LinearDirection -> Int -> List a -> List a

Remove a number of elements from one side.

tail =
    List.dropFrom FirstToLast 1


removeLast =
    List.dropFrom LastToFirst 1

Named this way to avoid name clashes with List.take.