Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Array/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ consTry maybeNewHead list =

-}
andMap : Array a -> Array (a -> b) -> Array b
andMap =
map2 (|>)
andMap x f =
map2 (|>) x f


{-| Apply a function to the elements in the array and collect the result in a List.
Expand Down
74 changes: 39 additions & 35 deletions src/Dict/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ groupBy : (a -> comparable) -> List a -> Dict comparable (List a)
groupBy keyfn list =
List.foldr
(\x acc ->
Dict.update (keyfn x)
(\value ->
value
|> Maybe.map ((::) x)
|> Maybe.withDefault [ x ]
|> Just
)
acc
let
key : comparable
key =
keyfn x
in
case Dict.get key acc of
Nothing ->
Dict.insert key [ x ] acc

Just found ->
Dict.insert key (x :: found) acc
)
Dict.empty
list
Expand Down Expand Up @@ -115,14 +118,12 @@ filterGroupBy keyfn list =
(\x acc ->
case keyfn x of
Just key ->
Dict.update key
(\value ->
value
|> Maybe.map ((::) x)
|> Maybe.withDefault [ x ]
|> Just
)
acc
case Dict.get key acc of
Nothing ->
Dict.insert key [ x ] acc

Just found ->
Dict.insert key (x :: found) acc

Nothing ->
acc
Expand Down Expand Up @@ -195,15 +196,17 @@ fromListByCombining combine keyfn xs =
-}
frequencies : List comparable -> Dict comparable Int
frequencies list =
list
|> List.foldl
(\el counter ->
Dict.get el counter
|> Maybe.withDefault 0
|> (\count -> count + 1)
|> (\count -> Dict.insert el count counter)
)
Dict.empty
List.foldl
(\el counter ->
case Dict.get el counter of
Just count ->
Dict.insert el (count + 1) counter

Nothing ->
Dict.insert el 1 counter
)
Dict.empty
list


{-| Remove elements which satisfies the predicate.
Expand Down Expand Up @@ -251,16 +254,12 @@ returns the element to be inserted.
-}
insertCombining : (v -> v -> v) -> comparable -> v -> Dict comparable v -> Dict comparable v
insertCombining combine key value dict =
let
with mbValue =
case mbValue of
Just oldValue ->
Just <| combine oldValue value
case Dict.get key dict of
Nothing ->
Dict.insert key value dict

Nothing ->
Just value
in
Dict.update key with dict
Just oldValue ->
Dict.insert key (combine oldValue value) dict


{-| Updates a value if the key is present in the dictionary, leaves the dictionary untouched otherwise.
Expand Down Expand Up @@ -317,7 +316,12 @@ keepOnly : Set comparable -> Dict comparable v -> Dict comparable v
keepOnly set dict =
Set.foldl
(\k acc ->
Maybe.withDefault acc <| Maybe.map (\v -> Dict.insert k v acc) (Dict.get k dict)
case Dict.get k dict of
Just found ->
Dict.insert k found acc

Nothing ->
acc
)
Dict.empty
set
Expand Down
14 changes: 3 additions & 11 deletions src/Float/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -267,20 +267,12 @@ roundToDecimal places value =
exp : Float
exp =
10.0 ^ toFloat places

multiplyByExp : Float -> Float
multiplyByExp =
(*) exp

divByExp : Float -> Float
divByExp v =
v / exp
in
value
|> multiplyByExp
((value * exp)
|> round
|> toFloat
|> divByExp
)
/ exp



Expand Down
4 changes: 2 additions & 2 deletions src/Order/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ field selected by the given function.

-}
byField : (a -> comparable) -> a -> a -> Order
byField =
byFieldWith Basics.compare
byField x y =
byFieldWith Basics.compare x y


{-| Produces an ordering that orders its elements using the given ordering on the
Expand Down
8 changes: 4 additions & 4 deletions src/Set/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,14 @@ toggle elem set =
-}
filterMap : (comparable -> Maybe comparable2) -> Set comparable -> Set comparable2
filterMap f xs =
Set.fromList <| Set.foldr (maybeCons f) [] xs
Set.foldr (maybeInsert f) Set.empty xs


maybeCons : (comparable -> Maybe comparable2) -> comparable -> List comparable2 -> List comparable2
maybeCons f mx xs =
maybeInsert : (a -> Maybe comparable) -> a -> Set comparable -> Set comparable
maybeInsert f mx xs =
case f mx of
Just x ->
x :: xs
Set.insert x xs

Nothing ->
xs
Expand Down
41 changes: 21 additions & 20 deletions src/String/Diacritics.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module String.Diacritics exposing (lookupArray, lookupTable, minCode)

import Array exposing (Array)
import Dict exposing (Dict)
import List.Extra


lookupTable : Dict Char String
Expand All @@ -14,28 +15,27 @@ the strings to replace them with.
-}
lookupArray : Array String
lookupArray =
List.range 0 maxCode
|> List.map
(\i ->
case Dict.get (Char.fromCode i) lookupTable of
Nothing ->
String.fromChar (Char.fromCode i)
Array.initialize (maxCode + 1)
(\i ->
case Dict.get (Char.fromCode i) lookupTable of
Nothing ->
String.fromChar (Char.fromCode i)

Just str ->
str
)
|> Array.fromList
Just str ->
str
)


{-| The highest Unicode code point of all the diacritics.
-}
maxCode : Int
maxCode =
lookupList
|> List.map Tuple.first
|> List.map Char.toCode
|> List.maximum
|> Maybe.withDefault maxUnicode
case List.Extra.maximumBy (\( c, _ ) -> Char.toCode c) lookupList of
Just ( c, _ ) ->
Char.toCode c

Nothing ->
maxUnicode


{-| The highest Unicode code point, see
Expand All @@ -50,11 +50,12 @@ maxUnicode =
-}
minCode : Int
minCode =
lookupList
|> List.map Tuple.first
|> List.map Char.toCode
|> List.minimum
|> Maybe.withDefault 0
case List.Extra.minimumBy (\( c, _ ) -> Char.toCode c) lookupList of
Just ( c, _ ) ->
Char.toCode c

Nothing ->
0


lookupList : List ( Char, String )
Expand Down
36 changes: 24 additions & 12 deletions src/String/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,15 @@ surround wrapper string =
unsurround : String -> String -> String
unsurround wrapper string =
if String.startsWith wrapper string && String.endsWith wrapper string then
let
length =
String.length wrapper
in
string
|> String.dropLeft length
|> String.dropRight length
if String.isEmpty wrapper then
string

else
let
length =
String.length wrapper
in
String.slice length -length string

else
string
Expand Down Expand Up @@ -534,14 +536,24 @@ unindent multilineSting =

minLead =
lines
|> List.filter (String.any isNotWhitespace)
|> List.map (countLeadingWhitespace 0)
|> List.filterMap
(\s ->
if String.any isNotWhitespace s then
Just (countLeadingWhitespace 0 s)

else
Nothing
)
|> List.minimum
|> Maybe.withDefault 0
in
lines
|> List.map (String.dropLeft minLead)
|> String.join "\n"
if minLead == 0 then
multilineSting

else
lines
|> List.map (String.dropLeft minLead)
|> String.join "\n"


{-| Return the number of occurrences of a substring in another string.
Expand Down
4 changes: 2 additions & 2 deletions src/Tuple/Extra.elm
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ string, join together two strings in a tuple.

-}
join : appendable -> ( appendable, appendable ) -> appendable
join =
joinBy identity identity
join s ( a, b ) =
a ++ s ++ b


{-| Works just like join, but first converts the values of the tuple to strings.
Expand Down