Skip to content

Commit cef7c86

Browse files
authored
+ StructuredFormatDisplay to NonEmptyList
1 parent 1283d35 commit cef7c86

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/FSharpPlus/Data/NonEmptyList.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@ open FSharpPlus.Control
88

99

1010
/// A type-safe list that contains at least one element.
11+
[<StructuredFormatDisplay("{StructuredFormatDisplay}")>]
1112
type NonEmptyList<'t> = {Head: 't; Tail: 't list} with
1213
interface IEnumerable<'t> with member x.GetEnumerator () = (let {Head = x; Tail = xs} = x in seq (x::xs)).GetEnumerator ()
1314
interface System.Collections.IEnumerable with member x.GetEnumerator () = (let {Head = x; Tail = xs} = x in seq (x::xs)).GetEnumerator () :> System.Collections.IEnumerator
1415
interface IReadOnlyCollection<'t> with member s.Count = 1 + List.length s.Tail
1516
interface IReadOnlyList<'t> with member s.Item with get index = s.Item index
1617
interface NonEmptySeq<'t> with member s.First = s.Head
1718

19+
member private this.StructuredFormatDisplay = "nelist {" + (sprintf "%A" (this.Head::this.Tail)).[1..^1] + "}"
20+
1821
[<System.Obsolete("Use Head instead.")>]
1922
member this.head = let {Head = a; Tail = _} = this in a
2023

0 commit comments

Comments
 (0)