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.180 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.179 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.178 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.177 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.176 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.175 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.174 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.173 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.172 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.171 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.170 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.169 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.167 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.166 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.165 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.164 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.163 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.162 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.161 tracks/fsharp/exercises/circular-buffer/Example.fs
trackler-2.2.1.160 tracks/fsharp/exercises/circular-buffer/Example.fs