77ZDLLUTFQ3L3FELAWZQTOG5DUPINOXV5VYLEYBEONDOW2BSVZJAC
defmodule Esperantisto.MixProject do
use Mix.Project
def project do
[
app: :esperantisto,
version: "0.1.0",
elixir: "~> 1.11",
start_permanent: Mix.env() == :prod,
deps: deps()
]
end
def application do
[
extra_applications: [:logger],
mod: {Esperantisto.Application, []}
]
end
defp deps do
[]
end
end
defmodule Esperantisto do
@moduledoc """
Documentation for `Esperantisto`.
"""
@doc """
Hello world.
## Examples
iex> Esperantisto.hello()
:world
"""
def hello do
:world
end
end
defmodule Esperantisto.Text do
@priv_dir Application.app_dir(:esperantisto, "priv/books")
def get_files() do
File.ls!(@priv_dir)
end
def iter_files() do
get_files()
|> Stream.map(fn file -> File.stream!(Path.join(@priv_dir, file)) end)
|> Stream.map(fn stream -> process_book(stream) end)
end
defp process_book(stream) do
stream
|> Stream.transform(&parse_title/1, fn line, parser ->
if parser == nil do
{:halt, nil}
else
case parser.(line) do
{nil, new_parser} -> {[], new_parser}
{value, new_parser} -> {[value], new_parser}
end
end
end)
|> Stream.take(50)
|> Enum.to_list()
end
defp parse_title("Title: " <> title = _line) do
{{:title, title}, &parse_author/1}
end
defp parse_title(_) do
{nil, &parse_title/1}
end
defp parse_author("Author: " <> name = _line) do
{{:author, name}, &identity/1}
end
defp parse_author(_) do
{nil, &parse_author/1}
end
defp identity(line) do
{line, &identity/1}
end
end
defmodule Esperantisto.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
# Starts a worker by calling: Esperantisto.Worker.start_link(arg)
# {Esperantisto.Worker, arg}
]
# See https://hexdocs.pm/elixir/Supervisor.html
# for other strategies and supported options
opts = [strategy: :one_for_one, name: Esperantisto.Supervisor]
Supervisor.start_link(children, opts)
end
end
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]