KimberlyBrooke

KimberlyBrooke

Exercism.io Secrets module - stuck on function combiner

Hello, I am working through Exercism.io Secrets module the first 6 functions I was able to figure out just fine. The last one I am stuck on.

This is the instruction for it:

Implement Secrets.secret_combine/2 . It should return a function which takes one argument and applies to it the two functions passed in to secret_combine in order.

multiply = Secrets.secret_multiply(7)
divide = Secrets.secret_divide(3)
combined = Secrets.secret_combine(multiply, divide)

combined.(6)
# => 14

Hints and tips :

Create a function combiner

  • Return an anonymous function which composes the functions passed in to Secret.secret_combine/2.
  • Use a . before () when calling an anonymous function.

Below is where my solutions start, like I said the first 6 functions I did just fine on it’s just the last one.

defmodule Secrets do
  def secret_add(secret) do
    fn(a) -> a + secret end
  end

  def secret_subtract(secret) do
    fn(a) -> a - secret end
  end

  def secret_multiply(secret) do
    fn(a) -> a * secret end
  end

  def secret_divide(secret) do
    fn(a) -> div(a, secret) end
  end 

  def secret_and(secret) do
  use Bitwise, only_operators: true
    fn(a) -> a &&& secret end
  end

  def secret_xor(secret) do
    use Bitwise
    fn(a) -> bxor(a, secret) end
  end

  def secret_combine(secret_function1, secret_function2) do
  end
end

Marked As Solved

cmo

cmo

def secret_combine(fn1, fn2) do
  fn x -> x |> fn1.() |> fn2.() end
end

Also Liked

KimberlyBrooke

KimberlyBrooke

Thank you!

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 47930 226
New
Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 126479 1222
New

We're in Beta

About us Mission Statement