New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pure #408

Closed
wants to merge 2 commits into
base: master
from

Conversation

Projects
None yet
3 participants
@Fresheyeball

Fresheyeball commented Sep 16, 2015

I find myself writing this function alot, perhaps its worth including?

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 16, 2015

Member

I'd rename it to singleton to be parallel with Dict and Set. I'll add this to the meta issue about core changes.

Member

evancz commented Sep 16, 2015

I'd rename it to singleton to be parallel with Dict and Set. I'll add this to the meta issue about core changes.

@evancz evancz closed this Sep 16, 2015

@evancz evancz referenced this pull request Sep 16, 2015

Open

API Ideas #322

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Sep 16, 2015

Member

The process for adding stuff to core is described here, so we'll go through and think about all these things in a big batch.

Member

evancz commented Sep 16, 2015

The process for adding stuff to core is described here, so we'll go through and think about all these things in a big batch.

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball Sep 16, 2015

Ok. Fair enough.

Fresheyeball commented Sep 16, 2015

Ok. Fair enough.

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Nov 30, 2015

Member

Can you share an example of when you use it? What kind of code calls for this?

Member

evancz commented Nov 30, 2015

Can you share an example of when you use it? What kind of code calls for this?

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball Nov 30, 2015

basically I use it in composition chains, for example

https://github.com/Fresheyeball/elm-students/blob/a5ed3ddf557f9a14a2a5f06f0f3d6c171e38ccb2/src/Test.elm#L180

pure : a -> List a
pure x = [x]

test : List H.Html
test = let
  details =
    pure << H.details [ A.style [ ("overflow", "hidden") ] ]
         << (::) (H.summary [] [ H.text "Tests" ])
         << pure << display << quickCheck << suite "Students"
  in details
    [ checkupdate
    , checkMetrics ]

I can find more examples if you need them. Looking back, I use it mostly when making functions that build html.

Fresheyeball commented Nov 30, 2015

basically I use it in composition chains, for example

https://github.com/Fresheyeball/elm-students/blob/a5ed3ddf557f9a14a2a5f06f0f3d6c171e38ccb2/src/Test.elm#L180

pure : a -> List a
pure x = [x]

test : List H.Html
test = let
  details =
    pure << H.details [ A.style [ ("overflow", "hidden") ] ]
         << (::) (H.summary [] [ H.text "Tests" ])
         << pure << display << quickCheck << suite "Students"
  in details
    [ checkupdate
    , checkMetrics ]

I can find more examples if you need them. Looking back, I use it mostly when making functions that build html.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Nov 30, 2015

Member

I ask because that's how I'd use it as well, but I was wondering if this is ever nicer code than just naming things. Your example would become:

test : List H.Html
test = let
  toDetails checks =
    H.details
      [ A.style [ ("overflow", "hidden") ] ]
      [ H.summary [] [ H.text "Tests" ]
      , display (quickCheck (suite "Students" checks))
      ]
  in
    [ toDetails
        [ checkUpdate
        , checkMetrics
        ]
    ]

I personally think that is better code. Do you have any other examples?

Member

evancz commented Nov 30, 2015

I ask because that's how I'd use it as well, but I was wondering if this is ever nicer code than just naming things. Your example would become:

test : List H.Html
test = let
  toDetails checks =
    H.details
      [ A.style [ ("overflow", "hidden") ] ]
      [ H.summary [] [ H.text "Tests" ]
      , display (quickCheck (suite "Students" checks))
      ]
  in
    [ toDetails
        [ checkUpdate
        , checkMetrics
        ]
    ]

I personally think that is better code. Do you have any other examples?

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball Nov 30, 2015

I think you could make a similar criticism of other code using pure, and its fair enough. That said I also find pure useful in development workflow even if I remove it later (which usually happens).

Fresheyeball commented Nov 30, 2015

I think you could make a similar criticism of other code using pure, and its fair enough. That said I also find pure useful in development workflow even if I remove it later (which usually happens).

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Nov 30, 2015

Member

Okay, thanks for sharing the example, that was very helpful!

Member

evancz commented Nov 30, 2015

Okay, thanks for sharing the example, that was very helpful!

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball commented Nov 30, 2015

Cheers!

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Dec 1, 2015

Contributor

If I may chime in: There are uses of pure/List.singleton in start-app here and here that are not as easily replaced as exercised for the above example. It seems these are conceptually different uses than the ones you discussed above.

Contributor

jvoigtlaender commented Dec 1, 2015

If I may chime in: There are uses of pure/List.singleton in start-app here and here that are not as easily replaced as exercised for the above example. It seems these are conceptually different uses than the ones you discussed above.

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball Dec 1, 2015

While I'm still in favor of List.singleton, it can be easily replaced in start-app:

address =
     Signal.forwardTo messages.address singleton

inputs =
     Signal.mergeMany (messages.signal :: List.map (Signal.map singleton) config.inputs)

vs

address =
     Signal.forwardTo messages.address (\x -> [x])

inputs =
     Signal.mergeMany (messages.signal :: List.map (Signal.map (\x -> [x])) config.inputs)

Fresheyeball commented Dec 1, 2015

While I'm still in favor of List.singleton, it can be easily replaced in start-app:

address =
     Signal.forwardTo messages.address singleton

inputs =
     Signal.mergeMany (messages.signal :: List.map (Signal.map singleton) config.inputs)

vs

address =
     Signal.forwardTo messages.address (\x -> [x])

inputs =
     Signal.mergeMany (messages.signal :: List.map (Signal.map (\x -> [x])) config.inputs)
@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Dec 1, 2015

Contributor

Sure. 😄

Actually, when I wrote that code I defined it as singleton, because I was hoping that at some point List.singleton would be moved from http://package.elm-lang.org/packages/circuithub/elm-list-extra to core, at which time I would come back to this code and use that function.

Contributor

jvoigtlaender commented Dec 1, 2015

Sure. 😄

Actually, when I wrote that code I defined it as singleton, because I was hoping that at some point List.singleton would be moved from http://package.elm-lang.org/packages/circuithub/elm-list-extra to core, at which time I would come back to this code and use that function.

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Dec 1, 2015

Contributor

So what I was trying to get at above was that that in these lines we really want singleton to be a function explicitly passed to another function, not inlining it like in the other examples above.

Contributor

jvoigtlaender commented Dec 1, 2015

So what I was trying to get at above was that that in these lines we really want singleton to be a function explicitly passed to another function, not inlining it like in the other examples above.

@Fresheyeball

This comment has been minimized.

Show comment
Hide comment
@Fresheyeball

Fresheyeball commented Dec 1, 2015

Agreed 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment