You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/FSharpPlus/Control/Traversable.fs
+18-7
Original file line number
Diff line number
Diff line change
@@ -81,8 +81,8 @@ type Traverse =
81
81
static member inlineTraverse(t:option<_>,f,[<Optional>]_output:'R,[<Optional>]_impl:Traverse):'R =match t with Some x -> Map.Invoke Some (f x)|_-> result None
82
82
83
83
static member inlineTraverse(t:Map<_,_>,f,[<Optional>]_output:'R,[<Optional>]_impl:Traverse):'R =
84
-
letinsert_fk x ys = Map.Invoke (Map.add k)(f x)<*>ys
85
-
Map.foldBack insert_f t (result Map.empty)
84
+
letinsert_fm k v = Map.Invoke (Map.add k)v <*>m
85
+
Map.fold insert_f (result Map.empty)(Map.mapValues f t)
86
86
87
87
static member inlineTraverse(t:Result<'T,'Error>,f:'T->'``Functor<'U>``,[<Optional>]_output:'``Functor<Result<'U,'Error>>``,[<Optional>]_impl:Traverse):'``Functor<Result<'U,'Error>>`` =
88
88
match t with
@@ -95,13 +95,24 @@ type Traverse =
95
95
| Choice2Of2 e -> Return.Invoke (Choice<'U,'Error>.Choice2Of2 e)
96
96
97
97
static member inlineTraverse(t:list<_>,f ,[<Optional>]_output:'R,[<Optional>]_impl:Traverse):'R =
98
-
letcons_f x ys = Map.Invoke List.cons (f x)<*> ys
99
-
List.foldBack cons_f t (result [])
98
+
let recloop acc =function
99
+
|[]-> acc
100
+
| x::xs ->
101
+
letv= f x
102
+
loop (v::acc) xs
103
+
letcons_f x xs = Map.Invoke List.cons xs <*> x
104
+
List.fold cons_f (result [])(loop [] t)
100
105
101
106
static member inlineTraverse(t:_ [],f ,[<Optional>]_output:'R,[<Optional>]_impl:Traverse):'R =
102
-
letcons x y = Array.append [|x|] y
103
-
letcons_f x ys = Map.Invoke cons (f x)<*> ys
104
-
Array.foldBack cons_f t (result [||])
107
+
letcons x y = Array.append [|x|] y
108
+
let recloop acc =function
109
+
|[||]-> acc
110
+
| xxs ->
111
+
letx,xs = Array.head xxs, Array.tail xxs
112
+
letv= f x
113
+
loop (cons v acc) xs
114
+
letcons_f x xs = Map.Invoke cons xs <*> x
115
+
Array.fold cons_f (result [||])(loop [||] t)
105
116
106
117
static member inlineInvoke(f:'T->'``Functor<'U>``)(t:'``Traversable<'T>``):'``Functor<'Traversable<'U>>`` =
107
118
let inlinecall_3(a:^a,b:^b,c:^c,f)=((^aor^bor^c):(static memberTraverse:_*_*_*_->_) b, f, c, a)
0 commit comments