@@ -130,9 +130,19 @@ module NonEmptyList =
130130 | h:: t -> cons s ( tails { Head = h; Tail = t})
131131
132132#if ! FABLE_ COMPILER || FABLE_ COMPILER_ 3
133- let inline traverse ( f : 'T -> '``Functor < 'U > ``) ( s : NonEmptyList < 'T >) =
134- let lst = traverse f ( toList s) : '`` Functor<'List<'U>> ``
133+
134+ /// <summary>
135+ /// Maps each element of the list to an action, evaluates these actions from left to right and collect the results.
136+ /// </summary>
137+ let inline traverse ( f : 'T -> '``Functor < 'U > ``) ( source : NonEmptyList < 'T >) =
138+ let lst = traverse f ( toList source) : '`` Functor<'List<'U>> ``
135139 ( create << List.head |> fun f x -> f x ( List.tail x)) <!> lst : '`` Functor<NonEmptyList<'U>> ``
140+
141+ /// <summary>
142+ /// Evaluates each action in the list from left to right and collect the results.
143+ /// </summary>
144+ let inline sequence ( source : NonEmptyList < '``Functor < 'T > ``>) : '``Functor < NonEmptyList < 'T >> `` = traverse id source
145+
136146#endif
137147
138148 /// <summary>Returns the average of the elements in the list.</summary>
@@ -255,7 +265,10 @@ type NonEmptyList<'t> with
255265 static member ToSeq ( s : NonEmptyList < 'a >, [<Optional>] _impl : ToSeq ) = NonEmptyList.toList s |> List.toSeq
256266
257267 [<EditorBrowsable( EditorBrowsableState.Never) >]
258- static member inline Traverse ( s : NonEmptyList < 'T >, f : 'T -> '``Functor < 'U > ``) : '``Functor < NonEmptyList < 'U >> `` = NonEmptyList.traverse f s
268+ static member inline Traverse ( s : NonEmptyList < 'T >, f : 'T -> '``Functor < 'U > ``) : '``Functor < NonEmptyList < 'U >> `` = NonEmptyList.traverse f s
269+
270+ [<EditorBrowsable( EditorBrowsableState.Never) >]
271+ static member inline Sequence ( s : NonEmptyList < '``Functor < 'T > ``>) : '``Functor < NonEmptyList < 'T >> `` = NonEmptyList.sequence s
259272
260273 static member Replace ( source : NonEmptyList < 'T >, oldValue : NonEmptyList < 'T >, newValue : NonEmptyList < 'T >, _impl : Replace ) =
261274 let lst = source |> NonEmptyList.toSeq |> Seq.replace oldValue newValue |> Seq.toList
0 commit comments