HomePage | RecentChanges | Preferences

No diff available--this is the first major revision. (no other diffs)

Elixir Slack 2015-11-10

wsmoak [9:14 PM] Regex.run returns either a List or nil. I need to return either a the first item in the list or nil (if there were no matches.) This (sending it through List.wrap and then List.first) works... but doesn't seem like the right way to do it. Suggestions? https://github.com/wsmoak/ex_doc/blob/h1_as_menu_title/lib/ex_doc/formatter/html.ex#L174-L177

bbense [10:38 PM] @wsmoak:

defp extract_title(content) do
  answer(Regex.run(@h1_regex, content, capture: :all_but_first))

defp answer(nil)  do

defp answer(list) when is_list(list) do 
defp answer(string) when is_binary(string) do 

bbense [10:40 PM] I'm writing that from memory, 2 and 1/2 hours of commuting and my second glass of wine, so I'm sure there's a typo in it somewhere.

bbense [10:46 PM] BTW, I think this is an example of "love of pipes" driving the code into a complicated direction. I'm pretty sure eventually I'll run into a case where "love of multiple function definitions" will also drive the code in a complex direction, but so far it's been a winner every time. Every time I write a case or if, I stop and think if there's a way I can write it as a multiply defined function instead.

HomePage | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited November 11, 2015 5:01 am by (diff)