g | x | w | all
Bytes Lang Time Link
060Nim250801T173409ZjanAkali
075AWK250731T182503Zxrs
008TinyAPL beta 0.13250603T144823ZRubenVer
037Swift 6250515T130153ZmacOSist
nan181207T191817Zflawr
024Juby250514T192000ZJordan
054Swift230119T171731ZSimonL
072Go230119T180315Zbigyihsu
nan230119T174651ZThe Thon
4911D181210T144334ZFeepingC
011x86 opcode230119T112549Zl4m2
029Arturo230119T101407Zchunes
012MATL181209T222225ZSuever
006Pip220308T163757ZDLosc
026Julia 1.0220308T162334ZMarcMush
008Brachylog181211T083556ZFatalize
006Pyth220308T143902Zsinvec
003Vyxal210531T023921Zwasif
025Factor + grouping.extras210531T025157Zchunes
014Add++210506T154253Zcaird co
102Google Sheets201203T184630ZGeneral
028Scala201202T192443Zuser
007K ngn/k181207T202529Zngn
060Reticular190111T013124ZWisław
097C gcc181209T120256Zuser7740
021Scala181210T080319ZBrian Mc
00805AB1E181223T001833Zkrinisto
034Bash181213T214335Zphilcolb
012APL Dyalog Unicode181213T165412ZJ. Sall&
037Elixir181213T140822ZKirill L
072Gambit Scheme gsi181212T185041Zsporkl
013Actually181212T194650Zuser4594
024Perl 5 + a181211T201506ZDom Hast
013Perl 6181207T225310ZSean
029Ruby181209T114716ZAsone Tu
031Ruby181208T212631ZEric Dum
021Clojure181211T000250ZNikoNyrh
006str181210T233523ZConor O&
022SWI PROLOG181210T224517Zstyrofoa
077Java 8+181208T002248Zბიმო
006MathGolf181210T125923ZKevin Cr
007MathGolf181210T144613Zmaxb
039R181207T201218ZGiuseppe
057FALSE181210T023520ZTerjerbe
012brainfuck181208T085629ZJo King
045F# Mono181209T110233Zdana
057Forth gforth181209T091715ZMaya
018Z80Golf181209T090917ZMaya
063Factor181209T061118Zcat
039C# Visual C# Interactive Compiler181209T043257Zdana
007MY181207T232705ZAdalynn
065Tcl181208T115947Zsergiol
007Pushy181208T093348ZFlipTack
004Japt181207T200518ZKamil Dr
024Powershell181208T082724Zmazzy
033JavaScript ES6181207T192258ZArnauld
032Kotlin181208T081338Zsnail_
076Red181208T080835ZGalen Iv
043brainfuck181208T070800Zuser2027
016Pip181208T050115ZASCII-on
023Pari/GP181208T045413Zalephalp
081Tcl181208T000529ZASCII-on
092Lua 5.3181208T022738Zcyclamin
005Japt181208T021135ZOliver
013Attache181208T005214ZConor O&
002Husk181208T003549Zბიმო
053F#181207T234730ZCiaran_M
048C# Visual C# Interactive Compiler181207T235135ZASCII-on
037Groovy181207T232500ZGolfIsAG
039Common Lisp181207T231822ZASCII-on
021Mathematica181207T213352ZLegionMa
036JavaScript181207T211619ZOliver
007RAD181207T205514ZAdalynn
00305AB1E181207T204327ZOkx
032Python 2181207T201533Zovs
005Canvas181207T194519Zdzaima
065PowerShell181207T193803ZAdmBorkB
020Haskell181207T194346ZØrj
003Jelly181207T200323ZDennis
006Charcoal181207T200219ZNeil
027Haskell181207T193414Zflawr
005J181207T192614ZFrownyFr

Nim, 60 bytes

proc(a= @[1]):seq[a.type]=(for i in..a.len:result&=a[0..<i])

Attempt This Online!

AWK, 75 bytes

{for(s="[[]";i++<NF;){s=s", [";for(j=0;j++<i;)s=s $j (j-i?",":"]")}}$0=s"]"

Attempt This Online!

TinyAPL (beta 0.13), 8 bytes

⦅⍬⊂⊸⍪⊂\⦆

⦅⍬⊂⊸⍪⊂\⦆­⁡​‎‎⁡⁠⁣‏⁠‎⁡⁠⁤‏⁠‎⁡⁠⁢⁡‏‏​⁡⁠⁡‌⁢​‎⁠‎⁡⁠⁢‏‏​⁡⁠⁡‌⁣​‎‎⁡⁠⁢⁢‏⁠‎⁡⁠⁢⁣‏‏​⁡⁠⁡‌­
  ⊂⊸⍪     ⍝ ‎⁡Prepend
 ⍬        ⍝ ‎⁢the empty list
     ⊂\   ⍝ ‎⁣to the list of nonempty prefixes
💎

Created with the help of Luminespire.

Swift 6, 43 37 bytes

{($0+[0]).indices.map($0.prefix(_:))}

Try it on SwiftFiddle!

CW for all trivial entries

Clean, 19 bytes

Haskell version works in Clean too.

import StdLib
inits

Try it online!

Haskell, 22 bytes

import Data.List
inits

Try it online!

Prolog (SWI), 6 bytes

prefix

Try it online!

Vyxal 3, 1 byte

P

Vyxal It Online!

J-uby, 24 bytes

:*%[:& &:take,:+@|:!~&0]

Attempt This Online!

Swift, 60 54 bytes

let f={(i:[Int])in return[[]]+i.indices.map{i[...$0]}}

Try it online!

Defines a function that takes an array of ints and returns an Array of ArraySlices (i.e, they reference the same memory as the input array). To turn into real arrays, it's 67 61 bytes.

let f={(i:[Int])in return[[]]+i.indices.map{Array(i[...$0])}}

Go, 72 bytes

func(I[]int)(o[][]int){for i:=0;i<=len(I);i++{o=append(o,I[:i])};return}

Attempt This Online!

Generic, 77 bytes

func f[T any](I[]T)(o[][]T){for i:=0;i<=len(I);i++{o=append(o,I[:i])};return}

Attempt This Online!

Thunno, \$ 11 \log_{256}(96) \approx \$ 9.05 bytes

0TzreRz0sAI

Attempt This Online!

Explanation

0TzreRz0sAI  # Implicit input
0T           # Append a 0 (so the length is increased by 1)
  zr         # Length range, [0..len)
    e        # Map over this list:
     R       #   Range from 0 to this number
        sAI  #   Index this into
      z0     #   The input
             # Implicit output

D, 49 bytes (11 imports, 38 expression)

import std;
alias prefixes = t=>iota(t.length+1).map!(i=>t.take(i));

Try it online!

edit: Do I count the alias prefixes = part? You can use the lambda without it, but you have to add parens to disambiguate, so should I count it as 42?

edit: We now got import std; as a shortcut. That solves things!

x86 opcode, 11 bytes

xor eax, eax
inc ecx
P:
xchg eax, esi
stosd
xchg eax, esi
stosd
inc eax
loop P
ret

Take ecx(length) esi(input array) edi(output buffer) output (array,length) pairs

Somehow cheaty :)

Arturo, 31 29 bytes

$[a][map 0..size a=>[take a]]

Try it

MATL, 15 12 bytes

3 bytes saved thanks to @Giuseppe

vin:"G@:)]Xh

Try it at MATL Online.

Due to the way that MATL displays the output, you can't explicitly see the empty array in the cell array. Here is a version that shows the output a little more explicitly.

Explanation

v       # Vertically concatenate the (empty) stack to create the array []
i       # Explicitly grab the input
n       # Compute the number of elements in the input (N)
:       # Create an array from [1, ..., N]
"       # Loop through this array
  G     # For each of these numbers, M
  @:    # Create an array from [1, ..., M]
  )     # Use this to index into the initial array
]       # End of the for loop
Xh      # Concatenate the entire stack into a cell array

Pip, 6 bytes

_H,U#_

Anonymous function that takes an iterable and returns a list of iterables. (A full program would be the same number of bytes, but would require flags.) Attempt This Online!

Explanation

    #_  ; Length of function argument
   U    ; Incremented
  ,     ; Range from 0 up to one less than that number, i.e. 0..len
_H      ; For each of those numbers n, get the first n elements of the function argument

Julia 1.0, 26 bytes

~l=0:length(l).|>i->l[1:i]

Try it online!

alternative solution in Julia 1.6+, 26 bytes:

~l=first.([l],0:length(l)) Try it online!

Brachylog, 9 8 bytes

{∧Ė|a₀}ᶠ

Try it online!

Explanation

{     }ᶠ    Find all:
 ∧Ė          The empty list
   |         Or
    a₀       A prefix of the input

Pyth, 6 bytes

Sa._QY

Try it online!

Vyxal, 3 bytes

K¾p

Try it Online!

Factor + grouping.extras, 25 bytes

[ head-clump { } prefix ]

Try it online!

Mostly a built-in. Just have to add the empty list at the beginning.

Compare to a non-trivial answer:

[ dup length [0,b] [ head ] with map ]

Try it online!

Add++, 14 bytes

L*,¬b[€bFbUBpA

Try it online!

How it works

L		; Lambda function. Takes A as argument
	*,	; Return the enire stack
		; E.g. A = [1 2 3 4]
	¬b[	; Scan pair;	STACK = [[1 [1 2] [[1 2] 3] [[[1 2] 3] 4]]]
	€bF	; Flatten each;	STACK = [[[1] [1 2] [1 2 3] [1 2 3 4]]]
	bU	; Splat;	STACK = [[1] [1 2] [1 2 3] [1 2 3 4]]
	Bp	; Pop each;	STACK = [[] [1] [1 2] [1 2 3]]
	A	; Push A;	STACK = [[] [1] [1 2] [1 2 3] [1 2 3 4]]

Google Sheets, 102

Output Formatted:

=ArrayFormula(IF(
  A2,
  {
    T(SEQUENCE(1,A2));
    IF(
      SEQUENCE(A2)>=SEQUENCE(1,A2),
      OFFSET(A1,,,,A2),
    )
  },
))

Scala, 28 bytes

_.scanLeft(Seq[Int]())(_:+_)

Try it online!

This is longer than the Scala answer that's already here, but uses a different method. Unfortunately, the [Int] must be used to avoid Nothing being inferred.

K (ngn/k), 8 7 bytes

1_',\0,

Try it online!

Reticular, 60 bytes

Bql:D=:D`:E=l[:D`@d]~*[:E`b@qM[$]:D`:E`-*:E`1-:E=]:D`1+*lbo;

Try it online!

Assumes that the input list is at the top of the stack. To test input, run the following code

'1''2''3''4''5'lbBql:D=:D`:E=l[:D`@d]~*[:E`b@qM[$]:D`:E`-*:E`1-:E=]:D`1+*lbo;

Explanation

B                         # Push every element from the input list to the stack.
 q                        # Reverse stack.
  l                       # Push the size of the stack to the stack.
   :D=                    # Save it as the variable D.
      :D`:E=              # Define the variable E = D.
            l             # Push D to the stack.
             [:D`@d]      # Push the function which duplicates the top D items in the stack
                    ~     # Swap the top two items in the stack
                     *    # Call the above function D number of times.



[                          ]            # Push a function that does the following:
 :E`b                                   # Put the top E items in a list.
     @q                                 # Reverse list that is at the top of the stack.
       M                                # Rotate stack so that top of stack -> bottom of stack.
        [$]:D`:E`-*                     # Delete the top D-E items from the stack.
                   :E`1-:E=             # Define E = E - 1.
                            :D`1+*      # Call the above function D+1 number of times.
                                  q     # Reverse stack.
                                   lb   # Put every item in the stack into a list.
                                     o; # Output the resulting list and exit.

C (gcc), 102 97 bytes

Pretty long, as C quite obviously isn't well-suited to manipulating lists of lists. Dependent on certain behavior; running on some platforms requires changing int to short (for +2 bytes), due to wchar_t being UTF-16 rather than UTF-32. Should work on Linux as-is.

Takes in a pointer to the first element of the input array, the length of the array, and a pointer to the variable in which the pointer to output will be stored. Produces a list of lists such that the first integer in the linear array stores the number of sub-lists. Sub-lists start with the number of elements, and are stored in memory in a contiguous manner.

p(r,e,f,i,x)int*e,**r,*x;{x=*r=malloc(4-++f*~f*2);*x++=f;for(i=0;i<f;x+=++i)wmemcpy(x+1,e,*x=i);}

Try it online!

Degolf

p(r,e,f,i,x) int**r,*e,*x; // Function p(), where r is a pointer to the output variable,
                           // e is a pointer to the input location and f is the size of
                           // the input.
{ 
  x=*r=malloc(4-++f*~f*2); // Allocate 4*(x+1)*(x+2)/2+4 bytes of memory. 
                           // This is the exact amount of memory needed.
  *x++=f;                  // Store n+1 (number of sub-lists) in the first four bytes. 
  for(i=0;i<f;x+=++i)      // Iterate over [0, n]->i and 
                           // increment the pointer to x by i+1 every iteration.
    wmemcpy(x+1,e,*x=i);   // Set first element at location pointed to by x to i,
                           // then copy i of either 2 or 4 byte elements, depending on
                           // the system wchar implementation, to location pointed to
                           // by x+1.
}

Scala, 21 bytes

_.inits.toSeq.reverse

Try it online!

Not quite a trivial answer, since I had to deal with the fact that the inits method returns an iterator in the reverse of the required order.

05AB1E, 8 bytes

That was my first succesfull golf! Thanks for being such a nice community!

)UŒ¹g£Xš

Try it online!

Explanation:

)UŒ¹g£Xš
)        : Create an empty list
 U       : Save it to variable ˙X˙
  Œ      : Make the "substrings" of the implicit input
   ¹g£   : Take the first n elements of the result where n is the lenght of input
      Xš : Add the empty list to the beginning       

Bash, 34 bytes

I output each list element on a new line as someone else did - bash only has 1-D arrays:

for((;c<=$#;c++)){ echo ${*:1:c};}

Could be 1 byte less but this does not work for null case - don't see why... c++ does not get evaluated...

for((;c<=$#;)){ echo ${*:1:c++};}

This can output text as suggested by OP:

C='echo -n ';A=(${1//[],[]/ });$C[[];for((c=0;c<${#A[*]};)){ B=${A[*]::++c};$C,[${B// /,}];};echo ]

No one should have to decode that. Here is annotated version:

C='echo -n '              # basically a macro to improve my golf
A=( ${1//[],[]/ } )       # convert [,] to spaces - like magic this one
$C[[]                     # echo [[] since every list needs this
for((c=0;c<${#A[*]};)){   # for all elements of list
  B=${A[*]::++c}          # make space separated list of first c elements
  $C,[${B// /,}]          # prefix with ,[ and convert space to comma
}
echo ]                    # terminate list with ]

APL (Dyalog Unicode), 12 bytes

(0,∘⍳∘≢⊢)↑¨⊂

Try it online!

Prefix tacit function. TIO link has boxing enabled to make the output more readable.

How:

(0,∘⍳∘≢⊢)↑¨⊂ ⍝ Tacit fn, taking a vector as argument, which will be called ⍵ for simplicity.
         ↑   ⍝ Take the first ⍺ (left arg) elements of ⍵
          ¨⊂ ⍝ Since the ⍺ for ↑ is a vector, we enclose the ⍵ and apply ↑ to it for each of the elements in ⍺.
(      ⊢)    ⍝ Use ⍵ as argument for
      ≢      ⍝ Tally; yields the number of elements in ⍵
    ⍳∘       ⍝ Then, yield the range [1..≢⍵]
 0,∘         ⍝ and prepend a 0.

The function returns a vector of vectors, each with the first [0..≢⍵] elements of the argument.

Elixir, 37 bytes

fn x->Enum.scan [[]|x],&(&2++[&1])end

Try it online!

Looking at other languages, this looks rather verbose, but I'm definitely not an expert in Elixir, so please let me know if I missed something obvious.

Gambit Scheme (gsi), 77 72 bytes

(define(p z)(if(pair?(car z))(p(cons(reverse(cdr(reverse(car z))))z))z))

Try it online!

First time using Scheme. It's a function that takes a wrapped list ((list (list 1 2 3 4))) as an argument.

Actually, 13 bytes

;╗ru⌠╜H⌡M[]@o

Try it online!

Explanation:

;╗ru⌠╜H⌡M[]@o
;╗             save a copy of input in register 0
  ru           range(1, len(input)+1)
    ⌠╜H⌡M      for i in range:
     ╜H          first i elements of input
         []@o  prepend an empty list

Perl 5 + -a, 24 bytes

say"@F[0..$_]"for-1..$#F

Try it online!

Perl 6, 13 bytes

{(),|[\,] @_}

Try it online!

To explain:

In Perl 6 you can wrap an operator in square brackets as an alternate way to write a list reduction. [+] @array returns the sum of the elements in @array, [*] @array returns the product, etc. You can also precede the operator with a backslash to make a "triangular" reduction, which some languages call "scan." So [\+] @array returns a list consisting of the first element of @array, then the sum of the first two elements, then the sum of the first three elements, etc.

Here [\,] @_ is a triangular reduction over the input array @_ using the list construction operator ,. So it evaluates to a lists of lists: the first element of @_, the first two elements of @_, etc. That's almost what's needed, but the problem calls for a single empty list first. So the first element of the return list is a literal empty list (),, then the reduction over the input list is flattened into the rest of the return list with |.

Ruby, 31 29 bytes

->a{[a*i=0]+a.map{a[0,i+=1]}}

Try it online!

Explanation:

->a{             # take array input a
  [a*i=0]+       # set i to 0 and add whatever comes next to [[]] (a*0 == [])
  a.map{         # for every element in a (basically do a.length times)
    a[0,i+=1]  # increment i and return the first i-1 elements of a to map
  }
}

Ruby, 34 31 bytes

->l{(0..l.size).map{|i|l[0,i]}}

Try it online!

Thanks @ConorO'Brien!

Clojure, 21 bytes

#(reductions conj[]%)

str, 6 bytes

e;:dno

Try it online!

Each output line corresponds to an entry in the prefix array.

Explanation

e;:dno
            -- preamble --
e           push empty string
            -- iteration --
  :         append current char to build string
   d        duplicate it
    n       push "\n"
     o      output it
            (implicitly output duplicated entry)

SWI PROLOG 22 bytes

i(X,Y):-append(X,_,Y).

Java 8+, 86 77 bytes

-9 bytes thanks to Kevin Cruijssen (getting rid of the import)!

x->java.util.stream.IntStream.range(0,x.size()+1).mapToObj(t->x.subList(0,t))

Try it online!

Alternative, 65 bytes

The following will print the results to stdout (due to Olivier Grégoire):

x->{for(int i=0;i<=x.size();)System.out.print(x.subList(0,i++));}

Try it online

MathGolf, 9 7 6 bytes

hÅ_╡]x

-1 byte thanks to @maxb.

Try it online or verify all test cases.

Explanation:

h        # Push the length of the (implicit) input-array, without popping the array
 Å       # Loop this length amount of times,
         # and do the following two commands each iteration:
  _      #  Duplicate the array at the top of the stack
   ╡     #  Remove the right-most item of the array
    ]    # After the loop, wrap everything on the stack in an array
     x   # Reverse it (and output implicitly)

MathGolf, 7 bytes

hæ_ï<\]

Try it online!

Explanation

h         length of array/string without popping
 æ        start block of length 4
  _       duplicate TOS
   ï      index of current loop, or length of last loop
    <     slice list
     \    swap top elements
      ]   end array / wrap stack in array

R, 40 39 bytes

function(L)lapply(0:length(L),head,x=L)

Try it online!

-1 byte thanks to digEmAll

The output of R's list type is a bit weird; it uses sequential indexing, so for instance, the output for

list(1,2) is

[[1]]                     # first list element
list()

[[2]]                     # second list element
[[2]][[1]]                # first element of second list element
[1] 1


[[3]]                     # third list element
[[3]][[1]]                # first element of third list element
[1] 1

[[3]][[2]]                # etc.
[1] 2

Taking input as a vector instead gives a neater output format, although then the inputs are not technically lists.

FALSE, 57 bytes

1^[$~][\1+^]#%a:0[$a;1->~][0[$@$@>][\$a;\-ø,1+]#\%10,1+]#

Try it online! (you'll have to copy paste the code. Click "Show" and then run)

Like brainf*ck, FALSE only takes one char at a time as input, so this program splits a string into prefixes, separating them with a newline.

Explanation:

1^         {push 1 {counter) and first character onto stack}
[$~][      {while a character is input:}
  \1+^     {add 1 to the counter}
]#

%          {drop truth value from stack}
a:         {define the counter as the variable "a'}
0          {push 0 onto stack (loopvar)}
[$a;1->~][ {while loopvar is less than a-1:}

  0        {push 0 (loopvar2)}
  [$@$@>][ {while loopvar is greater than loopvar2}
    \$a;\- {a-loopvar2 (to get index of char to print)}
    ø,     {copy value at index to top of stack and print}
    1+     {increment loopvar2}
  ]#
  \%       {swap'n'drop (get rid of loopvar2)}
  10,      {print newline}
  1+       {increment loopvar}
]#

A FALSE expert could probably do this using no variables (pure stack) but since I only learnt this language yesterday I think this is alright.

brainfuck, 21 12 bytes

-9 bytes thanks to Arnauld suggesting the separator ÿ instead of newlines

-[[<]>[.>],]

Try it online!

Takes bytes through STDIN with no null bytes and prints a series of prefixes separated by the ÿ character with a leading ÿ character. For example, for the input Prefixes, the output is ÿÿPÿPrÿPreÿPrefÿPrefiÿPrefixÿPrefixeÿPrefixes.

For readability, here's a version with newlines instead.

Explanation:

-              Create a ÿ character in cell 0
 [        ,]   While input, starting with the ÿ
  [<]>           Go to the start of the string
      [.>]       Print the string
          ,      Append the input to the end of the string

F# (Mono), 45 bytes

fun x->List.mapi(fun i y->List.take i x)x@[x]

Try it online!

I am not totally sure if this is valid, but it seems like it follows the same "anonymous lambda" syntax that I've seem used in several other languages.

Forth (gforth), 57 bytes

: x here 0 begin 2dup type cr 1+ key dup c, 5 < until ; x

Try it online!

Takes bytes through STDIN and prints a series of prefixes, each terminated by a newline.

Z80Golf, 18 bytes

00000000: 2511 00ff 1b1a ffa7 20fa cd03 802b 7730  %....... ....+w0
00000010: f076                                     .v

Try it online!

Takes bytes through STDIN with no null bytes and prints a series of prefixes, each terminated by a null byte.

Source code:

    dec h
start:
    ld de, $ff00
.printloop:
    dec de
    ld a, (de)
    rst $38
    and a
    jr nz, .printloop
    call $8003
    dec hl
    ld (hl), a
    jr nc, start
    halt

Factor, 63 bytes

USE: fry [ [ dup '[ nip _ swap head ] map-index ] keep suffix ]

Keeps a copy of the input to tack on at the end, like C#.

C# (Visual C# Interactive Compiler), 39 bytes

x=>x.Select((_,i)=>x.Take(i)).Append(x)

Try it online!

MY, 7 bytes

ωωι0;↑←

Try it online!

Woah ... never thought MY would actually come in handy.

How?

ωωι0;↑←

Tcl, 65 bytes

proc P {L J\ {{}}} {lmap e $L {lappend J [lappend K $e]}
list $J}

Try it online!

Pushy, 7 bytes

1@$O_vI

Try it online!

Japt, 4 bytes

²£¯Y

Try it online!

Explanation:

²       :Add an arbitrary extra item to the end of the array
 £      :For each item in the new array:
  ¯Y    : Get an array of the items that are before it

Powershell, 24 bytes

,@()
$args|%{,($x+=,$_)}

Explanation:

  1. The trivial accumulator wrapped to array by unary ,.
  2. The script uses splatting. See parameter @a.

Test script:

$f = {

,@()
$args|%{,($x+=,$_)}

}

@(
    ,( @()        , @() )
    ,( @(42)      , @(@(),@(42)) )
    ,( @(1,2,3,4) , @(@(), @(1), @(1,2), @(1,2,3), @(1,2,3,4)) )
    ,( @(4,3,2,1) , @(@(), @(4), @(4,3), @(4,3,2), @(4,3,2,1)) )
) | % {
    $a,$expected = $_
    $result = &$f @a

    $false -notin $(
        $result -is [array]
        $result.Count -eq $expected.Count
        for($j=0; $j-lt$result.Count; $j++){
            "$($result[$j])" -eq "$($expected[$j])"
        }
    )

    # $result   # uncomment this line to display a result

}

Output:

True
True
True
True

JavaScript (ES6), 33 bytes

a=>[b=[],...a.map(n=>b=[...b,n])]

Try it online!

How?

+--- a = input array
|
|       +--- initialize b to an empty array and include it as the first entry
|       |    of the output (whatever the input is)
|       |
|       |          +--- for each value n in a[]:
|       |          |
|       |          |        +--- append n to b[] and include this new array in
|       |          |        |    the final output
|       |          |        |
a => [b = [], ...a.map(n => b = [...b, n])]
               |                  |
               +---------+--------+
                         |
      spread syntax: expands all elements of
      the child array within the parent array

Kotlin, 32 bytes

{l->(0..l.size).map{l.take(it)}}

{ list ->
    (0..list.size).map {  // map over range [0, length of list]
        list.take(it)  // first n items of list
    }
}

Try it online!

Red, 76 bytes

func[b][a: copy[[]]c: b until[append/only a copy/part b c: next c tail? c]a]

Try it online!

brainfuck, 43 bytes

Take a list of non-null characters as input and returns all prefixes separated by newline. Requires double-infinite or wrapping tape.

,>-[+>,]<[-<]<<++++++++++[[<]>[.>]>[-<+>]<]

Try it online!

Pip, 16 bytes

{h@<a}M,1+#(h:a)

Try it online!

Explanation

      M            Map
{h@<a}                 Function returning global variable h, cut at index a, and left part taken (0-indexed)
       ,               Range from 1 to
        1+#(   )           1 + the length of
            h:a                Assign global variable h to a, evaulating to the value of h (which is also the value of a - the first parameter to the function)

Pari/GP, 23 bytes

a->[a[1..n]|n<-[0..#a]]

Try it online!

Tcl, 81 bytes

set i -1
set a {{}}
foreach _ $argv {lappend a [lrange $argv 0 [incr i]]}
puts $a

Try it online!

Lua 5.3, 92 bytes

function f(...)t=...if#t>0then return f({table.unpack(t,1,#t-1)},...)else return{...}end end

Keeps creating a copy of the array-like table with the element at the end removed and prepending it to the varargs until the length of the table is 0, then puts the varargs in a table. Relies on defining the variable f to allow recursion.

Lua 5.1, 87 bytes

function f(...)t=...if#t>0 then return f({unpack(t,1,#t-1)},...)else return{...}end end

unpack is a global variable rather than a member of the table library. 0then is syntactically invalid in Lua 5.1, but strangely not in Lua 5.3.

Japt, 5 bytes

Êò@¯Y

Try it online!

Attache, 13 bytes

{_[0...0:#_]}

Try it online!

Explanation

{_[0...0:#_]}
{           }    block taking `_` as input
 _[        ]     index from the input
       0:#_      range from 0 to the length of `_` inclusive
   0...          range from 0 to each number that range, right exclusive

Husk, 2 bytes

Θḣ

Gets all the eads and then prepends Θ (in this case []):

Try it online!

(needs type annotation for empty list: Try it online!)

F#, 53 bytes

I've actually got two pretty similar answers for this, both the same length. They both take a generic sequence s as a parameter.

First solution:

let i s=Seq.init(Seq.length s+1)(fun n->Seq.take n s)

Try it online!

Seq.take takes the first n elements of the sequence. Seq.init creates a new sequence with a count (in this case) of the length of sequence s plus 1, and for each element in the sequence takes the first n elements in s.

Second solution:

let i s=Seq.map(fun n->Seq.take n s){0..Seq.length s}

Similar to before, except it creates a sequence from 0 to the length of s. Then takes that number of elements from s.

Try this online too!

C# (Visual C# Interactive Compiler), 48 bytes

l=>new int[l.Count()+1].Select((_,n)=>l.Take(n))

Try it online!

Explanation

l=>                                                // Function with list l as argument
   new int[l.Count()+1]                            // A new array (int is shortest type available) of length l + 1
                       .Select((_,n)=>l.Take(n))   // Where every element is mapped to the first n elements of the input list, where n is the index

Groovy, 37 bytes

{x->(0..x.size()).collect{x[0..<it]}}

Try it online!

Common Lisp, 39 bytes

(defun f(l)`(,@(if l(f(butlast l))),l))

Try it online!

Explanation

(defun f(l)                           )  ; Define a function f
           `(                        )   ; With the list (essentially capable of interpolation), containing:
             ,@                          ;     The value of, flattened to one level
               (if l              )      ;         If l is not the empty list (which is the representation of nil, i.e. the only falsy value)
                    (f(butlast l))       ;         Recurse with all of l but the tail
                                   ,l    ;     The value of l

Mathematica, 22 21 bytes

-1 byte thanks to Misha Lavrov!

{}~FoldList@Append~#&

Pure function. Takes a list as input and returns a list of lists as output. I believe this is the shortest possible solution.

JavaScript, 36 bytes

a=>[...a,0].map((x,y)=>a.slice(0,y))

Try it online!

RAD, 7 bytes

(⊂⍬),,\

Try it online!

This also works in Dyalog APL as a function.

How?

This works the same for both APL and RAD, given their close relation.

05AB1E, 3 bytes

η¯š

Explanation:

η    Prefixes
  š  Prepend
 ¯   Global array (empty by default)

Try it online!

Python 2, 32 bytes

f=lambda l:(l and f(l[:-1]))+[l]

Try it online!

Canvas, 6 5 bytes

)╶[})

Try it here!

Outputs to the stack; Linked with a trailing raw so that's visible.

)      wrap the (currently empty) stack in an array
 ╶[}   map nothing over the prefixes of the input
    )  wrap the stack (the empty array and the prefixes) in an array

2 bytes without the starting empty array.

PowerShell, 65 bytes

param($a)'';$x=,0*($y=$a.count);0..--$y|%{$x[$_]=@($a[0..$_])};$x

Try it online!

PowerShell helpfully unrolls lists-of-lists when the default Write-Output happens at program completion, so you get one item per line. Tack on a -join',' to see the list-of-lists better, by converting the inner lists into strings.

(Ab)uses the fact that attempting to output an empty array (e.g., @()) results in no output, so an empty array input just has '' as the output, since the $a[0..$_] will result in nothing. It will also throw out some spectacular error messages.

Haskell, 20 bytes

Edit: Yet a byte shorter with a completely different scan.

An anonymous function slightly beating the trivial import.

scanr(\_->init)=<<id

Try it online!

Jelly, 3 bytes

ṭṖƤ

Try it online!

How it works

ṭṖƤ  Main link. Argument: A

  Ƥ  Map the link to the left over all non-empty(!) prefixes of A.
 Ṗ       Pop; remove the last element.
ṭ    Tack; append A to the resulting list.

Charcoal, 6 bytes

Eθ…θκθ

Try it online! Link is to verbose version of code. Explanation:

 θ      Input array
E       Map over elements
   θ    Input array
  …     Moulded to length
    κ   Current loop index
        Implicitly print each array double-spaced
     θ  Input array
        Implicitly print

It's possible at a cost of 1 byte to ask Charcoal to print an n+1-element array which includes the input as its last element, but the output is the same, although the cursor position would be different if you then went on to print something else.

Haskell, 27 bytes

i[]=[[]]
i l=i(init l)++[l]

Try it online!

J, 5 bytes

a:,<\

Try it online!