Auto fetch emoji list
This commit is contained in:
1525
elm/Emoji.elm
1525
elm/Emoji.elm
File diff suppressed because it is too large
Load Diff
52
elm/Main.elm
52
elm/Main.elm
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user