Skip to content

Commit 649bf19

Browse files
JBgusty
authored andcommitted
Surround files with Fable compiler directives (#199)
1 parent 6a87152 commit 649bf19

32 files changed

+434
-46
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,8 @@ docsrc/tools/FSharp.Formatting.svclog
202202
# Node install directory
203203

204204
tests/FSharpPlusFable.Tests/node_modules/
205+
206+
207+
# Fable compilation files
208+
209+
tests/FSharpPlusFable.Tests/FSharpPlusFable

src/FSharpPlus/Builders.fs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ module Builders =
1616
static member inline ($) (Idiomatic, si) = fun sfi x -> (Idiomatic $ x) (sfi <*> si)
1717
static member ($) (Idiomatic, Ii) = id
1818
let inline idiomatic a b = (Idiomatic $ b) a
19+
#if !FABLE_COMPILER
1920
let inline iI x = (idiomatic << result) x
2021
type Idiomatic with static member inline ($) (Idiomatic, Ji) = fun xii -> join xii
2122
type Idiomatic with static member inline ($) (Idiomatic, J ) = fun fii x -> (Idiomatic $ x) (join fii)
22-
23+
#endif
2324

2425

2526
// Workflows
@@ -30,10 +31,13 @@ module Builders =
3031

3132
type Builder () =
3233
member __.ReturnFrom (expr) = expr : '``Monad<'T>``
34+
#if !FABLE_COMPILER
3335
member inline __.Return (x: 'T) = result x : '``Monad<'T>``
3436
member inline __.Yield (x: 'T) = result x : '``Monad<'T>``
37+
#endif
3538
member inline __.Bind (p: '``Monad<'T>``, rest: 'T->'``Monad<'U>``) = p >>= rest : '``Monad<'U>``
3639

40+
#if !FABLE_COMPILER
3741
[<CustomOperation("select", MaintainsVariableSpaceUsingBind=true, AllowIntoPattern=true)>]
3842
member inline __.Select (x, [<ProjectionParameter>] f) = map f x
3943

@@ -51,16 +55,19 @@ module Builders =
5155

5256
[<CustomOperation("orderBy", MaintainsVariableSpaceUsingBind=true, AllowIntoPattern=true)>]
5357
member inline __.OrderBy (x,[<ProjectionParameter>] f : 'T -> 'key) = sortBy f x
58+
#endif
5459

5560
type StrictBuilder () =
5661
inherit Builder ()
5762
member inline __.Delay expr = expr : unit -> '``Monad<'T>``
5863
member __.Run f = f () : '``Monad<'T>``
5964
member __.TryWith (expr, handler) = try expr () with e -> handler e
6065
member __.TryFinally (expr, compensation) = try expr () finally compensation ()
66+
#if !FABLE_COMPILER
6167
member rs.Using (disposable: #IDisposable, body) =
6268
let body = fun () -> body disposable
6369
rs.TryFinally (body, fun () -> dispose disposable)
70+
#endif
6471

6572
type DelayedBuilder () =
6673
inherit Builder ()
@@ -86,8 +93,11 @@ module Builders =
8693

8794
type MonadFxStrictBuilder () =
8895
inherit StrictBuilder ()
96+
#if !FABLE_COMPILER
8997
member inline __.Zero () = result () : '``Monad<unit>``
98+
#endif
9099
member inline __.Combine (a: '``Monad<unit>``, b) = a >>= (fun () -> b ()) : '``Monad<'T>``
100+
#if !FABLE_COMPILER
91101
member inline __.While (guard, body: unit -> '``Monad<unit>``) : '``Monad<unit>`` =
92102
let rec loop guard body =
93103
if guard () then body () >>= fun () -> loop guard body
@@ -97,6 +107,7 @@ module Builders =
97107
Using.Invoke (p.GetEnumerator () :> IDisposable) (fun enum ->
98108
let enum = enum :?> IEnumerator<_>
99109
this.While (enum.MoveNext, fun () -> rest enum.Current) : '``Monad<unit>``)
110+
#endif
100111

101112
type MonadPlusBuilder () =
102113
inherit DelayedBuilder()
@@ -130,8 +141,11 @@ module Builders =
130141
/// Makes it a strict monadic computation expression with side-effects
131142
member __.fx' = new MonadFxStrictBuilder ()
132143

144+
#if !FABLE_COMPILER
133145
member inline __.Zero () = result () : '``Monad<unit>``
146+
#endif
134147
member inline __.Combine (a: '``Monad<unit>``, b) = a >>= (fun () -> b) : '``Monad<'T>``
148+
#if !FABLE_COMPILER
135149
member inline __.While (guard, body: '``Monad<unit>``) : '``Monad<unit>`` =
136150
let rec loop guard body =
137151
if guard () then body >>= (fun () -> loop guard body)
@@ -144,6 +158,7 @@ module Builders =
144158
let enum = enum :?> IEnumerator<_>
145159
if isReallyDelayed then this.While (enum.MoveNext, Delay.Invoke (fun () -> rest enum.Current))
146160
else this.strict.While (enum.MoveNext, fun () -> rest enum.Current))
161+
#endif
147162

148163

149164
/// Creates a (lazy) monadic computation expression with side-effects (see http://fsprojects.github.io/FSharpPlus/computation-expressions.html for more information)

src/FSharpPlus/Collection.fs

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,44 @@ open FSharpPlus.Internals
1212

1313
type OfSeq =
1414
inherit Default1
15+
#if !FABLE_COMPILER
1516
static member inline OfSeq (x: seq<'t> , _: '``Foldable'<T>`` , _: Default5) = x |> Seq.map Return.Invoke |> Sum.Invoke : '``Foldable'<T>``
17+
#endif
1618
static member OfSeq (x: seq<'t> , _: seq<'t> , _: Default4) = x
1719
static member OfSeq (x: seq<'t> , _: ICollection<'t> , _: Default4) = let d = ResizeArray () in Seq.iter d.Add x; d :> ICollection<'t>
1820
static member OfSeq (x: seq<'t> , _: IList<'t> , _: Default4) = let d = ResizeArray () in Seq.iter d.Add x; d :> IList<'t>
1921
static member OfSeq (x: seq<'t> , _: IList , _: Default4) = let d = ResizeArray () in Seq.iter d.Add x; d :> IList
22+
23+
#if !FABLE_COMPILER
2024
static member OfSeq (x: seq<'k*'v> , _: IReadOnlyDictionary<'k,'v> , _: Default4) = Dict.toIReadOnlyDictionary (dict x)
2125
static member OfSeq (x: seq<KeyValuePair<'k,'v>>, _: IReadOnlyDictionary<'k,'v> , _: Default4) = x |> Seq.map (|KeyValue|) |> dict |> Dict.toIReadOnlyDictionary
26+
#endif
27+
2228
static member OfSeq (x: seq<'k*'v> , _: IDictionary<'k,'v> , _: Default4) = dict x
2329
static member OfSeq (x: seq<KeyValuePair<'k,'v>>, _: IDictionary<'k,'v> , _: Default4) = x |> Seq.map (|KeyValue|) |> dict
30+
#if !FABLE_COMPILER
2431
static member OfSeq (x: seq<'k*'v> , _: IDictionary , _: Default4) = let d = Hashtable () in x |> Seq.iter d.Add; d :> IDictionary
2532
static member OfSeq (x: seq<KeyValuePair<'k,'v>>, _: IDictionary , _: Default4) = let d = Hashtable () in x |> Seq.iter (function (KeyValue x) -> d.Add x); d :> IDictionary
33+
#endif
2634
static member inline OfSeq (x: seq<'t> , _: 'R , _: Default3) = (^R : (new : seq<'t> -> ^R) x) : 'R
2735
static member inline OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'R , _: Default3) = (^R : (new : seq<'k*'v> -> ^R) (Seq.map (|KeyValue|) x)) : 'R
2836
static member inline OfSeq (x: seq<'t> , _: 'F , _: Default2) = let c = new 'F () in (Seq.iter (fun t -> ( ^F : (member Add : 't -> ^R) c, t) |> ignore) x); c
37+
#if !FABLE_COMPILER
2938
static member OfSeq (x: seq<'t> , _: 'T when 'T :> ICollection<'t> , _: Default1) = let d = new 'T () in x |> Seq.iter d.Add; d
3039
static member OfSeq (x: seq<'k*'v> , _: 'T when 'T :> IDictionary , _: Default1) = let d = new 'T () in x |> Seq.iter d.Add; d
3140
static member OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary , _: Default1) = let d = new 'T () in x |> Seq.iter (function (KeyValue x) -> d.Add x); d
3241
static member OfSeq (x: seq<'k*'v> , _: 'T when 'T :> IDictionary<'k,'v>, _: OfSeq ) = let d = new 'T () in x |> Seq.iter d.Add; d
3342
static member OfSeq (x: seq<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary<'k,'v>, _: OfSeq ) = let d = new 'T () in x |> Seq.iter d.Add; d
43+
#endif
44+
3445
static member inline OfSeq (x: seq<'t> , _: 'UserType , _: OfSeq ) = (^UserType : (static member OfSeq : seq<'t> -> ^UserType) x)
3546
static member OfSeq (x , _: 't [] , _: OfSeq ) = Array.ofSeq<'t> x
3647
static member OfSeq (x , _: 't list , _: OfSeq ) = List.ofSeq<'t> x
3748
static member OfSeq (x: seq<char> , _: string , _: OfSeq ) = String.ofSeq x
3849
static member OfSeq (x: seq<char> , _: Text.StringBuilder , _: OfSeq ) = (StringBuilder (), x) ||> Seq.fold (fun x -> x.Append)
50+
#if !FABLE_COMPILER
3951
static member OfSeq (x: seq<'t> , _: Stack<'t> , _: OfSeq ) = Generic.Stack x
52+
#endif
4053

4154
static member inline Invoke (value: seq<'t>) =
4255
let inline call_2 (a: ^a, b: ^b, s) = ((^a or ^b) : (static member OfSeq : _*_*_ -> _) s, b, a)
@@ -46,31 +59,44 @@ type OfSeq =
4659

4760
type OfList =
4861
inherit Default1
62+
#if !FABLE_COMPILER
4963
static member inline OfList (x: list<'t> , _: '``Foldable'<T>`` , _: Default5) = x |> List.map Return.Invoke |> Sum.Invoke : '``Foldable'<T>``
64+
#endif
5065
static member OfList (x: list<'t> , _: seq<'t> , _: Default4) = List.toSeq x
5166
static member OfList (x: list<'t> , _: ICollection<'t> , _: Default4) = let d = ResizeArray () in List.iter d.Add x; d :> ICollection<'t>
5267
static member OfList (x: list<'t> , _: IList<'t> , _: Default4) = let d = ResizeArray () in List.iter d.Add x; d :> IList<'t>
5368
static member OfList (x: list<'t> , _: IList , _: Default4) = let d = ResizeArray () in List.iter d.Add x; d :> IList
69+
70+
#if !FABLE_COMPILER
5471
static member OfList (x: list<'k*'v> , _: IReadOnlyDictionary<'k,'v> , _: Default4) = Dict.toIReadOnlyDictionary (dict x)
5572
static member OfList (x: list<KeyValuePair<'k,'v>>, _: IReadOnlyDictionary<'k,'v> , _: Default4) = x |> List.map (|KeyValue|) |> dict |> Dict.toIReadOnlyDictionary
73+
#endif
74+
5675
static member OfList (x: list<'k*'v> , _: IDictionary<'k,'v> , _: Default4) = dict x
5776
static member OfList (x: list<KeyValuePair<'k,'v>>, _: IDictionary<'k,'v> , _: Default4) = x |> List.map (|KeyValue|) |> dict
77+
#if !FABLE_COMPILER
5878
static member OfList (x: list<'k*'v> , _: IDictionary , _: Default4) = let d = Hashtable () in x |> List.iter d.Add; d :> IDictionary
5979
static member OfList (x: list<KeyValuePair<'k,'v>>, _: IDictionary , _: Default4) = let d = Hashtable () in x |> List.iter (function (KeyValue x) -> d.Add x); d :> IDictionary
80+
#endif
6081
static member inline OfList (x: list<'t> , _: 'R , _: Default3) = (^R : (new : seq<'t> -> ^R) (List.toSeq x)) : 'R
6182
static member inline OfList (x: list<KeyValuePair<'k,'v>>, _: 'R , _: Default3) = (^R : (new : seq<'k*'v> -> ^R) (Seq.map (|KeyValue|) x)) : 'R
6283
static member inline OfList (x: list<'t> , _: 'F , _: Default2) = let c = new 'F () in (List.iter (fun t -> ( ^F : (member Add : 't -> ^R) c, t) |> ignore) x); c
84+
#if !FABLE_COMPILER
6385
static member OfList (x: list<'t> , _: 'T when 'T :> ICollection<'t> , _: Default1) = let d = new 'T () in x |> List.iter d.Add; d
6486
static member OfList (x: list<'k*'v> , _: 'T when 'T :> IDictionary , _: Default1) = let d = new 'T () in x |> List.iter d.Add; d
6587
static member OfList (x: list<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary , _: Default1) = let d = new 'T () in x |> List.iter (function (KeyValue x) -> d.Add x); d
6688
static member OfList (x: list<'k*'v> , _: 'T when 'T :> IDictionary<'k,'v>, _: OfList ) = let d = new 'T () in x |> List.iter d.Add; d
6789
static member OfList (x: list<KeyValuePair<'k,'v>>, _: 'T when 'T :> IDictionary<'k,'v>, _: OfList ) = let d = new 'T () in x |> List.iter d.Add; d
90+
#endif
91+
6892
static member inline OfList (x: list<'t> , _: 'UserType , _: OfList ) = (^UserType : (static member OfList : list<'t> -> ^UserType) x)
6993
static member OfList (x , _: 't [] , _: OfList ) = Array.ofList<'t> x
7094
static member OfList (x , _: 't list , _: OfList ) = x
7195
static member OfList (x: list<char> , _: string , _: OfList ) = String.ofList x
7296
static member OfList (x: list<char> , _: Text.StringBuilder , _: OfList ) = (StringBuilder (), x) ||> List.fold (fun x -> x.Append)
97+
#if !FABLE_COMPILER
7398
static member OfList (x: list<'t> , _: Stack<'t> , _: OfList ) = Generic.Stack x
99+
#endif
74100

75101
static member inline Invoke (value: list<'t>) =
76102
let inline call_2 (a: ^a, b: ^b, s) = ((^a or ^b) : (static member OfList : _*_*_ -> _) s, b, a)
@@ -217,9 +243,10 @@ type Distinct =
217243
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Distinct : _->_) source) : ^``C<'T>``
218244

219245
static member inline Distinct (x: '``Collection<'T>`` , [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.distinct |> OfSeq.Invoke : '``Collection<'T>``
246+
#if !FABLE_COMPILER
220247
static member inline Distinct (x: ^``Collection<'T>`` , [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Distinct : _->_) x) : '``Collection<'T>``
221248
static member inline Distinct (_: ^t when ^t : null and ^t : struct, _mthd: Default1) = id
222-
249+
#endif
223250

224251
type DistinctBy =
225252
inherit Default1
@@ -290,9 +317,10 @@ type Rev =
290317
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Rev : _->_) source) : ^``C<'T>``
291318

292319
static member inline Rev (x: '``Collection<'T>``, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.rev |> OfSeq.Invoke : '``Collection<'T>``
320+
#if !FABLE_COMPILER
293321
static member inline Rev (x: ^``Collection<'T>``, [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Rev : _->_) x) : '``Collection<'T>``
294322
static member inline Rev (_: ^t when ^t: null and ^t: struct, _mthd: Default1) = id
295-
323+
#endif
296324

297325
type Scan =
298326
static member Scan (x: Id<'T> , f ,z: 'S, [<Optional>]_output: Id<'S> , [<Optional>]_impl: Scan) = Id.create (f z x.getValue)
@@ -319,9 +347,10 @@ type Sort =
319347
static member inline InvokeOnInstance (source: '``C<'T>``) : '``C<'T>`` = (^``C<'T>`` : (static member Sort : _->_) source) : ^``C<'T>``
320348

321349
static member inline Sort (x: '``Collection<'T>``, [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.sort |> OfSeq.Invoke : '``Collection<'T>``
350+
#if !FABLE_COMPILER
322351
static member inline Sort (x: ^``Collection<'T>``, [<Optional>]_impl: Default1) = (^``Collection<'T>`` : (static member Sort : _->_) x) : '``Collection<'T>``
323352
static member inline Sort (_: ^t when ^t: null and ^t: struct, _mthd: Default1) = id
324-
353+
#endif
325354

326355
type SortBy =
327356
inherit Default1
@@ -374,15 +403,18 @@ type Split =
374403
static member Split ((e: StringBuilder [] , x: StringBuilder), [<Optional>]_impl: Split) = x.ToString().Split (e |> Seq.map string |> Seq.toArray, StringSplitOptions.None) |> Array.map StringBuilder
375404
static member Split ((e: StringBuilder list, x: StringBuilder), [<Optional>]_impl: Split) = x.ToString().Split (e |> Seq.map string |> Seq.toArray, StringSplitOptions.None) |> Array.map StringBuilder |> Array.toList
376405

406+
377407
static member inline Invoke (sep: '``'Collection<'OrderedCollection>``) (source: 'OrderedCollection) =
378408
let inline call_2 (a: ^a, b: ^b, s) = ((^a or ^b) : (static member Split : (_*_)*_ -> _) (s, b), a)
379409
let inline call (a: 'a, b: 'b, s) = call_2 (a, b, s)
380410
call (Unchecked.defaultof<Split>, source, sep) : '``'Collection<'OrderedCollection>``
381411

382412
type Split with
383413
static member inline Split ((e: '``'Collection<'OrderedCollection>``, x: '``'OrderedCollection``), [<Optional>]_impl: Default2) = x |> ToSeq.Invoke |> Seq.split (ToSeq.Invoke e) |> Seq.map OfSeq.Invoke |> OfSeq.Invoke : '``'Collection<'OrderedCollection>``
414+
#if !FABLE_COMPILER
384415
static member inline Split ((e: '``'Collection<'OrderedCollection>``, x: '``'OrderedCollection``), [<Optional>]_impl: Default1) = (^``'OrderedCollection`` : (static member Split : _*_->_) e, x) : '``'Collection<'OrderedCollection>``
385416
static member inline Split ((_: ^t when ^t: null and ^t: struct, _ ), _mthd: Default1) = id
417+
#endif
386418

387419

388420
type Intersperse =
@@ -401,9 +433,11 @@ type Intersperse =
401433

402434
type Intercalate =
403435
inherit Default1
436+
#if !FABLE_COMPILER
404437
static member inline Intercalate (x: '``Foldable<'Monoid>``, e: 'Monoid , [<Optional>]_impl: Default2 ) = let f t x = match t, x with (true, _), x -> false, x | (_, acc ), x -> (false, Plus.Invoke (Plus.Invoke acc e) x) in Fold.Invoke f (true, Zero.Invoke ()) x |> snd
405438
static member inline Intercalate (x: seq<'``Foldable<'T>``>, e: '``Foldable<'T>``, [<Optional>]_impl: Default1 ) = x |> Seq.map ToSeq.Invoke |> Seq.intercalate (ToSeq.Invoke e) |> OfSeq.Invoke : '``Foldable<'T>``
406439
static member inline Intercalate (_: seq<'``Foldable<'T>``>, _: ^t when ^t: null and ^t: struct , _: Default1 ) = id
440+
#endif
407441
static member Intercalate (x: seq<list<'T>> , e: list<'T> , [<Optional>]_impl: Intercalate) = List.intercalate e x
408442
static member Intercalate (x: seq<'T []> , e: 'T [] , [<Optional>]_impl: Intercalate) = Array.intercalate e x
409443
static member Intercalate (x: seq<string> , e: string , [<Optional>]_impl: Intercalate) = String.Join (e, x)

src/FSharpPlus/Cont.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ type Cont<'r,'t> with
4343

4444
static member inline Lift (m: '``Monad<'T>``) = Cont ((>>=) m) : ContT<'``Monad<'R>``,'T>
4545

46-
static member inline LiftAsync (x: Async<'T>) = lift (liftAsync x) : ContT<Async<'R>,'T>
4746

47+
#if !FABLE_COMPILER
48+
static member inline LiftAsync (x: Async<'T>) = lift (liftAsync x) : ContT<Async<'R>,'T>
49+
#endif
50+
4851
static member inline get_Ask () = lift ask : '``ContT<'MonadReader<'R,'T>,'R>``
4952
static member inline Local (Cont m, f: 'R1 -> 'R2) : ContT<_,'``MonadReader<R1,'T>,'U``> =
5053
Cont <| fun c -> (ask >>= (fun r -> local f (m (local (konst r) << c))))

0 commit comments

Comments
 (0)