« Back to channel list

#elixir-lang - 12 May 2019

« Back 1 day Forward 1 day »
[00:00:58] cagomez: has joined #elixir-lang
[00:01:11] Sgeo_: has joined #elixir-lang
[00:28:37] Sgeo__: has joined #elixir-lang
[00:47:06] Sgeo__: has joined #elixir-lang
[00:51:40] orbyt_: has joined #elixir-lang
[01:04:35] Sgeo__: has joined #elixir-lang
[01:06:23] carldd: has joined #elixir-lang
[01:08:48] orbyt_: has joined #elixir-lang
[01:20:45] greengriminal: has joined #elixir-lang
[01:40:31] gvaughn_: has joined #elixir-lang
[01:41:04] thread: has joined #elixir-lang
[01:42:12] polymetis: has joined #elixir-lang
[01:43:28] lackac: has joined #elixir-lang
[01:43:38] comboy_: has joined #elixir-lang
[01:43:55] zkat: has joined #elixir-lang
[01:47:12] krigare[m]: has joined #elixir-lang
[01:47:15] grayWolf: has joined #elixir-lang
[01:48:35] Sgeo_: has joined #elixir-lang
[01:49:03] mcspud: has joined #elixir-lang
[01:50:35] tomterl: has joined #elixir-lang
[01:52:04] Dawgora: has joined #elixir-lang
[01:56:14] burbas: has joined #elixir-lang
[01:57:35] cagomez: has joined #elixir-lang
[02:02:31] blahdodo: has joined #elixir-lang
[02:05:23] minibikini1: has joined #elixir-lang
[02:07:34] Bla[m]: has joined #elixir-lang
[02:07:36] nolan_d: has joined #elixir-lang
[02:07:52] tkarstens[m]: has joined #elixir-lang
[02:08:16] ejpcmac: has joined #elixir-lang
[02:08:27] wilo[m]: has joined #elixir-lang
[02:09:04] dyce[m]: has joined #elixir-lang
[02:09:31] tcit: has joined #elixir-lang
[02:12:33] chronostamp: has joined #elixir-lang
[02:14:11] hindenbug[m]: has joined #elixir-lang
[02:14:25] borislehashoir[m: has joined #elixir-lang
[02:15:59] uhoreg: has joined #elixir-lang
[02:16:34] Hawkheart[m]: has joined #elixir-lang
[02:17:30] rassilon[m]: has joined #elixir-lang
[02:17:40] kamidev[m]: has joined #elixir-lang
[02:17:59] beatpanic: has joined #elixir-lang
[02:18:35] LordPtolemy[m]: has joined #elixir-lang
[02:20:01] is0x3F: has joined #elixir-lang
[02:22:21] pera: has joined #elixir-lang
[02:23:48] Anders[m]: has joined #elixir-lang
[02:24:08] Sgeo__: has joined #elixir-lang
[02:24:28] mindflayer[m]: has joined #elixir-lang
[02:24:58] Ablu: has joined #elixir-lang
[02:25:10] MartinFrost[m]: has joined #elixir-lang
[02:26:52] Nicd-[m]: has joined #elixir-lang
[02:27:46] whoops: has joined #elixir-lang
[02:27:47] tynanbe: has joined #elixir-lang
[02:27:50] Phillipp[m]: has joined #elixir-lang
[02:28:34] MatrixTravelerb4: has joined #elixir-lang
[02:45:16] FatalNIX: has joined #elixir-lang
[02:45:16] mozzarella: has joined #elixir-lang
[02:45:16] Liru: has joined #elixir-lang
[02:45:16] Czen: has joined #elixir-lang
[02:45:16] Sigma-: has joined #elixir-lang
[02:45:16] balo: has joined #elixir-lang
[02:45:16] meimeix: has joined #elixir-lang
[02:45:16] Notimik: has joined #elixir-lang
[02:45:16] codewaffle: has joined #elixir-lang
[02:45:16] knight-: has joined #elixir-lang
[02:45:16] agit0: has joined #elixir-lang
[02:45:16] bttf_: has joined #elixir-lang
[02:45:16] digia_: has joined #elixir-lang
[02:45:16] rkleef: has joined #elixir-lang
[02:45:16] rdxd_: has joined #elixir-lang
[02:45:16] c355E3B: has joined #elixir-lang
[02:45:17] pmarreck: has joined #elixir-lang
[02:58:37] __charly__: has joined #elixir-lang
[02:59:51] dtzuzu: has joined #elixir-lang
[03:00:23] kapilp: has joined #elixir-lang
[03:02:25] orbyt_: has joined #elixir-lang
[03:05:41] tnez: has joined #elixir-lang
[03:22:14] carldd: has joined #elixir-lang
[03:46:11] Sgeo__: has joined #elixir-lang
[03:58:42] gvaughn: has joined #elixir-lang
[04:25:51] Saukk: has joined #elixir-lang
[04:31:48] ncls: has joined #elixir-lang
[04:42:49] oneark: has joined #elixir-lang
[05:00:14] helmut_1: has joined #elixir-lang
[05:01:15] jeffro_: has joined #elixir-lang
[05:02:03] gvaughn: has joined #elixir-lang
[05:02:42] helmut_1: has left #elixir-lang: ()
[05:08:33] squall: has joined #elixir-lang
[05:11:28] jeffro_: has joined #elixir-lang
[05:20:01] voltone: has joined #elixir-lang
[05:33:11] kyrylo: has joined #elixir-lang
[05:44:15] Guest42: has joined #elixir-lang
[05:52:47] wsieroci: has joined #elixir-lang
[05:58:42] kansi: has joined #elixir-lang
[06:14:34] gvaughn: has joined #elixir-lang
[06:50:57] PragTob: has joined #elixir-lang
[06:55:54] azod: has joined #elixir-lang
[07:07:20] shiro[cloud]: has joined #elixir-lang
[07:11:09] kapilp: has joined #elixir-lang
[07:18:47] gvaughn: has joined #elixir-lang
[07:30:19] haircode: has joined #elixir-lang
[07:39:30] haircode: has left #elixir-lang: ("Leaving")
[07:43:26] Sgeo: has joined #elixir-lang
[08:02:14] kyrylo: has joined #elixir-lang
[08:36:28] gvaughn: has joined #elixir-lang
[08:38:04] harfangk: has joined #elixir-lang
[09:29:07] wsieroci: has joined #elixir-lang
[09:37:14] serafeim: has joined #elixir-lang
[09:37:50] serafeim: hello! i understand that the usage of if is discouraged in elixir. however, i'm not sure how should I write a snippet like the following w/o if: authority_name =
[09:37:50] serafeim: if user.authority_id && user.authority, do: user.authority.name, else: nil
[09:44:59] Sgeo: has joined #elixir-lang
[09:50:12] gvaughn: has joined #elixir-lang
[09:52:54] DTZUZO: has joined #elixir-lang
[09:55:16] serafeim: has joined #elixir-lang
[09:58:14] dysfun: serafeim: case user do %{authority: %{name: name}} -> {:ok, name} _ -> {:error, :not_found} end
[09:58:24] dysfun: is probably how i'd do it
[10:02:41] serafeim: dysfun thank you very much
[10:05:17] lexmag: has joined #elixir-lang
[10:07:19] serafeim: so i shouldn't do it in a single line
[10:09:30] dysfun: well if you do it in a single line and it's not there, it will crash
[10:09:41] dysfun: if you case match it, you can handle it
[10:09:57] dysfun: is crashing desirable here? do you have a mechanism from recovering from a crash?
[10:10:25] dysfun: i'm going to guess this is actually in your phoenix app and no, you probably don't want a blank 500 page to go to the user
[10:10:32] dysfun: so handle the errors
[10:10:49] dysfun: or set up the fallback controller to recover from this error
[10:13:08] serafeim: dysfun i understand thanks
[10:13:44] serafeim: however, using something like authority_name = if user.authority_id && user.authority, do: user.authority.name, else: nil shouldn't crash ; i make sure that user.authority is not null
[10:14:11] serafeim: it will either return authority.name or null
[10:14:27] serafeim: s/null/nil/g
[10:16:19] serafeim: however i agree that the case solution is more idiomatic
[10:16:36] serafeim: so i'll try to switch my thinking towards that
[10:17:01] dysfun: and ok/error tuples are generally better than thing-or-nil
[10:17:27] serafeim: dysfun yes i've also seen that however i want to pluck the authority_name to be able to use it in the next line
[10:17:51] serafeim: here's the whole snippet: https://dpaste.de/z0Zi
[10:18:27] serafeim: is there a reason to use the ok/error tuples for such a case ?
[10:18:28] dysfun: https://hexdocs.pm/elixir/Kernel.html#get_in/2 ?
[10:20:04] Sgeo: has joined #elixir-lang
[10:20:15] notzmv: has joined #elixir-lang
[10:22:12] serafeim: it would be great but doesn't work because user is an ecto schema (User does not implement the Access behaviour)
[10:24:03] dysfun: right, yeah
[10:27:40] serafeim: actually i was able to use the get_in using Access.key! like this: |> put_session(:authority_name, get_in(user, [Access.key!(:authority), Access.key!(:name)]))
[10:27:45] serafeim: and it works thanks !
[10:28:25] serafeim: but works *only* for users that have the authority :|
[10:28:38] serafeim: or else it throws Access.key!/1 expected a map/struct, got: nil
[10:46:39] Uniaika: has left #elixir-lang: ()
[10:53:00] gde33: has joined #elixir-lang
[10:56:21] fastfresh: has joined #elixir-lang
[11:05:11] mahmudov: has joined #elixir-lang
[11:09:11] gvaughn: has joined #elixir-lang
[11:33:04] netrino: has joined #elixir-lang
[11:47:00] lexmag: has joined #elixir-lang
[11:47:48] benwilson512: serafeim: I usually implement access for all my ecto schemas
[11:47:54] benwilson512: very convenient
[11:49:52] serafeim: benwilson512 interesting, how can i do this ?
[11:51:22] benwilson512: serafeim: at the top of your ecto schema to do you have `use Ecto.Schema` or do you have something like `use MyAppWeb.Model, :schema`
[11:58:12] lexmag: has joined #elixir-lang
[12:07:00] voltone: has joined #elixir-lang
[12:11:28] serafeim: benwilson512 i have use Ecto.Schema
[12:12:02] lexmag: has joined #elixir-lang
[12:22:40] bars0: has joined #elixir-lang
[12:23:18] lexmag: has joined #elixir-lang
[12:25:50] dysfun: i think the suggestion is you create your own MyappWeb.Model and `use MyappWeb.Model, :schema`
[12:26:13] dysfun: your MyappWeb.Model can define the magic macro and do whatever it wants
[12:26:38] gvaughn: has joined #elixir-lang
[12:27:12] serafeim: dysfun i'm not sure i understand this
[12:34:31] lexmag: has joined #elixir-lang
[12:39:00] dysfun: `use` is syntax sugar for calling a macro within the module
[12:39:28] dysfun: so you write that macro to define access for you
[12:39:49] dysfun: presumably using Map.get for the implementation
[12:47:25] serafeim: i haven't touched macros at all
[12:48:05] __charly__: has joined #elixir-lang
[12:52:32] dysfun: this only requires the basics actually
[12:53:06] dysfun: i think phoenix stopped generating a module that does this with 1.4, but it used to generate MyappWeb with the using macro
[12:56:09] serafeim: is there an example of this?
[12:59:24] dysfun: no, but there's https://stackoverflow.com/questions/28491306/elixir-use-vs-import#28504281 + https://elixir-lang.org/getting-started/meta/macros.html
[13:02:55] serafeim: ok i'll check these out
[13:03:34] dysfun: if you use a quote inside of the __using__ macro, you can have the effect of replacing the `use` call with some code that will be executed in that module
[13:03:51] elsurudo: has joined #elixir-lang
[13:03:52] dysfun: such as the `def`s required to implement Access
[13:04:31] dysfun: oh, it's a protocol, so a defimpl
[13:04:59] serafeim: yes I remember that with "use" you will put some code in your module
[13:05:49] serafeim: so you mean i'll need to implement a module myself which will be then used by my schemas? and this module will have everything that is needed to allow "Access" ?
[13:06:05] serafeim: but if it's that easy why isn't this implemented by default in ecto ?
[13:06:48] dysfun: presumably so it doesn't stop you from implementing it differently
[13:14:12] serafeim: dysfun would it be possible to use this module https://github.com/codedge-llc/accessible ?
[13:14:52] serafeim: it is very simple just a single module https://github.com/codedge-llc/accessible/blob/master/lib/accessible.ex
[13:15:26] dysfun: it also seems to only do a constant rather than the current value?
[13:16:02] serafeim: where is that ?
[13:16:25] dysfun: in the example there?
[13:16:44] dysfun: oh wait nevermind
[13:16:56] dysfun: yes, you could use that
[13:17:08] serafeim: dysfun great i'll try it now thanks !
[13:21:12] blahdodo: has joined #elixir-lang
[13:21:22] serafeim: it seems to be working; the only rather strange thing is that I need to put the "use Accessible" line in the end of the module (after I define my schema)
[13:21:50] dysfun: yes, that makes sense
[13:22:04] dysfun: (ecto schema generates a defstruct for you)
[13:25:40] serafeim: yeh that's what I thought
[13:25:43] lexmag: has joined #elixir-lang
[13:31:35] lexmag: has joined #elixir-lang
[13:33:53] ariedler: has joined #elixir-lang
[13:37:13] lexmag: has joined #elixir-lang
[13:43:49] runawayfive: has joined #elixir-lang
[13:45:40] lexmag: has joined #elixir-lang
[13:46:12] gvaughn: has joined #elixir-lang
[13:46:21] serafeim: I've got various snippets like this one: https://dpaste.de/N4OP where in the last line I want to pass through the error I received to the calling function (i.e {:error, reason} -> {:error, reason})... I understand that I could also write this as z -> z (to return the whole tuple). is there another; more idiomatic way to write thi ?
[13:49:13] fastfresh: has joined #elixir-lang
[13:49:58] dysfun: you can use `with {:ok, user} <- Auth.get_user_by_username(username), do: Argon2.check_pass(user, password)
[13:50:17] benwilson512: yup, with was created for exactly this purpose
[13:50:19] dysfun: with allows you to pattern match the result. if it doesn't match, it returns the value that was actually returned
[13:50:37] dysfun: if you need more than one case, you'll have to use a case
[13:50:44] dysfun: or with with `else`
[13:51:09] dysfun: i find `with` works best with modern libs that use the ok/error tuple format
[13:51:15] lexmag: has joined #elixir-lang
[13:59:01] serafeim: thank you !
[14:02:27] lexmag: has joined #elixir-lang
[14:08:09] lexmag: has joined #elixir-lang
[14:25:52] universa1: has joined #elixir-lang
[14:29:39] greengriminal: has joined #elixir-lang
[14:31:38] wsieroci: has joined #elixir-lang
[14:50:17] work_: has joined #elixir-lang
[14:51:14] tnez: has joined #elixir-lang
[14:52:03] lexmag: has joined #elixir-lang
[14:55:03] travis-ci: has joined #elixir-lang
[14:55:04] travis-ci: elixir-lang/elixir#22834 (v1.1.0-beta - a455549 : José Valim): The build is still failing.
[14:55:04] travis-ci: Change view : https://github.com/elixir-lang/elixir/compare/v1.1.0-beta
[14:55:04] travis-ci: Build details : https://travis-ci.org/elixir-lang/elixir/builds/531431034
[14:55:04] travis-ci: has left #elixir-lang: ()
[14:55:40] lexmag: has joined #elixir-lang
[14:57:53] cagomez: has joined #elixir-lang
[15:06:20] gvaughn: has joined #elixir-lang
[15:17:58] mahmudov: has joined #elixir-lang
[15:31:24] Sgeo: has joined #elixir-lang
[15:31:50] gvaughn: has joined #elixir-lang
[16:17:17] kansi: has joined #elixir-lang
[16:23:15] Guest42: has joined #elixir-lang
[16:36:32] kyrylo: has joined #elixir-lang
[16:45:47] jeffro_: has joined #elixir-lang
[16:51:12] infowolfe: has joined #elixir-lang
[16:51:13] infowolfe: has joined #elixir-lang
[16:51:30] elsurudo: has joined #elixir-lang
[16:52:27] Saukk: has joined #elixir-lang
[16:53:08] fastfresh: has joined #elixir-lang
[16:54:30] Exuma: has joined #elixir-lang
[17:21:50] bars0: has joined #elixir-lang
[17:22:55] voltone: has joined #elixir-lang
[17:57:51] Exuma: has joined #elixir-lang
[18:02:08] BitBot: has joined #elixir-lang
[18:18:50] thurloat: has joined #elixir-lang
[18:20:26] thurloat: has joined #elixir-lang
[18:24:35] tnez: has joined #elixir-lang
[18:27:31] lexmag: has joined #elixir-lang
[18:28:26] jeffro_: has joined #elixir-lang
[18:33:26] lexmag: has joined #elixir-lang
[18:34:03] PragTob: has joined #elixir-lang
[18:36:45] lexmag: has joined #elixir-lang
[18:38:12] netrino_: has joined #elixir-lang
[18:53:21] targaf: has joined #elixir-lang
[19:02:02] matt_d: has joined #elixir-lang
[19:05:49] b6b: has joined #elixir-lang
[19:05:49] b6b: has joined #elixir-lang
[19:12:54] work_: has joined #elixir-lang
[19:35:41] notzmv: has joined #elixir-lang
[20:09:46] craigp: has joined #elixir-lang
[20:20:57] b6b: has joined #elixir-lang
[20:21:02] b6b: has joined #elixir-lang
[20:54:00] Exuma: has joined #elixir-lang
[21:01:39] ur5us: has joined #elixir-lang
[21:23:54] thomasross: has joined #elixir-lang
[21:27:09] Exuma: has joined #elixir-lang
[21:44:34] kyrylo: has joined #elixir-lang
[22:06:32] carldd: has joined #elixir-lang
[22:31:57] b6b: has joined #elixir-lang
[22:56:26] gde33: has joined #elixir-lang
[22:58:53] laut: has joined #elixir-lang
[23:00:22] thomasross: has joined #elixir-lang
[23:07:13] Cloudflare: has joined #elixir-lang
[23:13:48] b6b: has joined #elixir-lang
[23:13:48] b6b: has joined #elixir-lang
[23:23:10] Cloudflare: has joined #elixir-lang
[23:35:48] b6b: has joined #elixir-lang
[23:35:51] b6b: has joined #elixir-lang
[23:48:00] craigp: has joined #elixir-lang