Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions src/Compiler/Utilities/illib.fs
Original file line number Diff line number Diff line change
Expand Up @@ -664,22 +664,19 @@ module List =
| Some x -> x :: l
| _ -> l

[<TailCall>]
let rec private vMapFoldWithAcc<'T, 'State, 'Result>
(mapping: 'State -> 'T -> struct ('Result * 'State))
let inline vMapFold
([<InlineIfLambda>] mapping: 'State -> 'T -> struct ('Result * 'State))
state
list
acc
: struct ('Result list * 'State) =
match list with
| [] -> acc, state
| [ h ] -> mapping state h |> ValueTuple.map1Of2 (fun x -> x :: acc)
| h :: t ->
let struct (mappedHead, stateHead) = mapping state h
vMapFoldWithAcc mapping stateHead t (mappedHead :: acc)

let vMapFold<'T, 'State, 'Result> (mapping: 'State -> 'T -> struct ('Result * 'State)) state list : struct ('Result list * 'State) =
vMapFoldWithAcc mapping state list [] |> ValueTuple.map1Of2 List.rev
let rec go state list acc =
match list with
| [] -> struct (List.rev acc, state)
| h :: t ->
let struct (mappedHead, stateHead) = mapping state h
go stateHead t (mappedHead :: acc)

go state list []

module ResizeArray =

Expand Down
4 changes: 2 additions & 2 deletions src/Compiler/Utilities/illib.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ module internal List =

val prependIfSome: x: 'a option -> l: 'a list -> 'a list

val vMapFold<'T, 'State, 'Result> :
mapping: ('State -> 'T -> struct ('Result * 'State)) ->
val inline vMapFold:
[<InlineIfLambda>] mapping: ('State -> 'T -> struct ('Result * 'State)) ->
state: 'State ->
list: 'T list ->
struct ('Result list * 'State)
Expand Down
Loading