8 ms·
I'll second @josevalim's comment, but I also wanted to mention how delighted I am to find out today that a joke[1] I probably spent way too much time 7 years ag
by crymer11 3y ago
I'll second @josevalim's comment, but I also wanted to mention how delighted I am to find out today that a joke[1] I probably spent way too much time 7 years ago has actually served a useful purpose!
1 - https://hex.pm/packages/leftpad https://hex.pm/packages/leftpad
- sodapopcan 3y agoHa! I just found this the other day and thought it was for real, lol. I wasn't actually looking for leftpad, of course, but, well done!
- networked 3y agoHaha. Thanks for writing it. I appreciate your and every leftpad porter's effort. :-) It makes for a perfect little dependency test with a standardized name. (Standardized up to /left[_-]?pad/i.) When a language doesn't have a leftpad package, I go looking for a concise way to make terminal text bold, which takes more time. Plus, seeing code like https://github.com/colinrymer/leftpad.ex/blob/8d2230bf094eed83c89e42352a81de184cf154c2/lib/leftpad.ex https://github.com/colinrymer/leftpad.ex/blob/8d2230bf094eed... is just fun: defmodule Leftpad do @moduledoc """ Remembering `String.rjust/3` can be difficult, so Leftpad provides you another way to easily left pad/right justify your UTF-8 encoded binaries. """ @doc ~S""" Provides basically the same functionality as [`String.rjust/3`](http://elixir-lang.org/docs/stable/elixir/String.html#rjust/3) ## Examples iex> Leftpad.pad("foo", 5) " foo" iex> Leftpad.pad("foobar", 6) "foobar" iex> Leftpad.pad("1", 2, ?0) "01" """ @spec pad(string :: String.t, count :: non_neg_integer, char :: char) :: String.t def pad(string, count, char \\ 32), do: String.rjust(string, count, char) end Look at that one line doing all the work, and even it delegates it to another function.
- nivertech 3y agowhy not: defdelegate pad(string, count, char \\ 32), to: String, as: :rjust