Skip to content
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

pattern matching IO? #8

Open
cobordism opened this issue Nov 7, 2024 · 5 comments
Open

pattern matching IO? #8

cobordism opened this issue Nov 7, 2024 · 5 comments

Comments

@cobordism
Copy link

Hello,
Is there any way I can use pattern matching to get a String from an IO String? I've tried, but the deeper I dig the more confused I get.
Relatedly, is there a way to have a map2 for IO? and a function IO ( IO a)) -> IO a ?

I apologise if these are easy questions. I am new at elm and got confused.
The context is that I have a function String -> String -> String and I want to read the first two arguments from a text file.

Or is there maybe even an "evil" way to just read in a String instead of IO String from a text file ?

@lue-bird
Copy link

lue-bird commented Nov 7, 2024

Indeed an IO.map2 would be nice.
You can create it yourself with andThen:

ioMap2 combineAB ioA ioB =
    ioA |> IO.andThen (\a -> IO.andThen (\b -> combineAB a b))
-- in
ioMap2
    (\a b -> yourFunction a b)
    (File.open "a.txt" |> IO.exitOnError identity)
    (File.open "b.txt" |> IO.exitOnError identity)

@cobordism
Copy link
Author

Thank you. I also just succeeded ... because I just discovered the new-api branch of this repo.
(I wish I had found that sooner. )

The instructions in the readme:

npm install -g @albertdahlin/elm-posix
elm install albertdahlin/elm-posix

gives me the older version.

What is the correct way to install the new elm-posix branch?

@lue-bird
Copy link

lue-bird commented Nov 7, 2024

Pretty sure the author didn't publish it yet.
So you can either try to vendor it, stick with the current API or switch to an alternative like elm-pages-scripts (not sure how) or state-interface etc.

@cobordism
Copy link
Author

pardon my ignorance, but what is 'vendor' as a verb?

@lue-bird
Copy link

lue-bird commented Nov 7, 2024

haha I'm not a native speaker but as I understood it it basically means copy it to your project directly and build/link/... it there with your project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants