<commit_before>﻿namespace IronJS

open System
open System.Reflection

///
module FSharp =

  ///
  module Char =
    let isDigit c = c >= '0' && c <= '9'

  ///
  module Utils =
    
    let toTrue _ = true
    let toFalse _ = false

    let print = printf "%s"
    let printn = printfn "%s"

    let inline refEq (a:obj) (b:obj) = Object.ReferenceEquals(a, b)
    let inline refNotEq a b = refEq a b |> not

    let inline isNull (a:obj) = Object.ReferenceEquals(a, null)
    let inline notNull (a:obj) = Object.ReferenceEquals(a, null) |> not

    let inline isSubClass (a:Type) (b:Type) = b.IsSubclassOf a
    let inline isSubClassT<'a> (b:Type) = isSubClass typeof<'a> b

    let inline isType (a:Type) (b:Type) = refEq a b || isSubClass a b
    let inline isTypeT<'a> (b:Type) = isType typeof<'a> b

    let inline isVoid (t:Type) = refEq typeof<Void> t
    let inline isNaNOrInf (d:double) = Double.IsNaN d || Double.IsInfinity d

    let inline isSameType a b = refEq a b
    let inline isSameTypeT<'a, 'b> = isSameType typeof<'a> typeof<'b>

  ///
  module Seq =
    
    ///
    let first seq' = Seq.find Utils.toTrue seq'

  ///
  module List =
    
    ///
    let headOr (f:Lazy<'a>) lst =
      match lst with
      | [] -> f.Value
      | x::_ -> x

  ///
  module Array =

    ///
    let copyRange (startAt:int) (length:int) (source:'a array) =
      if startAt >= source.Length then
        Array.zeroCreate<'a> 0

      else
        let length = System.Math.Min(length, source.Length-startAt)
        let target = Array.zeroCreate<'a> length
        System.Array.Copy(source, startAt, target, 0, length)
        target

    ///
    let copyFrom (startAt:int) (source:'a array) =
      source |> copyRange startAt source.Length

    ///
    let shrink (head:int) (tail:int) (source:'a array) =
      let head = System.Math.Max(head, 0)
      let tail = System.Math.Max(tail, 0)
      if head+tail >= source.Length 
        then Array.zeroCreate<'a> 0
        else source |> copyRange head (source.Length-head-tail)

    ///
    let shrinkStart (head:int) (source:'a array) =
      source |> shrink head 0

    ///
    let shrinkEnd (tail:int) (source:'a array) =
      source |> shrink 0 tail
      <commit_msg>Added more utility methods for working with Array<commit_after>﻿namespace IronJS

open System
open System.Reflection

///
module FSharp =

  ///
  module Char =
    let isDigit c = c >= '0' && c <= '9'

  ///
  module Utils =
    
    let toTrue _ = true
    let toFalse _ = false

    let print = printf "%s"
    let printn = printfn "%s"

    let inline refEq (a:obj) (b:obj) = Object.ReferenceEquals(a, b)
    let inline refNotEq a b = refEq a b |> not

    let inline isNull (a:obj) = Object.ReferenceEquals(a, null)
    let inline notNull (a:obj) = Object.ReferenceEquals(a, null) |> not

    let inline isSubClass (a:Type) (b:Type) = b.IsSubclassOf a
    let inline isSubClassT<'a> (b:Type) = isSubClass typeof<'a> b

    let inline isType (a:Type) (b:Type) = refEq a b || isSubClass a b
    let inline isTypeT<'a> (b:Type) = isType typeof<'a> b

    let inline isVoid (t:Type) = refEq typeof<Void> t
    let inline isNaNOrInf (d:double) = Double.IsNaN d || Double.IsInfinity d

    let inline isSameType a b = refEq a b
    let inline isSameTypeT<'a, 'b> = isSameType typeof<'a> typeof<'b>

  ///
  module Seq =
    
    ///
    let first seq' = Seq.find Utils.toTrue seq'

  ///
  module List =
    
    ///
    let headOr (f:Lazy<'a>) lst =
      match lst with
      | [] -> f.Value
      | x::_ -> x

  ///
  module Array =

    ///
    let copyRange (startAt:int) (length:int) (source:'a array) =
      if startAt >= source.Length then
        Array.zeroCreate<'a> 0

      else
        let length = System.Math.Min(length, source.Length-startAt)
        let target = Array.zeroCreate<'a> length
        System.Array.Copy(source, startAt, target, 0, length)
        target

    ///
    let expand (size:int) (front:bool) (source:'a array) =
      let newLength = source.Length + size
      let target = Array.zeroCreate<'a> newLength

      if front 
        then System.Array.Copy(source, 0, target, size, source.Length)
        else System.Array.Copy(source, 0, target, 0, source.Length)

      target

    ///
    let expandFront size source = 
      source |> expand size true

    ///
    let expandBack size source = 
      source |> expand size false

    ///
    let copyFrom (startAt:int) (source:'a array) =
      source |> copyRange startAt source.Length

    ///
    let shrink (head:int) (tail:int) (source:'a array) =
      let head = System.Math.Max(head, 0)
      let tail = System.Math.Max(tail, 0)
      if head+tail >= source.Length 
        then Array.zeroCreate<'a> 0
        else source |> copyRange head (source.Length-head-tail)

    ///
    let shrinkStart (head:int) (source:'a array) =
      source |> shrink head 0

    ///
    let shrinkEnd (tail:int) (source:'a array) =
      source |> shrink 0 tail
      
{'fraction_non_alphanumeric': 0.1301989150090416, 'fraction_numerical': 0.004219409282700422, 'mean_word_length': 2.307641196013289, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 52, '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': '469557', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1680, 'n_words': 502}