anchor.diff:          /// Convertes a generic sequence to a sequence of seperated string
           /// use write afterwards to save to file
   
  -        static member inline toCSVwith (separator:string) (header:bool) (data:'a seq) (formatFunctionsFst: string -> 'b -> (obj -> string)) (formatFunctionsRest: string -> 'b -> (obj -> string)) (formatFunctionHeader: string -> 'b -> string -> string) =
  -
  +        static member inline CSVwith (separator: string) (valFunc: 'a -> ('a -> obj)[]) (strFunc:string -> bool -> obj -> (obj -> string)) (header: bool) (flatten: bool) (data: seq<'a>)=
  +            
  +            let inline toPrettyHeaderString sep input fieldName flatten =
  +                let o = box input
  +                match o with
  +                | :? string       -> fieldName
  +                | :? System.Enum  -> fieldName
  +                | :? System.Collections.IEnumerable as e -> 
  +                    if flatten then
  +                        let count = seq {for i in e do yield i.ToString() } |> Seq.length
  +                        seq { for c = 1 to count do yield (sprintf "%s%i" fieldName c) } |> String.concat sep
  +                    else
  +                        fieldName
  +                | _               -> fieldName
  +        
  +            let valFuncs =
  +                let firstElement = data |> Seq.head
  +                valFunc firstElement
  +        
  +            let values =
  +                data
  +                |> Seq.map (fun entry ->
  +                    valFuncs
  +                    |> Seq.map (fun func -> func entry)
  +                    )
  +            let strFuncs : seq<(obj -> string)> =
  +                let firstElement = values |> Seq.head
  +                firstElement
  +                |> Seq.map (fun x -> strFunc separator flatten x)
  +            
               seq {
                   let dataType=typeof<'a>
  -
  +        
                   if header && (Seq.length(data) > 0) then
                       let (firstElement: 'a) = Seq.head data
  +                    //let ty2 = firstElement.GetType()
                       let header =
                           match dataType with
                           // simple value type to string
  
positive.code:                         | ty when ty = typeof<System.Enum> -> dataType.Name
                          // array type to string
                          | ty when ty.IsArray ->
                              data |> Seq.map (fun x -> formatFunctionHeader separator (box x) dataType.Name) |> String.concat separator
                          | ty when ty = typeof<System.Enum> -> dataType.Name
                          // union type
                          | ty when FSharpType.IsUnion ty -> dataType.Name
                          // record type
  
negative.code:                             let fields = Reflection.FSharpType.GetRecordFields(dataType)
                                           |> Array.map (fun field -> FSharpValue.GetRecordField(firstElement, field), field.Name)
                              fields
                              |> Seq.map(fun (field,name) -> toPrettyHeaderString separator field name flatten)
                              |> String.concat separator
                          // tuple type
                          | ty when FSharpType.IsTuple ty ->
                              if flatten then
                                  FSharpType.GetTupleElements dataType
                                  |> Seq.mapi (fun idx info -> (sprintf "%s_%i" info.Name idx) ) |> String.concat separator
                              else
                                  FSharpType.GetTupleElements dataType
                                  |> Seq.mapi (fun idx info -> (sprintf "%s_%i_Tuple" info.Name idx) ) |> String.concat "_"
                          // objects
                          | _ -> dataType.GetProperties()
                                 |> Seq.map (fun info -> info.Name) |> String.concat separator
                      yield header
          
          
                  let strings =
                      values
                      |> Seq.map (fun x ->
                          let sb =
                              let stringBuilder = new System.Text.StringBuilder()
                              stringBuilder.Append ((Seq.head strFuncs)(Seq.head x)) |> ignore
                              (Seq.tail x)
                              |> Seq.fold2 (fun (sb: System.Text.StringBuilder) (func: obj -> string) value ->
                                  sb.AppendFormat (sprintf "%s{0}" separator, (func value))
                                  ) stringBuilder (Seq.tail strFuncs)
          
                          let res = sb.ToString()
                          sb.Clear() |> ignore
                          res
                          )
                  yield! strings
              }