workspace
stringclasses 4
values | channel
stringclasses 4
values | text
stringlengths 1
3.93k
| ts
stringlengths 26
26
| user
stringlengths 2
11
|
---|---|---|---|---|
elmlang | general | but not just that, you could create a generic "optional" function, like my `nodeIf` example, but which returned `[]` if False, so it'd work on all lists! | 2019-01-29T12:16:31.264400 | Nana |
elmlang | general | Like `(::) : a -> List a -> List a` we could have a `(:?) : Maybe a -> List a -> List a` for example. | 2019-01-29T12:16:39.264700 | Antonette |
elmlang | general | They already work like how <@Nana> suggests except that you need to wrap the lists in a node | 2019-01-29T12:17:27.266100 | Carman |
elmlang | general | I guess it doesn't flatten though | 2019-01-29T12:18:19.266900 | Carman |
elmlang | general | so you could then write:
```
[ a
, b
, c
, ... optional condition [x, y]
]
``` | 2019-01-29T12:18:56.267200 | Nana |
elmlang | general | (`optional` being a function that returns `[]` if the first argument is `False`, otherwise returns the second argument) | 2019-01-29T12:19:36.268200 | Nana |
elmlang | general | (there's probably a better name though) | 2019-01-29T12:20:11.269300 | Nana |
elmlang | general | I was thinking something along the lines of:
```
a
:: b
:: c
:? Just d -- will be appended
:? Nothing -- won't count
:? optionallyC -- optionallyC being a Maybe of the right type
:: []
``` | 2019-01-29T12:20:29.269900 | Antonette |
elmlang | general | You _could_ have something like
```
conditionalList
[ hardcoded a
, hardcoded b
, hardcoded c
, optional condition [x y]
]
``` | 2019-01-29T12:22:01.271100 | Carman |
elmlang | general | That's not very different from `Maybe.Extra.values`, is it <@Carman>? | 2019-01-29T12:22:31.272000 | Antonette |
elmlang | general | here you're basically creating many lists (one for each row). i'm not sure if there are some optimizations that could happen at runtime | 2019-01-29T12:22:47.272100 | Lilli |
elmlang | general | Oh, no. | 2019-01-29T12:22:58.272300 | Antonette |
elmlang | general | Each element in this list is an item of the list (since `(::) : a -> List a -> List a` it just appends an item to the list). | 2019-01-29T12:23:36.273000 | Antonette |
elmlang | general | `(:?) : Maybe a -> List a -> List a` is different in that it takes a `Maybe a` and only appends to the list if it's a `Just` and not a `Nothing`. | 2019-01-29T12:24:12.274200 | Antonette |
elmlang | general | yes if you use a `Maybe` under the hood. | 2019-01-29T12:24:30.274800 | Carman |
elmlang | general | what's nice about the spread operator though is that you wouldn't have to use `filterMap` or whatever on the list afterwards | 2019-01-29T12:24:33.275000 | Nana |
elmlang | general | yea, but lists are immutable in elm. when you append to a list, you're actually creating a new list with 1 more item in the end | 2019-01-29T12:24:59.276200 | Lilli |
elmlang | general | to allow multiple items you'd probably want `List` under the hood in which case `conditionalList` is `List.concat` | 2019-01-29T12:25:01.276400 | Carman |
elmlang | general | Same with something like the `(:?)` idea. | 2019-01-29T12:25:14.276900 | Antonette |
elmlang | general | I feel like first constructing a list and then filtermapping it to a different type of list becomes kind of indirect | 2019-01-29T12:25:18.277100 | Nana |
elmlang | general | Needing to do logic inline in a list like that is a bit of a smell IMO. It's not _bad_ but when I see that I pause to see if I can move that elsewhere. | 2019-01-29T12:26:37.278600 | Carman |
elmlang | general | Sure ; it's an idea for cases where these are not very long lists though. | 2019-01-29T12:26:46.278900 | Antonette |
elmlang | general | Many conditionals can be pushed up higher in the decision tree | 2019-01-29T12:26:48.279200 | Carman |
elmlang | general | (and it's only the case because Elm doesn't do optimization like in Haskell, in which `a : b : c` is the same as `[a, b, c]`, memory serves) | 2019-01-29T12:28:00.280700 | Antonette |
elmlang | general | <@Carman> I think it makes sense for html nodes / attributes though
it's nice to have "linear" code where you don't have to jump around to read it | 2019-01-29T12:28:51.282000 | Nana |
elmlang | general | which I think is a bit of a problem with moving the logic elsewhere | 2019-01-29T12:29:21.282800 | Nana |
elmlang | general | Plus, you can use names to push the specifics up in a `let` rather than putting the condition in the list itself. | 2019-01-29T12:29:25.283000 | Antonette |
elmlang | general | I agree but that leads me to the opposite conclusion :smile:. Having "linear" code in your view is why I like moving the logic up | 2019-01-29T12:30:04.283900 | Carman |
elmlang | general | I guess it's just because I'm so used to writing HTML templates :thinking_face: so I try to write Elm node lists in the same way | 2019-01-29T12:31:40.284700 | Nana |
elmlang | general | (also, <@Nana>, you're entitled to your preferences as long as it fits your teams' :wink:) | 2019-01-29T12:33:44.286300 | Antonette |
elmlang | general | I'm a big fan of the idea of separating conditional logic from the implementation of each path. This is especially powerful if you start repeating conditionals. For example:
```
message : Bool -> Html a
message condition =
div (if condition then [class "active"] else [])
(if condition then [ text "true" ] else [ text "false" ])
```
is much easier to read if we separate the conditional logic from the branches
```
message : Bool -> Html a
message condition =
if condition then
activeMessage
else
inactiveMessage
activeMessage : Html a
activeMessage =
div [class "active"] [ text "true" ]
inactiveMessage : Html a
inactiveMessage =
div [ ] [ text "false" ]
``` | 2019-01-29T12:38:55.292700 | Carman |
elmlang | general | I guess this is related to the idea of keeping code in a function at a single level of abstraction | 2019-01-29T12:40:11.294100 | Carman |
elmlang | general | On a side note, beware, `nodeIf/viewIf` can be devastating for performance if it is used for a complex node (for example a full page with `elm-css` styling). Be sure to use a lazy version like <https://package.elm-lang.org/packages/elm-community/html-extra/latest/Html-Extra#viewIfLazy> for example when you want to avoid evaluating the node. | 2019-01-29T12:41:06.294800 | Velia |
elmlang | general | I take a similar approach to case statements:
```
case maybe of
Nothing -> emptyState
Just item -> viewItem item
``` | 2019-01-29T12:43:07.296600 | Carman |
elmlang | general | Turns out doing this is super powerful, not just for views. Moving the conditional up in the decision tree removes a lot of the pain around working with Maybe | 2019-01-29T12:43:57.297600 | Carman |
elmlang | general | Tinkering with these ideas led to this article: <https://robots.thoughtbot.com/problem-solving-with-maybe> and this ElmEurope talk <https://www.youtube.com/watch?v=43eM4kNbb6c> :slightly_smiling_face: | 2019-01-29T12:45:06.298400 | Carman |
elmlang | general | <@Antonette> I'm the only frontend dev :grin: | 2019-01-29T12:48:26.299100 | Nana |
elmlang | general | Good point! | 2019-01-29T12:53:21.299300 | Nana |
elmlang | general | <@Antonette> elm-ui, which I am in the process of switching to, actually has `Element.none` | 2019-01-29T13:40:47.300800 | Nana |
elmlang | general | Yay for them :grin::+1: | 2019-01-29T13:41:15.301000 | Antonette |
elmlang | general | (I should have suggested we use elm-ui on my company's app) | 2019-01-29T13:41:45.301200 | Antonette |
elmlang | general | yeah it's really nice | 2019-01-29T13:42:31.301400 | Nana |
elmlang | general | makes so much more sense than CSS | 2019-01-29T13:43:02.301600 | Nana |
elmlang | general | It can look a bit nicer if you hide the if/else behind a function and use List.concat to keep it all lined up
```
List.concat
[ [a, b, c]
, optionalItems
, moreOptionals
]
``` | 2019-01-29T13:52:06.301900 | Lorilee |
elmlang | general | <@Lorilee> good idea! might try that :slightly_smiling_face: | 2019-01-29T13:55:10.302100 | Nana |
elmlang | general | can I call `elm make` from another directory? I just get `It looks like you are starting a new Elm project. elm init` message … I can’t discover any flags :confused: | 2019-01-29T14:00:40.303300 | Elliot |
elmlang | general | You can make files at an arbitrary path but `elm make` must be run from the directory that contains the project's `elm.json` | 2019-01-29T14:02:00.304300 | Carman |
elmlang | general | okay! thank you for confirming that :blush: | 2019-01-29T14:02:47.304900 | Elliot |
elmlang | general | I've got another question related to splitting things up. I had a giant `Main.elm`. It's an app for letting a user search and then displaying those search results. The seam I split the file apart on was on my SearchResults type. There are a bunch of types that it included in it and it's a nicely contained part of the app. The only place where there is some leakage is in my `getSearchResults` method. The signature for it is `getSearchResults : SearchQuery -> Cmd Msg`. `Msg` is defined in `Main.elm`. I'm not crazy about needing to pull `Msg` out into its own file to prevent circular dependencies. So, I think I have two options, leave `getSearchResults` in `Main.elm` or use a type placeholder for `Msg`. Any recommendations? | 2019-01-29T18:13:14.309200 | Marcus |
elmlang | general | Side note, I just tried the type placeholder approach and I'm still picking compiler errors out of my forehead. | 2019-01-29T18:13:40.309700 | Marcus |
elmlang | general | You could try doing something like `getSearchResults : SearchQuery -> (SearchResults -> msg) -> Cmd msg`. Not sure if that's what you meant by 'type placeholder', but it seems like a decent API | 2019-01-29T18:21:42.312800 | Huong |
elmlang | general | "Type variable" is what I meant. | 2019-01-29T18:24:30.313100 | Marcus |
elmlang | general | That does look like a good API. So, is the second param a function that takes a `SearchResults` and returns a message? | 2019-01-29T18:25:30.314100 | Marcus |
elmlang | general | Ah, I got it to work, although I don't understand the syntax entirely. | 2019-01-29T18:42:09.314700 | Marcus |
elmlang | general | Which part? | 2019-01-29T18:42:34.314900 | Kris |
elmlang | general | Hullo all - I'm implementing drag-and-drop that should interoperate with other software. In the past, I've used something like `onDragStart(e) => e.dataTransfer.setData("custom/mime-type", value)` and `val = dataTransfer.getData("custom/mime-type")` over in the receiver but this is feeling pretty janky in Elm right now. Has anyone else solved this problem? | 2019-01-29T18:53:08.316800 | Elvis |
elmlang | general | In particular, I've noticed that I can use a gross manual HTML attribute to "shell out" and set the custom data on the dragStart event but it's not clear to me how I could decode the data out of the event on the flip side. Advice or links are welcome! | 2019-01-29T18:54:19.317000 | Elvis |
elmlang | general | <@Kris> The type definition. The definition of the method in my module is this:
```
getSearchResults : SearchQuery -> (Result Http.Error SearchResults -> msg) -> Cmd msg
```
and the way I call it is:
```
getSearchResults model.searchQuery NewResults
``
The second parameter of the method is tripping me up a bit. | 2019-01-29T19:12:38.317200 | Marcus |
elmlang | general | It's just a function `Result Http.Error SearchResults -> msg` like you said | 2019-01-29T19:13:35.318200 | Kris |
elmlang | general | Yeah, I just haven't internalized that syntax. I can give the definition of what it is doing, but can't give a nuanced explanation. It will come. | 2019-01-29T19:18:42.321300 | Marcus |
elmlang | general | anyone know why I would be getting this compile error?
```
-- NAMING ERROR -------- ./src/ui/src/elm/Conversion/ClickEnergy/Validations.elm
Module `Char` does not expose `isAlpha`
3| import Char exposing (isDigit, isAlpha)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
``` | 2019-01-29T20:18:13.321900 | Son |
elmlang | general | AFAIK, `Char` _does_ expose `isAlpha`… | 2019-01-29T20:18:36.322300 | Son |
elmlang | general | <@Son> `isAlpha` was added in Elm 0.19 | 2019-01-29T20:27:50.323000 | Earlean |
elmlang | general | it looks like you're using Elm 0.18 | 2019-01-29T20:28:45.323700 | Earlean |
elmlang | general | <@Earlean> ah, no equivalent in 0.18? | 2019-01-29T20:31:13.324000 | Son |
elmlang | general | will I just have to use a range? | 2019-01-29T20:31:18.324200 | Son |
elmlang | general | ```
isAlpha : Char -> Bool
isAlpha char =
Char.isLower char || Char.isUpper char
``` | 2019-01-29T20:33:56.324800 | Earlean |
elmlang | general | Nice tip. Adding this and a variation with two Maybe values really helped clean up my code. | 2019-01-30T02:10:50.325500 | Annika |
elmlang | general | ```maybeView2 : (a -> b -> Html msg) -> Maybe a -> Maybe b -> Html msg
maybeView2 f maybeA maybeB =
case ( maybeA, maybeB ) of
( Just a, Just b ) ->
f a b
_ ->
div [] []``` | 2019-01-30T02:18:06.325700 | Annika |
elmlang | general | Which I guess is equivalent to: | 2019-01-30T02:42:03.326000 | Annika |
elmlang | general | ```maybeView2 : (a -> b -> Html msg) -> Maybe a -> Maybe b -> Html msg
maybeView2 f maybeA maybeB =
Maybe.map2 f maybeA maybeB
|> Maybe.withDefault (div [] [])``` | 2019-01-30T02:42:07.326200 | Annika |
elmlang | general | Does anyone know which github repository the Debugger code is defined in? | 2019-01-30T03:11:46.327200 | Norris |
elmlang | general | <@Norris> <https://github.com/elm/browser/tree/master/src/Debugger> | 2019-01-30T03:14:56.327600 | Earlean |
elmlang | general | and <https://github.com/elm/browser/blob/master/src/Elm/Kernel/Debugger.js> | 2019-01-30T03:15:59.327800 | Earlean |
elmlang | general | ah thank you! I'm looking for it because there is an issue with the `File.Select.file` code on certain browsers (e.g. safari on iOS), and it appears the issue can be mitigated by temporarily appending an input element to the DOM and then removing it. I noticed that this is exactly what the Debugger kernel code does. | 2019-01-30T03:17:55.329700 | Norris |
elmlang | general | Here's the `elm/file` issue I'm referencing, which I just posted my quick-and-dirty fix in: <https://github.com/elm/file/issues/4> | 2019-01-30T03:18:27.330400 | Norris |
elmlang | general | is `text ""` even added to the dom? | 2019-01-30T03:40:36.330500 | Saran |
elmlang | general | I heard there were plans to make the compiler detect functions and give a type error if you try to compare them? Could that also mean that all types which don't contain functions would be moved into `comparable`? :slightly_smiling_face: | 2019-01-30T03:57:42.332400 | Nana |
elmlang | general | That's a good question <@Saran> and I'm not sure. Still, I prefer having an `Element.none` that says it's no element than a `text ""` that's a little bit less clear on why it's here. | 2019-01-30T03:58:25.332800 | Antonette |
elmlang | general | So then we could have native any-dicts! | 2019-01-30T03:58:39.333200 | Nana |
elmlang | general | <@Antonette> I actually considered defining `none = text ""` for myself hehe | 2019-01-30T03:59:57.333300 | Nana |
elmlang | general | yeah, it should be a zero element | 2019-01-30T04:00:53.333500 | Saran |
elmlang | general | `comparable` is kind of a confusing name. It's types where `<` and `>` and `==` are defined | 2019-01-30T04:02:36.335100 | Earlean |
elmlang | general | <@Earlean> indeed, but if you know there are no functions, you could use an internal function like `Debug.toString` and then maybe put it through a hashing function | 2019-01-30T04:03:53.336800 | Nana |
elmlang | general | or would it be too "weird" that users could use `>` and `<` on random types? | 2019-01-30T04:05:31.337900 | Nana |
elmlang | general | `comparable` required ordering, and custom types don't have an order, unless the compiler assumes the order is the one in which they are defined, e.g. `type Custom = First | Second | Third`, and then `First < Second` | 2019-01-30T04:06:35.339400 | Norris |
elmlang | general | off the top of my head, that's how Haskell works if you define a custom data type with the `Ord` typeclass | 2019-01-30T04:07:19.340200 | Norris |
elmlang | general | <@Norris> I was thinking it would just be an arbitrary ordering, only really used for performance in data structures | 2019-01-30T04:08:16.340700 | Nana |
elmlang | general | maybe it could have an alternate API instead of `>` and `<` though | 2019-01-30T04:09:07.341300 | Nana |
elmlang | general | then you just want equality | 2019-01-30T04:09:15.341500 | Norris |
elmlang | general | not orderability | 2019-01-30T04:09:21.341700 | Norris |
elmlang | general | which Elm doesn't have | 2019-01-30T04:09:24.341900 | Norris |
elmlang | general | again to go back to Haskell, there's `Eq` and there's `Ord` | 2019-01-30T04:09:38.342300 | Norris |
elmlang | general | one gives you `==`, the other gives you `>` and `<` | 2019-01-30T04:09:58.342700 | Norris |
elmlang | general | but `Ord` requires `Eq` | 2019-01-30T04:10:02.343000 | Norris |
elmlang | general | <@Norris> but orderability can give you better performance for lookups
example: <https://github.com/pzp1997/assoc-list/blob/master/Performance.md> | 2019-01-30T04:10:45.344000 | Nana |
elmlang | general | I think it is generally hard (if not impossible) to come with both fast and reliable hashing function for arbitrary data | 2019-01-30T04:27:53.345700 | Lynne |
elmlang | general | If you convert elements to string and use, say, md5 hash (or whatever else out there without collisions), creation and insertion will be a major bottleneck | 2019-01-30T04:29:28.346800 | Lynne |
elmlang | general | <@Lynne> yeah that may be true | 2019-01-30T04:31:03.347100 | Nana |
elmlang | general | Not to mention that comparing large strings is not that efficient | 2019-01-30T04:31:42.347500 | Lynne |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.