Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded pure #408
Conversation
Fresheyeball
added some commits
Sep 16, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
I'd rename it to |
evancz
closed this
Sep 16, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fresheyeball
commented
Sep 16, 2015
|
Ok. Fair enough. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fresheyeball
commented
Sep 16, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Nov 30, 2015
Member
Can you share an example of when you use it? What kind of code calls for this?
|
Can you share an example of when you use it? What kind of code calls for this? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fresheyeball
Nov 30, 2015
basically I use it in composition chains, for example
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 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. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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?
|
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? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Okay, thanks for sharing the example, that was very helpful! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fresheyeball
commented
Nov 30, 2015
|
Cheers! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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 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) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
Sure. Actually, when I wrote that code I defined it as |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
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.
|
So what I was trying to get at above was that that in these lines we really want |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Fresheyeball
commented
Dec 1, 2015
|
Agreed |
Fresheyeball commentedSep 16, 2015
I find myself writing this function alot, perhaps its worth including?