laszlopandy / elm-console Goto Github PK
View Code? Open in Web Editor NEWThis project forked from maxsnew/io
Elm library to read and write to the console in Node.
License: BSD 3-Clause "New" or "Revised" License
This project forked from maxsnew/io
Elm library to read and write to the console in Node.
License: BSD 3-Clause "New" or "Revised" License
First of all, thanks for picking this up for Elm 0.16!
I was trying to use elm-console in a context where I have a Task
that produces a String
, and I want to write this string to the console. Here's some code to illustrate:
task : Task () String
task =
Task.succeed "String"
io : Task () (IO ())
io =
Task.map Console.putStrLn task
port runner : Task () (Signal (Task x ()))
port runner =
Task.map Console.run io
Now, in this case the Task
is obviously trivial, but imagine code where there really was an substantial Task
involved that ultimately could be mapped to a String
.
The code above will compile, but it doesn't really make any sense (and doesn't work), because a Task
which results in a signal of tasks isn't really sensible within Elm, for a variety of reasons. So, it's a dead end.
So, I was trying to conceive of what is missing here. One way of thinking about it would be that we need a function of this form:
fromTask : Task x a -> IO (x, a)
Now, one complication for implementation would be arranging for the task to be executed when the IO is executed, but that doesn't seem impossible.
If one had this "bridge" between Task-world and IO-world, I think it would cover a lot of cases.
Some others one could imagine are:
onSuccess : Task x (IO a) -> IO a
onError : Task (IO x) a -> IO x
So, I'm wondering whether I'm thinking about this the right way -- is there a better way to imagine how this might work?
In passing, I think there are similar puzzles re: Signals and IO ... for instance, what if you had a Signal String
and you wanted to write each String
to the console as it arrived? I'm not sure how you'd do that either, but I haven't thought much about it.
I wish I could send you a PR for upgrading from 0.16, but now that Signal is gone I'm not sure how to do it....
Hello,
So, I'm using elm-console to run elm-test tests. But I have the case where I'm trying to test signals and effects.
Long story short, I manage to end up with a Signal Test
, and I need to map those tests to consoleRunner
then Console.run
to run the tests each time a new test comes from the signal.
But Console.run
takes an IO and returns a Signal of Tasks, so I would end up with Signal (Signal (Task.Task x ()))
, and Signal of Signals aren't allowed in elm.
My workaround to solve this was creating this library: signal-concat-map that allows me to concatMap
signals, by using native modules.
You can check out the final code of the TestRunner here.
I wouldn't need this if there was a way to run signals of IO, like this:
Console.runSignal : Signal IO -> Signal (Task x ())
Is this possible in elm-console?
Thanks!
Full details are here deadfoxygrandpa/elm-test#32 (comment)
Essentially what is going on is that I am seeing
require is not defined
Open the developer console for more details.
Appears to be happening because when compiling my test code with webpack via the elm-webpack-loader. module.exports = Elm;
is appended to the resulting file making the current guards around the require call insufficient.
Fix seems to be to just add a check to see if require is defined. Will send out a pull request.
Hi, can you bump up the version to work with Elm 0.18.0?
It would be nice to read from a file. readFile : String -> IO String
. An invalid path would be the same as pure ""
; alternatively it may return an IO (Maybe String)
or similarly with a Result
.
If you like the idea but don't have time to implement it, I could sent a PR sometime next week.
Hello!
Love your work!
Im here asking if there will be a port over to elm 0.17?
Elm 0.16 is too outdated. I'm upgrading this package for Elm 0.18 at openirc/elm-console
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.