Skip to content

Commit 6e78058

Browse files
dbrattliclaude
andauthored
fix(beam): handle string binaries in Seq enumerator (#4591)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d4bf3f4 commit 6e78058

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/fable-library-beam/fable_utils.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ get_enumerator(Map) when is_map(Map) ->
153153
get_enumerator({group_collection, Items, _Names}) ->
154154
%% Regex GroupCollection: iterate over the group items list
155155
get_enumerator(Items);
156+
get_enumerator(Bin) when is_binary(Bin) ->
157+
%% String binary used as seq<char>: enumerate Unicode codepoints.
158+
get_enumerator(unicode:characters_to_list(Bin));
156159
get_enumerator(Other) ->
157160
%% Fallback: treat as list
158161
get_enumerator(lists:flatten([Other])).

tests/Beam/StringTests.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,3 +1055,25 @@ let ``test String.forall works`` () =
10551055
"aaa" |> String.forall (fun c -> c = 'a') |> equal true
10561056
"aab" |> String.forall (fun c -> c = 'a') |> equal false
10571057
"" |> String.forall (fun c -> c = 'a') |> equal true
1058+
1059+
[<Fact>]
1060+
let ``test Seq.mapi over string works`` () =
1061+
"Hello"
1062+
|> Seq.mapi (fun _ c -> string c)
1063+
|> String.concat ""
1064+
|> equal "Hello"
1065+
1066+
[<Fact>]
1067+
let ``test Seq.map over string works`` () =
1068+
"abc"
1069+
|> Seq.map (fun c -> string c)
1070+
|> String.concat "-"
1071+
|> equal "a-b-c"
1072+
1073+
[<Fact>]
1074+
let ``test Seq.toList over string works`` () =
1075+
"abc" |> Seq.toList |> equal [ 'a'; 'b'; 'c' ]
1076+
1077+
[<Fact>]
1078+
let ``test Seq.length over string works`` () =
1079+
"Hello" |> Seq.length |> equal 5

0 commit comments

Comments
 (0)