Back
Close

Function notation

Statement

 Goal

Given a function expressed exclusively using function compositions and function sums, rewrite it by replacing the composition operator . with the reverse composition operator |>.

The reverse function composition operator behaves, unsurprisingly, by reversing the order of function application, that is:

(f |> g)(x) = g(f(x))

Examples:

f . g -- g |> f
f + g -- f + g
f . g + h -- g |> f + h
(f + h) . g -- g |> (f + h)
f . (g + h) -- (g + h) |> f
g + f . h -- g + h |> f

Notes:
(1) Function names are only one lowercase English letter.
(2) The + and . operators are given between spaces for easier visualization.
(3) As shown in the examples, parentheses are relevant.
(4) The expressions are well formed. They don't contain unnecessary parentheses like f . (( g + h )) or consecutive + signs etc.
(5) For debugging, notice how the transformation from . to |> is symmetric, and that the same logic, from |> to . should give back the original expression.
Input
Line 1: A string function representing a function expressed exclusively using function compositions and function sums.
Output
One line containing the original function rewritten with the |> operator.
Constraints
Function names are only one lowercase English letter.
0 < length function < 256
Example
Input
f . g
Output
g |> f

Tags
Parsing, String manipulation, Recursion

Difficulty
Medium

Test cases
Test 1 Test
Input
f . g
Output
g |> f

Validator 1 Validator
Input
a . b
Output
b |> a

Test 2 Test
Input
f . g . f . h
Output
h |> f |> g |> f

Validator 2 Validator
Input
x . y . z
Output
z |> y |> x

Test 3 Test
Input
f + g
Output
f + g

Validator 3 Validator
Input
a + b + c
Output
a + b + c

Test 4 Test
Input
f . (g + h)
Output
(g + h) |> f

Validator 4 Validator
Input
f . (g + h + i + j)
Output
(g + h + i + j) |> f

Test 5 Test
Input
f . (g . h + h)
Output
(h |> g + h) |> f

Validator 5 Validator
Input
f . (a + g . h + b)
Output
(a + h |> g + b) |> f

Test 6 Test
Input
f . h . (y + z)
Output
(y + z) |> h |> f

Validator 6 Validator
Input
f . h . g . (y + z + w)
Output
(y + z + w) |> g |> h |> f

Test 7 Test
Input
f . (g . (h + i) + h)
Output
((h + i) |> g + h) |> f

Validator 7 Validator
Input
f . (g . (h + i + j) + h + z)
Output
((h + i + j) |> g + h + z) |> f

Test 8 Test
Input
(f + g) . h
Output
h |> (f + g)

Validator 8 Validator
Input
(f + g + f) . h
Output
h |> (f + g + f)

Test 9 Test
Input
(f + g) . (h + i)
Output
(h + i) |> (f + g)

Validator 9 Validator
Input
(f + g + a) . (b + h + i)
Output
(b + h + i) |> (f + g + a)

Test 10 Test
Input
(f + g) . (h + i) . (j + k)
Output
(j + k) |> (h + i) |> (f + g)

Validator 10 Validator
Input
(j + k) . (h + i) . (f + g)
Output
(f + g) |> (h + i) |> (j + k)

Test 11 Test
Input
((a + b) . d + e) . f
Output
f |> (d |> (a + b) + e)

Validator 11 Validator
Input
(g + (a + b + c) . d + e) . f
Output
f |> (g + d |> (a + b + c) + e)

Test 12 Test
Input
(f + g) . h + (a + b) . c
Output
h |> (f + g) + c |> (a + b)

Validator 12 Validator
Input
(f + g) . h + (a + b + z) . c
Output
h |> (f + g) + c |> (a + b + z)

Test 13 Test
Input
g . (a + b + c) . f
Output
f |> (a + b + c) |> g

Validator 13 Validator
Input
g . (c + b + a) . f
Output
f |> (c + b + a) |> g

Test 14 Test
Input
f . (a + g . (b . c + d) + e) . h
Output
h |> (a + (c |> b + d) |> g + e) |> f

Validator 14 Validator
Input
f . (a + g . z + e) . h
Output
h |> (a + z |> g + e) |> f

Test 15 Test
Input
(h . (a + b) + h . a + b) . (b + y + e)
Output
(b + y + e) |> ((a + b) |> h + a |> h + b)

Validator 15 Validator
Input
a + b . c . d . (e + f . (g + h))
Output
a + (e + (g + h) |> f) |> d |> c |> b

Test 16 Test
Input
a . (b . (c . d + e) . f + g)
Output
(f |> (d |> c + e) |> b + g) |> a

Validator 16 Validator
Input
g + b . (c . d + e) . f
Output
g + f |> (d |> c + e) |> b

Test 17 Test
Input
a . a . a . (a + a)
Output
(a + a) |> a |> a |> a

Validator 17 Validator
Input
b . b . (b + b)
Output
(b + b) |> b |> b

Solution language

Solution

Stub generator input