Sha256: 7fc4040244ba7646f6bccec7249c36ee11a2886418c694e791c74424fb99798d

Contents?: true

Size: 716 Bytes

Versions: 396

Compression:

Stored size: 716 Bytes

Contents

module CircularBuffer

type CircularBuffer<'a> = { items: 'a list; size: int }

let mkCircularBuffer size = { items = []; size = size }

let clear buffer = { buffer with items = [] }    

let write value buffer = 
    if List.length buffer.items = buffer.size then failwith "Cannot write to full buffer"
    else { buffer with items = buffer.items @ [value] }
        
let forceWrite value buffer =
    if List.length buffer.items = buffer.size then  { buffer with items = List.tail buffer.items @ [value] }
    else { buffer with items = buffer.items @ [value] }

let read buffer =
    match buffer.items with    
    | x::xs -> x, { buffer with items = xs }
    | [] -> failwith "Cannot read from empty buffer" 

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.138 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.137 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.136 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.135 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.134 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.133 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.132 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.131 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.130 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.129 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.128 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.127 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.126 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.125 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.124 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.123 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.122 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.121 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.120 tracks/fsharp/exercises/circular-buffer/Example.fs