Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ListCollector #3700

Closed
nojaf opened this issue Jan 19, 2024 · 2 comments
Closed

Support ListCollector #3700

nojaf opened this issue Jan 19, 2024 · 2 comments

Comments

@nojaf
Copy link
Member

nojaf commented Jan 19, 2024

Description

It would be great if Fable could support ListCollector<'T>

Repro code

    let cutOffLast list =
        let mutable headList = ListCollector<'a>()

        let rec visit list =
            match list with
            | []
            | [ _ ] -> ()
            | head :: tail ->
                headList.Add(head)
                visit tail

        visit list
        headList.Close()

Expected and actual results

Expected:

// Something along the lines of
// let mutable headList = ListCollector<'a>()
const headList = [];

// headList.Add(head)
headList.push(head);

// headList.Close()
import { ofArray } from "fable-library/List.js";
ofArray(headList);

Actual: error FABLE: Microsoft.FSharp.Core.CompilerServices.ListCollector1.Close is not supported by Fable`.

Related information

  • Fable version: dotnet fable --version: 4.9.0
  • Operating system: Windows

I might wanna dig into this if approved.

@MangelMaxime
Copy link
Member

It seems to be a small enough type to write Source so fo me it is ok to add it.

Because this is an F# type, what we do in general is we take heavy inspiration from the FSharp.Core implementation and include it inside of the fable-library folder. For example, this is what we did for StringBuilder.

The only things I have question about is that ListCollector is using RuntimeHelpers.FreshConsNoTail which is defined as:

let inline FreshConsNoTail head = head :: (# "ldnull" : 'T list #)

so it is emitting IL code and we will not be able to do that same goes for SetFreshConsTail. But I don't think this is blocking.

@nojaf nojaf mentioned this issue Feb 8, 2024
@ncave
Copy link
Collaborator

ncave commented Feb 20, 2024

Closing as implemented by #3745, feel free to reopen if needed.

@ncave ncave closed this as completed Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants