davedawkins/Sutil

Bind.each requires F# list instead of array

Closed this issue · 5 comments

Hello. I've been attempting to write a sample app using this, and was wondering about Bind.each requiring an F# list instead of the more general seq. As I understand Fable, F# lists get transpiled using a special list.js helper library from fable, instead of the native JavaScript array, whereas .Net arrays do get transpiled to JS arrays.

Is there a specific reason Bind.each requires a list? I would like to be able to use the JS array in my fable app, both for familiarity on how it behaves, as well as avoiding the extra import if possible.

e.g.:

    let tags: IStore<string array> = Store.make [| "one"; "two" |]
    let otherTags: IStore<string list> = Store.make [ "one"; "two" ]

    Html.div [
        disposeOnUnmount [
            tags
            otherTags
        ]
        Bind.each (tags, (fun tag -> Html.div [ text tag ])) // This one is compiler error
        Bind.each (otherTags, (fun tag -> Html.div [ text tag ])) // This one works

    ]

thanks

This is just my inexperience with F# showing through. I made the same observation myself a couple of weeks ago, and I'll fix the API. Thanks for reporting.

Probably a seq, array, and list overloads would be nice to have, I've been hitting these recently as well

As I understand it, a single seq overload will cover all the others. At worst, it can be specified as #seq

OK.. I tried this and of course, we have not just list<'T> but IObservable<list<'T>>. I was able to make everything compile with IObservable<#seq<'T>>, but the compiler really wasn't happy about and then the samples no longer worked.
So..I need to think a little more.

This is now working with both Lists and Arrays. I kind of made a DIY typeclass, which I might throw out to the #fsharp community so they can tell me exactly why that was a bad idea and how to do it better. The main this, this works now, and will be in the next release