diff options
author | Connor Schembor <connor.schembor@rutgers.edu> | 2020-09-03 22:05:14 -0400 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2020-09-04 10:27:50 +0100 |
commit | d3f64eb083743bcb32e427d751d8d76bf25a15e2 (patch) | |
tree | 0e59adbfc6b10b0f8c5348b4ac74dd6185aa2386 /src | |
parent | 2e1aa38cfccb85a90c562c715bf51401e0acf29c (diff) | |
download | gleam_stdlib-d3f64eb083743bcb32e427d751d8d76bf25a15e2.tar.gz gleam_stdlib-d3f64eb083743bcb32e427d751d8d76bf25a15e2.zip |
Run formatter
Diffstat (limited to 'src')
-rw-r--r-- | src/gleam/bit_builder.gleam | 5 | ||||
-rw-r--r-- | src/gleam/dynamic.gleam | 23 | ||||
-rw-r--r-- | src/gleam/float.gleam | 9 | ||||
-rw-r--r-- | src/gleam/int.gleam | 9 | ||||
-rw-r--r-- | src/gleam/iterator.gleam | 37 | ||||
-rw-r--r-- | src/gleam/queue.gleam | 9 | ||||
-rw-r--r-- | src/gleam/set.gleam | 16 | ||||
-rw-r--r-- | src/gleam/string.gleam | 23 | ||||
-rw-r--r-- | src/gleam/uri.gleam | 116 |
9 files changed, 123 insertions, 124 deletions
diff --git a/src/gleam/bit_builder.gleam b/src/gleam/bit_builder.gleam index bcc4c4c..165099f 100644 --- a/src/gleam/bit_builder.gleam +++ b/src/gleam/bit_builder.gleam @@ -42,10 +42,7 @@ pub external fn prepend_builder( /// /// Runs in constant time. /// -pub external fn append_builder( - to: BitBuilder, - suffix: BitBuilder, -) -> BitBuilder = +pub external fn append_builder(to: BitBuilder, suffix: BitBuilder) -> BitBuilder = "gleam_stdlib" "iodata_append" /// Prepend a string onto the start of a builder. diff --git a/src/gleam/dynamic.gleam b/src/gleam/dynamic.gleam index efd8dd5..bf7963f 100644 --- a/src/gleam/dynamic.gleam +++ b/src/gleam/dynamic.gleam @@ -54,14 +54,12 @@ pub external fn bit_string(from: Dynamic) -> Result(BitString, String) = /// pub fn string(from: Dynamic) -> Result(String, String) { bit_string(from) - |> result.then( - fn(raw) { - case bit_string_mod.to_string(raw) { - Ok(string) -> Ok(string) - Error(Nil) -> Error("Expected a string, got a bit_string") - } - }, - ) + |> result.then(fn(raw) { + case bit_string_mod.to_string(raw) { + Ok(string) -> Ok(string) + Error(Nil) -> Error("Expected a string, got a bit_string") + } + }) } /// Check to see whether a Dynamic value is an int, and return the int if it @@ -215,10 +213,7 @@ pub external fn field(from: Dynamic, named: a) -> Result(Dynamic, String) = /// > element(from(""), 2) /// Error("Expected a tuple, got a binary") /// -pub external fn element( - from: Dynamic, - position: Int, -) -> Result(Dynamic, String) = +pub external fn element(from: Dynamic, position: Int) -> Result(Dynamic, String) = "gleam_stdlib" "decode_element" /// Check to see if the Dynamic value is a 2 element tuple. @@ -237,9 +232,7 @@ pub external fn element( /// > tuple2(from("")) /// Error("Expected a tuple, got a binary") /// -pub external fn tuple2( - from: Dynamic, -) -> Result(tuple(Dynamic, Dynamic), String) = +pub external fn tuple2(from: Dynamic) -> Result(tuple(Dynamic, Dynamic), String) = "gleam_stdlib" "decode_tuple2" /// Check to see if the Dynamic value is a 2 element tuple containing two diff --git a/src/gleam/float.gleam b/src/gleam/float.gleam index 254e5f0..ecb203c 100644 --- a/src/gleam/float.gleam +++ b/src/gleam/float.gleam @@ -38,10 +38,11 @@ pub fn to_string(f: Float) -> String { pub fn compare(a: Float, with b: Float) -> Order { case a == b { True -> order.Eq - False -> case a <. b { - True -> order.Lt - False -> order.Gt - } + False -> + case a <. b { + True -> order.Lt + False -> order.Gt + } } } diff --git a/src/gleam/int.gleam b/src/gleam/int.gleam index 1e9f17c..151bfa3 100644 --- a/src/gleam/int.gleam +++ b/src/gleam/int.gleam @@ -58,10 +58,11 @@ pub external fn to_base_string(Int, Int) -> String = pub fn compare(a: Int, with b: Int) -> Order { case a == b { True -> order.Eq - False -> case a < b { - True -> order.Lt - False -> order.Gt - } + False -> + case a < b { + True -> order.Lt + False -> order.Gt + } } } diff --git a/src/gleam/iterator.gleam b/src/gleam/iterator.gleam index 2365317..8cb01c1 100644 --- a/src/gleam/iterator.gleam +++ b/src/gleam/iterator.gleam @@ -174,15 +174,16 @@ fn do_take( acc: List(e), ) -> List(e) { case desired > 0 { - True -> case continuation() { - Continue( - element, - iterator, - ) -> do_take(iterator, desired - 1, [element, ..acc]) - Stop -> acc - |> list.reverse - } - False -> acc + True -> + case continuation() { + Continue(element, iterator) -> + do_take(iterator, desired - 1, [element, ..acc]) + Stop -> + acc + |> list.reverse + } + False -> + acc |> list.reverse } } @@ -207,10 +208,11 @@ pub fn take(from iterator: Iterator(e), up_to desired: Int) -> List(e) { fn do_drop(continuation: fn() -> Action(e), desired: Int) -> fn() -> Action(e) { case desired > 0 { - True -> case continuation() { - Continue(_, iterator) -> do_drop(iterator, desired - 1) - Stop -> fn() { Stop } - } + True -> + case continuation() { + Continue(_, iterator) -> do_drop(iterator, desired - 1) + Stop -> fn() { Stop } + } False -> continuation } } @@ -272,10 +274,11 @@ fn do_filter( ) -> fn() -> Action(e) { fn() { case continuation() { - Continue(e, iterator) -> case predicate(e) { - True -> Continue(e, do_filter(iterator, predicate)) - False -> do_filter(iterator, predicate)() - } + Continue(e, iterator) -> + case predicate(e) { + True -> Continue(e, do_filter(iterator, predicate)) + False -> do_filter(iterator, predicate)() + } Stop -> Stop } } diff --git a/src/gleam/queue.gleam b/src/gleam/queue.gleam index 5e67d50..1df8d12 100644 --- a/src/gleam/queue.gleam +++ b/src/gleam/queue.gleam @@ -210,10 +210,11 @@ fn check_equal( ) -> Bool { case xs, x_tail, ys, y_tail { [], [], [], [] -> True - [x, ..xs], _, [y, ..ys], _ -> case eq(x, y) { - False -> False - True -> check_equal(xs, x_tail, ys, y_tail, eq) - } + [x, ..xs], _, [y, ..ys], _ -> + case eq(x, y) { + False -> False + True -> check_equal(xs, x_tail, ys, y_tail, eq) + } [], [_, ..], _, _ -> check_equal(list.reverse(x_tail), [], ys, y_tail, eq) _, _, [], [_, ..] -> check_equal(xs, x_tail, list.reverse(y_tail), [], eq) _, _, _, _ -> False diff --git a/src/gleam/set.gleam b/src/gleam/set.gleam index a023bae..0455081 100644 --- a/src/gleam/set.gleam +++ b/src/gleam/set.gleam @@ -104,11 +104,12 @@ pub fn to_list(set: Set(member)) -> List(member) { /// [1, 3, 3, 4] /// pub fn from_list(members: List(member)) -> Set(member) { - let map = list.fold( - over: members, - from: map.new(), - with: fn(k, m) { map.insert(m, k, []) }, - ) + let map = + list.fold( + over: members, + from: map.new(), + with: fn(k, m) { map.insert(m, k, []) }, + ) Set(map) } @@ -163,10 +164,7 @@ pub fn filter( /// > from_list([1, 2, 3]) |> take([1, 3, 5]) |> to_list /// [1, 3] /// -pub fn take( - from set: Set(member), - keeping desired: List(member), -) -> Set(member) { +pub fn take(from set: Set(member), keeping desired: List(member)) -> Set(member) { Set(map.take(from: set.map, keeping: desired)) } diff --git a/src/gleam/string.gleam b/src/gleam/string.gleam index 26bf01d..941cd0c 100644 --- a/src/gleam/string.gleam +++ b/src/gleam/string.gleam @@ -150,23 +150,20 @@ external fn erl_slice(String, Int, Int) -> String = /// > slice(from: "gleam", at_index: -12, length: 2) /// "" /// -pub fn slice( - from string: String, - at_index idx: Int, - length len: Int, -) -> String { +pub fn slice(from string: String, at_index idx: Int, length len: Int) -> String { case len < 0 { True -> "" - False -> case idx < 0 { - True -> { - let translated_idx = length(string) + idx - case translated_idx < 0 { - True -> "" - False -> erl_slice(string, translated_idx, len) + False -> + case idx < 0 { + True -> { + let translated_idx = length(string) + idx + case translated_idx < 0 { + True -> "" + False -> erl_slice(string, translated_idx, len) + } } + False -> erl_slice(string, idx, len) } - False -> erl_slice(string, idx, len) - } } } diff --git a/src/gleam/uri.gleam b/src/gleam/uri.gleam index b900f2c..32910b5 100644 --- a/src/gleam/uri.gleam +++ b/src/gleam/uri.gleam @@ -49,7 +49,8 @@ type UriKey { /// The opposite operation is `uri.to_string` /// pub fn parse(string: String) -> Result(Uri, Nil) { - try uri_map = dynamic.map(erl_parse(string)) + try uri_map = + dynamic.map(erl_parse(string)) |> result.nil_error let get = fn(k: UriKey, decode_type: dynamic.Decoder(t)) -> Option(t) { uri_map @@ -58,15 +59,16 @@ pub fn parse(string: String) -> Result(Uri, Nil) { |> option.from_result } - let uri = Uri( - scheme: get(Scheme, dynamic.string), - userinfo: get(Userinfo, dynamic.string), - host: get(Host, dynamic.string), - port: get(Port, dynamic.int), - path: option.unwrap(get(Path, dynamic.string), ""), - query: get(Query, dynamic.string), - fragment: get(Fragment, dynamic.string), - ) + let uri = + Uri( + scheme: get(Scheme, dynamic.string), + userinfo: get(Userinfo, dynamic.string), + host: get(Host, dynamic.string), + port: get(Port, dynamic.int), + path: option.unwrap(get(Path, dynamic.string), ""), + query: get(Query, dynamic.string), + fragment: get(Fragment, dynamic.string), + ) Ok(uri) } @@ -157,10 +159,10 @@ external fn erl_to_string(Map(UriKey, Dynamic)) -> Dynamic = /// The opposite operation is `uri.parse`. /// pub fn to_string(uri: Uri) -> String { - let field = fn( - key: UriKey, - value: Option(anything), - ) -> Result(tuple(UriKey, Dynamic), Nil) { + let field = fn(key: UriKey, value: Option(anything)) -> Result( + tuple(UriKey, Dynamic), + Nil, + ) { case value { Some(v) -> Ok(tuple(key, dynamic.from(v))) None -> Error(Nil) @@ -215,50 +217,56 @@ fn join_segments(segments: List(String)) -> String { /// The algorithm for merging uris is described in [RFC 3986](https://tools.ietf.org/html/rfc3986#section-5.2) pub fn merge(base: Uri, relative: Uri) -> Result(Uri, Nil) { case base { - Uri(scheme: Some(_), host: Some(_), ..) -> case relative { - Uri(host: Some(_), ..) -> { - let path = string.split(relative.path, "/") - |> remove_dot_segments() - |> join_segments() - let resolved = Uri( - option.or(relative.scheme, base.scheme), - None, - relative.host, - relative.port, - path, - relative.query, - relative.fragment, - ) - Ok(resolved) - } - Uri(scheme: None, host: None, ..) -> { - let tuple(new_path, new_query) = case relative.path { - "" -> tuple(base.path, option.or(relative.query, base.query)) - _ -> { - let path_segments = case string.starts_with(relative.path, "/") { - True -> string.split(relative.path, "/") - False -> string.split(base.path, "/") - |> drop_last() - |> list.append(string.split(relative.path, "/")) + Uri(scheme: Some(_), host: Some(_), ..) -> + case relative { + Uri(host: Some(_), ..) -> { + let path = + string.split(relative.path, "/") + |> remove_dot_segments() + |> join_segments() + let resolved = + Uri( + option.or(relative.scheme, base.scheme), + None, + relative.host, + relative.port, + path, + relative.query, + relative.fragment, + ) + Ok(resolved) + } + Uri(scheme: None, host: None, ..) -> { + let tuple(new_path, new_query) = case relative.path { + "" -> tuple(base.path, option.or(relative.query, base.query)) + _ -> { + let path_segments = case string.starts_with(relative.path, "/") { + True -> string.split(relative.path, "/") + False -> + string.split(base.path, "/") + |> drop_last() + |> list.append(string.split(relative.path, "/")) + } + let path = + path_segments + |> remove_dot_segments() + |> join_segments() + tuple(path, relative.query) } - let path = path_segments - |> remove_dot_segments() - |> join_segments() - tuple(path, relative.query) } + let resolved = + Uri( + base.scheme, + None, + base.host, + base.port, + new_path, + new_query, + relative.fragment, + ) + Ok(resolved) } - let resolved = Uri( - base.scheme, - None, - base.host, - base.port, - new_path, - new_query, - relative.fragment, - ) - Ok(resolved) } - } _ -> Error(Nil) } } |