Skip to content

Instantly share code, notes, and snippets.

@ImkeF
Last active November 18, 2019 20:35
Show Gist options
  • Save ImkeF/2d494c6b6ecdb059b76a69a200edb200 to your computer and use it in GitHub Desktop.
Save ImkeF/2d494c6b6ecdb059b76a69a200edb200 to your computer and use it in GitHub Desktop.
let func =
(inputList as list, chunkSize as number) =>
let
ListSelectPositions = (SelectionList as list, ListOfPositions as list) => List.Transform(ListOfPositions, each try SelectionList{_} otherwise null),
Source = inputList,
ChunkSize = chunkSize,
Count = Number.RoundUp(List.Count(Source)/ChunkSize),
Chunks = {1..Count},
Positions = List.Transform(Chunks, each {_*ChunkSize-ChunkSize.._*ChunkSize-1}),
Allocate = List.Transform(Positions, each ListSelectPositions(Source, _))
in
Allocate
, documentation = [
Documentation.Name = " List.ChunkUp
", Documentation.Description = " Chunks up an <code>inputList</code> into groups of <code>chunkSize</code>.
" , Documentation.LongDescription = " Chunks up an <code>inputList</code> into groups of <code>chunkSize</code>.
", Documentation.Category = " List
", Documentation.Source = " local
", Documentation.Author = " Imke Feldmann: www.TheBIccountant.com .
", Documentation.Examples = {[Description = "
" , Code = " List.ChunkUp({1, 2, 3, 4, 5}, 2)
", Result = " {{1,2}, {3,4}, {5, null}}
"]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment