Array operations that can be applied in either direction.
A certain number of elements from one side.
Array.fromList [ 1, 2, 3, 4, 5, 6 ]
|> Array.take 4 FirstToLast
|> Array.take 2 LastToFirst
--> Array.fromList [ 3, 4 ]
Array.fromList [ 1, 2, 3 ]
|> Array.take 100
--> Array.fromList [ 1, 2, 3 ]Just the element at an index in a direction.
Array.fromList [ "lose", "win", "lose" ]
|> Array.at 0 LastToFirst
--> Just "lose"
Array.fromList [ 1, 2, 3 ]
|> Array.at 0 FirstToLast
--> Just "lose"Nothing, if the index is out of range.
Array.fromList [ 1, 2, 3 ]
|> Array.at -1
--> NothingSet the element at an index in a direction.
Array.fromList [ "I", "am", "ok" ]
|> Array.replaceAt 2 FirstToLast "confusion"
--> Array.fromList [ "I", "am", "confusion" ]
Array.fromList [ "I", "am", "ok" ]
|> Array.replaceAt 1 LastToFirst "feel"
--> Array.fromList [ "I", "feel", "ok" ]If the index is out of range, the array is unaltered.
Array.fromList [ "I", "am", "ok" ]
|> Array.replaceAt -1 FirstToLast "is"
--> Array.fromList [ "I", "am", "ok" ]Kick an element out of an Array at a given index in a direction.
Array.fromList [ 'a', 'a', 'b' ]
|> Array.removeAt 1 FirstToLast
--> Array.fromList [ 'a', 'b', 'c', 'd' ]
Array.fromList [ 'a', 'b', 'c', 'd' ]
|> Array.removeAt 0 LastToFirst
--> Array.fromList [ 'a', 'b', 'c' ]If the index is out of bounds, the Array is unaltered.
Array.fromList [ 'a', 'a', 'b' ]
|> Array.removeAt -1 FirstToLast
--> Array.fromList [ 'a', 'a', 'b' ]Put an element in an Array at a given index in a direction.
Array.fromList [ 'a', 'c', 'd' ]
|> Array.insertAt 1 FirstToLast 'b'
--> Array.fromList [ 'a', 'b', 'c', 'd' ]
Array.fromList [ 'a', 'c', 'd' ]
|> Array.insertAt 2 LastToFirst 'b'
--> Array.fromList [ 'a', 'b', 'c', 'd' ]If the index is out of bounds, nothing gets inserted.
Array.fromList [ 'a', 'c', 'd' ]
|> Array.insertAt -1 'b'
--> Array.fromList [ 'a', 'c', 'd' ]
Array.fromList [ 'a', 'c', 'd' ]
|> Array.insertAt 10 'b'
--> Array.fromList [ 'a', 'c', 'd' ]
Reduce an
Arrayin a direction.