Skip to content

Commit

Permalink
fix for loops in dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Apr 11, 2022
1 parent 9987927 commit 9f2903d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 66 deletions.
9 changes: 6 additions & 3 deletions src/FsSpreadsheet/DSL/ColumnBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type ColumnBuilder() =
member inline _.Yield(cs: ColumnElement list) =
Missing.ok cs

member inline _.Yield(cs: Missing<ColumnElement list>) =
cs

member inline _.Yield(c: Missing<CellElement>) =
match c with
| Ok ((v,Some i),messages) ->
Expand Down Expand Up @@ -60,15 +63,15 @@ type ColumnBuilder() =
Missing.ok [ColumnElement.UnindexedCell v]


member inline this.YieldFrom(ns: Missing<CellElement> seq) =
member inline this.YieldFrom(ns: Missing<ColumnElement list> seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))
this.Combine(state,we)

) ColumnBuilder.Empty


member inline this.For(vs : seq<'T>, f : 'T -> Missing<CellElement>) =
member inline this.For(vs : seq<'T>, f : 'T -> Missing<ColumnElement list>) =
vs
|> Seq.map f
|> this.YieldFrom
Expand Down
9 changes: 6 additions & 3 deletions src/FsSpreadsheet/DSL/RowBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ type RowBuilder() =
member inline _.Yield(cs: RowElement list) =
Missing.ok cs

member inline _.Yield(cs: Missing<RowElement list>) =
cs

member inline _.Yield(c: Missing<CellElement>) =
match c with
| Ok ((v,Some i),messages) ->
Expand Down Expand Up @@ -60,15 +63,15 @@ type RowBuilder() =
Missing.ok [RowElement.UnindexedCell v]


member inline this.YieldFrom(ns: Missing<CellElement> seq) =
member inline this.YieldFrom(ns: Missing<RowElement list> seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))
this.Combine(state,we)

) RowBuilder.Empty


member inline this.For(vs : seq<'T>, f : 'T -> Missing<CellElement>) =
member inline this.For(vs : seq<'T>, f : 'T -> Missing<RowElement list>) =
vs
|> Seq.map f
|> this.YieldFrom
Expand Down
44 changes: 6 additions & 38 deletions src/FsSpreadsheet/DSL/SheetBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ type SheetBuilder(name : string) =

member inline _.Yield(cs: SheetElement list) =
Missing.ok cs

member inline _.Yield(cs: Missing<SheetElement list>) =
cs

member inline _.Yield(c: Missing<RowElement list>) =
match c with
Expand Down Expand Up @@ -54,50 +57,15 @@ type SheetBuilder(name : string) =
member inline _.Yield(cs: ColumnBuilder) =
Missing.ok [SheetElement.UnindexedColumn []]

member inline this.YieldFrom(ns: (RowElement list) seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))

) SheetBuilder.Empty

member inline this.YieldFrom(ns: Missing<RowElement list> seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))

) SheetBuilder.Empty

member inline this.YieldFrom(ns: (ColumnElement list) seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))

) SheetBuilder.Empty

member inline this.YieldFrom(ns: Missing<ColumnElement list> seq) =
member inline this.YieldFrom(ns: Missing<SheetElement list> seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))
this.Combine(state,we)

) SheetBuilder.Empty

member inline this.For(vs : seq<'T>, f : 'T -> Missing<RowElement list>) =
vs
|> Seq.map f
|> this.YieldFrom

member inline this.For(vs : seq<'T>, f : 'T -> RowElement list) =
vs
|> Seq.map f
|> this.YieldFrom

member inline this.For(vs : seq<'T>, f : 'T -> Missing<ColumnElement list>) =
vs
|> Seq.map f
|> this.YieldFrom

member inline this.For(vs : seq<'T>, f : 'T -> ColumnElement list) =
member inline this.For(vs : seq<'T>, f : 'T -> Missing<SheetElement list>) =
vs
|> Seq.map f
|> this.YieldFrom
Expand Down
28 changes: 6 additions & 22 deletions src/FsSpreadsheet/DSL/WorkbookBuilder.fs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ type WorkbookBuilder() =

member inline _.Yield(cs: WorkbookElement list) =
Missing.ok cs


member inline _.Yield(cs: Missing<WorkbookElement list> ) =
cs

member inline _.Yield(c: Missing<SheetElement list>) =
match c with
Expand All @@ -49,38 +51,20 @@ type WorkbookBuilder() =
member inline _.Yield(cs: string * SheetElement list) =
Missing.ok [WorkbookElement.NamedSheet (cs)]

//member inline this.Yield(n: 'a when 'a :> System.IFormattable) =
// let v = DataType.InferCellValue n
// Missing.ok [RowElement.UnindexedCell v]

//member inline _.Yield(s : string) =
// let v = DataType.InferCellValue s
// Missing.ok [RowElement.UnindexedCell v]

member inline this.YieldFrom(ns: (SheetElement list) seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))

) WorkbookBuilder.Empty

member inline this.YieldFrom(ns: Missing<SheetElement list> seq) =
member inline this.YieldFrom(ns: Missing<WorkbookElement list> seq) =
ns
|> Seq.fold (fun state we ->
this.Combine(state,this.Yield(we))
this.Combine(state,we)

) WorkbookBuilder.Empty


member inline this.For(vs : seq<'T>, f : 'T -> Missing<SheetElement list>) =
member inline this.For(vs : seq<'T>, f : 'T -> Missing<WorkbookElement list>) =
vs
|> Seq.map f
|> this.YieldFrom

member inline this.For(vs : seq<'T>, f : 'T -> SheetElement list) =
vs
|> Seq.map f
|> this.YieldFrom

member inline this.Run(children: Missing<WorkbookElement list>) =
match children with
Expand Down

0 comments on commit 9f2903d

Please sign in to comment.