<commit_before>module Array

open Fable.Core

type ArrayCons =
    [<Emit("new $0($1)")>]
    abstract Create: capacity: int -> 'T array
    [<Emit("$0.from($1)")>]
    abstract From: 'T seq -> 'T array

let map (f: 'T->'U) (source: 'T[]) (cons: ArrayCons) =
    let len = source.Length
    let target = cons.Create(len)
    for i = 0 to (len - 1) do
        target.[i] <- f source.[i]
    target<commit_msg>Start working on #1323: fable-core/Array module migration to .fs<commit_after>module Array

open Fable.Core

type ArrayCons =
    [<Emit("new $0($1)")>]
    abstract Create: capacity: int -> 'T array
    [<Emit("$0.from($1)")>]
    abstract From: 'T seq -> 'T array

let mapIndexed (f: int -> 'T -> 'U) (source: 'T[]) (cons: ArrayCons) =
    let len = source.Length
    let target = cons.Create(len)
    for i = 0 to (len - 1) do
        target.[i] <- f i source.[i]
    target

let map (f: 'T -> 'U) (source: 'T[]) (cons: ArrayCons) =
    // TODO: Should we involve currying and re-use mapIndexed here?
    // Don't quite know yet how is it optimized so can't decide on performance vs code reuse.
    // mapIndexed (fun _ x -> f x) source

    let len = source.Length
    let target = cons.Create(len)
    for i = 0 to (len - 1) do
        target.[i] <- f source.[i]
    target

let indexed (source: 'T[]) (cons: ArrayCons) =
    // TODO: How do we get concrete instance of ArrayCons for dynamic JS Arrays creation?
    // Passing as a parameter for now.
    source |> mapIndexed (fun i x -> i, x) <| cons;
{'fraction_non_alphanumeric': 0.1551155115511551, 'fraction_numerical': 0.011881188118811881, 'mean_word_length': 2.644230769230769, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973563', 'n_tokens_mistral': 541, 'n_tokens_neox': 523, 'n_words': 193}