<commit_before>module TypeAlias where

import String
import Regex exposing (..)
import Types
import Json.Encode as Json

knownDecoders =
    [ "maybe"
    , "list"
    , "int"
    , "float"
    , "bool"
    , "string"
    ]

capitalize : String -> String
capitalize name =
    case String.toList name of
        [] ->
            ""
        x::xs ->
            (String.toUpper (String.fromChar x)) ++ (String.fromList xs)

fieldFormat : (String, String) -> String
fieldFormat (key, typeName) =
    key ++ " : " ++ typeName


aliasFormat : String -> List (String, String) -> String
aliasFormat aliasName fields =
    let
        joinedFields =
            List.map fieldFormat fields
                |> String.join "\n    , "
    in

        String.join ""
            [ "type alias "
            , aliasName
            , " =\n    { "
            , joinedFields
            , "\n    }"
            ]


createTypeAlias : Json.Value -> String -> List String
createTypeAlias stuff aliasName =
    let
        fields : List (String, String, Json.Value)
        fields =
            Types.keys stuff
                |> List.map (\key ->
                    let
                        value =
                            Types.unsafeGet key stuff
                    in
                        (key, Types.suggestType value, value)
                    )

        fixedFields =
            fields
                |> List.map (\(key, typeName, _) ->
                    case typeName of
                        "Something" ->
                            (key, capitalize key)
                        _ ->
                            (key, typeName)
                    )

        update (key, typeName, value) extras =
            case typeName of
                "Something" ->
                    (createTypeAlias value (capitalize key)) ++ extras
                _ ->
                    extras

        extraAliases =
            List.foldl update [] fields
    in
        (aliasFormat aliasName fixedFields) :: extraAliases




getTypeAliasName : String -> Maybe String<commit_msg>only return unique type aliases<commit_after>module TypeAlias where

import String
import Set
import Regex exposing (..)
import Types
import Json.Encode as Json

knownDecoders =
    [ "maybe"
    , "list"
    , "int"
    , "float"
    , "bool"
    , "string"
    ]

capitalize : String -> String
capitalize name =
    case String.toList name of
        [] ->
            ""
        x::xs ->
            (String.toUpper (String.fromChar x)) ++ (String.fromList xs)

fieldFormat : (String, String) -> String
fieldFormat (key, typeName) =
    key ++ " : " ++ typeName


aliasFormat : String -> List (String, String) -> String
aliasFormat aliasName fields =
    let
        joinedFields =
            List.map fieldFormat fields
                |> String.join "\n    , "
    in

        String.join ""
            [ "type alias "
            , aliasName
            , " =\n    { "
            , joinedFields
            , "\n    }"
            ]


createTypeAlias : Json.Value -> String -> List String
createTypeAlias stuff aliasName =
    let
        fields : List (String, String, Json.Value)
        fields =
            Types.keys stuff
                |> List.map (\key ->
                    let
                        value =
                            Types.unsafeGet key stuff
                    in
                        (key, Types.suggestType value, value)
                    )

        fixedFields =
            fields
                |> List.map (\(key, typeName, _) ->
                    case typeName of
                        "Something" ->
                            (key, capitalize key)
                        _ ->
                            (key, typeName)
                    )

        update (key, typeName, value) extras =
            case typeName of
                "Something" ->
                    (createTypeAlias value (capitalize key)) ++ extras
                _ ->
                    extras

        extraAliases =
            List.foldl update [] fields
    in
        (aliasFormat aliasName fixedFields) :: extraAliases
            |> Set.fromList
            |> Set.toList




getTypeAliasName : String -> Maybe String
{'fraction_non_alphanumeric': 0.09191609710110771, 'fraction_numerical': 0.0, 'mean_word_length': 1.161996943453897, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 41, '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': '3170727', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1040, 'n_words': 287}