mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
roc format examples
This commit is contained in:
parent
7ed35eca50
commit
7908e8c176
32 changed files with 231 additions and 232 deletions
|
@ -5,8 +5,8 @@ quicksort = \list, low, high ->
|
||||||
when partition low high list is
|
when partition low high list is
|
||||||
Pair partitionIndex partitioned ->
|
Pair partitionIndex partitioned ->
|
||||||
partitioned
|
partitioned
|
||||||
|> quicksort low (partitionIndex - 1)
|
|> quicksort low (partitionIndex - 1)
|
||||||
|> quicksort (partitionIndex + 1) high
|
|> quicksort (partitionIndex + 1) high
|
||||||
|
|
||||||
|
|
||||||
swap : Nat, Nat, List a -> List a
|
swap : Nat, Nat, List a -> List a
|
||||||
|
@ -14,8 +14,8 @@ swap = \i, j, list ->
|
||||||
when Pair (List.get list i) (List.get list j) is
|
when Pair (List.get list i) (List.get list j) is
|
||||||
Pair (Ok atI) (Ok atJ) ->
|
Pair (Ok atI) (Ok atJ) ->
|
||||||
list
|
list
|
||||||
|> List.set i atJ
|
|> List.set i atJ
|
||||||
|> List.set j atI
|
|> List.set j atI
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -7,8 +7,8 @@ quicksort = \originalList ->
|
||||||
when partition low high list is
|
when partition low high list is
|
||||||
Pair partitionIndex partitioned ->
|
Pair partitionIndex partitioned ->
|
||||||
partitioned
|
partitioned
|
||||||
|> quicksortHelp low (partitionIndex - 1)
|
|> quicksortHelp low (partitionIndex - 1)
|
||||||
|> quicksortHelp (partitionIndex + 1) high
|
|> quicksortHelp (partitionIndex + 1) high
|
||||||
else
|
else
|
||||||
list
|
list
|
||||||
|
|
||||||
|
@ -18,8 +18,8 @@ quicksort = \originalList ->
|
||||||
when Pair (List.get list i) (List.get list j) is
|
when Pair (List.get list i) (List.get list j) is
|
||||||
Pair (Ok atI) (Ok atJ) ->
|
Pair (Ok atI) (Ok atJ) ->
|
||||||
list
|
list
|
||||||
|> List.set i atJ
|
|> List.set i atJ
|
||||||
|> List.set j atI
|
|> List.set j atI
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -40,8 +40,8 @@ const ROC_LIST_MAP_WITH_INDEX: &str = indoc::indoc!(
|
||||||
main : List I64 -> Nat
|
main : List I64 -> Nat
|
||||||
main = \list ->
|
main = \list ->
|
||||||
list
|
list
|
||||||
|> List.mapWithIndex (\x, _ -> x + 2)
|
|> List.mapWithIndex (\x, _ -> x + 2)
|
||||||
|> List.len
|
|> List.len
|
||||||
"#
|
"#
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -572,8 +572,8 @@ fn quicksort_help() {
|
||||||
(Pair partitionIndex partitioned) = Pair 0 []
|
(Pair partitionIndex partitioned) = Pair 0 []
|
||||||
|
|
||||||
partitioned
|
partitioned
|
||||||
|> quicksortHelp low (partitionIndex - 1)
|
|> quicksortHelp low (partitionIndex - 1)
|
||||||
|> quicksortHelp (partitionIndex + 1) high
|
|> quicksortHelp (partitionIndex + 1) high
|
||||||
else
|
else
|
||||||
list
|
list
|
||||||
|
|
||||||
|
@ -591,8 +591,8 @@ fn quicksort_swap() {
|
||||||
when Pair (List.get list 0) (List.get list 0) is
|
when Pair (List.get list 0) (List.get list 0) is
|
||||||
Pair (Ok atI) (Ok atJ) ->
|
Pair (Ok atI) (Ok atJ) ->
|
||||||
list
|
list
|
||||||
|> List.set 0 atJ
|
|> List.set 0 atJ
|
||||||
|> List.set 0 atI
|
|> List.set 0 atI
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
|
|
@ -14,8 +14,8 @@ quicksortHelp = \list, low, high ->
|
||||||
when partition low high list is
|
when partition low high list is
|
||||||
Pair partitionIndex partitioned ->
|
Pair partitionIndex partitioned ->
|
||||||
partitioned
|
partitioned
|
||||||
|> quicksortHelp low (partitionIndex - 1)
|
|> quicksortHelp low (partitionIndex - 1)
|
||||||
|> quicksortHelp (partitionIndex + 1) high
|
|> quicksortHelp (partitionIndex + 1) high
|
||||||
else
|
else
|
||||||
list
|
list
|
||||||
|
|
||||||
|
@ -50,8 +50,8 @@ swap = \i, j, list ->
|
||||||
when Pair (List.get list i) (List.get list j) is
|
when Pair (List.get list i) (List.get list j) is
|
||||||
Pair (Ok atI) (Ok atJ) ->
|
Pair (Ok atI) (Ok atJ) ->
|
||||||
list
|
list
|
||||||
|> List.set i atJ
|
|> List.set i atJ
|
||||||
|> List.set j atI
|
|> List.set j atI
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
# to prevent a decrement on list
|
# to prevent a decrement on list
|
||||||
|
|
|
@ -21,17 +21,17 @@ initialModel = \start -> {
|
||||||
cheapestOpen : (position -> F64), Model position -> Result position {}
|
cheapestOpen : (position -> F64), Model position -> Result position {}
|
||||||
cheapestOpen = \costFn, model ->
|
cheapestOpen = \costFn, model ->
|
||||||
model.openSet
|
model.openSet
|
||||||
|> Set.toList
|
|> Set.toList
|
||||||
|> List.keepOks
|
|> List.keepOks
|
||||||
(\position ->
|
(\position ->
|
||||||
when Dict.get model.costs position is
|
when Dict.get model.costs position is
|
||||||
Err _ -> Err {}
|
Err _ -> Err {}
|
||||||
Ok cost -> Ok { cost: cost + costFn position, position }
|
Ok cost -> Ok { cost: cost + costFn position, position }
|
||||||
)
|
)
|
||||||
|> Quicksort.sortBy .cost
|
|> Quicksort.sortBy .cost
|
||||||
|> List.first
|
|> List.first
|
||||||
|> Result.map .position
|
|> Result.map .position
|
||||||
|> Result.mapErr (\_ -> {})
|
|> Result.mapErr (\_ -> {})
|
||||||
|
|
||||||
reconstructPath : Dict position position, position -> List position
|
reconstructPath : Dict position position, position -> List position
|
||||||
reconstructPath = \cameFrom, goal ->
|
reconstructPath = \cameFrom, goal ->
|
||||||
|
@ -49,8 +49,8 @@ updateCost = \current, neighbor, model ->
|
||||||
|
|
||||||
distanceTo =
|
distanceTo =
|
||||||
reconstructPath newCameFrom neighbor
|
reconstructPath newCameFrom neighbor
|
||||||
|> List.len
|
|> List.len
|
||||||
|> Num.toFrac
|
|> Num.toFrac
|
||||||
|
|
||||||
newModel =
|
newModel =
|
||||||
{ model &
|
{ model &
|
||||||
|
|
|
@ -63,23 +63,23 @@ bitsToCharsHelp = \bits, missing ->
|
||||||
# any 6-bit number is a valid base64 digit, so this is actually safe
|
# any 6-bit number is a valid base64 digit, so this is actually safe
|
||||||
p =
|
p =
|
||||||
Num.shiftRightZfBy 18 bits
|
Num.shiftRightZfBy 18 bits
|
||||||
|> Num.intCast
|
|> Num.intCast
|
||||||
|> unsafeToChar
|
|> unsafeToChar
|
||||||
|
|
||||||
q =
|
q =
|
||||||
Num.bitwiseAnd (Num.shiftRightZfBy 12 bits) lowest6BitsMask
|
Num.bitwiseAnd (Num.shiftRightZfBy 12 bits) lowest6BitsMask
|
||||||
|> Num.intCast
|
|> Num.intCast
|
||||||
|> unsafeToChar
|
|> unsafeToChar
|
||||||
|
|
||||||
r =
|
r =
|
||||||
Num.bitwiseAnd (Num.shiftRightZfBy 6 bits) lowest6BitsMask
|
Num.bitwiseAnd (Num.shiftRightZfBy 6 bits) lowest6BitsMask
|
||||||
|> Num.intCast
|
|> Num.intCast
|
||||||
|> unsafeToChar
|
|> unsafeToChar
|
||||||
|
|
||||||
s =
|
s =
|
||||||
Num.bitwiseAnd bits lowest6BitsMask
|
Num.bitwiseAnd bits lowest6BitsMask
|
||||||
|> Num.intCast
|
|> Num.intCast
|
||||||
|> unsafeToChar
|
|> unsafeToChar
|
||||||
|
|
||||||
equals : U8
|
equals : U8
|
||||||
equals = 61
|
equals = 61
|
||||||
|
|
|
@ -8,15 +8,15 @@ InvalidChar : U8
|
||||||
toBytes : Str -> List U8
|
toBytes : Str -> List U8
|
||||||
toBytes = \str ->
|
toBytes = \str ->
|
||||||
str
|
str
|
||||||
|> Str.toUtf8
|
|> Str.toUtf8
|
||||||
|> encodeChunks
|
|> encodeChunks
|
||||||
|> Bytes.Encode.sequence
|
|> Bytes.Encode.sequence
|
||||||
|> Bytes.Encode.encode
|
|> Bytes.Encode.encode
|
||||||
|
|
||||||
encodeChunks : List U8 -> List Encoder
|
encodeChunks : List U8 -> List Encoder
|
||||||
encodeChunks = \bytes ->
|
encodeChunks = \bytes ->
|
||||||
List.walk bytes { output: [], accum: None } folder
|
List.walk bytes { output: [], accum: None } folder
|
||||||
|> encodeResidual
|
|> encodeResidual
|
||||||
|
|
||||||
coerce : Nat, a -> a
|
coerce : Nat, a -> a
|
||||||
coerce = \_, x -> x
|
coerce = \_, x -> x
|
||||||
|
|
|
@ -49,7 +49,7 @@ encode = \encoder ->
|
||||||
output = List.repeat 0 (getWidth encoder)
|
output = List.repeat 0 (getWidth encoder)
|
||||||
|
|
||||||
encodeHelp encoder 0 output
|
encodeHelp encoder 0 output
|
||||||
|> .output
|
|> .output
|
||||||
|
|
||||||
encodeHelp : Encoder, Nat, List U8 -> { output : List U8, offset : Nat }
|
encodeHelp : Encoder, Nat, List U8 -> { output : List U8, offset : Nat }
|
||||||
encodeHelp = \encoder, offset, output ->
|
encodeHelp = \encoder, offset, output ->
|
||||||
|
@ -80,13 +80,13 @@ encodeHelp = \encoder, offset, output ->
|
||||||
when endianness is
|
when endianness is
|
||||||
BE ->
|
BE ->
|
||||||
output
|
output
|
||||||
|> List.set (offset + 0) a
|
|> List.set (offset + 0) a
|
||||||
|> List.set (offset + 1) b
|
|> List.set (offset + 1) b
|
||||||
|
|
||||||
LE ->
|
LE ->
|
||||||
output
|
output
|
||||||
|> List.set (offset + 0) b
|
|> List.set (offset + 0) b
|
||||||
|> List.set (offset + 1) a
|
|> List.set (offset + 1) a
|
||||||
|
|
||||||
{
|
{
|
||||||
output: newOutput,
|
output: newOutput,
|
||||||
|
@ -104,13 +104,13 @@ encodeHelp = \encoder, offset, output ->
|
||||||
when endianness is
|
when endianness is
|
||||||
BE ->
|
BE ->
|
||||||
output
|
output
|
||||||
|> List.set (offset + 0) a
|
|> List.set (offset + 0) a
|
||||||
|> List.set (offset + 1) b
|
|> List.set (offset + 1) b
|
||||||
|
|
||||||
LE ->
|
LE ->
|
||||||
output
|
output
|
||||||
|> List.set (offset + 0) b
|
|> List.set (offset + 0) b
|
||||||
|> List.set (offset + 1) a
|
|> List.set (offset + 1) a
|
||||||
|
|
||||||
{
|
{
|
||||||
output: newOutput,
|
output: newOutput,
|
||||||
|
|
|
@ -14,10 +14,10 @@ main =
|
||||||
optimized = eval (constFolding (reassoc e))
|
optimized = eval (constFolding (reassoc e))
|
||||||
|
|
||||||
unoptimized
|
unoptimized
|
||||||
|> Num.toStr
|
|> Num.toStr
|
||||||
|> Str.concat " & "
|
|> Str.concat " & "
|
||||||
|> Str.concat (Num.toStr optimized)
|
|> Str.concat (Num.toStr optimized)
|
||||||
|> Task.putLine
|
|> Task.putLine
|
||||||
|
|
||||||
Expr : [
|
Expr : [
|
||||||
Add Expr Expr,
|
Add Expr Expr,
|
||||||
|
|
|
@ -13,7 +13,7 @@ main = closure1 {}
|
||||||
closure1 : {} -> Task.Task {} []
|
closure1 : {} -> Task.Task {} []
|
||||||
closure1 = \_ ->
|
closure1 = \_ ->
|
||||||
Task.succeed (foo toUnitBorrowed "a long string such that it's malloced")
|
Task.succeed (foo toUnitBorrowed "a long string such that it's malloced")
|
||||||
|> Task.map (\_ -> {})
|
|> Task.map \_ -> {}
|
||||||
|
|
||||||
toUnitBorrowed = \x -> Str.countGraphemes x
|
toUnitBorrowed = \x -> Str.countGraphemes x
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ main =
|
||||||
f = pow x x
|
f = pow x x
|
||||||
|
|
||||||
nest deriv n f # original koka n = 10
|
nest deriv n f # original koka n = 10
|
||||||
|> Task.map (\_ -> {})
|
|> Task.map \_ -> {}
|
||||||
|
|
||||||
nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
|
nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
|
||||||
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp
|
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp
|
||||||
|
@ -160,8 +160,8 @@ deriv = \i, f ->
|
||||||
fprime = d "x" f
|
fprime = d "x" f
|
||||||
line =
|
line =
|
||||||
Num.toStr (i + 1)
|
Num.toStr (i + 1)
|
||||||
|> Str.concat " count: "
|
|> Str.concat " count: "
|
||||||
|> Str.concat (Num.toStr (count fprime))
|
|> Str.concat (Num.toStr (count fprime))
|
||||||
|
|
||||||
Task.putLine line
|
Task.putLine line
|
||||||
|> Task.after \_ -> Task.succeed fprime
|
|> Task.after \_ -> Task.succeed fprime
|
||||||
|
|
|
@ -9,8 +9,8 @@ main =
|
||||||
Task.getInt
|
Task.getInt
|
||||||
\n ->
|
\n ->
|
||||||
queens n # original koka 13
|
queens n # original koka 13
|
||||||
|> Num.toStr
|
|> Num.toStr
|
||||||
|> Task.putLine
|
|> Task.putLine
|
||||||
|
|
||||||
ConsList a : [Nil, Cons a (ConsList a)]
|
ConsList a : [Nil, Cons a (ConsList a)]
|
||||||
|
|
||||||
|
|
|
@ -7,8 +7,8 @@ show = \list ->
|
||||||
else
|
else
|
||||||
content =
|
content =
|
||||||
list
|
list
|
||||||
|> List.map Num.toStr
|
|> List.map Num.toStr
|
||||||
|> Str.joinWith ", "
|
|> Str.joinWith ", "
|
||||||
|
|
||||||
"[\(content)]"
|
"[\(content)]"
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ quicksortHelp = \list, order, low, high ->
|
||||||
when partition low high list order is
|
when partition low high list order is
|
||||||
Pair partitionIndex partitioned ->
|
Pair partitionIndex partitioned ->
|
||||||
partitioned
|
partitioned
|
||||||
|> quicksortHelp order low (Num.subSaturated partitionIndex 1)
|
|> quicksortHelp order low (Num.subSaturated partitionIndex 1)
|
||||||
|> quicksortHelp order (partitionIndex + 1) high
|
|> quicksortHelp order (partitionIndex + 1) high
|
||||||
else
|
else
|
||||||
list
|
list
|
||||||
|
|
||||||
|
@ -68,8 +68,8 @@ swap = \i, j, list ->
|
||||||
when Pair (List.get list i) (List.get list j) is
|
when Pair (List.get list i) (List.get list j) is
|
||||||
Pair (Ok atI) (Ok atJ) ->
|
Pair (Ok atI) (Ok atJ) ->
|
||||||
list
|
list
|
||||||
|> List.set i atJ
|
|> List.set i atJ
|
||||||
|> List.set j atI
|
|> List.set j atI
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -52,8 +52,8 @@ main =
|
||||||
val = fold (\_, v, r -> if v then r + 1 else r) head 0
|
val = fold (\_, v, r -> if v then r + 1 else r) head 0
|
||||||
|
|
||||||
val
|
val
|
||||||
|> Num.toStr
|
|> Num.toStr
|
||||||
|> Task.putLine
|
|> Task.putLine
|
||||||
|
|
||||||
Nil ->
|
Nil ->
|
||||||
Task.putLine "fail"
|
Task.putLine "fail"
|
||||||
|
|
|
@ -20,8 +20,8 @@ main =
|
||||||
val = fold (\_, v, r -> if v then r + 1 else r) m 0
|
val = fold (\_, v, r -> if v then r + 1 else r) m 0
|
||||||
|
|
||||||
val
|
val
|
||||||
|> Num.toStr
|
|> Num.toStr
|
||||||
|> Task.putLine
|
|> Task.putLine
|
||||||
|
|
||||||
boom : Str -> a
|
boom : Str -> a
|
||||||
boom = \_ -> boom ""
|
boom = \_ -> boom ""
|
||||||
|
|
|
@ -9,8 +9,8 @@ main =
|
||||||
tree = insert 0 {} Empty
|
tree = insert 0 {} Empty
|
||||||
|
|
||||||
tree
|
tree
|
||||||
|> show
|
|> show
|
||||||
|> Task.putLine
|
|> Task.putLine
|
||||||
|
|
||||||
show : RedBlackTree I64 {} -> Str
|
show : RedBlackTree I64 {} -> Str
|
||||||
show = \tree -> showRBTree tree Num.toStr (\{} -> "{}")
|
show = \tree -> showRBTree tree Num.toStr (\{} -> "{}")
|
||||||
|
|
|
@ -8,11 +8,11 @@ forever : Task val err -> Task * err
|
||||||
forever = \task ->
|
forever = \task ->
|
||||||
looper = \{} ->
|
looper = \{} ->
|
||||||
task
|
task
|
||||||
|> Effect.map
|
|> Effect.map
|
||||||
\res ->
|
\res ->
|
||||||
when res is
|
when res is
|
||||||
Ok _ -> Step {}
|
Ok _ -> Step {}
|
||||||
Err e -> Done (Err e)
|
Err e -> Done (Err e)
|
||||||
|
|
||||||
Effect.loop {} looper
|
Effect.loop {} looper
|
||||||
|
|
||||||
|
@ -20,12 +20,12 @@ loop : state, (state -> Task [Step state, Done done] err) -> Task done err
|
||||||
loop = \state, step ->
|
loop = \state, step ->
|
||||||
looper = \current ->
|
looper = \current ->
|
||||||
step current
|
step current
|
||||||
|> Effect.map
|
|> Effect.map
|
||||||
\res ->
|
\res ->
|
||||||
when res is
|
when res is
|
||||||
Ok (Step newState) -> Step newState
|
Ok (Step newState) -> Step newState
|
||||||
Ok (Done result) -> Done (Ok result)
|
Ok (Done result) -> Done (Ok result)
|
||||||
Err e -> Done (Err e)
|
Err e -> Done (Err e)
|
||||||
|
|
||||||
Effect.loop state looper
|
Effect.loop state looper
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ update = \model, event ->
|
||||||
tick : Model -> Model
|
tick : Model -> Model
|
||||||
tick = \model ->
|
tick = \model ->
|
||||||
model
|
model
|
||||||
|> moveBall
|
|> moveBall
|
||||||
|
|
||||||
moveBall : Model -> Model
|
moveBall : Model -> Model
|
||||||
moveBall = \model ->
|
moveBall = \model ->
|
||||||
|
@ -99,12 +99,12 @@ render = \model ->
|
||||||
\index ->
|
\index ->
|
||||||
col =
|
col =
|
||||||
Num.rem index numCols
|
Num.rem index numCols
|
||||||
|> Num.toF32
|
|> Num.toF32
|
||||||
|
|
||||||
row =
|
row =
|
||||||
index
|
index
|
||||||
// numCols
|
// numCols
|
||||||
|> Num.toF32
|
|> Num.toF32
|
||||||
|
|
||||||
red = col / Num.toF32 numCols
|
red = col / Num.toF32 numCols
|
||||||
green = row / Num.toF32 numRows
|
green = row / Num.toF32 numRows
|
||||||
|
|
|
@ -90,8 +90,8 @@ translate = \child, toChild, toParent ->
|
||||||
Button config label ->
|
Button config label ->
|
||||||
onPress = \parentState, event ->
|
onPress = \parentState, event ->
|
||||||
toChild parentState
|
toChild parentState
|
||||||
|> config.onPress event
|
|> config.onPress event
|
||||||
|> Action.map \c -> toParent parentState c
|
|> Action.map \c -> toParent parentState c
|
||||||
|
|
||||||
Button { onPress } (translate label toChild toParent)
|
Button { onPress } (translate label toChild toParent)
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ list = \renderChild, parent, toChildren, toParent ->
|
||||||
toChild
|
toChild
|
||||||
\par, ch ->
|
\par, ch ->
|
||||||
toChildren par
|
toChildren par
|
||||||
|> List.set ch index
|
|> List.set ch index
|
||||||
|> toParent
|
|> toParent
|
||||||
|
|
||||||
renderChild newChild
|
renderChild newChild
|
||||||
|
|
||||||
|
@ -165,8 +165,8 @@ translateOrDrop = \child, toChild, toParent ->
|
||||||
when toChild parentState is
|
when toChild parentState is
|
||||||
Ok newChild ->
|
Ok newChild ->
|
||||||
newChild
|
newChild
|
||||||
|> config.onPress event
|
|> config.onPress event
|
||||||
|> Action.map \c -> toParent parentState c
|
|> Action.map \c -> toParent parentState c
|
||||||
|
|
||||||
Err _ ->
|
Err _ ->
|
||||||
# The child was removed from the list before this onPress handler resolved.
|
# The child was removed from the list before this onPress handler resolved.
|
||||||
|
@ -182,7 +182,7 @@ translateOrDrop = \child, toChild, toParent ->
|
||||||
when toChild parentState is
|
when toChild parentState is
|
||||||
Ok newChild ->
|
Ok newChild ->
|
||||||
renderChild newChild
|
renderChild newChild
|
||||||
|> translateOrDrop toChild toParent
|
|> translateOrDrop toChild toParent
|
||||||
|
|
||||||
Err _ ->
|
Err _ ->
|
||||||
None
|
None
|
||||||
|
|
|
@ -21,7 +21,7 @@ InterpreterErrors : [BadUtf8, DivByZero, EmptyStack, InvalidBooleanValue, Invali
|
||||||
main : Str -> Task {} []
|
main : Str -> Task {} []
|
||||||
main = \filename ->
|
main = \filename ->
|
||||||
interpretFile filename
|
interpretFile filename
|
||||||
|> Task.onFail (\StringErr e -> Stdout.line "Ran into problem:\n\(e)\n")
|
|> Task.onFail \StringErr e -> Stdout.line "Ran into problem:\n\(e)\n"
|
||||||
|
|
||||||
interpretFile : Str -> Task {} [StringErr Str]
|
interpretFile : Str -> Task {} [StringErr Str]
|
||||||
interpretFile = \filename ->
|
interpretFile = \filename ->
|
||||||
|
@ -70,19 +70,19 @@ interpretFile = \filename ->
|
||||||
isDigit : U8 -> Bool
|
isDigit : U8 -> Bool
|
||||||
isDigit = \char ->
|
isDigit = \char ->
|
||||||
char
|
char
|
||||||
>= 0x30 # `0`
|
>= 0x30 # `0`
|
||||||
&& char
|
&& char
|
||||||
<= 0x39 # `0`
|
<= 0x39 # `0`
|
||||||
isWhitespace : U8 -> Bool
|
isWhitespace : U8 -> Bool
|
||||||
isWhitespace = \char ->
|
isWhitespace = \char ->
|
||||||
char
|
char
|
||||||
== 0xA # new line
|
== 0xA # new line
|
||||||
|| char
|
|| char
|
||||||
== 0xB # carriage return
|
== 0xB # carriage return
|
||||||
|| char
|
|| char
|
||||||
== 0x20 # space
|
== 0x20 # space
|
||||||
|| char
|
|| char
|
||||||
== 0x9 # tab
|
== 0x9 # tab
|
||||||
interpretCtx : Context -> Task Context InterpreterErrors
|
interpretCtx : Context -> Task Context InterpreterErrors
|
||||||
interpretCtx = \ctx ->
|
interpretCtx = \ctx ->
|
||||||
Task.loop ctx interpretCtxLoop
|
Task.loop ctx interpretCtxLoop
|
||||||
|
|
|
@ -9,8 +9,8 @@ Variable := U8
|
||||||
totalCount : Nat
|
totalCount : Nat
|
||||||
totalCount =
|
totalCount =
|
||||||
0x7A # "z"
|
0x7A # "z"
|
||||||
- 0x61 # "a"
|
- 0x61 # "a"
|
||||||
+ 1
|
+ 1
|
||||||
|
|
||||||
toStr : Variable -> Str
|
toStr : Variable -> Str
|
||||||
toStr = \@Variable char ->
|
toStr = \@Variable char ->
|
||||||
|
@ -22,10 +22,9 @@ fromUtf8 : U8 -> Result Variable [InvalidVariableUtf8]
|
||||||
fromUtf8 = \char ->
|
fromUtf8 = \char ->
|
||||||
if
|
if
|
||||||
char
|
char
|
||||||
>= 0x61 # "a"
|
>= 0x61 # "a"
|
||||||
&& char
|
&& char
|
||||||
<= 0x7A
|
<= 0x7A # "z"
|
||||||
# "z"
|
|
||||||
then
|
then
|
||||||
Ok (@Variable char)
|
Ok (@Variable char)
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,8 +13,8 @@ chunk = \@Handle handle -> Effect.after (Effect.getFileBytes handle) Task.succee
|
||||||
open : Str -> Task.Task Handle *
|
open : Str -> Task.Task Handle *
|
||||||
open = \path ->
|
open = \path ->
|
||||||
Effect.openFile path
|
Effect.openFile path
|
||||||
|> Effect.map (\id -> @Handle id)
|
|> Effect.map (\id -> @Handle id)
|
||||||
|> Effect.after Task.succeed
|
|> Effect.after Task.succeed
|
||||||
|
|
||||||
close : Handle -> Task.Task {} *
|
close : Handle -> Task.Task {} *
|
||||||
close = \@Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed
|
close = \@Handle handle -> Effect.after (Effect.closeFile handle) Task.succeed
|
||||||
|
|
|
@ -8,12 +8,12 @@ loop : state, (state -> Task [Step state, Done done] err) -> Task done err
|
||||||
loop = \state, step ->
|
loop = \state, step ->
|
||||||
looper = \current ->
|
looper = \current ->
|
||||||
step current
|
step current
|
||||||
|> Effect.map
|
|> Effect.map
|
||||||
\res ->
|
\res ->
|
||||||
when res is
|
when res is
|
||||||
Ok (Step newState) -> Step newState
|
Ok (Step newState) -> Step newState
|
||||||
Ok (Done result) -> Done (Ok result)
|
Ok (Done result) -> Done (Ok result)
|
||||||
Err e -> Done (Err e)
|
Err e -> Done (Err e)
|
||||||
|
|
||||||
Effect.loop state looper
|
Effect.loop state looper
|
||||||
|
|
||||||
|
|
|
@ -90,8 +90,8 @@ translate = \child, toChild, toParent ->
|
||||||
Button config label ->
|
Button config label ->
|
||||||
onPress = \parentState, event ->
|
onPress = \parentState, event ->
|
||||||
toChild parentState
|
toChild parentState
|
||||||
|> config.onPress event
|
|> config.onPress event
|
||||||
|> Action.map \c -> toParent parentState c
|
|> Action.map \c -> toParent parentState c
|
||||||
|
|
||||||
Button { onPress } (translate label toChild toParent)
|
Button { onPress } (translate label toChild toParent)
|
||||||
|
|
||||||
|
@ -136,8 +136,8 @@ list = \renderChild, parent, toChildren, toParent ->
|
||||||
toChild
|
toChild
|
||||||
\par, ch ->
|
\par, ch ->
|
||||||
toChildren par
|
toChildren par
|
||||||
|> List.set ch index
|
|> List.set ch index
|
||||||
|> toParent
|
|> toParent
|
||||||
|
|
||||||
renderChild newChild
|
renderChild newChild
|
||||||
|
|
||||||
|
@ -165,8 +165,8 @@ translateOrDrop = \child, toChild, toParent ->
|
||||||
when toChild parentState is
|
when toChild parentState is
|
||||||
Ok newChild ->
|
Ok newChild ->
|
||||||
newChild
|
newChild
|
||||||
|> config.onPress event
|
|> config.onPress event
|
||||||
|> Action.map \c -> toParent parentState c
|
|> Action.map \c -> toParent parentState c
|
||||||
|
|
||||||
Err _ ->
|
Err _ ->
|
||||||
# The child was removed from the list before this onPress handler resolved.
|
# The child was removed from the list before this onPress handler resolved.
|
||||||
|
@ -182,7 +182,7 @@ translateOrDrop = \child, toChild, toParent ->
|
||||||
when toChild parentState is
|
when toChild parentState is
|
||||||
Ok newChild ->
|
Ok newChild ->
|
||||||
renderChild newChild
|
renderChild newChild
|
||||||
|> translateOrDrop toChild toParent
|
|> translateOrDrop toChild toParent
|
||||||
|
|
||||||
Err _ ->
|
Err _ ->
|
||||||
None
|
None
|
||||||
|
|
|
@ -226,37 +226,37 @@ append = \@Path prefix, @Path suffix ->
|
||||||
NoInteriorNul suffixBytes ->
|
NoInteriorNul suffixBytes ->
|
||||||
# Neither prefix nor suffix had interior nuls, so the answer won't either
|
# Neither prefix nor suffix had interior nuls, so the answer won't either
|
||||||
List.append prefixBytes suffixBytes
|
List.append prefixBytes suffixBytes
|
||||||
|> NoInteriorNul
|
|> NoInteriorNul
|
||||||
|
|
||||||
ArbitraryBytes suffixBytes ->
|
ArbitraryBytes suffixBytes ->
|
||||||
List.append prefixBytes suffixBytes
|
List.append prefixBytes suffixBytes
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
FromStr suffixStr ->
|
FromStr suffixStr ->
|
||||||
# Append suffixStr by writing it to the end of prefixBytes
|
# Append suffixStr by writing it to the end of prefixBytes
|
||||||
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
ArbitraryBytes prefixBytes ->
|
ArbitraryBytes prefixBytes ->
|
||||||
when suffix is
|
when suffix is
|
||||||
ArbitraryBytes suffixBytes | NoInteriorNul suffixBytes ->
|
ArbitraryBytes suffixBytes | NoInteriorNul suffixBytes ->
|
||||||
List.append prefixBytes suffixBytes
|
List.append prefixBytes suffixBytes
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
FromStr suffixStr ->
|
FromStr suffixStr ->
|
||||||
# Append suffixStr by writing it to the end of prefixBytes
|
# Append suffixStr by writing it to the end of prefixBytes
|
||||||
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
FromStr prefixStr ->
|
FromStr prefixStr ->
|
||||||
when suffix is
|
when suffix is
|
||||||
ArbitraryBytes suffixBytes | NoInteriorNul suffixBytes ->
|
ArbitraryBytes suffixBytes | NoInteriorNul suffixBytes ->
|
||||||
List.append (Str.toUtf8 prefixStr) suffixBytes
|
List.append (Str.toUtf8 prefixStr) suffixBytes
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
FromStr suffixStr ->
|
FromStr suffixStr ->
|
||||||
Str.append prefixStr suffixStr
|
Str.append prefixStr suffixStr
|
||||||
|> FromStr
|
|> FromStr
|
||||||
|
|
||||||
@Path content
|
@Path content
|
||||||
|
|
||||||
|
@ -267,11 +267,11 @@ appendStr = \@Path prefix, suffixStr ->
|
||||||
NoInteriorNul prefixBytes | ArbitraryBytes prefixBytes ->
|
NoInteriorNul prefixBytes | ArbitraryBytes prefixBytes ->
|
||||||
# Append suffixStr by writing it to the end of prefixBytes
|
# Append suffixStr by writing it to the end of prefixBytes
|
||||||
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
Str.writeUtf8 suffixStr prefixBytes (List.len prefixBytes)
|
||||||
|> ArbitraryBytes
|
|> ArbitraryBytes
|
||||||
|
|
||||||
FromStr prefixStr ->
|
FromStr prefixStr ->
|
||||||
Str.append prefixStr suffixStr
|
Str.append prefixStr suffixStr
|
||||||
|> FromStr
|
|> FromStr
|
||||||
|
|
||||||
@Path content
|
@Path content
|
||||||
|
|
||||||
|
@ -354,9 +354,9 @@ withExtension = \@Path path, extension ->
|
||||||
Err NotFound -> list
|
Err NotFound -> list
|
||||||
|
|
||||||
beforeDot
|
beforeDot
|
||||||
|> List.reserve (1 + List.len bytes)
|
|> List.reserve (1 + List.len bytes)
|
||||||
|> List.append '.'
|
|> List.append '.'
|
||||||
|> List.concat bytes
|
|> List.concat bytes
|
||||||
|
|
||||||
FromStr str ->
|
FromStr str ->
|
||||||
beforeDot =
|
beforeDot =
|
||||||
|
@ -365,9 +365,9 @@ withExtension = \@Path path, extension ->
|
||||||
Err NotFound -> str
|
Err NotFound -> str
|
||||||
|
|
||||||
beforeDot
|
beforeDot
|
||||||
|> Str.reserve (1 + Str.byteCount str)
|
|> Str.reserve (1 + Str.byteCount str)
|
||||||
|> Str.append "."
|
|> Str.append "."
|
||||||
|> Str.concat str
|
|> Str.concat str
|
||||||
|
|
||||||
# NOTE: no withExtensionBytes because it's too narrow. If you really need to get some
|
# NOTE: no withExtensionBytes because it's too narrow. If you really need to get some
|
||||||
# non-Unicode in there, do it with
|
# non-Unicode in there, do it with
|
||||||
|
|
|
@ -5,5 +5,5 @@ interface Stdin
|
||||||
line : Task Str * [Read [Stdin]*]*
|
line : Task Str * [Read [Stdin]*]*
|
||||||
line =
|
line =
|
||||||
Effect.getLine
|
Effect.getLine
|
||||||
|> Effect.map Ok
|
|> Effect.map Ok
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
|
@ -5,4 +5,4 @@ interface Stdout
|
||||||
line : Str -> Task {} * [Write [Stdout]*]*
|
line : Str -> Task {} * [Write [Stdout]*]*
|
||||||
line = \str ->
|
line = \str ->
|
||||||
Effect.map (Effect.putLine str) (\_ -> Ok {})
|
Effect.map (Effect.putLine str) (\_ -> Ok {})
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
|
@ -8,40 +8,40 @@ forever : Task val err fx -> Task * err fx
|
||||||
forever = \task ->
|
forever = \task ->
|
||||||
looper = \{} ->
|
looper = \{} ->
|
||||||
task
|
task
|
||||||
|> InternalTask.toEffect
|
|> InternalTask.toEffect
|
||||||
|> Effect.map
|
|> Effect.map
|
||||||
\res ->
|
\res ->
|
||||||
when res is
|
when res is
|
||||||
Ok _ -> Step {}
|
Ok _ -> Step {}
|
||||||
Err e -> Done (Err e)
|
Err e -> Done (Err e)
|
||||||
|
|
||||||
Effect.loop {} looper
|
Effect.loop {} looper
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
||||||
loop : state, (state -> Task [Step state, Done done] err fx) -> Task done err fx
|
loop : state, (state -> Task [Step state, Done done] err fx) -> Task done err fx
|
||||||
loop = \state, step ->
|
loop = \state, step ->
|
||||||
looper = \current ->
|
looper = \current ->
|
||||||
step current
|
step current
|
||||||
|> InternalTask.toEffect
|
|> InternalTask.toEffect
|
||||||
|> Effect.map
|
|> Effect.map
|
||||||
\res ->
|
\res ->
|
||||||
when res is
|
when res is
|
||||||
Ok (Step newState) -> Step newState
|
Ok (Step newState) -> Step newState
|
||||||
Ok (Done result) -> Done (Ok result)
|
Ok (Done result) -> Done (Ok result)
|
||||||
Err e -> Done (Err e)
|
Err e -> Done (Err e)
|
||||||
|
|
||||||
Effect.loop state looper
|
Effect.loop state looper
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
||||||
succeed : val -> Task val * *
|
succeed : val -> Task val * *
|
||||||
succeed = \val ->
|
succeed = \val ->
|
||||||
Effect.always (Ok val)
|
Effect.always (Ok val)
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
||||||
fail : err -> Task * err *
|
fail : err -> Task * err *
|
||||||
fail = \val ->
|
fail = \val ->
|
||||||
Effect.always (Err val)
|
Effect.always (Err val)
|
||||||
|> InternalTask.fromEffect
|
|> InternalTask.fromEffect
|
||||||
|
|
||||||
attempt : Task a b fx, (Result a b -> Task c d fx) -> Task c d fx
|
attempt : Task a b fx, (Result a b -> Task c d fx) -> Task c d fx
|
||||||
attempt = \task, transform ->
|
attempt = \task, transform ->
|
||||||
|
|
|
@ -104,17 +104,17 @@ append = \@Url urlStr, suffixUnencoded ->
|
||||||
Ok { before, after } ->
|
Ok { before, after } ->
|
||||||
bytes =
|
bytes =
|
||||||
Str.countUtf8Bytes before
|
Str.countUtf8Bytes before
|
||||||
+ 1 # for "/"
|
+ 1 # for "/"
|
||||||
+ Str.countUtf8Bytes suffix
|
+ Str.countUtf8Bytes suffix
|
||||||
+ 1 # for "?"
|
+ 1 # for "?"
|
||||||
+ Str.countUtf8Bytes after
|
+ Str.countUtf8Bytes after
|
||||||
|
|
||||||
before
|
before
|
||||||
|> Str.reserve bytes
|
|> Str.reserve bytes
|
||||||
|> appendHelp suffix
|
|> appendHelp suffix
|
||||||
|> Str.concat "?"
|
|> Str.concat "?"
|
||||||
|> Str.concat after
|
|> Str.concat after
|
||||||
|> @Url
|
|> @Url
|
||||||
|
|
||||||
Err NotFound ->
|
Err NotFound ->
|
||||||
# There wasn't a query, but there might still be a fragment
|
# There wasn't a query, but there might still be a fragment
|
||||||
|
@ -122,17 +122,17 @@ append = \@Url urlStr, suffixUnencoded ->
|
||||||
Ok { before, after } ->
|
Ok { before, after } ->
|
||||||
bytes =
|
bytes =
|
||||||
Str.countUtf8Bytes before
|
Str.countUtf8Bytes before
|
||||||
+ 1 # for "/"
|
+ 1 # for "/"
|
||||||
+ Str.countUtf8Bytes suffix
|
+ Str.countUtf8Bytes suffix
|
||||||
+ 1 # for "#"
|
+ 1 # for "#"
|
||||||
+ Str.countUtf8Bytes after
|
+ Str.countUtf8Bytes after
|
||||||
|
|
||||||
before
|
before
|
||||||
|> Str.reserve bytes
|
|> Str.reserve bytes
|
||||||
|> appendHelp suffix
|
|> appendHelp suffix
|
||||||
|> Str.concat "#"
|
|> Str.concat "#"
|
||||||
|> Str.concat after
|
|> Str.concat after
|
||||||
|> @Url
|
|> @Url
|
||||||
|
|
||||||
Err NotFound ->
|
Err NotFound ->
|
||||||
# No query and no fragment, so just append it
|
# No query and no fragment, so just append it
|
||||||
|
@ -169,8 +169,8 @@ appendHelp = \prefix, suffix ->
|
||||||
else
|
else
|
||||||
# Neither is empty, but neither has a "/", so add one in between.
|
# Neither is empty, but neither has a "/", so add one in between.
|
||||||
prefix
|
prefix
|
||||||
|> Str.concat "/"
|
|> Str.concat "/"
|
||||||
|> Str.concat suffix
|
|> Str.concat suffix
|
||||||
|
|
||||||
## Internal helper. This is intentionally unexposed so that you don't accidentally
|
## Internal helper. This is intentionally unexposed so that you don't accidentally
|
||||||
## double-encode things. If you really want to percent-encode an arbitrary string,
|
## double-encode things. If you really want to percent-encode an arbitrary string,
|
||||||
|
@ -194,30 +194,30 @@ percentEncode = \input ->
|
||||||
# Spec for percent-encoding: https://www.ietf.org/rfc/rfc3986.txt
|
# Spec for percent-encoding: https://www.ietf.org/rfc/rfc3986.txt
|
||||||
if
|
if
|
||||||
(byte >= 97 && byte <= 122) # lowercase ASCII
|
(byte >= 97 && byte <= 122) # lowercase ASCII
|
||||||
|| (byte >= 65 && byte <= 90) # uppercase ASCII
|
|| (byte >= 65 && byte <= 90) # uppercase ASCII
|
||||||
|| (byte >= 48 && byte <= 57) # digit
|
|| (byte >= 48 && byte <= 57) # digit
|
||||||
then
|
then
|
||||||
# This is the most common case: an unreserved character,
|
# This is the most common case: an unreserved character,
|
||||||
# which needs no encoding in a path
|
# which needs no encoding in a path
|
||||||
Str.appendScalar output (Num.toU32 byte)
|
Str.appendScalar output (Num.toU32 byte)
|
||||||
|> Result.withDefault "" # this will never fail
|
|> Result.withDefault "" # this will never fail
|
||||||
else
|
else
|
||||||
when byte is
|
when byte is
|
||||||
46 # '.'
|
46 # '.'
|
||||||
| 95 # '_'
|
| 95 # '_'
|
||||||
| 126 # '~'
|
| 126 # '~'
|
||||||
| 150 -> # '-'
|
| 150 -> # '-'
|
||||||
# These special characters can all be unescaped in paths
|
# These special characters can all be unescaped in paths
|
||||||
Str.appendScalar output (Num.toU32 byte)
|
Str.appendScalar output (Num.toU32 byte)
|
||||||
|> Result.withDefault "" # this will never fail
|
|> Result.withDefault "" # this will never fail
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
# This needs encoding in a path
|
# This needs encoding in a path
|
||||||
suffix =
|
suffix =
|
||||||
Str.toUtf8 percentEncoded
|
Str.toUtf8 percentEncoded
|
||||||
|> List.sublist { len: 3, start: 3 * Num.toNat byte }
|
|> List.sublist { len: 3, start: 3 * Num.toNat byte }
|
||||||
|> Str.fromUtf8
|
|> Str.fromUtf8
|
||||||
|> Result.withDefault "" # This will never fail
|
|> Result.withDefault "" # This will never fail
|
||||||
|
|
||||||
Str.concat output suffix
|
Str.concat output suffix
|
||||||
|
|
||||||
|
@ -251,20 +251,20 @@ appendParam = \@Url urlStr, key, value ->
|
||||||
|
|
||||||
bytes =
|
bytes =
|
||||||
Str.countUtf8Bytes withoutFragment
|
Str.countUtf8Bytes withoutFragment
|
||||||
+ 1 # for "?" or "&"
|
+ 1 # for "?" or "&"
|
||||||
+ Str.countUtf8Bytes encodedKey
|
+ Str.countUtf8Bytes encodedKey
|
||||||
+ 1 # for "="
|
+ 1 # for "="
|
||||||
+ Str.countUtf8Bytes encodedValue
|
+ Str.countUtf8Bytes encodedValue
|
||||||
+ Str.countUtf8Bytes afterQuery
|
+ Str.countUtf8Bytes afterQuery
|
||||||
|
|
||||||
withoutFragment
|
withoutFragment
|
||||||
|> Str.reserve bytes
|
|> Str.reserve bytes
|
||||||
|> Str.concat (if hasQuery (@Url withoutFragment) then "&" else "?")
|
|> Str.concat (if hasQuery (@Url withoutFragment) then "&" else "?")
|
||||||
|> Str.concat encodedKey
|
|> Str.concat encodedKey
|
||||||
|> Str.concat "="
|
|> Str.concat "="
|
||||||
|> Str.concat encodedValue
|
|> Str.concat encodedValue
|
||||||
|> Str.concat afterQuery
|
|> Str.concat afterQuery
|
||||||
|> @Url
|
|> @Url
|
||||||
|
|
||||||
## Replaces the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
## Replaces the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
||||||
## the `?`, if it has one, but before any `#` it might have.
|
## the `?`, if it has one, but before any `#` it might have.
|
||||||
|
@ -300,16 +300,16 @@ withQuery = \@Url urlStr, queryStr ->
|
||||||
else
|
else
|
||||||
bytes =
|
bytes =
|
||||||
Str.countUtf8Bytes beforeQuery
|
Str.countUtf8Bytes beforeQuery
|
||||||
+ 1 # for "?"
|
+ 1 # for "?"
|
||||||
+ Str.countUtf8Bytes queryStr
|
+ Str.countUtf8Bytes queryStr
|
||||||
+ Str.countUtf8Bytes afterQuery
|
+ Str.countUtf8Bytes afterQuery
|
||||||
|
|
||||||
beforeQuery
|
beforeQuery
|
||||||
|> Str.reserve bytes
|
|> Str.reserve bytes
|
||||||
|> Str.concat "?"
|
|> Str.concat "?"
|
||||||
|> Str.concat queryStr
|
|> Str.concat queryStr
|
||||||
|> Str.concat afterQuery
|
|> Str.concat afterQuery
|
||||||
|> @Url
|
|> @Url
|
||||||
|
|
||||||
## Returns the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
## Returns the URL's [query](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
||||||
## the `?`, if it has one, but before any `#` it might have.
|
## the `?`, if it has one, but before any `#` it might have.
|
||||||
|
@ -348,7 +348,7 @@ hasQuery = \@Url urlStr ->
|
||||||
# TODO use Str.contains once it exists. It should have a "fast path"
|
# TODO use Str.contains once it exists. It should have a "fast path"
|
||||||
# with SIMD iteration if the string is small enough to fit in a SIMD register.
|
# with SIMD iteration if the string is small enough to fit in a SIMD register.
|
||||||
Str.toUtf8 urlStr
|
Str.toUtf8 urlStr
|
||||||
|> List.contains (Num.toU8 '?')
|
|> List.contains (Num.toU8 '?')
|
||||||
|
|
||||||
## Returns the URL's [fragment](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
## Returns the URL's [fragment](https://en.wikipedia.org/wiki/URL#Syntax)—the part after
|
||||||
## the `#`, if it has one.
|
## the `#`, if it has one.
|
||||||
|
@ -418,7 +418,7 @@ hasFragment = \@Url urlStr ->
|
||||||
# TODO use Str.contains once it exists. It should have a "fast path"
|
# TODO use Str.contains once it exists. It should have a "fast path"
|
||||||
# with SIMD iteration if the string is small enough to fit in a SIMD register.
|
# with SIMD iteration if the string is small enough to fit in a SIMD register.
|
||||||
Str.toUtf8 urlStr
|
Str.toUtf8 urlStr
|
||||||
|> List.contains (Num.toU8 '#')
|
|> List.contains (Num.toU8 '#')
|
||||||
|
|
||||||
strWithCapacity : Nat -> Str
|
strWithCapacity : Nat -> Str
|
||||||
strWithCapacity = \cap ->
|
strWithCapacity = \cap ->
|
||||||
|
|
|
@ -21,13 +21,13 @@ echo = \shout ->
|
||||||
List.repeat spaceInUtf8 length
|
List.repeat spaceInUtf8 length
|
||||||
|
|
||||||
shout
|
shout
|
||||||
|> Str.toUtf8
|
|> Str.toUtf8
|
||||||
|> List.mapWithIndex
|
|> List.mapWithIndex
|
||||||
(\_, i ->
|
(\_, i ->
|
||||||
length = (List.len (Str.toUtf8 shout) - i)
|
length = (List.len (Str.toUtf8 shout) - i)
|
||||||
phrase = (List.split (Str.toUtf8 shout) length).before
|
phrase = (List.split (Str.toUtf8 shout) length).before
|
||||||
|
|
||||||
List.concat (silence (if i == 0 then 2 * length else length)) phrase)
|
List.concat (silence (if i == 0 then 2 * length else length)) phrase)
|
||||||
|> List.join
|
|> List.join
|
||||||
|> Str.fromUtf8
|
|> Str.fromUtf8
|
||||||
|> Result.withDefault ""
|
|> Result.withDefault ""
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue