gusty / FsControl

[ARCHIVED] FsControl in now included in FSharpPlus https://fsprojects.github.io/FSharpPlus
Apache License 2.0
105 stars 16 forks source link

Replace doesn't work with Enumerables #70

Closed gusty closed 7 years ago

gusty commented 7 years ago

This code fails:

> Replace.Invoke { NonEmptyList.Head =  1; Tail =  [2] } { NonEmptyList.Head =  1; Tail =  [] } { NonEmptyList.Head =  100; Tail =  [200] } ;;

  Replace.Invoke { NonEmptyList.Head =  1; Tail =  [2] } { NonEmptyList.Head =  1; Tail =  [] } { NonEmptyList.Head =  100; Tail =  [200] } ;;
  ---------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

stdin(3,16): error FS0001: This expression was expected to have type
    'NonEmptyList<'a>'    
but here has type
     'seq<'a>'   

Note: NonEmptyList from F#+

gusty commented 7 years ago

Actually it will never work with any Enumerable but that's the correct behavior, because it requires also that the IEnumerable converts back from Seq for instance with the OfSeq method.

The NonEmptyList however can be fixed by adding a specific Replace instance which uses the knowledge that the resulting string will never be empty because the newValue parameter is also NonEmpty.

So the only thing to do in FsControl is to add a method with the right signature which operates using ToSeq and OfSeq.