Auto fetch emoji list

This commit is contained in:
2022-02-19 13:59:43 +01:00
parent 5077d09594
commit 2900823554
6 changed files with 164 additions and 1534 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -9,7 +9,7 @@ import Html
import Html.Attributes
import Html.Events
import Json.Decode as Decode
import Levenshtein
import Levenshtein exposing (distance)
main =
@@ -58,15 +58,16 @@ modelEmojis model =
Search s ->
Emoji.categories
|> List.concatMap Emoji.getEmojis
|> List.map (\x -> ( x, minimum ( Levenshtein.distance s x.name, List.map (\v -> Levenshtein.distance s v + 1) x.tags ) ))
|> List.sortBy Tuple.second
|> List.map Emoji.getEmojis
|> doubleMap (\x -> ( x, distance s x.name ))
|> List.map (List.sortBy Tuple.second)
|> mergeBy Tuple.second
|> List.map Tuple.first
init : () -> ( Model, Cmd Msg )
init _ =
( Category Emoji.Recent, Cmd.none )
( Category Emoji.Smileys, Cmd.none )
type Msg
@@ -236,3 +237,44 @@ onEnter msg =
)
)
)
mergeAux : (a -> comparable) -> List a -> List a -> List a
mergeAux comparator listOne listTwo =
case ( listOne, listTwo ) of
( _, [] ) ->
listOne
( [], _ ) ->
listTwo
( frontOne :: restOne, frontTwo :: restTwo ) ->
if comparator frontOne < comparator frontTwo then
frontOne :: mergeAux comparator restOne listTwo
else
frontTwo :: mergeAux comparator listOne restTwo
mergeBy : (a -> comparable) -> List (List a) -> List a
mergeBy comparator input =
case input of
[] ->
[]
[ [] ] ->
[]
[ a ] ->
a
[ a, b ] ->
mergeAux comparator a b
a :: b :: t ->
mergeBy comparator (mergeAux comparator a b :: t)
doubleMap : (a -> b) -> List (List a) -> List (List b)
doubleMap map input =
List.map (\x -> List.map map x) input